aboutsummaryrefslogtreecommitdiffstats
path: root/drivers
diff options
context:
space:
mode:
authorLen Brown <len.brown@intel.com>2005-09-08 01:45:47 -0400
committerLen Brown <len.brown@intel.com>2005-09-08 01:45:47 -0400
commit64e47488c913ac704d465a6af86a26786d1412a5 (patch)
treed3b0148592963dcde26e4bb35ddfec8b1eaf8e23 /drivers
parent4a35a46bf1cda4737c428380d1db5d15e2590d18 (diff)
parentcaf39e87cc1182f7dae84eefc43ca14d54c78ef9 (diff)
Merge linux-2.6 with linux-acpi-2.6
Diffstat (limited to 'drivers')
-rw-r--r--drivers/atm/zatm.c4
-rw-r--r--drivers/base/attribute_container.c86
-rw-r--r--drivers/base/bus.c42
-rw-r--r--drivers/base/class.c39
-rw-r--r--drivers/base/core.c19
-rw-r--r--drivers/base/dd.c2
-rw-r--r--drivers/base/driver.c15
-rw-r--r--drivers/base/firmware_class.c79
-rw-r--r--drivers/base/node.c24
-rw-r--r--drivers/base/power/resume.c8
-rw-r--r--drivers/base/power/runtime.c8
-rw-r--r--drivers/base/power/suspend.c12
-rw-r--r--drivers/base/power/sysfs.c8
-rw-r--r--drivers/base/sys.c110
-rw-r--r--drivers/base/transport_class.c19
-rw-r--r--drivers/block/Kconfig46
-rw-r--r--drivers/block/aoe/aoedev.c2
-rw-r--r--drivers/block/cfq-iosched.c3
-rw-r--r--drivers/block/cryptoloop.c6
-rw-r--r--drivers/block/deadline-iosched.c12
-rw-r--r--drivers/block/floppy.c41
-rw-r--r--drivers/block/genhd.c2
-rw-r--r--drivers/block/ll_rw_blk.c196
-rw-r--r--drivers/block/scsi_ioctl.c60
-rw-r--r--drivers/cdrom/cdrom.c15
-rw-r--r--drivers/char/Kconfig7
-rw-r--r--drivers/char/digi1.h38
-rw-r--r--drivers/char/digiFep1.h154
-rw-r--r--drivers/char/drm/drm_bufs.c66
-rw-r--r--drivers/char/drm/drm_context.c2
-rw-r--r--drivers/char/drm/drm_sysfs.c1
-rw-r--r--drivers/char/drm/mga_dma.c14
-rw-r--r--drivers/char/epca.c1588
-rw-r--r--drivers/char/epca.h108
-rw-r--r--drivers/char/hpet.c4
-rw-r--r--drivers/char/ipmi/ipmi_bt_sm.c69
-rw-r--r--drivers/char/ipmi/ipmi_devintf.c101
-rw-r--r--drivers/char/ipmi/ipmi_kcs_sm.c3
-rw-r--r--drivers/char/ipmi/ipmi_msghandler.c336
-rw-r--r--drivers/char/ipmi/ipmi_poweroff.c168
-rw-r--r--drivers/char/ipmi/ipmi_si_intf.c395
-rw-r--r--drivers/char/ipmi/ipmi_smic_sm.c3
-rw-r--r--drivers/char/ipmi/ipmi_watchdog.c46
-rw-r--r--drivers/char/mbcs.c2
-rw-r--r--drivers/char/mem.c4
-rw-r--r--drivers/char/misc.c9
-rw-r--r--drivers/char/moxa.c2
-rw-r--r--drivers/char/mxser.c1
-rw-r--r--drivers/char/rtc.c5
-rw-r--r--drivers/char/sonypi.c118
-rw-r--r--drivers/char/tpm/tpm_atmel.c3
-rw-r--r--drivers/char/tpm/tpm_infineon.c76
-rw-r--r--drivers/char/tty_io.c6
-rw-r--r--drivers/char/vt.c21
-rw-r--r--drivers/char/watchdog/Kconfig7
-rw-r--r--drivers/char/watchdog/Makefile72
-rw-r--r--drivers/char/watchdog/booke_wdt.c192
-rw-r--r--drivers/char/watchdog/ixp2000_wdt.c2
-rw-r--r--drivers/char/watchdog/ixp4xx_wdt.c2
-rw-r--r--drivers/char/watchdog/s3c2410_wdt.c87
-rw-r--r--drivers/char/watchdog/scx200_wdt.c2
-rw-r--r--drivers/char/watchdog/softdog.c13
-rw-r--r--drivers/char/watchdog/w83627hf_wdt.c6
-rw-r--r--drivers/firmware/Kconfig27
-rw-r--r--drivers/firmware/Makefile2
-rw-r--r--drivers/firmware/dcdbas.c596
-rw-r--r--drivers/firmware/dcdbas.h107
-rw-r--r--drivers/firmware/dell_rbu.c634
-rw-r--r--drivers/hwmon/Kconfig72
-rw-r--r--drivers/hwmon/Makefile4
-rw-r--r--drivers/hwmon/adm1021.c35
-rw-r--r--drivers/hwmon/adm1025.c31
-rw-r--r--drivers/hwmon/adm1026.c25
-rw-r--r--drivers/hwmon/adm1031.c24
-rw-r--r--drivers/hwmon/adm9240.c33
-rw-r--r--drivers/hwmon/asb100.c56
-rw-r--r--drivers/hwmon/atxp1.c26
-rw-r--r--drivers/hwmon/ds1621.c29
-rw-r--r--drivers/hwmon/fscher.c27
-rw-r--r--drivers/hwmon/fscpos.c27
-rw-r--r--drivers/hwmon/gl518sm.c28
-rw-r--r--drivers/hwmon/gl520sm.c31
-rw-r--r--drivers/hwmon/hwmon-vid.c189
-rw-r--r--drivers/hwmon/hwmon.c98
-rw-r--r--drivers/hwmon/it87.c76
-rw-r--r--drivers/hwmon/lm63.c27
-rw-r--r--drivers/hwmon/lm75.c41
-rw-r--r--drivers/hwmon/lm75.h2
-rw-r--r--drivers/hwmon/lm77.c24
-rw-r--r--drivers/hwmon/lm78.c84
-rw-r--r--drivers/hwmon/lm80.c27
-rw-r--r--drivers/hwmon/lm83.c27
-rw-r--r--drivers/hwmon/lm85.c39
-rw-r--r--drivers/hwmon/lm87.c31
-rw-r--r--drivers/hwmon/lm90.c27
-rw-r--r--drivers/hwmon/lm92.c28
-rw-r--r--drivers/hwmon/max1619.c28
-rw-r--r--drivers/hwmon/pc87360.c852
-rw-r--r--drivers/hwmon/sis5595.c70
-rw-r--r--drivers/hwmon/smsc47b397.c74
-rw-r--r--drivers/hwmon/smsc47m1.c70
-rw-r--r--drivers/hwmon/via686a.c76
-rw-r--r--drivers/hwmon/w83627ehf.c64
-rw-r--r--drivers/hwmon/w83627hf.c80
-rw-r--r--drivers/hwmon/w83781d.c90
-rw-r--r--drivers/hwmon/w83792d.c1649
-rw-r--r--drivers/hwmon/w83l785ts.c27
-rw-r--r--drivers/i2c/Makefile4
-rw-r--r--drivers/i2c/algos/i2c-algo-bit.c4
-rw-r--r--drivers/i2c/algos/i2c-algo-ite.c4
-rw-r--r--drivers/i2c/algos/i2c-algo-pca.c16
-rw-r--r--drivers/i2c/algos/i2c-algo-pcf.c4
-rw-r--r--drivers/i2c/algos/i2c-algo-sgi.c5
-rw-r--r--drivers/i2c/algos/i2c-algo-sibyte.c4
-rw-r--r--drivers/i2c/busses/Kconfig8
-rw-r--r--drivers/i2c/busses/i2c-ali1535.c2
-rw-r--r--drivers/i2c/busses/i2c-ali1563.c2
-rw-r--r--drivers/i2c/busses/i2c-ali15x3.c2
-rw-r--r--drivers/i2c/busses/i2c-amd756.c2
-rw-r--r--drivers/i2c/busses/i2c-amd8111.c2
-rw-r--r--drivers/i2c/busses/i2c-au1550.c2
-rw-r--r--drivers/i2c/busses/i2c-i801.c2
-rw-r--r--drivers/i2c/busses/i2c-ibm_iic.c4
-rw-r--r--drivers/i2c/busses/i2c-iop3xx.c2
-rw-r--r--drivers/i2c/busses/i2c-isa.c161
-rw-r--r--drivers/i2c/busses/i2c-keywest.c15
-rw-r--r--drivers/i2c/busses/i2c-mpc.c4
-rw-r--r--drivers/i2c/busses/i2c-mv64xxx.c12
-rw-r--r--drivers/i2c/busses/i2c-nforce2.c33
-rw-r--r--drivers/i2c/busses/i2c-piix4.c2
-rw-r--r--drivers/i2c/busses/i2c-s3c2410.c1
-rw-r--r--drivers/i2c/busses/i2c-sis5595.c2
-rw-r--r--drivers/i2c/busses/i2c-sis630.c2
-rw-r--r--drivers/i2c/busses/i2c-sis96x.c2
-rw-r--r--drivers/i2c/busses/i2c-stub.c2
-rw-r--r--drivers/i2c/busses/i2c-viapro.c2
-rw-r--r--drivers/i2c/busses/scx200_acb.c4
-rw-r--r--drivers/i2c/chips/Kconfig10
-rw-r--r--drivers/i2c/chips/ds1337.c11
-rw-r--r--drivers/i2c/chips/ds1374.c3
-rw-r--r--drivers/i2c/chips/eeprom.c17
-rw-r--r--drivers/i2c/chips/isp1301_omap.c2
-rw-r--r--drivers/i2c/chips/m41t00.c3
-rw-r--r--drivers/i2c/chips/max6875.c462
-rw-r--r--drivers/i2c/chips/pca9539.c12
-rw-r--r--drivers/i2c/chips/pcf8574.c13
-rw-r--r--drivers/i2c/chips/pcf8591.c13
-rw-r--r--drivers/i2c/chips/rtc8564.c1
-rw-r--r--drivers/i2c/i2c-core.c256
-rw-r--r--drivers/i2c/i2c-dev.c5
-rw-r--r--drivers/i2c/i2c-sensor-detect.c145
-rw-r--r--drivers/i2c/i2c-sensor-vid.c98
-rw-r--r--drivers/ide/ide-disk.c2
-rw-r--r--drivers/ide/ide-io.c2
-rw-r--r--drivers/ide/ide.c4
-rw-r--r--drivers/ide/pci/sc1200.c12
-rw-r--r--drivers/ide/ppc/pmac.c16
-rw-r--r--drivers/ieee1394/nodemgr.c8
-rw-r--r--drivers/ieee1394/pcilynx.c20
-rw-r--r--drivers/infiniband/core/sysfs.c2
-rw-r--r--drivers/input/evdev.c10
-rw-r--r--drivers/input/gameport/emu10k1-gp.c2
-rw-r--r--drivers/input/gameport/fm801-gp.c2
-rw-r--r--drivers/input/gameport/ns558.c4
-rw-r--r--drivers/input/input.c11
-rw-r--r--drivers/input/joystick/a3d.c2
-rw-r--r--drivers/input/joystick/adi.c2
-rw-r--r--drivers/input/joystick/analog.c2
-rw-r--r--drivers/input/joystick/cobra.c2
-rw-r--r--drivers/input/joystick/db9.c2
-rw-r--r--drivers/input/joystick/gamecon.c2
-rw-r--r--drivers/input/joystick/gf2k.c2
-rw-r--r--drivers/input/joystick/grip.c2
-rw-r--r--drivers/input/joystick/grip_mp.c2
-rw-r--r--drivers/input/joystick/guillemot.c2
-rw-r--r--drivers/input/joystick/interact.c2
-rw-r--r--drivers/input/joystick/sidewinder.c2
-rw-r--r--drivers/input/joystick/tmdc.c2
-rw-r--r--drivers/input/joystick/turbografx.c2
-rw-r--r--drivers/input/keyboard/corgikbd.c104
-rw-r--r--drivers/input/mouse/psmouse-base.c2
-rw-r--r--drivers/input/serio/serport.c4
-rw-r--r--drivers/input/touchscreen/corgi_ts.c51
-rw-r--r--drivers/isdn/hisax/hisax.h3
-rw-r--r--drivers/isdn/i4l/isdn_v110.c4
-rw-r--r--drivers/macintosh/mediabay.c6
-rw-r--r--drivers/macintosh/via-pmu.c2
-rw-r--r--drivers/md/dm-crypt.c7
-rw-r--r--drivers/md/dm-io.c6
-rw-r--r--drivers/md/dm.c6
-rw-r--r--drivers/media/common/saa7146_i2c.c4
-rw-r--r--drivers/media/dvb/b2c2/flexcop-i2c.c3
-rw-r--r--drivers/media/dvb/bt8xx/Kconfig6
-rw-r--r--drivers/media/dvb/cinergyT2/cinergyT2.c2
-rw-r--r--drivers/media/dvb/dvb-usb/cxusb.c2
-rw-r--r--drivers/media/dvb/dvb-usb/dibusb-common.c2
-rw-r--r--drivers/media/dvb/dvb-usb/digitv.c2
-rw-r--r--drivers/media/dvb/dvb-usb/dvb-usb-i2c.c1
-rw-r--r--drivers/media/dvb/frontends/lgdt330x.c50
-rw-r--r--drivers/media/dvb/pluto2/pluto2.c1
-rw-r--r--drivers/media/dvb/ttusb-budget/dvb-ttusb-budget.c3
-rw-r--r--drivers/media/video/Kconfig1
-rw-r--r--drivers/media/video/Makefile2
-rw-r--r--drivers/media/video/adv7170.c2
-rw-r--r--drivers/media/video/adv7175.c2
-rw-r--r--drivers/media/video/bt819.c2
-rw-r--r--drivers/media/video/bt832.c4
-rw-r--r--drivers/media/video/bt856.c2
-rw-r--r--drivers/media/video/bttv-driver.c1
-rw-r--r--drivers/media/video/bttv-i2c.c12
-rw-r--r--drivers/media/video/cx88/cx88-i2c.c8
-rw-r--r--drivers/media/video/indycam.c412
-rw-r--r--drivers/media/video/indycam.h112
-rw-r--r--drivers/media/video/ir-kbd-i2c.c6
-rw-r--r--drivers/media/video/meye.c3
-rw-r--r--drivers/media/video/msp3400.c8
-rw-r--r--drivers/media/video/ovcamchip/ov6x20.c6
-rw-r--r--drivers/media/video/ovcamchip/ov6x30.c4
-rw-r--r--drivers/media/video/ovcamchip/ovcamchip_core.c14
-rw-r--r--drivers/media/video/saa7110.c1
-rw-r--r--drivers/media/video/saa7111.c2
-rw-r--r--drivers/media/video/saa7114.c2
-rw-r--r--drivers/media/video/saa7134/saa6752hs.c2
-rw-r--r--drivers/media/video/saa7134/saa7134-i2c.c10
-rw-r--r--drivers/media/video/saa7185.c2
-rw-r--r--drivers/media/video/saa7191.c512
-rw-r--r--drivers/media/video/saa7191.h139
-rw-r--r--drivers/media/video/tda7432.c4
-rw-r--r--drivers/media/video/tda9840.c4
-rw-r--r--drivers/media/video/tda9875.c4
-rw-r--r--drivers/media/video/tda9887.c10
-rw-r--r--drivers/media/video/tea6415c.c4
-rw-r--r--drivers/media/video/tea6420.c4
-rw-r--r--drivers/media/video/tuner-3036.c3
-rw-r--r--drivers/media/video/tuner-core.c4
-rw-r--r--drivers/media/video/tvaudio.c51
-rw-r--r--drivers/media/video/tveeprom.c2
-rw-r--r--drivers/media/video/tvmixer.c14
-rw-r--r--drivers/media/video/vino.c4273
-rw-r--r--drivers/media/video/vino.h61
-rw-r--r--drivers/media/video/vpx3220.c1
-rw-r--r--drivers/media/video/zoran_card.c2
-rw-r--r--drivers/message/fusion/lsi/mpi.h19
-rw-r--r--drivers/message/fusion/lsi/mpi_cnfg.h85
-rw-r--r--drivers/message/fusion/lsi/mpi_history.txt67
-rw-r--r--drivers/message/fusion/lsi/mpi_init.h203
-rw-r--r--drivers/message/fusion/lsi/mpi_ioc.h11
-rw-r--r--drivers/message/fusion/lsi/mpi_targ.h74
-rw-r--r--drivers/message/fusion/mptbase.c321
-rw-r--r--drivers/message/fusion/mptbase.h5
-rw-r--r--drivers/message/fusion/mptctl.c14
-rw-r--r--drivers/message/fusion/mptscsih.c140
-rw-r--r--drivers/message/fusion/mptspi.c6
-rw-r--r--drivers/misc/Kconfig2
-rw-r--r--drivers/misc/ibmasm/uart.c20
-rw-r--r--drivers/mmc/mmc.c530
-rw-r--r--drivers/mmc/mmc_block.c9
-rw-r--r--drivers/mmc/mmc_sysfs.c21
-rw-r--r--drivers/mmc/pxamci.c11
-rw-r--r--drivers/mmc/wbsd.c118
-rw-r--r--drivers/mmc/wbsd.h6
-rw-r--r--drivers/mtd/nand/nand_base.c1
-rw-r--r--drivers/net/3c59x.c19
-rw-r--r--drivers/net/Kconfig16
-rw-r--r--drivers/net/Makefile2
-rw-r--r--drivers/net/ac3200.c2
-rw-r--r--drivers/net/arcnet/arcnet.c25
-rw-r--r--drivers/net/atarilance.c2
-rw-r--r--drivers/net/bnx2.c18
-rw-r--r--drivers/net/chelsio/common.h4
-rw-r--r--drivers/net/chelsio/cxgb2.c2
-rw-r--r--drivers/net/dm9000.c2
-rw-r--r--drivers/net/e1000/e1000_hw.h2
-rw-r--r--drivers/net/e1000/e1000_main.c14
-rw-r--r--drivers/net/forcedeth.c4
-rw-r--r--drivers/net/hamachi.c4
-rw-r--r--drivers/net/irda/smsc-ircc2.c1179
-rw-r--r--drivers/net/irda/smsc-ircc2.h50
-rw-r--r--drivers/net/irda/vlsi_ir.c21
-rw-r--r--drivers/net/iseries_veth.c1
-rw-r--r--drivers/net/mv643xx_eth.c139
-rw-r--r--drivers/net/mv643xx_eth.h4
-rw-r--r--drivers/net/ne3210.c9
-rw-r--r--drivers/net/phy/Kconfig2
-rw-r--r--drivers/net/phy/mdio_bus.c4
-rw-r--r--drivers/net/s2io-regs.h13
-rw-r--r--drivers/net/s2io.c122
-rw-r--r--drivers/net/s2io.h5
-rw-r--r--drivers/net/sis190.c131
-rw-r--r--drivers/net/smc91x.h2
-rw-r--r--drivers/net/spider_net.c2334
-rw-r--r--drivers/net/spider_net.h469
-rw-r--r--drivers/net/spider_net_ethtool.c126
-rw-r--r--drivers/net/sun3lance.c2
-rw-r--r--drivers/net/sungem.c1
-rw-r--r--drivers/net/sungem.h2
-rw-r--r--drivers/net/tg3.c202
-rw-r--r--drivers/net/tulip/uli526x.c2
-rw-r--r--drivers/net/tun.c15
-rw-r--r--drivers/net/wan/syncppp.c1
-rw-r--r--drivers/net/wireless/Kconfig38
-rw-r--r--drivers/net/wireless/Makefile2
-rw-r--r--drivers/net/wireless/airo.c58
-rw-r--r--drivers/net/wireless/atmel.c17
-rw-r--r--drivers/net/wireless/hostap/hostap_pci.c2
-rw-r--r--drivers/net/wireless/ipw2100.c69
-rw-r--r--drivers/net/wireless/ipw2200.c2274
-rw-r--r--drivers/net/wireless/ipw2200.h408
-rw-r--r--drivers/net/wireless/netwave_cs.c7
-rw-r--r--drivers/net/wireless/orinoco.c93
-rw-r--r--drivers/net/wireless/orinoco_cs.c1
-rw-r--r--drivers/net/wireless/orinoco_nortel.c324
-rw-r--r--drivers/net/wireless/orinoco_pci.c2
-rw-r--r--drivers/net/wireless/prism54/isl_ioctl.c3
-rw-r--r--drivers/net/wireless/prism54/islpci_dev.c3
-rw-r--r--drivers/net/wireless/prism54/islpci_hotplug.c2
-rw-r--r--drivers/net/wireless/ray_cs.c866
-rw-r--r--drivers/net/wireless/ray_cs.h7
-rw-r--r--drivers/net/wireless/spectrum_cs.c1120
-rw-r--r--drivers/net/wireless/wl3501.h1
-rw-r--r--drivers/net/wireless/wl3501_cs.c7
-rw-r--r--drivers/parport/parport_pc.c3
-rw-r--r--drivers/pci/msi.c17
-rw-r--r--drivers/pci/msi.h5
-rw-r--r--drivers/pci/pci.c14
-rw-r--r--drivers/pci/quirks.c19
-rw-r--r--drivers/pcmcia/pxa2xx_base.c2
-rw-r--r--drivers/pcmcia/pxa2xx_mainstone.c2
-rw-r--r--drivers/pcmcia/pxa2xx_sharpsl.c116
-rw-r--r--drivers/pcmcia/sa1100_generic.c2
-rw-r--r--drivers/pcmcia/sa1111_generic.c2
-rw-r--r--drivers/pcmcia/sa11xx_base.c2
-rw-r--r--drivers/pcmcia/topic.h17
-rw-r--r--drivers/pcmcia/yenta_socket.c125
-rw-r--r--drivers/pcmcia/yenta_socket.h8
-rw-r--r--drivers/pnp/card.c7
-rw-r--r--drivers/pnp/driver.c7
-rw-r--r--drivers/pnp/isapnp/core.c33
-rw-r--r--drivers/pnp/manager.c7
-rw-r--r--drivers/pnp/pnpacpi/core.c16
-rw-r--r--drivers/pnp/pnpacpi/pnpacpi.h1
-rw-r--r--drivers/pnp/pnpacpi/rsparser.c18
-rw-r--r--drivers/pnp/pnpbios/core.c26
-rw-r--r--drivers/pnp/pnpbios/pnpbios.h1
-rw-r--r--drivers/pnp/pnpbios/proc.c8
-rw-r--r--drivers/pnp/pnpbios/rsparser.c16
-rw-r--r--drivers/pnp/quirks.c7
-rw-r--r--drivers/pnp/support.c7
-rw-r--r--drivers/s390/block/Kconfig2
-rw-r--r--drivers/s390/block/dasd.c19
-rw-r--r--drivers/s390/block/dasd_devmap.c8
-rw-r--r--drivers/s390/block/dasd_diag.c334
-rw-r--r--drivers/s390/block/dasd_diag.h105
-rw-r--r--drivers/s390/block/dasd_genhd.c10
-rw-r--r--drivers/s390/block/dasd_int.h3
-rw-r--r--drivers/s390/block/dasd_ioctl.c17
-rw-r--r--drivers/s390/block/dasd_proc.c8
-rw-r--r--drivers/s390/char/raw3270.c16
-rw-r--r--drivers/s390/cio/cio.c7
-rw-r--r--drivers/s390/cio/device_fsm.c3
-rw-r--r--drivers/s390/cio/device_ops.c4
-rw-r--r--drivers/s390/cio/ioasm.h26
-rw-r--r--drivers/s390/crypto/z90common.h3
-rw-r--r--drivers/s390/crypto/z90hardware.c127
-rw-r--r--drivers/s390/crypto/z90main.c246
-rw-r--r--drivers/s390/net/claw.c20
-rw-r--r--drivers/s390/s390mach.c2
-rw-r--r--drivers/sbus/char/Kconfig39
-rw-r--r--drivers/scsi/3w-xxxx.c57
-rw-r--r--drivers/scsi/Kconfig17
-rw-r--r--drivers/scsi/Makefile3
-rw-r--r--drivers/scsi/NCR5380.c9
-rw-r--r--drivers/scsi/NCR53c406a.c2
-rw-r--r--drivers/scsi/aacraid/aachba.c327
-rw-r--r--drivers/scsi/aacraid/aacraid.h55
-rw-r--r--drivers/scsi/aacraid/commctrl.c20
-rw-r--r--drivers/scsi/aacraid/comminit.c4
-rw-r--r--drivers/scsi/aacraid/commsup.c20
-rw-r--r--drivers/scsi/aacraid/linit.c106
-rw-r--r--drivers/scsi/aacraid/rkt.c20
-rw-r--r--drivers/scsi/aacraid/rx.c20
-rw-r--r--drivers/scsi/aacraid/sa.c22
-rw-r--r--drivers/scsi/advansys.c4
-rw-r--r--drivers/scsi/ahci.c54
-rw-r--r--drivers/scsi/aic7xxx/Kconfig.aic79xx1
-rw-r--r--drivers/scsi/aic7xxx/aic7770.c1
-rw-r--r--drivers/scsi/aic7xxx/aic79xx.h6
-rw-r--r--drivers/scsi/aic7xxx/aic79xx_core.c104
-rw-r--r--drivers/scsi/aic7xxx/aic79xx_osm.c4570
-rw-r--r--drivers/scsi/aic7xxx/aic79xx_osm.h288
-rw-r--r--drivers/scsi/aic7xxx/aic79xx_osm_pci.c82
-rw-r--r--drivers/scsi/aic7xxx/aic79xx_pci.c14
-rw-r--r--drivers/scsi/aic7xxx/aic79xx_proc.c88
-rw-r--r--drivers/scsi/aic7xxx/aic7xxx.h4
-rw-r--r--drivers/scsi/aic7xxx/aic7xxx.reg4
-rw-r--r--drivers/scsi/aic7xxx/aic7xxx.seq5
-rw-r--r--drivers/scsi/aic7xxx/aic7xxx_93cx6.c36
-rw-r--r--drivers/scsi/aic7xxx/aic7xxx_core.c60
-rw-r--r--drivers/scsi/aic7xxx/aic7xxx_osm.c97
-rw-r--r--drivers/scsi/aic7xxx/aic7xxx_osm.h2
-rw-r--r--drivers/scsi/aic7xxx/aic7xxx_osm_pci.c29
-rw-r--r--drivers/scsi/aic7xxx/aic7xxx_proc.c45
-rw-r--r--drivers/scsi/aic7xxx/aic7xxx_reg.h_shipped6
-rw-r--r--drivers/scsi/aic7xxx/aic7xxx_reg_print.c_shipped4
-rw-r--r--drivers/scsi/aic7xxx/aic7xxx_seq.h_shipped933
-rw-r--r--drivers/scsi/aic7xxx/aiclib.c1377
-rw-r--r--drivers/scsi/aic7xxx/aiclib.h890
-rw-r--r--drivers/scsi/ata_piix.c11
-rw-r--r--drivers/scsi/ch.c42
-rw-r--r--drivers/scsi/constants.c49
-rw-r--r--drivers/scsi/hosts.c113
-rw-r--r--drivers/scsi/ibmvscsi/ibmvscsi.c179
-rw-r--r--drivers/scsi/ibmvscsi/ibmvscsi.h2
-rw-r--r--drivers/scsi/libata-core.c19
-rw-r--r--drivers/scsi/libata-scsi.c8
-rw-r--r--drivers/scsi/libata.h1
-rw-r--r--drivers/scsi/lpfc/lpfc.h5
-rw-r--r--drivers/scsi/lpfc/lpfc_attr.c6
-rw-r--r--drivers/scsi/lpfc/lpfc_ct.c2
-rw-r--r--drivers/scsi/lpfc/lpfc_els.c1
-rw-r--r--drivers/scsi/lpfc/lpfc_hbadisc.c3
-rw-r--r--drivers/scsi/lpfc/lpfc_init.c5
-rw-r--r--drivers/scsi/lpfc/lpfc_mbox.c5
-rw-r--r--drivers/scsi/lpfc/lpfc_mem.c5
-rw-r--r--drivers/scsi/lpfc/lpfc_nportdisc.c1
-rw-r--r--drivers/scsi/lpfc/lpfc_scsi.c24
-rw-r--r--drivers/scsi/lpfc/lpfc_scsi.h13
-rw-r--r--drivers/scsi/lpfc/lpfc_sli.c2
-rw-r--r--drivers/scsi/lpfc/lpfc_version.h2
-rw-r--r--drivers/scsi/mesh.c6
-rw-r--r--drivers/scsi/qla1280.c359
-rw-r--r--drivers/scsi/qla1280.h336
-rw-r--r--drivers/scsi/qla2xxx/qla_attr.c136
-rw-r--r--drivers/scsi/qla2xxx/qla_dbg.h7
-rw-r--r--drivers/scsi/qla2xxx/qla_def.h157
-rw-r--r--drivers/scsi/qla2xxx/qla_gbl.h12
-rw-r--r--drivers/scsi/qla2xxx/qla_gs.c564
-rw-r--r--drivers/scsi/qla2xxx/qla_init.c24
-rw-r--r--drivers/scsi/qla2xxx/qla_iocb.c6
-rw-r--r--drivers/scsi/qla2xxx/qla_isr.c2
-rw-r--r--drivers/scsi/qla2xxx/qla_mbx.c97
-rw-r--r--drivers/scsi/qla2xxx/qla_os.c117
-rw-r--r--drivers/scsi/qla2xxx/qla_sup.c34
-rw-r--r--drivers/scsi/qla2xxx/qla_version.h4
-rw-r--r--drivers/scsi/raid_class.c250
-rw-r--r--drivers/scsi/sata_mv.c843
-rw-r--r--drivers/scsi/sata_nv.c9
-rw-r--r--drivers/scsi/sata_promise.c20
-rw-r--r--drivers/scsi/sata_qstor.c10
-rw-r--r--drivers/scsi/sata_sil.c12
-rw-r--r--drivers/scsi/sata_svw.c7
-rw-r--r--drivers/scsi/sata_sx4.c54
-rw-r--r--drivers/scsi/sata_uli.c4
-rw-r--r--drivers/scsi/sata_vsc.c5
-rw-r--r--drivers/scsi/scsi.c17
-rw-r--r--drivers/scsi/scsi_devinfo.c4
-rw-r--r--drivers/scsi/scsi_error.c48
-rw-r--r--drivers/scsi/scsi_ioctl.c64
-rw-r--r--drivers/scsi/scsi_lib.c296
-rw-r--r--drivers/scsi/scsi_priv.h3
-rw-r--r--drivers/scsi/scsi_scan.c128
-rw-r--r--drivers/scsi/scsi_sysfs.c62
-rw-r--r--drivers/scsi/scsi_transport_fc.c6
-rw-r--r--drivers/scsi/scsi_transport_spi.c168
-rw-r--r--drivers/scsi/sd.c185
-rw-r--r--drivers/scsi/sg.c11
-rw-r--r--drivers/scsi/sr.c75
-rw-r--r--drivers/scsi/sr.h1
-rw-r--r--drivers/scsi/sr_ioctl.c62
-rw-r--r--drivers/scsi/st.c156
-rw-r--r--drivers/scsi/st.h3
-rw-r--r--drivers/serial/68328serial.c1
-rw-r--r--drivers/serial/68360serial.c8
-rw-r--r--drivers/serial/Kconfig2
-rw-r--r--drivers/serial/cpm_uart/cpm_uart_core.c13
-rw-r--r--drivers/serial/cpm_uart/cpm_uart_cpm2.c11
-rw-r--r--drivers/serial/crisv10.c15
-rw-r--r--drivers/serial/icom.c1
-rw-r--r--drivers/serial/mcfserial.c1
-rw-r--r--drivers/serial/pmac_zilog.c6
-rw-r--r--drivers/serial/serial_core.c20
-rw-r--r--drivers/serial/serial_lh7a40x.c4
-rw-r--r--drivers/serial/sunsu.c10
-rw-r--r--drivers/usb/atm/usbatm.c2
-rw-r--r--drivers/usb/core/hcd.c4
-rw-r--r--drivers/usb/core/hub.c18
-rw-r--r--drivers/usb/core/usb.c2
-rw-r--r--drivers/usb/host/ehci-dbg.c2
-rw-r--r--drivers/usb/host/ehci-sched.c2
-rw-r--r--drivers/usb/host/isp116x-hcd.c2
-rw-r--r--drivers/usb/host/ohci-dbg.c2
-rw-r--r--drivers/usb/host/sl811-hcd.c8
-rw-r--r--drivers/usb/input/acecad.c2
-rw-r--r--drivers/usb/input/itmtouch.c2
-rw-r--r--drivers/usb/input/pid.c2
-rw-r--r--drivers/usb/media/w9968cf.c12
-rw-r--r--drivers/usb/misc/usbtest.c2
-rw-r--r--drivers/video/aty/aty128fb.c14
-rw-r--r--drivers/video/aty/atyfb_base.c11
-rw-r--r--drivers/video/aty/radeon_i2c.c2
-rw-r--r--drivers/video/aty/radeon_pm.c12
-rw-r--r--drivers/video/backlight/Makefile1
-rw-r--r--drivers/video/backlight/locomolcd.c157
-rw-r--r--drivers/video/chipsfb.c4
-rw-r--r--drivers/video/i810/i810_main.c6
-rw-r--r--drivers/video/matrox/matroxfb_maven.c2
-rw-r--r--drivers/video/nvidia/nv_i2c.c3
-rw-r--r--drivers/video/pmag-aa-fb.c2
-rw-r--r--drivers/video/pmag-ba-fb.c285
-rw-r--r--drivers/video/pmagb-b-fb.c417
-rw-r--r--drivers/video/q40fb.c1
-rw-r--r--drivers/video/riva/rivafb-i2c.c3
-rw-r--r--drivers/video/s1d13xxxfb.c2
-rw-r--r--drivers/video/savage/savagefb-i2c.c3
-rw-r--r--drivers/video/savage/savagefb_driver.c1
-rw-r--r--drivers/video/w100fb.c1912
-rw-r--r--drivers/video/w100fb.h777
517 files changed, 30554 insertions, 18542 deletions
diff --git a/drivers/atm/zatm.c b/drivers/atm/zatm.c
index c4b75ecf946..55959e4d1cb 100644
--- a/drivers/atm/zatm.c
+++ b/drivers/atm/zatm.c
@@ -417,9 +417,9 @@ printk("dummy: 0x%08lx, 0x%08lx\n",dummy[0],dummy[1]);
417 chan = (here[3] & uPD98401_AAL5_CHAN) >> 417 chan = (here[3] & uPD98401_AAL5_CHAN) >>
418 uPD98401_AAL5_CHAN_SHIFT; 418 uPD98401_AAL5_CHAN_SHIFT;
419 if (chan < zatm_dev->chans && zatm_dev->rx_map[chan]) { 419 if (chan < zatm_dev->chans && zatm_dev->rx_map[chan]) {
420 int pos = ZATM_VCC(vcc)->pool; 420 int pos;
421
422 vcc = zatm_dev->rx_map[chan]; 421 vcc = zatm_dev->rx_map[chan];
422 pos = ZATM_VCC(vcc)->pool;
423 if (skb == zatm_dev->last_free[pos]) 423 if (skb == zatm_dev->last_free[pos])
424 zatm_dev->last_free[pos] = NULL; 424 zatm_dev->last_free[pos] = NULL;
425 skb_unlink(skb, zatm_dev->pool + pos); 425 skb_unlink(skb, zatm_dev->pool + pos);
diff --git a/drivers/base/attribute_container.c b/drivers/base/attribute_container.c
index ec615d854be..373e7b728fa 100644
--- a/drivers/base/attribute_container.c
+++ b/drivers/base/attribute_container.c
@@ -22,11 +22,26 @@
22/* This is a private structure used to tie the classdev and the 22/* This is a private structure used to tie the classdev and the
23 * container .. it should never be visible outside this file */ 23 * container .. it should never be visible outside this file */
24struct internal_container { 24struct internal_container {
25 struct list_head node; 25 struct klist_node node;
26 struct attribute_container *cont; 26 struct attribute_container *cont;
27 struct class_device classdev; 27 struct class_device classdev;
28}; 28};
29 29
30static void internal_container_klist_get(struct klist_node *n)
31{
32 struct internal_container *ic =
33 container_of(n, struct internal_container, node);
34 class_device_get(&ic->classdev);
35}
36
37static void internal_container_klist_put(struct klist_node *n)
38{
39 struct internal_container *ic =
40 container_of(n, struct internal_container, node);
41 class_device_put(&ic->classdev);
42}
43
44
30/** 45/**
31 * attribute_container_classdev_to_container - given a classdev, return the container 46 * attribute_container_classdev_to_container - given a classdev, return the container
32 * 47 *
@@ -57,7 +72,8 @@ int
57attribute_container_register(struct attribute_container *cont) 72attribute_container_register(struct attribute_container *cont)
58{ 73{
59 INIT_LIST_HEAD(&cont->node); 74 INIT_LIST_HEAD(&cont->node);
60 INIT_LIST_HEAD(&cont->containers); 75 klist_init(&cont->containers,internal_container_klist_get,
76 internal_container_klist_put);
61 77
62 down(&attribute_container_mutex); 78 down(&attribute_container_mutex);
63 list_add_tail(&cont->node, &attribute_container_list); 79 list_add_tail(&cont->node, &attribute_container_list);
@@ -77,11 +93,13 @@ attribute_container_unregister(struct attribute_container *cont)
77{ 93{
78 int retval = -EBUSY; 94 int retval = -EBUSY;
79 down(&attribute_container_mutex); 95 down(&attribute_container_mutex);
80 if (!list_empty(&cont->containers)) 96 spin_lock(&cont->containers.k_lock);
97 if (!list_empty(&cont->containers.k_list))
81 goto out; 98 goto out;
82 retval = 0; 99 retval = 0;
83 list_del(&cont->node); 100 list_del(&cont->node);
84 out: 101 out:
102 spin_unlock(&cont->containers.k_lock);
85 up(&attribute_container_mutex); 103 up(&attribute_container_mutex);
86 return retval; 104 return retval;
87 105
@@ -140,7 +158,6 @@ attribute_container_add_device(struct device *dev,
140 continue; 158 continue;
141 } 159 }
142 memset(ic, 0, sizeof(struct internal_container)); 160 memset(ic, 0, sizeof(struct internal_container));
143 INIT_LIST_HEAD(&ic->node);
144 ic->cont = cont; 161 ic->cont = cont;
145 class_device_initialize(&ic->classdev); 162 class_device_initialize(&ic->classdev);
146 ic->classdev.dev = get_device(dev); 163 ic->classdev.dev = get_device(dev);
@@ -151,11 +168,22 @@ attribute_container_add_device(struct device *dev,
151 fn(cont, dev, &ic->classdev); 168 fn(cont, dev, &ic->classdev);
152 else 169 else
153 attribute_container_add_class_device(&ic->classdev); 170 attribute_container_add_class_device(&ic->classdev);
154 list_add_tail(&ic->node, &cont->containers); 171 klist_add_tail(&ic->node, &cont->containers);
155 } 172 }
156 up(&attribute_container_mutex); 173 up(&attribute_container_mutex);
157} 174}
158 175
176/* FIXME: can't break out of this unless klist_iter_exit is also
177 * called before doing the break
178 */
179#define klist_for_each_entry(pos, head, member, iter) \
180 for (klist_iter_init(head, iter); (pos = ({ \
181 struct klist_node *n = klist_next(iter); \
182 n ? container_of(n, typeof(*pos), member) : \
183 ({ klist_iter_exit(iter) ; NULL; }); \
184 }) ) != NULL; )
185
186
159/** 187/**
160 * attribute_container_remove_device - make device eligible for removal. 188 * attribute_container_remove_device - make device eligible for removal.
161 * 189 *
@@ -182,17 +210,19 @@ attribute_container_remove_device(struct device *dev,
182 210
183 down(&attribute_container_mutex); 211 down(&attribute_container_mutex);
184 list_for_each_entry(cont, &attribute_container_list, node) { 212 list_for_each_entry(cont, &attribute_container_list, node) {
185 struct internal_container *ic, *tmp; 213 struct internal_container *ic;
214 struct klist_iter iter;
186 215
187 if (attribute_container_no_classdevs(cont)) 216 if (attribute_container_no_classdevs(cont))
188 continue; 217 continue;
189 218
190 if (!cont->match(cont, dev)) 219 if (!cont->match(cont, dev))
191 continue; 220 continue;
192 list_for_each_entry_safe(ic, tmp, &cont->containers, node) { 221
222 klist_for_each_entry(ic, &cont->containers, node, &iter) {
193 if (dev != ic->classdev.dev) 223 if (dev != ic->classdev.dev)
194 continue; 224 continue;
195 list_del(&ic->node); 225 klist_del(&ic->node);
196 if (fn) 226 if (fn)
197 fn(cont, dev, &ic->classdev); 227 fn(cont, dev, &ic->classdev);
198 else { 228 else {
@@ -225,12 +255,18 @@ attribute_container_device_trigger(struct device *dev,
225 255
226 down(&attribute_container_mutex); 256 down(&attribute_container_mutex);
227 list_for_each_entry(cont, &attribute_container_list, node) { 257 list_for_each_entry(cont, &attribute_container_list, node) {
228 struct internal_container *ic, *tmp; 258 struct internal_container *ic;
259 struct klist_iter iter;
229 260
230 if (!cont->match(cont, dev)) 261 if (!cont->match(cont, dev))
231 continue; 262 continue;
232 263
233 list_for_each_entry_safe(ic, tmp, &cont->containers, node) { 264 if (attribute_container_no_classdevs(cont)) {
265 fn(cont, dev, NULL);
266 continue;
267 }
268
269 klist_for_each_entry(ic, &cont->containers, node, &iter) {
234 if (dev == ic->classdev.dev) 270 if (dev == ic->classdev.dev)
235 fn(cont, dev, &ic->classdev); 271 fn(cont, dev, &ic->classdev);
236 } 272 }
@@ -368,6 +404,36 @@ attribute_container_class_device_del(struct class_device *classdev)
368} 404}
369EXPORT_SYMBOL_GPL(attribute_container_class_device_del); 405EXPORT_SYMBOL_GPL(attribute_container_class_device_del);
370 406
407/**
408 * attribute_container_find_class_device - find the corresponding class_device
409 *
410 * @cont: the container
411 * @dev: the generic device
412 *
413 * Looks up the device in the container's list of class devices and returns
414 * the corresponding class_device.
415 */
416struct class_device *
417attribute_container_find_class_device(struct attribute_container *cont,
418 struct device *dev)
419{
420 struct class_device *cdev = NULL;
421 struct internal_container *ic;
422 struct klist_iter iter;
423
424 klist_for_each_entry(ic, &cont->containers, node, &iter) {
425 if (ic->classdev.dev == dev) {
426 cdev = &ic->classdev;
427 /* FIXME: must exit iterator then break */
428 klist_iter_exit(&iter);
429 break;
430 }
431 }
432
433 return cdev;
434}
435EXPORT_SYMBOL_GPL(attribute_container_find_class_device);
436
371int __init 437int __init
372attribute_container_init(void) 438attribute_container_init(void)
373{ 439{
diff --git a/drivers/base/bus.c b/drivers/base/bus.c
index ab53832d57e..03204bfd17a 100644
--- a/drivers/base/bus.c
+++ b/drivers/base/bus.c
@@ -156,7 +156,9 @@ static ssize_t driver_unbind(struct device_driver *drv,
156 device_release_driver(dev); 156 device_release_driver(dev);
157 err = count; 157 err = count;
158 } 158 }
159 return err; 159 if (err)
160 return err;
161 return count;
160} 162}
161static DRIVER_ATTR(unbind, S_IWUSR, NULL, driver_unbind); 163static DRIVER_ATTR(unbind, S_IWUSR, NULL, driver_unbind);
162 164
@@ -358,7 +360,7 @@ int bus_add_device(struct device * dev)
358 if (bus) { 360 if (bus) {
359 pr_debug("bus %s: add device %s\n", bus->name, dev->bus_id); 361 pr_debug("bus %s: add device %s\n", bus->name, dev->bus_id);
360 device_attach(dev); 362 device_attach(dev);
361 klist_add_tail(&bus->klist_devices, &dev->knode_bus); 363 klist_add_tail(&dev->knode_bus, &bus->klist_devices);
362 error = device_add_attrs(bus, dev); 364 error = device_add_attrs(bus, dev);
363 if (!error) { 365 if (!error) {
364 sysfs_create_link(&bus->devices.kobj, &dev->kobj, dev->bus_id); 366 sysfs_create_link(&bus->devices.kobj, &dev->kobj, dev->bus_id);
@@ -446,7 +448,7 @@ int bus_add_driver(struct device_driver * drv)
446 } 448 }
447 449
448 driver_attach(drv); 450 driver_attach(drv);
449 klist_add_tail(&bus->klist_drivers, &drv->knode_bus); 451 klist_add_tail(&drv->knode_bus, &bus->klist_drivers);
450 module_add_driver(drv->owner, drv); 452 module_add_driver(drv->owner, drv);
451 453
452 driver_add_attrs(bus, drv); 454 driver_add_attrs(bus, drv);
@@ -566,6 +568,36 @@ static void bus_remove_attrs(struct bus_type * bus)
566 } 568 }
567} 569}
568 570
571static void klist_devices_get(struct klist_node *n)
572{
573 struct device *dev = container_of(n, struct device, knode_bus);
574
575 get_device(dev);
576}
577
578static void klist_devices_put(struct klist_node *n)
579{
580 struct device *dev = container_of(n, struct device, knode_bus);
581
582 put_device(dev);
583}
584
585static void klist_drivers_get(struct klist_node *n)
586{
587 struct device_driver *drv = container_of(n, struct device_driver,
588 knode_bus);
589
590 get_driver(drv);
591}
592
593static void klist_drivers_put(struct klist_node *n)
594{
595 struct device_driver *drv = container_of(n, struct device_driver,
596 knode_bus);
597
598 put_driver(drv);
599}
600
569/** 601/**
570 * bus_register - register a bus with the system. 602 * bus_register - register a bus with the system.
571 * @bus: bus. 603 * @bus: bus.
@@ -600,8 +632,8 @@ int bus_register(struct bus_type * bus)
600 if (retval) 632 if (retval)
601 goto bus_drivers_fail; 633 goto bus_drivers_fail;
602 634
603 klist_init(&bus->klist_devices); 635 klist_init(&bus->klist_devices, klist_devices_get, klist_devices_put);
604 klist_init(&bus->klist_drivers); 636 klist_init(&bus->klist_drivers, klist_drivers_get, klist_drivers_put);
605 bus_add_attrs(bus); 637 bus_add_attrs(bus);
606 638
607 pr_debug("bus type '%s' registered\n", bus->name); 639 pr_debug("bus type '%s' registered\n", bus->name);
diff --git a/drivers/base/class.c b/drivers/base/class.c
index 0154a1623b2..d164c32a97a 100644
--- a/drivers/base/class.c
+++ b/drivers/base/class.c
@@ -299,10 +299,8 @@ static void class_dev_release(struct kobject * kobj)
299 299
300 pr_debug("device class '%s': release.\n", cd->class_id); 300 pr_debug("device class '%s': release.\n", cd->class_id);
301 301
302 if (cd->devt_attr) { 302 kfree(cd->devt_attr);
303 kfree(cd->devt_attr); 303 cd->devt_attr = NULL;
304 cd->devt_attr = NULL;
305 }
306 304
307 if (cls->release) 305 if (cls->release)
308 cls->release(cd); 306 cls->release(cd);
@@ -452,10 +450,29 @@ void class_device_initialize(struct class_device *class_dev)
452 INIT_LIST_HEAD(&class_dev->node); 450 INIT_LIST_HEAD(&class_dev->node);
453} 451}
454 452
453static char *make_class_name(struct class_device *class_dev)
454{
455 char *name;
456 int size;
457
458 size = strlen(class_dev->class->name) +
459 strlen(kobject_name(&class_dev->kobj)) + 2;
460
461 name = kmalloc(size, GFP_KERNEL);
462 if (!name)
463 return ERR_PTR(-ENOMEM);
464
465 strcpy(name, class_dev->class->name);
466 strcat(name, ":");
467 strcat(name, kobject_name(&class_dev->kobj));
468 return name;
469}
470
455int class_device_add(struct class_device *class_dev) 471int class_device_add(struct class_device *class_dev)
456{ 472{
457 struct class * parent = NULL; 473 struct class * parent = NULL;
458 struct class_interface * class_intf; 474 struct class_interface * class_intf;
475 char *class_name = NULL;
459 int error; 476 int error;
460 477
461 class_dev = class_device_get(class_dev); 478 class_dev = class_device_get(class_dev);
@@ -500,9 +517,13 @@ int class_device_add(struct class_device *class_dev)
500 } 517 }
501 518
502 class_device_add_attrs(class_dev); 519 class_device_add_attrs(class_dev);
503 if (class_dev->dev) 520 if (class_dev->dev) {
521 class_name = make_class_name(class_dev);
504 sysfs_create_link(&class_dev->kobj, 522 sysfs_create_link(&class_dev->kobj,
505 &class_dev->dev->kobj, "device"); 523 &class_dev->dev->kobj, "device");
524 sysfs_create_link(&class_dev->dev->kobj, &class_dev->kobj,
525 class_name);
526 }
506 527
507 /* notify any interfaces this device is now here */ 528 /* notify any interfaces this device is now here */
508 if (parent) { 529 if (parent) {
@@ -519,6 +540,7 @@ int class_device_add(struct class_device *class_dev)
519 if (error && parent) 540 if (error && parent)
520 class_put(parent); 541 class_put(parent);
521 class_device_put(class_dev); 542 class_device_put(class_dev);
543 kfree(class_name);
522 return error; 544 return error;
523} 545}
524 546
@@ -584,6 +606,7 @@ void class_device_del(struct class_device *class_dev)
584{ 606{
585 struct class * parent = class_dev->class; 607 struct class * parent = class_dev->class;
586 struct class_interface * class_intf; 608 struct class_interface * class_intf;
609 char *class_name = NULL;
587 610
588 if (parent) { 611 if (parent) {
589 down(&parent->sem); 612 down(&parent->sem);
@@ -594,8 +617,11 @@ void class_device_del(struct class_device *class_dev)
594 up(&parent->sem); 617 up(&parent->sem);
595 } 618 }
596 619
597 if (class_dev->dev) 620 if (class_dev->dev) {
621 class_name = make_class_name(class_dev);
598 sysfs_remove_link(&class_dev->kobj, "device"); 622 sysfs_remove_link(&class_dev->kobj, "device");
623 sysfs_remove_link(&class_dev->dev->kobj, class_name);
624 }
599 if (class_dev->devt_attr) 625 if (class_dev->devt_attr)
600 class_device_remove_file(class_dev, class_dev->devt_attr); 626 class_device_remove_file(class_dev, class_dev->devt_attr);
601 class_device_remove_attrs(class_dev); 627 class_device_remove_attrs(class_dev);
@@ -605,6 +631,7 @@ void class_device_del(struct class_device *class_dev)
605 631
606 if (parent) 632 if (parent)
607 class_put(parent); 633 class_put(parent);
634 kfree(class_name);
608} 635}
609 636
610void class_device_unregister(struct class_device *class_dev) 637void class_device_unregister(struct class_device *class_dev)
diff --git a/drivers/base/core.c b/drivers/base/core.c
index efe03a024a5..6ab73f5c799 100644
--- a/drivers/base/core.c
+++ b/drivers/base/core.c
@@ -191,6 +191,20 @@ void device_remove_file(struct device * dev, struct device_attribute * attr)
191 } 191 }
192} 192}
193 193
194static void klist_children_get(struct klist_node *n)
195{
196 struct device *dev = container_of(n, struct device, knode_parent);
197
198 get_device(dev);
199}
200
201static void klist_children_put(struct klist_node *n)
202{
203 struct device *dev = container_of(n, struct device, knode_parent);
204
205 put_device(dev);
206}
207
194 208
195/** 209/**
196 * device_initialize - init device structure. 210 * device_initialize - init device structure.
@@ -207,7 +221,8 @@ void device_initialize(struct device *dev)
207{ 221{
208 kobj_set_kset_s(dev, devices_subsys); 222 kobj_set_kset_s(dev, devices_subsys);
209 kobject_init(&dev->kobj); 223 kobject_init(&dev->kobj);
210 klist_init(&dev->klist_children); 224 klist_init(&dev->klist_children, klist_children_get,
225 klist_children_put);
211 INIT_LIST_HEAD(&dev->dma_pools); 226 INIT_LIST_HEAD(&dev->dma_pools);
212 init_MUTEX(&dev->sem); 227 init_MUTEX(&dev->sem);
213} 228}
@@ -249,7 +264,7 @@ int device_add(struct device *dev)
249 if ((error = bus_add_device(dev))) 264 if ((error = bus_add_device(dev)))
250 goto BusError; 265 goto BusError;
251 if (parent) 266 if (parent)
252 klist_add_tail(&parent->klist_children, &dev->knode_parent); 267 klist_add_tail(&dev->knode_parent, &parent->klist_children);
253 268
254 /* notify platform of device entry */ 269 /* notify platform of device entry */
255 if (platform_notify) 270 if (platform_notify)
diff --git a/drivers/base/dd.c b/drivers/base/dd.c
index 16323f9cbff..d5bbce38282 100644
--- a/drivers/base/dd.c
+++ b/drivers/base/dd.c
@@ -42,7 +42,7 @@ void device_bind_driver(struct device * dev)
42{ 42{
43 pr_debug("bound device '%s' to driver '%s'\n", 43 pr_debug("bound device '%s' to driver '%s'\n",
44 dev->bus_id, dev->driver->name); 44 dev->bus_id, dev->driver->name);
45 klist_add_tail(&dev->driver->klist_devices, &dev->knode_driver); 45 klist_add_tail(&dev->knode_driver, &dev->driver->klist_devices);
46 sysfs_create_link(&dev->driver->kobj, &dev->kobj, 46 sysfs_create_link(&dev->driver->kobj, &dev->kobj,
47 kobject_name(&dev->kobj)); 47 kobject_name(&dev->kobj));
48 sysfs_create_link(&dev->kobj, &dev->driver->kobj, "driver"); 48 sysfs_create_link(&dev->kobj, &dev->driver->kobj, "driver");
diff --git a/drivers/base/driver.c b/drivers/base/driver.c
index 291c5954a3a..ef3fe513e39 100644
--- a/drivers/base/driver.c
+++ b/drivers/base/driver.c
@@ -142,6 +142,19 @@ void put_driver(struct device_driver * drv)
142 kobject_put(&drv->kobj); 142 kobject_put(&drv->kobj);
143} 143}
144 144
145static void klist_devices_get(struct klist_node *n)
146{
147 struct device *dev = container_of(n, struct device, knode_driver);
148
149 get_device(dev);
150}
151
152static void klist_devices_put(struct klist_node *n)
153{
154 struct device *dev = container_of(n, struct device, knode_driver);
155
156 put_device(dev);
157}
145 158
146/** 159/**
147 * driver_register - register driver with bus 160 * driver_register - register driver with bus
@@ -157,7 +170,7 @@ void put_driver(struct device_driver * drv)
157 */ 170 */
158int driver_register(struct device_driver * drv) 171int driver_register(struct device_driver * drv)
159{ 172{
160 klist_init(&drv->klist_devices); 173 klist_init(&drv->klist_devices, klist_devices_get, klist_devices_put);
161 init_completion(&drv->unloaded); 174 init_completion(&drv->unloaded);
162 return bus_add_driver(drv); 175 return bus_add_driver(drv);
163} 176}
diff --git a/drivers/base/firmware_class.c b/drivers/base/firmware_class.c
index 652281402c9..5bfa2e9a7c2 100644
--- a/drivers/base/firmware_class.c
+++ b/drivers/base/firmware_class.c
@@ -28,6 +28,7 @@ enum {
28 FW_STATUS_DONE, 28 FW_STATUS_DONE,
29 FW_STATUS_ABORT, 29 FW_STATUS_ABORT,
30 FW_STATUS_READY, 30 FW_STATUS_READY,
31 FW_STATUS_READY_NOHOTPLUG,
31}; 32};
32 33
33static int loading_timeout = 10; /* In seconds */ 34static int loading_timeout = 10; /* In seconds */
@@ -344,7 +345,7 @@ error_kfree:
344 345
345static int 346static int
346fw_setup_class_device(struct firmware *fw, struct class_device **class_dev_p, 347fw_setup_class_device(struct firmware *fw, struct class_device **class_dev_p,
347 const char *fw_name, struct device *device) 348 const char *fw_name, struct device *device, int hotplug)
348{ 349{
349 struct class_device *class_dev; 350 struct class_device *class_dev;
350 struct firmware_priv *fw_priv; 351 struct firmware_priv *fw_priv;
@@ -376,7 +377,10 @@ fw_setup_class_device(struct firmware *fw, struct class_device **class_dev_p,
376 goto error_unreg; 377 goto error_unreg;
377 } 378 }
378 379
379 set_bit(FW_STATUS_READY, &fw_priv->status); 380 if (hotplug)
381 set_bit(FW_STATUS_READY, &fw_priv->status);
382 else
383 set_bit(FW_STATUS_READY_NOHOTPLUG, &fw_priv->status);
380 *class_dev_p = class_dev; 384 *class_dev_p = class_dev;
381 goto out; 385 goto out;
382 386
@@ -386,21 +390,9 @@ out:
386 return retval; 390 return retval;
387} 391}
388 392
389/** 393static int
390 * request_firmware: - request firmware to hotplug and wait for it 394_request_firmware(const struct firmware **firmware_p, const char *name,
391 * Description: 395 struct device *device, int hotplug)
392 * @firmware will be used to return a firmware image by the name
393 * of @name for device @device.
394 *
395 * Should be called from user context where sleeping is allowed.
396 *
397 * @name will be use as $FIRMWARE in the hotplug environment and
398 * should be distinctive enough not to be confused with any other
399 * firmware image for this or any other device.
400 **/
401int
402request_firmware(const struct firmware **firmware_p, const char *name,
403 struct device *device)
404{ 396{
405 struct class_device *class_dev; 397 struct class_device *class_dev;
406 struct firmware_priv *fw_priv; 398 struct firmware_priv *fw_priv;
@@ -419,22 +411,25 @@ request_firmware(const struct firmware **firmware_p, const char *name,
419 } 411 }
420 memset(firmware, 0, sizeof (*firmware)); 412 memset(firmware, 0, sizeof (*firmware));
421 413
422 retval = fw_setup_class_device(firmware, &class_dev, name, device); 414 retval = fw_setup_class_device(firmware, &class_dev, name, device,
415 hotplug);
423 if (retval) 416 if (retval)
424 goto error_kfree_fw; 417 goto error_kfree_fw;
425 418
426 fw_priv = class_get_devdata(class_dev); 419 fw_priv = class_get_devdata(class_dev);
427 420
428 if (loading_timeout > 0) { 421 if (hotplug) {
429 fw_priv->timeout.expires = jiffies + loading_timeout * HZ; 422 if (loading_timeout > 0) {
430 add_timer(&fw_priv->timeout); 423 fw_priv->timeout.expires = jiffies + loading_timeout * HZ;
431 } 424 add_timer(&fw_priv->timeout);
432 425 }
433 kobject_hotplug(&class_dev->kobj, KOBJ_ADD);
434 wait_for_completion(&fw_priv->completion);
435 set_bit(FW_STATUS_DONE, &fw_priv->status);
436 426
437 del_timer_sync(&fw_priv->timeout); 427 kobject_hotplug(&class_dev->kobj, KOBJ_ADD);
428 wait_for_completion(&fw_priv->completion);
429 set_bit(FW_STATUS_DONE, &fw_priv->status);
430 del_timer_sync(&fw_priv->timeout);
431 } else
432 wait_for_completion(&fw_priv->completion);
438 433
439 down(&fw_lock); 434 down(&fw_lock);
440 if (!fw_priv->fw->size || test_bit(FW_STATUS_ABORT, &fw_priv->status)) { 435 if (!fw_priv->fw->size || test_bit(FW_STATUS_ABORT, &fw_priv->status)) {
@@ -455,6 +450,26 @@ out:
455} 450}
456 451
457/** 452/**
453 * request_firmware: - request firmware to hotplug and wait for it
454 * Description:
455 * @firmware will be used to return a firmware image by the name
456 * of @name for device @device.
457 *
458 * Should be called from user context where sleeping is allowed.
459 *
460 * @name will be use as $FIRMWARE in the hotplug environment and
461 * should be distinctive enough not to be confused with any other
462 * firmware image for this or any other device.
463 **/
464int
465request_firmware(const struct firmware **firmware_p, const char *name,
466 struct device *device)
467{
468 int hotplug = 1;
469 return _request_firmware(firmware_p, name, device, hotplug);
470}
471
472/**
458 * release_firmware: - release the resource associated with a firmware image 473 * release_firmware: - release the resource associated with a firmware image
459 **/ 474 **/
460void 475void
@@ -491,6 +506,7 @@ struct firmware_work {
491 struct device *device; 506 struct device *device;
492 void *context; 507 void *context;
493 void (*cont)(const struct firmware *fw, void *context); 508 void (*cont)(const struct firmware *fw, void *context);
509 int hotplug;
494}; 510};
495 511
496static int 512static int
@@ -503,7 +519,8 @@ request_firmware_work_func(void *arg)
503 return 0; 519 return 0;
504 } 520 }
505 daemonize("%s/%s", "firmware", fw_work->name); 521 daemonize("%s/%s", "firmware", fw_work->name);
506 request_firmware(&fw, fw_work->name, fw_work->device); 522 _request_firmware(&fw, fw_work->name, fw_work->device,
523 fw_work->hotplug);
507 fw_work->cont(fw, fw_work->context); 524 fw_work->cont(fw, fw_work->context);
508 release_firmware(fw); 525 release_firmware(fw);
509 module_put(fw_work->module); 526 module_put(fw_work->module);
@@ -518,6 +535,9 @@ request_firmware_work_func(void *arg)
518 * Asynchronous variant of request_firmware() for contexts where 535 * Asynchronous variant of request_firmware() for contexts where
519 * it is not possible to sleep. 536 * it is not possible to sleep.
520 * 537 *
538 * @hotplug invokes hotplug event to copy the firmware image if this flag
539 * is non-zero else the firmware copy must be done manually.
540 *
521 * @cont will be called asynchronously when the firmware request is over. 541 * @cont will be called asynchronously when the firmware request is over.
522 * 542 *
523 * @context will be passed over to @cont. 543 * @context will be passed over to @cont.
@@ -527,7 +547,7 @@ request_firmware_work_func(void *arg)
527 **/ 547 **/
528int 548int
529request_firmware_nowait( 549request_firmware_nowait(
530 struct module *module, 550 struct module *module, int hotplug,
531 const char *name, struct device *device, void *context, 551 const char *name, struct device *device, void *context,
532 void (*cont)(const struct firmware *fw, void *context)) 552 void (*cont)(const struct firmware *fw, void *context))
533{ 553{
@@ -548,6 +568,7 @@ request_firmware_nowait(
548 .device = device, 568 .device = device,
549 .context = context, 569 .context = context,
550 .cont = cont, 570 .cont = cont,
571 .hotplug = hotplug,
551 }; 572 };
552 573
553 ret = kernel_thread(request_firmware_work_func, fw_work, 574 ret = kernel_thread(request_firmware_work_func, fw_work,
diff --git a/drivers/base/node.c b/drivers/base/node.c
index 904b27caf69..16c513aa4d4 100644
--- a/drivers/base/node.c
+++ b/drivers/base/node.c
@@ -39,13 +39,25 @@ static ssize_t node_read_meminfo(struct sys_device * dev, char * buf)
39 int n; 39 int n;
40 int nid = dev->id; 40 int nid = dev->id;
41 struct sysinfo i; 41 struct sysinfo i;
42 struct page_state ps;
42 unsigned long inactive; 43 unsigned long inactive;
43 unsigned long active; 44 unsigned long active;
44 unsigned long free; 45 unsigned long free;
45 46
46 si_meminfo_node(&i, nid); 47 si_meminfo_node(&i, nid);
48 get_page_state_node(&ps, nid);
47 __get_zone_counts(&active, &inactive, &free, NODE_DATA(nid)); 49 __get_zone_counts(&active, &inactive, &free, NODE_DATA(nid));
48 50
51 /* Check for negative values in these approximate counters */
52 if ((long)ps.nr_dirty < 0)
53 ps.nr_dirty = 0;
54 if ((long)ps.nr_writeback < 0)
55 ps.nr_writeback = 0;
56 if ((long)ps.nr_mapped < 0)
57 ps.nr_mapped = 0;
58 if ((long)ps.nr_slab < 0)
59 ps.nr_slab = 0;
60
49 n = sprintf(buf, "\n" 61 n = sprintf(buf, "\n"
50 "Node %d MemTotal: %8lu kB\n" 62 "Node %d MemTotal: %8lu kB\n"
51 "Node %d MemFree: %8lu kB\n" 63 "Node %d MemFree: %8lu kB\n"
@@ -55,7 +67,11 @@ static ssize_t node_read_meminfo(struct sys_device * dev, char * buf)
55 "Node %d HighTotal: %8lu kB\n" 67 "Node %d HighTotal: %8lu kB\n"
56 "Node %d HighFree: %8lu kB\n" 68 "Node %d HighFree: %8lu kB\n"
57 "Node %d LowTotal: %8lu kB\n" 69 "Node %d LowTotal: %8lu kB\n"
58 "Node %d LowFree: %8lu kB\n", 70 "Node %d LowFree: %8lu kB\n"
71 "Node %d Dirty: %8lu kB\n"
72 "Node %d Writeback: %8lu kB\n"
73 "Node %d Mapped: %8lu kB\n"
74 "Node %d Slab: %8lu kB\n",
59 nid, K(i.totalram), 75 nid, K(i.totalram),
60 nid, K(i.freeram), 76 nid, K(i.freeram),
61 nid, K(i.totalram - i.freeram), 77 nid, K(i.totalram - i.freeram),
@@ -64,7 +80,11 @@ static ssize_t node_read_meminfo(struct sys_device * dev, char * buf)
64 nid, K(i.totalhigh), 80 nid, K(i.totalhigh),
65 nid, K(i.freehigh), 81 nid, K(i.freehigh),
66 nid, K(i.totalram - i.totalhigh), 82 nid, K(i.totalram - i.totalhigh),
67 nid, K(i.freeram - i.freehigh)); 83 nid, K(i.freeram - i.freehigh),
84 nid, K(ps.nr_dirty),
85 nid, K(ps.nr_writeback),
86 nid, K(ps.nr_mapped),
87 nid, K(ps.nr_slab));
68 n += hugetlb_report_node_meminfo(nid, buf + n); 88 n += hugetlb_report_node_meminfo(nid, buf + n);
69 return n; 89 return n;
70} 90}
diff --git a/drivers/base/power/resume.c b/drivers/base/power/resume.c
index bdd96b03b88..0a7aa07b9a2 100644
--- a/drivers/base/power/resume.c
+++ b/drivers/base/power/resume.c
@@ -26,11 +26,11 @@ int resume_device(struct device * dev)
26 26
27 down(&dev->sem); 27 down(&dev->sem);
28 if (dev->power.pm_parent 28 if (dev->power.pm_parent
29 && dev->power.pm_parent->power.power_state) { 29 && dev->power.pm_parent->power.power_state.event) {
30 dev_err(dev, "PM: resume from %d, parent %s still %d\n", 30 dev_err(dev, "PM: resume from %d, parent %s still %d\n",
31 dev->power.power_state, 31 dev->power.power_state.event,
32 dev->power.pm_parent->bus_id, 32 dev->power.pm_parent->bus_id,
33 dev->power.pm_parent->power.power_state); 33 dev->power.pm_parent->power.power_state.event);
34 } 34 }
35 if (dev->bus && dev->bus->resume) { 35 if (dev->bus && dev->bus->resume) {
36 dev_dbg(dev,"resuming\n"); 36 dev_dbg(dev,"resuming\n");
@@ -54,7 +54,7 @@ void dpm_resume(void)
54 list_add_tail(entry, &dpm_active); 54 list_add_tail(entry, &dpm_active);
55 55
56 up(&dpm_list_sem); 56 up(&dpm_list_sem);
57 if (!dev->power.prev_state) 57 if (!dev->power.prev_state.event)
58 resume_device(dev); 58 resume_device(dev);
59 down(&dpm_list_sem); 59 down(&dpm_list_sem);
60 put_device(dev); 60 put_device(dev);
diff --git a/drivers/base/power/runtime.c b/drivers/base/power/runtime.c
index 325962d8019..e8f0519f5df 100644
--- a/drivers/base/power/runtime.c
+++ b/drivers/base/power/runtime.c
@@ -13,10 +13,10 @@
13static void runtime_resume(struct device * dev) 13static void runtime_resume(struct device * dev)
14{ 14{
15 dev_dbg(dev, "resuming\n"); 15 dev_dbg(dev, "resuming\n");
16 if (!dev->power.power_state) 16 if (!dev->power.power_state.event)
17 return; 17 return;
18 if (!resume_device(dev)) 18 if (!resume_device(dev))
19 dev->power.power_state = 0; 19 dev->power.power_state = PMSG_ON;
20} 20}
21 21
22 22
@@ -49,10 +49,10 @@ int dpm_runtime_suspend(struct device * dev, pm_message_t state)
49 int error = 0; 49 int error = 0;
50 50
51 down(&dpm_sem); 51 down(&dpm_sem);
52 if (dev->power.power_state == state) 52 if (dev->power.power_state.event == state.event)
53 goto Done; 53 goto Done;
54 54
55 if (dev->power.power_state) 55 if (dev->power.power_state.event)
56 runtime_resume(dev); 56 runtime_resume(dev);
57 57
58 if (!(error = suspend_device(dev, state))) 58 if (!(error = suspend_device(dev, state)))
diff --git a/drivers/base/power/suspend.c b/drivers/base/power/suspend.c
index 2ccee3763ac..50501764d05 100644
--- a/drivers/base/power/suspend.c
+++ b/drivers/base/power/suspend.c
@@ -40,22 +40,22 @@ int suspend_device(struct device * dev, pm_message_t state)
40 int error = 0; 40 int error = 0;
41 41
42 down(&dev->sem); 42 down(&dev->sem);
43 if (dev->power.power_state) { 43 if (dev->power.power_state.event) {
44 dev_dbg(dev, "PM: suspend %d-->%d\n", 44 dev_dbg(dev, "PM: suspend %d-->%d\n",
45 dev->power.power_state, state); 45 dev->power.power_state.event, state.event);
46 } 46 }
47 if (dev->power.pm_parent 47 if (dev->power.pm_parent
48 && dev->power.pm_parent->power.power_state) { 48 && dev->power.pm_parent->power.power_state.event) {
49 dev_err(dev, 49 dev_err(dev,
50 "PM: suspend %d->%d, parent %s already %d\n", 50 "PM: suspend %d->%d, parent %s already %d\n",
51 dev->power.power_state, state, 51 dev->power.power_state.event, state.event,
52 dev->power.pm_parent->bus_id, 52 dev->power.pm_parent->bus_id,
53 dev->power.pm_parent->power.power_state); 53 dev->power.pm_parent->power.power_state.event);
54 } 54 }
55 55
56 dev->power.prev_state = dev->power.power_state; 56 dev->power.prev_state = dev->power.power_state;
57 57
58 if (dev->bus && dev->bus->suspend && !dev->power.power_state) { 58 if (dev->bus && dev->bus->suspend && !dev->power.power_state.event) {
59 dev_dbg(dev, "suspending\n"); 59 dev_dbg(dev, "suspending\n");
60 error = dev->bus->suspend(dev, state); 60 error = dev->bus->suspend(dev, state);
61 } 61 }
diff --git a/drivers/base/power/sysfs.c b/drivers/base/power/sysfs.c
index f82b3df9545..8d04fb435c1 100644
--- a/drivers/base/power/sysfs.c
+++ b/drivers/base/power/sysfs.c
@@ -26,19 +26,19 @@
26 26
27static ssize_t state_show(struct device * dev, struct device_attribute *attr, char * buf) 27static ssize_t state_show(struct device * dev, struct device_attribute *attr, char * buf)
28{ 28{
29 return sprintf(buf, "%u\n", dev->power.power_state); 29 return sprintf(buf, "%u\n", dev->power.power_state.event);
30} 30}
31 31
32static ssize_t state_store(struct device * dev, struct device_attribute *attr, const char * buf, size_t n) 32static ssize_t state_store(struct device * dev, struct device_attribute *attr, const char * buf, size_t n)
33{ 33{
34 u32 state; 34 pm_message_t state;
35 char * rest; 35 char * rest;
36 int error = 0; 36 int error = 0;
37 37
38 state = simple_strtoul(buf, &rest, 10); 38 state.event = simple_strtoul(buf, &rest, 10);
39 if (*rest) 39 if (*rest)
40 return -EINVAL; 40 return -EINVAL;
41 if (state) 41 if (state.event)
42 error = dpm_runtime_suspend(dev, state); 42 error = dpm_runtime_suspend(dev, state);
43 else 43 else
44 dpm_runtime_resume(dev); 44 dpm_runtime_resume(dev);
diff --git a/drivers/base/sys.c b/drivers/base/sys.c
index 214b9643540..3431eb6004c 100644
--- a/drivers/base/sys.c
+++ b/drivers/base/sys.c
@@ -288,6 +288,27 @@ void sysdev_shutdown(void)
288 up(&sysdev_drivers_lock); 288 up(&sysdev_drivers_lock);
289} 289}
290 290
291static void __sysdev_resume(struct sys_device *dev)
292{
293 struct sysdev_class *cls = dev->cls;
294 struct sysdev_driver *drv;
295
296 /* First, call the class-specific one */
297 if (cls->resume)
298 cls->resume(dev);
299
300 /* Call auxillary drivers next. */
301 list_for_each_entry(drv, &cls->drivers, entry) {
302 if (drv->resume)
303 drv->resume(dev);
304 }
305
306 /* Call global drivers. */
307 list_for_each_entry(drv, &sysdev_drivers, entry) {
308 if (drv->resume)
309 drv->resume(dev);
310 }
311}
291 312
292/** 313/**
293 * sysdev_suspend - Suspend all system devices. 314 * sysdev_suspend - Suspend all system devices.
@@ -305,38 +326,93 @@ void sysdev_shutdown(void)
305int sysdev_suspend(pm_message_t state) 326int sysdev_suspend(pm_message_t state)
306{ 327{
307 struct sysdev_class * cls; 328 struct sysdev_class * cls;
329 struct sys_device *sysdev, *err_dev;
330 struct sysdev_driver *drv, *err_drv;
331 int ret;
308 332
309 pr_debug("Suspending System Devices\n"); 333 pr_debug("Suspending System Devices\n");
310 334
311 list_for_each_entry_reverse(cls, &system_subsys.kset.list, 335 list_for_each_entry_reverse(cls, &system_subsys.kset.list,
312 kset.kobj.entry) { 336 kset.kobj.entry) {
313 struct sys_device * sysdev;
314 337
315 pr_debug("Suspending type '%s':\n", 338 pr_debug("Suspending type '%s':\n",
316 kobject_name(&cls->kset.kobj)); 339 kobject_name(&cls->kset.kobj));
317 340
318 list_for_each_entry(sysdev, &cls->kset.list, kobj.entry) { 341 list_for_each_entry(sysdev, &cls->kset.list, kobj.entry) {
319 struct sysdev_driver * drv;
320 pr_debug(" %s\n", kobject_name(&sysdev->kobj)); 342 pr_debug(" %s\n", kobject_name(&sysdev->kobj));
321 343
322 /* Call global drivers first. */ 344 /* Call global drivers first. */
323 list_for_each_entry(drv, &sysdev_drivers, entry) { 345 list_for_each_entry(drv, &sysdev_drivers, entry) {
324 if (drv->suspend) 346 if (drv->suspend) {
325 drv->suspend(sysdev, state); 347 ret = drv->suspend(sysdev, state);
348 if (ret)
349 goto gbl_driver;
350 }
326 } 351 }
327 352
328 /* Call auxillary drivers next. */ 353 /* Call auxillary drivers next. */
329 list_for_each_entry(drv, &cls->drivers, entry) { 354 list_for_each_entry(drv, &cls->drivers, entry) {
330 if (drv->suspend) 355 if (drv->suspend) {
331 drv->suspend(sysdev, state); 356 ret = drv->suspend(sysdev, state);
357 if (ret)
358 goto aux_driver;
359 }
332 } 360 }
333 361
334 /* Now call the generic one */ 362 /* Now call the generic one */
335 if (cls->suspend) 363 if (cls->suspend) {
336 cls->suspend(sysdev, state); 364 ret = cls->suspend(sysdev, state);
365 if (ret)
366 goto cls_driver;
367 }
337 } 368 }
338 } 369 }
339 return 0; 370 return 0;
371 /* resume current sysdev */
372cls_driver:
373 drv = NULL;
374 printk(KERN_ERR "Class suspend failed for %s\n",
375 kobject_name(&sysdev->kobj));
376
377aux_driver:
378 if (drv)
379 printk(KERN_ERR "Class driver suspend failed for %s\n",
380 kobject_name(&sysdev->kobj));
381 list_for_each_entry(err_drv, &cls->drivers, entry) {
382 if (err_drv == drv)
383 break;
384 if (err_drv->resume)
385 err_drv->resume(sysdev);
386 }
387 drv = NULL;
388
389gbl_driver:
390 if (drv)
391 printk(KERN_ERR "sysdev driver suspend failed for %s\n",
392 kobject_name(&sysdev->kobj));
393 list_for_each_entry(err_drv, &sysdev_drivers, entry) {
394 if (err_drv == drv)
395 break;
396 if (err_drv->resume)
397 err_drv->resume(sysdev);
398 }
399 /* resume other sysdevs in current class */
400 list_for_each_entry(err_dev, &cls->kset.list, kobj.entry) {
401 if (err_dev == sysdev)
402 break;
403 pr_debug(" %s\n", kobject_name(&err_dev->kobj));
404 __sysdev_resume(err_dev);
405 }
406
407 /* resume other classes */
408 list_for_each_entry_continue(cls, &system_subsys.kset.list,
409 kset.kobj.entry) {
410 list_for_each_entry(err_dev, &cls->kset.list, kobj.entry) {
411 pr_debug(" %s\n", kobject_name(&err_dev->kobj));
412 __sysdev_resume(err_dev);
413 }
414 }
415 return ret;
340} 416}
341 417
342 418
@@ -362,25 +438,9 @@ int sysdev_resume(void)
362 kobject_name(&cls->kset.kobj)); 438 kobject_name(&cls->kset.kobj));
363 439
364 list_for_each_entry(sysdev, &cls->kset.list, kobj.entry) { 440 list_for_each_entry(sysdev, &cls->kset.list, kobj.entry) {
365 struct sysdev_driver * drv;
366 pr_debug(" %s\n", kobject_name(&sysdev->kobj)); 441 pr_debug(" %s\n", kobject_name(&sysdev->kobj));
367 442
368 /* First, call the class-specific one */ 443 __sysdev_resume(sysdev);
369 if (cls->resume)
370 cls->resume(sysdev);
371
372 /* Call auxillary drivers next. */
373 list_for_each_entry(drv, &cls->drivers, entry) {
374 if (drv->resume)
375 drv->resume(sysdev);
376 }
377
378 /* Call global drivers. */
379 list_for_each_entry(drv, &sysdev_drivers, entry) {
380 if (drv->resume)
381 drv->resume(sysdev);
382 }
383
384 } 444 }
385 } 445 }
386 return 0; 446 return 0;
diff --git a/drivers/base/transport_class.c b/drivers/base/transport_class.c
index 6c2b447a333..f25e7c6b2d2 100644
--- a/drivers/base/transport_class.c
+++ b/drivers/base/transport_class.c
@@ -7,7 +7,7 @@
7 * This file is licensed under GPLv2 7 * This file is licensed under GPLv2
8 * 8 *
9 * The basic idea here is to allow any "device controller" (which 9 * The basic idea here is to allow any "device controller" (which
10 * would most often be a Host Bus Adapter" to use the services of one 10 * would most often be a Host Bus Adapter to use the services of one
11 * or more tranport classes for performing transport specific 11 * or more tranport classes for performing transport specific
12 * services. Transport specific services are things that the generic 12 * services. Transport specific services are things that the generic
13 * command layer doesn't want to know about (speed settings, line 13 * command layer doesn't want to know about (speed settings, line
@@ -64,7 +64,9 @@ void transport_class_unregister(struct transport_class *tclass)
64} 64}
65EXPORT_SYMBOL_GPL(transport_class_unregister); 65EXPORT_SYMBOL_GPL(transport_class_unregister);
66 66
67static int anon_transport_dummy_function(struct device *dev) 67static int anon_transport_dummy_function(struct transport_container *tc,
68 struct device *dev,
69 struct class_device *cdev)
68{ 70{
69 /* do nothing */ 71 /* do nothing */
70 return 0; 72 return 0;
@@ -115,9 +117,10 @@ static int transport_setup_classdev(struct attribute_container *cont,
115 struct class_device *classdev) 117 struct class_device *classdev)
116{ 118{
117 struct transport_class *tclass = class_to_transport_class(cont->class); 119 struct transport_class *tclass = class_to_transport_class(cont->class);
120 struct transport_container *tcont = attribute_container_to_transport_container(cont);
118 121
119 if (tclass->setup) 122 if (tclass->setup)
120 tclass->setup(dev); 123 tclass->setup(tcont, dev, classdev);
121 124
122 return 0; 125 return 0;
123} 126}
@@ -178,12 +181,14 @@ void transport_add_device(struct device *dev)
178EXPORT_SYMBOL_GPL(transport_add_device); 181EXPORT_SYMBOL_GPL(transport_add_device);
179 182
180static int transport_configure(struct attribute_container *cont, 183static int transport_configure(struct attribute_container *cont,
181 struct device *dev) 184 struct device *dev,
185 struct class_device *cdev)
182{ 186{
183 struct transport_class *tclass = class_to_transport_class(cont->class); 187 struct transport_class *tclass = class_to_transport_class(cont->class);
188 struct transport_container *tcont = attribute_container_to_transport_container(cont);
184 189
185 if (tclass->configure) 190 if (tclass->configure)
186 tclass->configure(dev); 191 tclass->configure(tcont, dev, cdev);
187 192
188 return 0; 193 return 0;
189} 194}
@@ -202,7 +207,7 @@ static int transport_configure(struct attribute_container *cont,
202 */ 207 */
203void transport_configure_device(struct device *dev) 208void transport_configure_device(struct device *dev)
204{ 209{
205 attribute_container_trigger(dev, transport_configure); 210 attribute_container_device_trigger(dev, transport_configure);
206} 211}
207EXPORT_SYMBOL_GPL(transport_configure_device); 212EXPORT_SYMBOL_GPL(transport_configure_device);
208 213
@@ -215,7 +220,7 @@ static int transport_remove_classdev(struct attribute_container *cont,
215 struct transport_class *tclass = class_to_transport_class(cont->class); 220 struct transport_class *tclass = class_to_transport_class(cont->class);
216 221
217 if (tclass->remove) 222 if (tclass->remove)
218 tclass->remove(dev); 223 tclass->remove(tcont, dev, classdev);
219 224
220 if (tclass->remove != anon_transport_dummy_function) { 225 if (tclass->remove != anon_transport_dummy_function) {
221 if (tcont->statistics) 226 if (tcont->statistics)
diff --git a/drivers/block/Kconfig b/drivers/block/Kconfig
index b594768b024..51b0af1cebe 100644
--- a/drivers/block/Kconfig
+++ b/drivers/block/Kconfig
@@ -6,7 +6,7 @@ menu "Block devices"
6 6
7config BLK_DEV_FD 7config BLK_DEV_FD
8 tristate "Normal floppy disk support" 8 tristate "Normal floppy disk support"
9 depends on (!ARCH_S390 && !M68K && !IA64 && !UML && !ARM) || Q40 || (SUN3X && BROKEN) || ARCH_RPC || ARCH_EBSA285 9 depends on ARCH_MAY_HAVE_PC_FDC
10 ---help--- 10 ---help---
11 If you want to use the floppy disk drive(s) of your PC under Linux, 11 If you want to use the floppy disk drive(s) of your PC under Linux,
12 say Y. Information about this driver, especially important for IBM 12 say Y. Information about this driver, especially important for IBM
@@ -408,54 +408,12 @@ config BLK_DEV_INITRD
408 "real" root file system, etc. See <file:Documentation/initrd.txt> 408 "real" root file system, etc. See <file:Documentation/initrd.txt>
409 for details. 409 for details.
410 410
411config INITRAMFS_SOURCE
412 string "Initramfs source file(s)"
413 default ""
414 help
415 This can be either a single cpio archive with a .cpio suffix or a
416 space-separated list of directories and files for building the
417 initramfs image. A cpio archive should contain a filesystem archive
418 to be used as an initramfs image. Directories should contain a
419 filesystem layout to be included in the initramfs image. Files
420 should contain entries according to the format described by the
421 "usr/gen_init_cpio" program in the kernel tree.
422
423 When multiple directories and files are specified then the
424 initramfs image will be the aggregate of all of them.
425
426 See <file:Documentation/early-userspace/README for more details.
427
428 If you are not sure, leave it blank.
429
430config INITRAMFS_ROOT_UID
431 int "User ID to map to 0 (user root)"
432 depends on INITRAMFS_SOURCE!=""
433 default "0"
434 help
435 This setting is only meaningful if the INITRAMFS_SOURCE is
436 contains a directory. Setting this user ID (UID) to something
437 other than "0" will cause all files owned by that UID to be
438 owned by user root in the initial ramdisk image.
439
440 If you are not sure, leave it set to "0".
441
442config INITRAMFS_ROOT_GID
443 int "Group ID to map to 0 (group root)"
444 depends on INITRAMFS_SOURCE!=""
445 default "0"
446 help
447 This setting is only meaningful if the INITRAMFS_SOURCE is
448 contains a directory. Setting this group ID (GID) to something
449 other than "0" will cause all files owned by that GID to be
450 owned by group root in the initial ramdisk image.
451
452 If you are not sure, leave it set to "0".
453 411
454#XXX - it makes sense to enable this only for 32-bit subarch's, not for x86_64 412#XXX - it makes sense to enable this only for 32-bit subarch's, not for x86_64
455#for instance. 413#for instance.
456config LBD 414config LBD
457 bool "Support for Large Block Devices" 415 bool "Support for Large Block Devices"
458 depends on X86 || MIPS32 || PPC32 || ARCH_S390_31 || SUPERH || UML 416 depends on X86 || (MIPS && 32BIT) || PPC32 || ARCH_S390_31 || SUPERH || UML
459 help 417 help
460 Say Y here if you want to attach large (bigger than 2TB) discs to 418 Say Y here if you want to attach large (bigger than 2TB) discs to
461 your machine, or if you want to have a raid or loopback device 419 your machine, or if you want to have a raid or loopback device
diff --git a/drivers/block/aoe/aoedev.c b/drivers/block/aoe/aoedev.c
index 6e231c5a119..ded33ba31ac 100644
--- a/drivers/block/aoe/aoedev.c
+++ b/drivers/block/aoe/aoedev.c
@@ -35,7 +35,7 @@ aoedev_newdev(ulong nframes)
35 struct aoedev *d; 35 struct aoedev *d;
36 struct frame *f, *e; 36 struct frame *f, *e;
37 37
38 d = kcalloc(1, sizeof *d, GFP_ATOMIC); 38 d = kzalloc(sizeof *d, GFP_ATOMIC);
39 if (d == NULL) 39 if (d == NULL)
40 return NULL; 40 return NULL;
41 f = kcalloc(nframes, sizeof *f, GFP_ATOMIC); 41 f = kcalloc(nframes, sizeof *f, GFP_ATOMIC);
diff --git a/drivers/block/cfq-iosched.c b/drivers/block/cfq-iosched.c
index cd056e7e64e..30c0903c7cd 100644
--- a/drivers/block/cfq-iosched.c
+++ b/drivers/block/cfq-iosched.c
@@ -2260,8 +2260,6 @@ static void cfq_put_cfqd(struct cfq_data *cfqd)
2260 if (!atomic_dec_and_test(&cfqd->ref)) 2260 if (!atomic_dec_and_test(&cfqd->ref))
2261 return; 2261 return;
2262 2262
2263 blk_put_queue(q);
2264
2265 cfq_shutdown_timer_wq(cfqd); 2263 cfq_shutdown_timer_wq(cfqd);
2266 q->elevator->elevator_data = NULL; 2264 q->elevator->elevator_data = NULL;
2267 2265
@@ -2318,7 +2316,6 @@ static int cfq_init_queue(request_queue_t *q, elevator_t *e)
2318 e->elevator_data = cfqd; 2316 e->elevator_data = cfqd;
2319 2317
2320 cfqd->queue = q; 2318 cfqd->queue = q;
2321 atomic_inc(&q->refcnt);
2322 2319
2323 cfqd->max_queued = q->nr_requests / 4; 2320 cfqd->max_queued = q->nr_requests / 4;
2324 q->nr_batching = cfq_queued; 2321 q->nr_batching = cfq_queued;
diff --git a/drivers/block/cryptoloop.c b/drivers/block/cryptoloop.c
index 5be6f998d8c..3d4261c39f1 100644
--- a/drivers/block/cryptoloop.c
+++ b/drivers/block/cryptoloop.c
@@ -57,9 +57,11 @@ cryptoloop_init(struct loop_device *lo, const struct loop_info64 *info)
57 mode = strsep(&cmsp, "-"); 57 mode = strsep(&cmsp, "-");
58 58
59 if (mode == NULL || strcmp(mode, "cbc") == 0) 59 if (mode == NULL || strcmp(mode, "cbc") == 0)
60 tfm = crypto_alloc_tfm(cipher, CRYPTO_TFM_MODE_CBC); 60 tfm = crypto_alloc_tfm(cipher, CRYPTO_TFM_MODE_CBC |
61 CRYPTO_TFM_REQ_MAY_SLEEP);
61 else if (strcmp(mode, "ecb") == 0) 62 else if (strcmp(mode, "ecb") == 0)
62 tfm = crypto_alloc_tfm(cipher, CRYPTO_TFM_MODE_ECB); 63 tfm = crypto_alloc_tfm(cipher, CRYPTO_TFM_MODE_ECB |
64 CRYPTO_TFM_REQ_MAY_SLEEP);
63 if (tfm == NULL) 65 if (tfm == NULL)
64 return -EINVAL; 66 return -EINVAL;
65 67
diff --git a/drivers/block/deadline-iosched.c b/drivers/block/deadline-iosched.c
index ff5201e0215..24594c57c32 100644
--- a/drivers/block/deadline-iosched.c
+++ b/drivers/block/deadline-iosched.c
@@ -507,18 +507,12 @@ static int deadline_dispatch_requests(struct deadline_data *dd)
507 const int reads = !list_empty(&dd->fifo_list[READ]); 507 const int reads = !list_empty(&dd->fifo_list[READ]);
508 const int writes = !list_empty(&dd->fifo_list[WRITE]); 508 const int writes = !list_empty(&dd->fifo_list[WRITE]);
509 struct deadline_rq *drq; 509 struct deadline_rq *drq;
510 int data_dir, other_dir; 510 int data_dir;
511 511
512 /* 512 /*
513 * batches are currently reads XOR writes 513 * batches are currently reads XOR writes
514 */ 514 */
515 drq = NULL; 515 drq = dd->next_drq[WRITE] ? : dd->next_drq[READ];
516
517 if (dd->next_drq[READ])
518 drq = dd->next_drq[READ];
519
520 if (dd->next_drq[WRITE])
521 drq = dd->next_drq[WRITE];
522 516
523 if (drq) { 517 if (drq) {
524 /* we have a "next request" */ 518 /* we have a "next request" */
@@ -544,7 +538,6 @@ static int deadline_dispatch_requests(struct deadline_data *dd)
544 goto dispatch_writes; 538 goto dispatch_writes;
545 539
546 data_dir = READ; 540 data_dir = READ;
547 other_dir = WRITE;
548 541
549 goto dispatch_find_request; 542 goto dispatch_find_request;
550 } 543 }
@@ -560,7 +553,6 @@ dispatch_writes:
560 dd->starved = 0; 553 dd->starved = 0;
561 554
562 data_dir = WRITE; 555 data_dir = WRITE;
563 other_dir = READ;
564 556
565 goto dispatch_find_request; 557 goto dispatch_find_request;
566 } 558 }
diff --git a/drivers/block/floppy.c b/drivers/block/floppy.c
index f0c1084b840..888dad5eef3 100644
--- a/drivers/block/floppy.c
+++ b/drivers/block/floppy.c
@@ -493,6 +493,8 @@ static struct floppy_struct user_params[N_DRIVE];
493 493
494static sector_t floppy_sizes[256]; 494static sector_t floppy_sizes[256];
495 495
496static char floppy_device_name[] = "floppy";
497
496/* 498/*
497 * The driver is trying to determine the correct media format 499 * The driver is trying to determine the correct media format
498 * while probing is set. rw_interrupt() clears it after a 500 * while probing is set. rw_interrupt() clears it after a
@@ -4191,18 +4193,24 @@ static int __init floppy_setup(char *str)
4191 4193
4192static int have_no_fdc = -ENODEV; 4194static int have_no_fdc = -ENODEV;
4193 4195
4196static ssize_t floppy_cmos_show(struct device *dev,
4197 struct device_attribute *attr, char *buf)
4198{
4199 struct platform_device *p;
4200 int drive;
4201
4202 p = container_of(dev, struct platform_device,dev);
4203 drive = p->id;
4204 return sprintf(buf, "%X\n", UDP->cmos);
4205}
4206DEVICE_ATTR(cmos,S_IRUGO,floppy_cmos_show,NULL);
4207
4194static void floppy_device_release(struct device *dev) 4208static void floppy_device_release(struct device *dev)
4195{ 4209{
4196 complete(&device_release); 4210 complete(&device_release);
4197} 4211}
4198 4212
4199static struct platform_device floppy_device = { 4213static struct platform_device floppy_device[N_DRIVE];
4200 .name = "floppy",
4201 .id = 0,
4202 .dev = {
4203 .release = floppy_device_release,
4204 }
4205};
4206 4214
4207static struct kobject *floppy_find(dev_t dev, int *part, void *data) 4215static struct kobject *floppy_find(dev_t dev, int *part, void *data)
4208{ 4216{
@@ -4370,20 +4378,26 @@ static int __init floppy_init(void)
4370 goto out_flush_work; 4378 goto out_flush_work;
4371 } 4379 }
4372 4380
4373 err = platform_device_register(&floppy_device);
4374 if (err)
4375 goto out_flush_work;
4376
4377 for (drive = 0; drive < N_DRIVE; drive++) { 4381 for (drive = 0; drive < N_DRIVE; drive++) {
4378 if (!(allowed_drive_mask & (1 << drive))) 4382 if (!(allowed_drive_mask & (1 << drive)))
4379 continue; 4383 continue;
4380 if (fdc_state[FDC(drive)].version == FDC_NONE) 4384 if (fdc_state[FDC(drive)].version == FDC_NONE)
4381 continue; 4385 continue;
4386
4387 floppy_device[drive].name = floppy_device_name;
4388 floppy_device[drive].id = drive;
4389 floppy_device[drive].dev.release = floppy_device_release;
4390
4391 err = platform_device_register(&floppy_device[drive]);
4392 if (err)
4393 goto out_flush_work;
4394
4395 device_create_file(&floppy_device[drive].dev,&dev_attr_cmos);
4382 /* to be cleaned up... */ 4396 /* to be cleaned up... */
4383 disks[drive]->private_data = (void *)(long)drive; 4397 disks[drive]->private_data = (void *)(long)drive;
4384 disks[drive]->queue = floppy_queue; 4398 disks[drive]->queue = floppy_queue;
4385 disks[drive]->flags |= GENHD_FL_REMOVABLE; 4399 disks[drive]->flags |= GENHD_FL_REMOVABLE;
4386 disks[drive]->driverfs_dev = &floppy_device.dev; 4400 disks[drive]->driverfs_dev = &floppy_device[drive].dev;
4387 add_disk(disks[drive]); 4401 add_disk(disks[drive]);
4388 } 4402 }
4389 4403
@@ -4603,10 +4617,11 @@ void cleanup_module(void)
4603 fdc_state[FDC(drive)].version != FDC_NONE) { 4617 fdc_state[FDC(drive)].version != FDC_NONE) {
4604 del_gendisk(disks[drive]); 4618 del_gendisk(disks[drive]);
4605 unregister_devfs_entries(drive); 4619 unregister_devfs_entries(drive);
4620 device_remove_file(&floppy_device[drive].dev, &dev_attr_cmos);
4621 platform_device_unregister(&floppy_device[drive]);
4606 } 4622 }
4607 put_disk(disks[drive]); 4623 put_disk(disks[drive]);
4608 } 4624 }
4609 platform_device_unregister(&floppy_device);
4610 devfs_remove("floppy"); 4625 devfs_remove("floppy");
4611 4626
4612 del_timer_sync(&fd_timeout); 4627 del_timer_sync(&fd_timeout);
diff --git a/drivers/block/genhd.c b/drivers/block/genhd.c
index 47fd3659a06..d42840cc0d1 100644
--- a/drivers/block/genhd.c
+++ b/drivers/block/genhd.c
@@ -45,7 +45,7 @@ int get_blkdev_list(char *p, int used)
45 struct blk_major_name *n; 45 struct blk_major_name *n;
46 int i, len; 46 int i, len;
47 47
48 len = sprintf(p, "\nBlock devices:\n"); 48 len = snprintf(p, (PAGE_SIZE-used), "\nBlock devices:\n");
49 49
50 down(&block_subsys_sem); 50 down(&block_subsys_sem);
51 for (i = 0; i < ARRAY_SIZE(major_names); i++) { 51 for (i = 0; i < ARRAY_SIZE(major_names); i++) {
diff --git a/drivers/block/ll_rw_blk.c b/drivers/block/ll_rw_blk.c
index 3c818544475..483d71b10cf 100644
--- a/drivers/block/ll_rw_blk.c
+++ b/drivers/block/ll_rw_blk.c
@@ -235,8 +235,8 @@ void blk_queue_make_request(request_queue_t * q, make_request_fn * mfn)
235 * set defaults 235 * set defaults
236 */ 236 */
237 q->nr_requests = BLKDEV_MAX_RQ; 237 q->nr_requests = BLKDEV_MAX_RQ;
238 q->max_phys_segments = MAX_PHYS_SEGMENTS; 238 blk_queue_max_phys_segments(q, MAX_PHYS_SEGMENTS);
239 q->max_hw_segments = MAX_HW_SEGMENTS; 239 blk_queue_max_hw_segments(q, MAX_HW_SEGMENTS);
240 q->make_request_fn = mfn; 240 q->make_request_fn = mfn;
241 q->backing_dev_info.ra_pages = (VM_MAX_READAHEAD * 1024) / PAGE_CACHE_SIZE; 241 q->backing_dev_info.ra_pages = (VM_MAX_READAHEAD * 1024) / PAGE_CACHE_SIZE;
242 q->backing_dev_info.state = 0; 242 q->backing_dev_info.state = 0;
@@ -284,6 +284,7 @@ static inline void rq_init(request_queue_t *q, struct request *rq)
284 rq->special = NULL; 284 rq->special = NULL;
285 rq->data_len = 0; 285 rq->data_len = 0;
286 rq->data = NULL; 286 rq->data = NULL;
287 rq->nr_phys_segments = 0;
287 rq->sense = NULL; 288 rq->sense = NULL;
288 rq->end_io = NULL; 289 rq->end_io = NULL;
289 rq->end_io_data = NULL; 290 rq->end_io_data = NULL;
@@ -2115,7 +2116,7 @@ EXPORT_SYMBOL(blk_insert_request);
2115/** 2116/**
2116 * blk_rq_map_user - map user data to a request, for REQ_BLOCK_PC usage 2117 * blk_rq_map_user - map user data to a request, for REQ_BLOCK_PC usage
2117 * @q: request queue where request should be inserted 2118 * @q: request queue where request should be inserted
2118 * @rw: READ or WRITE data 2119 * @rq: request structure to fill
2119 * @ubuf: the user buffer 2120 * @ubuf: the user buffer
2120 * @len: length of user data 2121 * @len: length of user data
2121 * 2122 *
@@ -2132,21 +2133,19 @@ EXPORT_SYMBOL(blk_insert_request);
2132 * original bio must be passed back in to blk_rq_unmap_user() for proper 2133 * original bio must be passed back in to blk_rq_unmap_user() for proper
2133 * unmapping. 2134 * unmapping.
2134 */ 2135 */
2135struct request *blk_rq_map_user(request_queue_t *q, int rw, void __user *ubuf, 2136int blk_rq_map_user(request_queue_t *q, struct request *rq, void __user *ubuf,
2136 unsigned int len) 2137 unsigned int len)
2137{ 2138{
2138 unsigned long uaddr; 2139 unsigned long uaddr;
2139 struct request *rq;
2140 struct bio *bio; 2140 struct bio *bio;
2141 int reading;
2141 2142
2142 if (len > (q->max_sectors << 9)) 2143 if (len > (q->max_sectors << 9))
2143 return ERR_PTR(-EINVAL); 2144 return -EINVAL;
2144 if ((!len && ubuf) || (len && !ubuf)) 2145 if (!len || !ubuf)
2145 return ERR_PTR(-EINVAL); 2146 return -EINVAL;
2146 2147
2147 rq = blk_get_request(q, rw, __GFP_WAIT); 2148 reading = rq_data_dir(rq) == READ;
2148 if (!rq)
2149 return ERR_PTR(-ENOMEM);
2150 2149
2151 /* 2150 /*
2152 * if alignment requirement is satisfied, map in user pages for 2151 * if alignment requirement is satisfied, map in user pages for
@@ -2154,9 +2153,9 @@ struct request *blk_rq_map_user(request_queue_t *q, int rw, void __user *ubuf,
2154 */ 2153 */
2155 uaddr = (unsigned long) ubuf; 2154 uaddr = (unsigned long) ubuf;
2156 if (!(uaddr & queue_dma_alignment(q)) && !(len & queue_dma_alignment(q))) 2155 if (!(uaddr & queue_dma_alignment(q)) && !(len & queue_dma_alignment(q)))
2157 bio = bio_map_user(q, NULL, uaddr, len, rw == READ); 2156 bio = bio_map_user(q, NULL, uaddr, len, reading);
2158 else 2157 else
2159 bio = bio_copy_user(q, uaddr, len, rw == READ); 2158 bio = bio_copy_user(q, uaddr, len, reading);
2160 2159
2161 if (!IS_ERR(bio)) { 2160 if (!IS_ERR(bio)) {
2162 rq->bio = rq->biotail = bio; 2161 rq->bio = rq->biotail = bio;
@@ -2164,28 +2163,70 @@ struct request *blk_rq_map_user(request_queue_t *q, int rw, void __user *ubuf,
2164 2163
2165 rq->buffer = rq->data = NULL; 2164 rq->buffer = rq->data = NULL;
2166 rq->data_len = len; 2165 rq->data_len = len;
2167 return rq; 2166 return 0;
2168 } 2167 }
2169 2168
2170 /* 2169 /*
2171 * bio is the err-ptr 2170 * bio is the err-ptr
2172 */ 2171 */
2173 blk_put_request(rq); 2172 return PTR_ERR(bio);
2174 return (struct request *) bio;
2175} 2173}
2176 2174
2177EXPORT_SYMBOL(blk_rq_map_user); 2175EXPORT_SYMBOL(blk_rq_map_user);
2178 2176
2179/** 2177/**
2178 * blk_rq_map_user_iov - map user data to a request, for REQ_BLOCK_PC usage
2179 * @q: request queue where request should be inserted
2180 * @rq: request to map data to
2181 * @iov: pointer to the iovec
2182 * @iov_count: number of elements in the iovec
2183 *
2184 * Description:
2185 * Data will be mapped directly for zero copy io, if possible. Otherwise
2186 * a kernel bounce buffer is used.
2187 *
2188 * A matching blk_rq_unmap_user() must be issued at the end of io, while
2189 * still in process context.
2190 *
2191 * Note: The mapped bio may need to be bounced through blk_queue_bounce()
2192 * before being submitted to the device, as pages mapped may be out of
2193 * reach. It's the callers responsibility to make sure this happens. The
2194 * original bio must be passed back in to blk_rq_unmap_user() for proper
2195 * unmapping.
2196 */
2197int blk_rq_map_user_iov(request_queue_t *q, struct request *rq,
2198 struct sg_iovec *iov, int iov_count)
2199{
2200 struct bio *bio;
2201
2202 if (!iov || iov_count <= 0)
2203 return -EINVAL;
2204
2205 /* we don't allow misaligned data like bio_map_user() does. If the
2206 * user is using sg, they're expected to know the alignment constraints
2207 * and respect them accordingly */
2208 bio = bio_map_user_iov(q, NULL, iov, iov_count, rq_data_dir(rq)== READ);
2209 if (IS_ERR(bio))
2210 return PTR_ERR(bio);
2211
2212 rq->bio = rq->biotail = bio;
2213 blk_rq_bio_prep(q, rq, bio);
2214 rq->buffer = rq->data = NULL;
2215 rq->data_len = bio->bi_size;
2216 return 0;
2217}
2218
2219EXPORT_SYMBOL(blk_rq_map_user_iov);
2220
2221/**
2180 * blk_rq_unmap_user - unmap a request with user data 2222 * blk_rq_unmap_user - unmap a request with user data
2181 * @rq: request to be unmapped 2223 * @bio: bio to be unmapped
2182 * @bio: bio for the request
2183 * @ulen: length of user buffer 2224 * @ulen: length of user buffer
2184 * 2225 *
2185 * Description: 2226 * Description:
2186 * Unmap a request previously mapped by blk_rq_map_user(). 2227 * Unmap a bio previously mapped by blk_rq_map_user().
2187 */ 2228 */
2188int blk_rq_unmap_user(struct request *rq, struct bio *bio, unsigned int ulen) 2229int blk_rq_unmap_user(struct bio *bio, unsigned int ulen)
2189{ 2230{
2190 int ret = 0; 2231 int ret = 0;
2191 2232
@@ -2196,31 +2237,89 @@ int blk_rq_unmap_user(struct request *rq, struct bio *bio, unsigned int ulen)
2196 ret = bio_uncopy_user(bio); 2237 ret = bio_uncopy_user(bio);
2197 } 2238 }
2198 2239
2199 blk_put_request(rq); 2240 return 0;
2200 return ret;
2201} 2241}
2202 2242
2203EXPORT_SYMBOL(blk_rq_unmap_user); 2243EXPORT_SYMBOL(blk_rq_unmap_user);
2204 2244
2205/** 2245/**
2246 * blk_rq_map_kern - map kernel data to a request, for REQ_BLOCK_PC usage
2247 * @q: request queue where request should be inserted
2248 * @rq: request to fill
2249 * @kbuf: the kernel buffer
2250 * @len: length of user data
2251 * @gfp_mask: memory allocation flags
2252 */
2253int blk_rq_map_kern(request_queue_t *q, struct request *rq, void *kbuf,
2254 unsigned int len, unsigned int gfp_mask)
2255{
2256 struct bio *bio;
2257
2258 if (len > (q->max_sectors << 9))
2259 return -EINVAL;
2260 if (!len || !kbuf)
2261 return -EINVAL;
2262
2263 bio = bio_map_kern(q, kbuf, len, gfp_mask);
2264 if (IS_ERR(bio))
2265 return PTR_ERR(bio);
2266
2267 if (rq_data_dir(rq) == WRITE)
2268 bio->bi_rw |= (1 << BIO_RW);
2269
2270 rq->bio = rq->biotail = bio;
2271 blk_rq_bio_prep(q, rq, bio);
2272
2273 rq->buffer = rq->data = NULL;
2274 rq->data_len = len;
2275 return 0;
2276}
2277
2278EXPORT_SYMBOL(blk_rq_map_kern);
2279
2280/**
2281 * blk_execute_rq_nowait - insert a request into queue for execution
2282 * @q: queue to insert the request in
2283 * @bd_disk: matching gendisk
2284 * @rq: request to insert
2285 * @at_head: insert request at head or tail of queue
2286 * @done: I/O completion handler
2287 *
2288 * Description:
2289 * Insert a fully prepared request at the back of the io scheduler queue
2290 * for execution. Don't wait for completion.
2291 */
2292void blk_execute_rq_nowait(request_queue_t *q, struct gendisk *bd_disk,
2293 struct request *rq, int at_head,
2294 void (*done)(struct request *))
2295{
2296 int where = at_head ? ELEVATOR_INSERT_FRONT : ELEVATOR_INSERT_BACK;
2297
2298 rq->rq_disk = bd_disk;
2299 rq->flags |= REQ_NOMERGE;
2300 rq->end_io = done;
2301 elv_add_request(q, rq, where, 1);
2302 generic_unplug_device(q);
2303}
2304
2305/**
2206 * blk_execute_rq - insert a request into queue for execution 2306 * blk_execute_rq - insert a request into queue for execution
2207 * @q: queue to insert the request in 2307 * @q: queue to insert the request in
2208 * @bd_disk: matching gendisk 2308 * @bd_disk: matching gendisk
2209 * @rq: request to insert 2309 * @rq: request to insert
2310 * @at_head: insert request at head or tail of queue
2210 * 2311 *
2211 * Description: 2312 * Description:
2212 * Insert a fully prepared request at the back of the io scheduler queue 2313 * Insert a fully prepared request at the back of the io scheduler queue
2213 * for execution. 2314 * for execution and wait for completion.
2214 */ 2315 */
2215int blk_execute_rq(request_queue_t *q, struct gendisk *bd_disk, 2316int blk_execute_rq(request_queue_t *q, struct gendisk *bd_disk,
2216 struct request *rq) 2317 struct request *rq, int at_head)
2217{ 2318{
2218 DECLARE_COMPLETION(wait); 2319 DECLARE_COMPLETION(wait);
2219 char sense[SCSI_SENSE_BUFFERSIZE]; 2320 char sense[SCSI_SENSE_BUFFERSIZE];
2220 int err = 0; 2321 int err = 0;
2221 2322
2222 rq->rq_disk = bd_disk;
2223
2224 /* 2323 /*
2225 * we need an extra reference to the request, so we can look at 2324 * we need an extra reference to the request, so we can look at
2226 * it after io completion 2325 * it after io completion
@@ -2233,11 +2332,8 @@ int blk_execute_rq(request_queue_t *q, struct gendisk *bd_disk,
2233 rq->sense_len = 0; 2332 rq->sense_len = 0;
2234 } 2333 }
2235 2334
2236 rq->flags |= REQ_NOMERGE;
2237 rq->waiting = &wait; 2335 rq->waiting = &wait;
2238 rq->end_io = blk_end_sync_rq; 2336 blk_execute_rq_nowait(q, bd_disk, rq, at_head, blk_end_sync_rq);
2239 elv_add_request(q, rq, ELEVATOR_INSERT_BACK, 1);
2240 generic_unplug_device(q);
2241 wait_for_completion(&wait); 2337 wait_for_completion(&wait);
2242 rq->waiting = NULL; 2338 rq->waiting = NULL;
2243 2339
@@ -2277,6 +2373,44 @@ int blkdev_issue_flush(struct block_device *bdev, sector_t *error_sector)
2277 2373
2278EXPORT_SYMBOL(blkdev_issue_flush); 2374EXPORT_SYMBOL(blkdev_issue_flush);
2279 2375
2376/**
2377 * blkdev_scsi_issue_flush_fn - issue flush for SCSI devices
2378 * @q: device queue
2379 * @disk: gendisk
2380 * @error_sector: error offset
2381 *
2382 * Description:
2383 * Devices understanding the SCSI command set, can use this function as
2384 * a helper for issuing a cache flush. Note: driver is required to store
2385 * the error offset (in case of error flushing) in ->sector of struct
2386 * request.
2387 */
2388int blkdev_scsi_issue_flush_fn(request_queue_t *q, struct gendisk *disk,
2389 sector_t *error_sector)
2390{
2391 struct request *rq = blk_get_request(q, WRITE, __GFP_WAIT);
2392 int ret;
2393
2394 rq->flags |= REQ_BLOCK_PC | REQ_SOFTBARRIER;
2395 rq->sector = 0;
2396 memset(rq->cmd, 0, sizeof(rq->cmd));
2397 rq->cmd[0] = 0x35;
2398 rq->cmd_len = 12;
2399 rq->data = NULL;
2400 rq->data_len = 0;
2401 rq->timeout = 60 * HZ;
2402
2403 ret = blk_execute_rq(q, disk, rq, 0);
2404
2405 if (ret && error_sector)
2406 *error_sector = rq->sector;
2407
2408 blk_put_request(rq);
2409 return ret;
2410}
2411
2412EXPORT_SYMBOL(blkdev_scsi_issue_flush_fn);
2413
2280static void drive_stat_acct(struct request *rq, int nr_sectors, int new_io) 2414static void drive_stat_acct(struct request *rq, int nr_sectors, int new_io)
2281{ 2415{
2282 int rw = rq_data_dir(rq); 2416 int rw = rq_data_dir(rq);
diff --git a/drivers/block/scsi_ioctl.c b/drivers/block/scsi_ioctl.c
index 681871ca5d6..abb2df249fd 100644
--- a/drivers/block/scsi_ioctl.c
+++ b/drivers/block/scsi_ioctl.c
@@ -216,7 +216,7 @@ static int sg_io(struct file *file, request_queue_t *q,
216 struct gendisk *bd_disk, struct sg_io_hdr *hdr) 216 struct gendisk *bd_disk, struct sg_io_hdr *hdr)
217{ 217{
218 unsigned long start_time; 218 unsigned long start_time;
219 int reading, writing; 219 int writing = 0, ret = 0;
220 struct request *rq; 220 struct request *rq;
221 struct bio *bio; 221 struct bio *bio;
222 char sense[SCSI_SENSE_BUFFERSIZE]; 222 char sense[SCSI_SENSE_BUFFERSIZE];
@@ -231,38 +231,48 @@ static int sg_io(struct file *file, request_queue_t *q,
231 if (verify_command(file, cmd)) 231 if (verify_command(file, cmd))
232 return -EPERM; 232 return -EPERM;
233 233
234 /*
235 * we'll do that later
236 */
237 if (hdr->iovec_count)
238 return -EOPNOTSUPP;
239
240 if (hdr->dxfer_len > (q->max_sectors << 9)) 234 if (hdr->dxfer_len > (q->max_sectors << 9))
241 return -EIO; 235 return -EIO;
242 236
243 reading = writing = 0; 237 if (hdr->dxfer_len)
244 if (hdr->dxfer_len) {
245 switch (hdr->dxfer_direction) { 238 switch (hdr->dxfer_direction) {
246 default: 239 default:
247 return -EINVAL; 240 return -EINVAL;
248 case SG_DXFER_TO_FROM_DEV: 241 case SG_DXFER_TO_FROM_DEV:
249 reading = 1;
250 /* fall through */
251 case SG_DXFER_TO_DEV: 242 case SG_DXFER_TO_DEV:
252 writing = 1; 243 writing = 1;
253 break; 244 break;
254 case SG_DXFER_FROM_DEV: 245 case SG_DXFER_FROM_DEV:
255 reading = 1;
256 break; 246 break;
257 } 247 }
258 248
259 rq = blk_rq_map_user(q, writing ? WRITE : READ, hdr->dxferp, 249 rq = blk_get_request(q, writing ? WRITE : READ, GFP_KERNEL);
260 hdr->dxfer_len); 250 if (!rq)
251 return -ENOMEM;
252
253 if (hdr->iovec_count) {
254 const int size = sizeof(struct sg_iovec) * hdr->iovec_count;
255 struct sg_iovec *iov;
256
257 iov = kmalloc(size, GFP_KERNEL);
258 if (!iov) {
259 ret = -ENOMEM;
260 goto out;
261 }
262
263 if (copy_from_user(iov, hdr->dxferp, size)) {
264 kfree(iov);
265 ret = -EFAULT;
266 goto out;
267 }
268
269 ret = blk_rq_map_user_iov(q, rq, iov, hdr->iovec_count);
270 kfree(iov);
271 } else if (hdr->dxfer_len)
272 ret = blk_rq_map_user(q, rq, hdr->dxferp, hdr->dxfer_len);
261 273
262 if (IS_ERR(rq)) 274 if (ret)
263 return PTR_ERR(rq); 275 goto out;
264 } else
265 rq = blk_get_request(q, READ, __GFP_WAIT);
266 276
267 /* 277 /*
268 * fill in request structure 278 * fill in request structure
@@ -298,7 +308,7 @@ static int sg_io(struct file *file, request_queue_t *q,
298 * (if he doesn't check that is his problem). 308 * (if he doesn't check that is his problem).
299 * N.B. a non-zero SCSI status is _not_ necessarily an error. 309 * N.B. a non-zero SCSI status is _not_ necessarily an error.
300 */ 310 */
301 blk_execute_rq(q, bd_disk, rq); 311 blk_execute_rq(q, bd_disk, rq, 0);
302 312
303 /* write to all output members */ 313 /* write to all output members */
304 hdr->status = 0xff & rq->errors; 314 hdr->status = 0xff & rq->errors;
@@ -320,12 +330,14 @@ static int sg_io(struct file *file, request_queue_t *q,
320 hdr->sb_len_wr = len; 330 hdr->sb_len_wr = len;
321 } 331 }
322 332
323 if (blk_rq_unmap_user(rq, bio, hdr->dxfer_len)) 333 if (blk_rq_unmap_user(bio, hdr->dxfer_len))
324 return -EFAULT; 334 ret = -EFAULT;
325 335
326 /* may not have succeeded, but output values written to control 336 /* may not have succeeded, but output values written to control
327 * structure (struct sg_io_hdr). */ 337 * structure (struct sg_io_hdr). */
328 return 0; 338out:
339 blk_put_request(rq);
340 return ret;
329} 341}
330 342
331#define OMAX_SB_LEN 16 /* For backward compatibility */ 343#define OMAX_SB_LEN 16 /* For backward compatibility */
@@ -408,7 +420,7 @@ static int sg_scsi_ioctl(struct file *file, request_queue_t *q,
408 rq->data_len = bytes; 420 rq->data_len = bytes;
409 rq->flags |= REQ_BLOCK_PC; 421 rq->flags |= REQ_BLOCK_PC;
410 422
411 blk_execute_rq(q, bd_disk, rq); 423 blk_execute_rq(q, bd_disk, rq, 0);
412 err = rq->errors & 0xff; /* only 8 bit SCSI status */ 424 err = rq->errors & 0xff; /* only 8 bit SCSI status */
413 if (err) { 425 if (err) {
414 if (rq->sense_len && rq->sense) { 426 if (rq->sense_len && rq->sense) {
@@ -561,7 +573,7 @@ int scsi_cmd_ioctl(struct file *file, struct gendisk *bd_disk, unsigned int cmd,
561 rq->cmd[0] = GPCMD_START_STOP_UNIT; 573 rq->cmd[0] = GPCMD_START_STOP_UNIT;
562 rq->cmd[4] = 0x02 + (close != 0); 574 rq->cmd[4] = 0x02 + (close != 0);
563 rq->cmd_len = 6; 575 rq->cmd_len = 6;
564 err = blk_execute_rq(q, bd_disk, rq); 576 err = blk_execute_rq(q, bd_disk, rq, 0);
565 blk_put_request(rq); 577 blk_put_request(rq);
566 break; 578 break;
567 default: 579 default:
diff --git a/drivers/cdrom/cdrom.c b/drivers/cdrom/cdrom.c
index beaa561f2ed..15396034841 100644
--- a/drivers/cdrom/cdrom.c
+++ b/drivers/cdrom/cdrom.c
@@ -2097,6 +2097,10 @@ static int cdrom_read_cdda_bpc(struct cdrom_device_info *cdi, __u8 __user *ubuf,
2097 if (!q) 2097 if (!q)
2098 return -ENXIO; 2098 return -ENXIO;
2099 2099
2100 rq = blk_get_request(q, READ, GFP_KERNEL);
2101 if (!rq)
2102 return -ENOMEM;
2103
2100 cdi->last_sense = 0; 2104 cdi->last_sense = 0;
2101 2105
2102 while (nframes) { 2106 while (nframes) {
@@ -2108,9 +2112,9 @@ static int cdrom_read_cdda_bpc(struct cdrom_device_info *cdi, __u8 __user *ubuf,
2108 2112
2109 len = nr * CD_FRAMESIZE_RAW; 2113 len = nr * CD_FRAMESIZE_RAW;
2110 2114
2111 rq = blk_rq_map_user(q, READ, ubuf, len); 2115 ret = blk_rq_map_user(q, rq, ubuf, len);
2112 if (IS_ERR(rq)) 2116 if (ret)
2113 return PTR_ERR(rq); 2117 break;
2114 2118
2115 memset(rq->cmd, 0, sizeof(rq->cmd)); 2119 memset(rq->cmd, 0, sizeof(rq->cmd));
2116 rq->cmd[0] = GPCMD_READ_CD; 2120 rq->cmd[0] = GPCMD_READ_CD;
@@ -2132,13 +2136,13 @@ static int cdrom_read_cdda_bpc(struct cdrom_device_info *cdi, __u8 __user *ubuf,
2132 if (rq->bio) 2136 if (rq->bio)
2133 blk_queue_bounce(q, &rq->bio); 2137 blk_queue_bounce(q, &rq->bio);
2134 2138
2135 if (blk_execute_rq(q, cdi->disk, rq)) { 2139 if (blk_execute_rq(q, cdi->disk, rq, 0)) {
2136 struct request_sense *s = rq->sense; 2140 struct request_sense *s = rq->sense;
2137 ret = -EIO; 2141 ret = -EIO;
2138 cdi->last_sense = s->sense_key; 2142 cdi->last_sense = s->sense_key;
2139 } 2143 }
2140 2144
2141 if (blk_rq_unmap_user(rq, bio, len)) 2145 if (blk_rq_unmap_user(bio, len))
2142 ret = -EFAULT; 2146 ret = -EFAULT;
2143 2147
2144 if (ret) 2148 if (ret)
@@ -2149,6 +2153,7 @@ static int cdrom_read_cdda_bpc(struct cdrom_device_info *cdi, __u8 __user *ubuf,
2149 ubuf += len; 2153 ubuf += len;
2150 } 2154 }
2151 2155
2156 blk_put_request(rq);
2152 return ret; 2157 return ret;
2153} 2158}
2154 2159
diff --git a/drivers/char/Kconfig b/drivers/char/Kconfig
index 7333b41d422..2bc9d64db10 100644
--- a/drivers/char/Kconfig
+++ b/drivers/char/Kconfig
@@ -138,7 +138,7 @@ config CYZ_INTR
138 138
139config DIGIEPCA 139config DIGIEPCA
140 tristate "Digiboard Intelligent Async Support" 140 tristate "Digiboard Intelligent Async Support"
141 depends on SERIAL_NONSTANDARD && BROKEN_ON_SMP && (!64BIT || BROKEN) 141 depends on SERIAL_NONSTANDARD
142 ---help--- 142 ---help---
143 This is a driver for Digi International's Xx, Xeve, and Xem series 143 This is a driver for Digi International's Xx, Xeve, and Xem series
144 of cards which provide multiple serial ports. You would need 144 of cards which provide multiple serial ports. You would need
@@ -735,7 +735,7 @@ config SGI_IP27_RTC
735 735
736config GEN_RTC 736config GEN_RTC
737 tristate "Generic /dev/rtc emulation" 737 tristate "Generic /dev/rtc emulation"
738 depends on RTC!=y && !IA64 && !ARM && !PPC64 && !M32R && !SPARC32 738 depends on RTC!=y && !IA64 && !ARM && !PPC64 && !M32R && !SPARC32 && !SPARC64
739 ---help--- 739 ---help---
740 If you say Y here and create a character special file /dev/rtc with 740 If you say Y here and create a character special file /dev/rtc with
741 major number 10 and minor number 135 using mknod ("man mknod"), you 741 major number 10 and minor number 135 using mknod ("man mknod"), you
@@ -842,8 +842,7 @@ config SONYPI
842 842
843config TANBAC_TB0219 843config TANBAC_TB0219
844 tristate "TANBAC TB0219 base board support" 844 tristate "TANBAC TB0219 base board support"
845 depends TANBAC_TB0229 845 depends TANBAC_TB022X
846
847 846
848menu "Ftape, the floppy tape device driver" 847menu "Ftape, the floppy tape device driver"
849 848
diff --git a/drivers/char/digi1.h b/drivers/char/digi1.h
index 184378d23f8..94d4eab5d3c 100644
--- a/drivers/char/digi1.h
+++ b/drivers/char/digi1.h
@@ -1,46 +1,46 @@
1/* Definitions for DigiBoard ditty(1) command. */ 1/* Definitions for DigiBoard ditty(1) command. */
2 2
3#if !defined(TIOCMODG) 3#if !defined(TIOCMODG)
4#define TIOCMODG ('d'<<8) | 250 /* get modem ctrl state */ 4#define TIOCMODG (('d'<<8) | 250) /* get modem ctrl state */
5#define TIOCMODS ('d'<<8) | 251 /* set modem ctrl state */ 5#define TIOCMODS (('d'<<8) | 251) /* set modem ctrl state */
6#endif 6#endif
7 7
8#if !defined(TIOCMSET) 8#if !defined(TIOCMSET)
9#define TIOCMSET ('d'<<8) | 252 /* set modem ctrl state */ 9#define TIOCMSET (('d'<<8) | 252) /* set modem ctrl state */
10#define TIOCMGET ('d'<<8) | 253 /* set modem ctrl state */ 10#define TIOCMGET (('d'<<8) | 253) /* set modem ctrl state */
11#endif 11#endif
12 12
13#if !defined(TIOCMBIC) 13#if !defined(TIOCMBIC)
14#define TIOCMBIC ('d'<<8) | 254 /* set modem ctrl state */ 14#define TIOCMBIC (('d'<<8) | 254) /* set modem ctrl state */
15#define TIOCMBIS ('d'<<8) | 255 /* set modem ctrl state */ 15#define TIOCMBIS (('d'<<8) | 255) /* set modem ctrl state */
16#endif 16#endif
17 17
18#if !defined(TIOCSDTR) 18#if !defined(TIOCSDTR)
19#define TIOCSDTR ('e'<<8) | 0 /* set DTR */ 19#define TIOCSDTR (('e'<<8) | 0) /* set DTR */
20#define TIOCCDTR ('e'<<8) | 1 /* clear DTR */ 20#define TIOCCDTR (('e'<<8) | 1) /* clear DTR */
21#endif 21#endif
22 22
23/************************************************************************ 23/************************************************************************
24 * Ioctl command arguments for DIGI parameters. 24 * Ioctl command arguments for DIGI parameters.
25 ************************************************************************/ 25 ************************************************************************/
26#define DIGI_GETA ('e'<<8) | 94 /* Read params */ 26#define DIGI_GETA (('e'<<8) | 94) /* Read params */
27 27
28#define DIGI_SETA ('e'<<8) | 95 /* Set params */ 28#define DIGI_SETA (('e'<<8) | 95) /* Set params */
29#define DIGI_SETAW ('e'<<8) | 96 /* Drain & set params */ 29#define DIGI_SETAW (('e'<<8) | 96) /* Drain & set params */
30#define DIGI_SETAF ('e'<<8) | 97 /* Drain, flush & set params */ 30#define DIGI_SETAF (('e'<<8) | 97) /* Drain, flush & set params */
31 31
32#define DIGI_GETFLOW ('e'<<8) | 99 /* Get startc/stopc flow */ 32#define DIGI_GETFLOW (('e'<<8) | 99) /* Get startc/stopc flow */
33 /* control characters */ 33 /* control characters */
34#define DIGI_SETFLOW ('e'<<8) | 100 /* Set startc/stopc flow */ 34#define DIGI_SETFLOW (('e'<<8) | 100) /* Set startc/stopc flow */
35 /* control characters */ 35 /* control characters */
36#define DIGI_GETAFLOW ('e'<<8) | 101 /* Get Aux. startc/stopc */ 36#define DIGI_GETAFLOW (('e'<<8) | 101) /* Get Aux. startc/stopc */
37 /* flow control chars */ 37 /* flow control chars */
38#define DIGI_SETAFLOW ('e'<<8) | 102 /* Set Aux. startc/stopc */ 38#define DIGI_SETAFLOW (('e'<<8) | 102) /* Set Aux. startc/stopc */
39 /* flow control chars */ 39 /* flow control chars */
40 40
41#define DIGI_GETINFO ('e'<<8) | 103 /* Fill in digi_info */ 41#define DIGI_GETINFO (('e'<<8) | 103) /* Fill in digi_info */
42#define DIGI_POLLER ('e'<<8) | 104 /* Turn on/off poller */ 42#define DIGI_POLLER (('e'<<8) | 104) /* Turn on/off poller */
43#define DIGI_INIT ('e'<<8) | 105 /* Allow things to run. */ 43#define DIGI_INIT (('e'<<8) | 105) /* Allow things to run. */
44 44
45struct digiflow_struct 45struct digiflow_struct
46{ 46{
diff --git a/drivers/char/digiFep1.h b/drivers/char/digiFep1.h
index c47d7fcb840..3c1f1922c79 100644
--- a/drivers/char/digiFep1.h
+++ b/drivers/char/digiFep1.h
@@ -13,88 +13,88 @@
13 13
14struct global_data 14struct global_data
15{ 15{
16 volatile ushort cin; 16 u16 cin;
17 volatile ushort cout; 17 u16 cout;
18 volatile ushort cstart; 18 u16 cstart;
19 volatile ushort cmax; 19 u16 cmax;
20 volatile ushort ein; 20 u16 ein;
21 volatile ushort eout; 21 u16 eout;
22 volatile ushort istart; 22 u16 istart;
23 volatile ushort imax; 23 u16 imax;
24}; 24};
25 25
26 26
27struct board_chan 27struct board_chan
28{ 28{
29 int filler1; 29 u32 filler1;
30 int filler2; 30 u32 filler2;
31 volatile ushort tseg; 31 u16 tseg;
32 volatile ushort tin; 32 u16 tin;
33 volatile ushort tout; 33 u16 tout;
34 volatile ushort tmax; 34 u16 tmax;
35 35
36 volatile ushort rseg; 36 u16 rseg;
37 volatile ushort rin; 37 u16 rin;
38 volatile ushort rout; 38 u16 rout;
39 volatile ushort rmax; 39 u16 rmax;
40 40
41 volatile ushort tlow; 41 u16 tlow;
42 volatile ushort rlow; 42 u16 rlow;
43 volatile ushort rhigh; 43 u16 rhigh;
44 volatile ushort incr; 44 u16 incr;
45 45
46 volatile ushort etime; 46 u16 etime;
47 volatile ushort edelay; 47 u16 edelay;
48 volatile unchar *dev; 48 unchar *dev;
49 49
50 volatile ushort iflag; 50 u16 iflag;
51 volatile ushort oflag; 51 u16 oflag;
52 volatile ushort cflag; 52 u16 cflag;
53 volatile ushort gmask; 53 u16 gmask;
54 54
55 volatile ushort col; 55 u16 col;
56 volatile ushort delay; 56 u16 delay;
57 volatile ushort imask; 57 u16 imask;
58 volatile ushort tflush; 58 u16 tflush;
59 59
60 int filler3; 60 u32 filler3;
61 int filler4; 61 u32 filler4;
62 int filler5; 62 u32 filler5;
63 int filler6; 63 u32 filler6;
64 64
65 volatile unchar num; 65 u8 num;
66 volatile unchar ract; 66 u8 ract;
67 volatile unchar bstat; 67 u8 bstat;
68 volatile unchar tbusy; 68 u8 tbusy;
69 volatile unchar iempty; 69 u8 iempty;
70 volatile unchar ilow; 70 u8 ilow;
71 volatile unchar idata; 71 u8 idata;
72 volatile unchar eflag; 72 u8 eflag;
73 73
74 volatile unchar tflag; 74 u8 tflag;
75 volatile unchar rflag; 75 u8 rflag;
76 volatile unchar xmask; 76 u8 xmask;
77 volatile unchar xval; 77 u8 xval;
78 volatile unchar mstat; 78 u8 mstat;
79 volatile unchar mchange; 79 u8 mchange;
80 volatile unchar mint; 80 u8 mint;
81 volatile unchar lstat; 81 u8 lstat;
82 82
83 volatile unchar mtran; 83 u8 mtran;
84 volatile unchar orun; 84 u8 orun;
85 volatile unchar startca; 85 u8 startca;
86 volatile unchar stopca; 86 u8 stopca;
87 volatile unchar startc; 87 u8 startc;
88 volatile unchar stopc; 88 u8 stopc;
89 volatile unchar vnext; 89 u8 vnext;
90 volatile unchar hflow; 90 u8 hflow;
91 91
92 volatile unchar fillc; 92 u8 fillc;
93 volatile unchar ochar; 93 u8 ochar;
94 volatile unchar omask; 94 u8 omask;
95 95
96 unchar filler7; 96 u8 filler7;
97 unchar filler8[28]; 97 u8 filler8[28];
98}; 98};
99 99
100 100
diff --git a/drivers/char/drm/drm_bufs.c b/drivers/char/drm/drm_bufs.c
index e0743ebbe4b..f28e70ae660 100644
--- a/drivers/char/drm/drm_bufs.c
+++ b/drivers/char/drm/drm_bufs.c
@@ -48,8 +48,8 @@ unsigned long drm_get_resource_len(drm_device_t *dev, unsigned int resource)
48} 48}
49EXPORT_SYMBOL(drm_get_resource_len); 49EXPORT_SYMBOL(drm_get_resource_len);
50 50
51static drm_local_map_t *drm_find_matching_map(drm_device_t *dev, 51static drm_map_list_t *drm_find_matching_map(drm_device_t *dev,
52 drm_local_map_t *map) 52 drm_local_map_t *map)
53{ 53{
54 struct list_head *list; 54 struct list_head *list;
55 55
@@ -57,7 +57,7 @@ static drm_local_map_t *drm_find_matching_map(drm_device_t *dev,
57 drm_map_list_t *entry = list_entry(list, drm_map_list_t, head); 57 drm_map_list_t *entry = list_entry(list, drm_map_list_t, head);
58 if (entry->map && map->type == entry->map->type && 58 if (entry->map && map->type == entry->map->type &&
59 entry->map->offset == map->offset) { 59 entry->map->offset == map->offset) {
60 return entry->map; 60 return entry;
61 } 61 }
62 } 62 }
63 63
@@ -114,14 +114,13 @@ static __inline__ unsigned int HandleID(unsigned long lhandle, drm_device_t *dev
114 * type. Adds the map to the map list drm_device::maplist. Adds MTRR's where 114 * type. Adds the map to the map list drm_device::maplist. Adds MTRR's where
115 * applicable and if supported by the kernel. 115 * applicable and if supported by the kernel.
116 */ 116 */
117int drm_addmap(drm_device_t * dev, unsigned int offset, 117int drm_addmap_core(drm_device_t * dev, unsigned int offset,
118 unsigned int size, drm_map_type_t type, 118 unsigned int size, drm_map_type_t type,
119 drm_map_flags_t flags, drm_local_map_t ** map_ptr) 119 drm_map_flags_t flags, drm_map_list_t **maplist)
120{ 120{
121 drm_map_t *map; 121 drm_map_t *map;
122 drm_map_list_t *list; 122 drm_map_list_t *list;
123 drm_dma_handle_t *dmah; 123 drm_dma_handle_t *dmah;
124 drm_local_map_t *found_map;
125 124
126 map = drm_alloc( sizeof(*map), DRM_MEM_MAPS ); 125 map = drm_alloc( sizeof(*map), DRM_MEM_MAPS );
127 if ( !map ) 126 if ( !map )
@@ -166,17 +165,17 @@ int drm_addmap(drm_device_t * dev, unsigned int offset,
166 * needing to be aware of it. Therefore, we just return success 165 * needing to be aware of it. Therefore, we just return success
167 * when the server tries to create a duplicate map. 166 * when the server tries to create a duplicate map.
168 */ 167 */
169 found_map = drm_find_matching_map(dev, map); 168 list = drm_find_matching_map(dev, map);
170 if (found_map != NULL) { 169 if (list != NULL) {
171 if (found_map->size != map->size) { 170 if (list->map->size != map->size) {
172 DRM_DEBUG("Matching maps of type %d with " 171 DRM_DEBUG("Matching maps of type %d with "
173 "mismatched sizes, (%ld vs %ld)\n", 172 "mismatched sizes, (%ld vs %ld)\n",
174 map->type, map->size, found_map->size); 173 map->type, map->size, list->map->size);
175 found_map->size = map->size; 174 list->map->size = map->size;
176 } 175 }
177 176
178 drm_free(map, sizeof(*map), DRM_MEM_MAPS); 177 drm_free(map, sizeof(*map), DRM_MEM_MAPS);
179 *map_ptr = found_map; 178 *maplist = list;
180 return 0; 179 return 0;
181 } 180 }
182 181
@@ -264,9 +263,22 @@ int drm_addmap(drm_device_t * dev, unsigned int offset,
264 : map->offset, dev); 263 : map->offset, dev);
265 up(&dev->struct_sem); 264 up(&dev->struct_sem);
266 265
267 *map_ptr = map; 266 *maplist = list;
268 return 0; 267 return 0;
269} 268}
269
270int drm_addmap(drm_device_t *dev, unsigned int offset,
271 unsigned int size, drm_map_type_t type,
272 drm_map_flags_t flags, drm_local_map_t **map_ptr)
273{
274 drm_map_list_t *list;
275 int rc;
276
277 rc = drm_addmap_core(dev, offset, size, type, flags, &list);
278 if (!rc)
279 *map_ptr = list->map;
280 return rc;
281}
270EXPORT_SYMBOL(drm_addmap); 282EXPORT_SYMBOL(drm_addmap);
271 283
272int drm_addmap_ioctl(struct inode *inode, struct file *filp, 284int drm_addmap_ioctl(struct inode *inode, struct file *filp,
@@ -275,10 +287,9 @@ int drm_addmap_ioctl(struct inode *inode, struct file *filp,
275 drm_file_t *priv = filp->private_data; 287 drm_file_t *priv = filp->private_data;
276 drm_device_t *dev = priv->head->dev; 288 drm_device_t *dev = priv->head->dev;
277 drm_map_t map; 289 drm_map_t map;
278 drm_map_t *map_ptr; 290 drm_map_list_t *maplist;
279 drm_map_t __user *argp = (void __user *)arg; 291 drm_map_t __user *argp = (void __user *)arg;
280 int err; 292 int err;
281 unsigned long handle = 0;
282 293
283 if (!(filp->f_mode & 3)) 294 if (!(filp->f_mode & 3))
284 return -EACCES; /* Require read/write */ 295 return -EACCES; /* Require read/write */
@@ -287,26 +298,15 @@ int drm_addmap_ioctl(struct inode *inode, struct file *filp,
287 return -EFAULT; 298 return -EFAULT;
288 } 299 }
289 300
290 err = drm_addmap(dev, map.offset, map.size, map.type, map.flags, 301 err = drm_addmap_core(dev, map.offset, map.size, map.type, map.flags,
291 &map_ptr); 302 &maplist);
292 303
293 if (err) { 304 if (err)
294 return err; 305 return err;
295 }
296
297 {
298 drm_map_list_t *_entry;
299 list_for_each_entry(_entry, &dev->maplist->head, head) {
300 if (_entry->map == map_ptr)
301 handle = _entry->user_token;
302 }
303 if (!handle)
304 return -EFAULT;
305 }
306 306
307 if (copy_to_user(argp, map_ptr, sizeof(*map_ptr))) 307 if (copy_to_user(argp, maplist->map, sizeof(drm_map_t)))
308 return -EFAULT; 308 return -EFAULT;
309 if (put_user(handle, &argp->handle)) 309 if (put_user(maplist->user_token, &argp->handle))
310 return -EFAULT; 310 return -EFAULT;
311 return 0; 311 return 0;
312} 312}
@@ -1041,7 +1041,7 @@ static int drm_addbufs_sg(drm_device_t *dev, drm_buf_desc_t *request)
1041 return 0; 1041 return 0;
1042} 1042}
1043 1043
1044int drm_addbufs_fb(drm_device_t *dev, drm_buf_desc_t *request) 1044static int drm_addbufs_fb(drm_device_t *dev, drm_buf_desc_t *request)
1045{ 1045{
1046 drm_device_dma_t *dma = dev->dma; 1046 drm_device_dma_t *dma = dev->dma;
1047 drm_buf_entry_t *entry; 1047 drm_buf_entry_t *entry;
diff --git a/drivers/char/drm/drm_context.c b/drivers/char/drm/drm_context.c
index f515567e5b6..502892794c1 100644
--- a/drivers/char/drm/drm_context.c
+++ b/drivers/char/drm/drm_context.c
@@ -308,7 +308,7 @@ found:
308 * 308 *
309 * Attempt to set drm_device::context_flag. 309 * Attempt to set drm_device::context_flag.
310 */ 310 */
311int drm_context_switch( drm_device_t *dev, int old, int new ) 311static int drm_context_switch( drm_device_t *dev, int old, int new )
312{ 312{
313 if ( test_and_set_bit( 0, &dev->context_flag ) ) { 313 if ( test_and_set_bit( 0, &dev->context_flag ) ) {
314 DRM_ERROR( "Reentering -- FIXME\n" ); 314 DRM_ERROR( "Reentering -- FIXME\n" );
diff --git a/drivers/char/drm/drm_sysfs.c b/drivers/char/drm/drm_sysfs.c
index 2fc10c4bbcd..475cc5e555e 100644
--- a/drivers/char/drm/drm_sysfs.c
+++ b/drivers/char/drm/drm_sysfs.c
@@ -17,6 +17,7 @@
17#include <linux/err.h> 17#include <linux/err.h>
18 18
19#include "drm_core.h" 19#include "drm_core.h"
20#include "drmP.h"
20 21
21struct drm_sysfs_class { 22struct drm_sysfs_class {
22 struct class_device_attribute attr; 23 struct class_device_attribute attr;
diff --git a/drivers/char/drm/mga_dma.c b/drivers/char/drm/mga_dma.c
index 567b425b784..fc7d4a594bc 100644
--- a/drivers/char/drm/mga_dma.c
+++ b/drivers/char/drm/mga_dma.c
@@ -417,6 +417,7 @@ int mga_driver_preinit(drm_device_t *dev, unsigned long flags)
417 return 0; 417 return 0;
418} 418}
419 419
420#if __OS_HAS_AGP
420/** 421/**
421 * Bootstrap the driver for AGP DMA. 422 * Bootstrap the driver for AGP DMA.
422 * 423 *
@@ -560,6 +561,13 @@ static int mga_do_agp_dma_bootstrap(drm_device_t * dev,
560 DRM_INFO("Initialized card for AGP DMA.\n"); 561 DRM_INFO("Initialized card for AGP DMA.\n");
561 return 0; 562 return 0;
562} 563}
564#else
565static int mga_do_agp_dma_bootstrap(drm_device_t * dev,
566 drm_mga_dma_bootstrap_t * dma_bs)
567{
568 return -EINVAL;
569}
570#endif
563 571
564/** 572/**
565 * Bootstrap the driver for PCI DMA. 573 * Bootstrap the driver for PCI DMA.
@@ -697,7 +705,6 @@ static int mga_do_dma_bootstrap(drm_device_t * dev,
697 * carve off portions of it for internal uses. The remaining memory 705 * carve off portions of it for internal uses. The remaining memory
698 * is returned to user-mode to be used for AGP textures. 706 * is returned to user-mode to be used for AGP textures.
699 */ 707 */
700
701 if (is_agp) { 708 if (is_agp) {
702 err = mga_do_agp_dma_bootstrap(dev, dma_bs); 709 err = mga_do_agp_dma_bootstrap(dev, dma_bs);
703 } 710 }
@@ -932,6 +939,7 @@ static int mga_do_cleanup_dma( drm_device_t *dev )
932 drm_core_ioremapfree(dev->agp_buffer_map, dev); 939 drm_core_ioremapfree(dev->agp_buffer_map, dev);
933 940
934 if (dev_priv->used_new_dma_init) { 941 if (dev_priv->used_new_dma_init) {
942#if __OS_HAS_AGP
935 if (dev_priv->agp_mem != NULL) { 943 if (dev_priv->agp_mem != NULL) {
936 dev_priv->agp_textures = NULL; 944 dev_priv->agp_textures = NULL;
937 drm_unbind_agp(dev_priv->agp_mem); 945 drm_unbind_agp(dev_priv->agp_mem);
@@ -944,7 +952,7 @@ static int mga_do_cleanup_dma( drm_device_t *dev )
944 if ((dev->agp != NULL) && dev->agp->acquired) { 952 if ((dev->agp != NULL) && dev->agp->acquired) {
945 err = drm_agp_release(dev); 953 err = drm_agp_release(dev);
946 } 954 }
947 955#endif
948 dev_priv->used_new_dma_init = 0; 956 dev_priv->used_new_dma_init = 0;
949 } 957 }
950 958
@@ -965,7 +973,7 @@ static int mga_do_cleanup_dma( drm_device_t *dev )
965 } 973 }
966 } 974 }
967 975
968 return 0; 976 return err;
969} 977}
970 978
971int mga_dma_init( DRM_IOCTL_ARGS ) 979int mga_dma_init( DRM_IOCTL_ARGS )
diff --git a/drivers/char/epca.c b/drivers/char/epca.c
index 6025e1866c7..58d3738a2b7 100644
--- a/drivers/char/epca.c
+++ b/drivers/char/epca.c
@@ -6,6 +6,8 @@
6 For technical support please email digiLinux@dgii.com or 6 For technical support please email digiLinux@dgii.com or
7 call Digi tech support at (612) 912-3456 7 call Digi tech support at (612) 912-3456
8 8
9 ** This driver is no longer supported by Digi **
10
9 Much of this design and code came from epca.c which was 11 Much of this design and code came from epca.c which was
10 copyright (C) 1994, 1995 Troy De Jongh, and subsquently 12 copyright (C) 1994, 1995 Troy De Jongh, and subsquently
11 modified by David Nugent, Christoph Lameter, Mike McLagan. 13 modified by David Nugent, Christoph Lameter, Mike McLagan.
@@ -43,31 +45,19 @@
43#include <linux/interrupt.h> 45#include <linux/interrupt.h>
44#include <asm/uaccess.h> 46#include <asm/uaccess.h>
45#include <asm/io.h> 47#include <asm/io.h>
46 48#include <linux/spinlock.h>
47#ifdef CONFIG_PCI
48#define ENABLE_PCI
49#endif /* CONFIG_PCI */
50
51#define putUser(arg1, arg2) put_user(arg1, (unsigned long __user *)arg2)
52#define getUser(arg1, arg2) get_user(arg1, (unsigned __user *)arg2)
53
54#ifdef ENABLE_PCI
55#include <linux/pci.h> 49#include <linux/pci.h>
56#include "digiPCI.h" 50#include "digiPCI.h"
57#endif /* ENABLE_PCI */ 51
58 52
59#include "digi1.h" 53#include "digi1.h"
60#include "digiFep1.h" 54#include "digiFep1.h"
61#include "epca.h" 55#include "epca.h"
62#include "epcaconfig.h" 56#include "epcaconfig.h"
63 57
64#if BITS_PER_LONG != 32
65# error FIXME: this driver only works on 32-bit platforms
66#endif
67
68/* ---------------------- Begin defines ------------------------ */ 58/* ---------------------- Begin defines ------------------------ */
69 59
70#define VERSION "1.3.0.1-LK" 60#define VERSION "1.3.0.1-LK2.6"
71 61
72/* This major needs to be submitted to Linux to join the majors list */ 62/* This major needs to be submitted to Linux to join the majors list */
73 63
@@ -81,13 +71,17 @@
81 71
82/* ----------------- Begin global definitions ------------------- */ 72/* ----------------- Begin global definitions ------------------- */
83 73
84static char mesg[100];
85static int nbdevs, num_cards, liloconfig; 74static int nbdevs, num_cards, liloconfig;
86static int digi_poller_inhibited = 1 ; 75static int digi_poller_inhibited = 1 ;
87 76
88static int setup_error_code; 77static int setup_error_code;
89static int invalid_lilo_config; 78static int invalid_lilo_config;
90 79
80/* The ISA boards do window flipping into the same spaces so its only sane
81 with a single lock. It's still pretty efficient */
82
83static spinlock_t epca_lock = SPIN_LOCK_UNLOCKED;
84
91/* ----------------------------------------------------------------------- 85/* -----------------------------------------------------------------------
92 MAXBOARDS is typically 12, but ISA and EISA cards are restricted to 86 MAXBOARDS is typically 12, but ISA and EISA cards are restricted to
93 7 below. 87 7 below.
@@ -129,58 +123,58 @@ static struct timer_list epca_timer;
129 configured. 123 configured.
130----------------------------------------------------------------------- */ 124----------------------------------------------------------------------- */
131 125
132static inline void memwinon(struct board_info *b, unsigned int win); 126static void memwinon(struct board_info *b, unsigned int win);
133static inline void memwinoff(struct board_info *b, unsigned int win); 127static void memwinoff(struct board_info *b, unsigned int win);
134static inline void globalwinon(struct channel *ch); 128static void globalwinon(struct channel *ch);
135static inline void rxwinon(struct channel *ch); 129static void rxwinon(struct channel *ch);
136static inline void txwinon(struct channel *ch); 130static void txwinon(struct channel *ch);
137static inline void memoff(struct channel *ch); 131static void memoff(struct channel *ch);
138static inline void assertgwinon(struct channel *ch); 132static void assertgwinon(struct channel *ch);
139static inline void assertmemoff(struct channel *ch); 133static void assertmemoff(struct channel *ch);
140 134
141/* ---- Begin more 'specific' memory functions for cx_like products --- */ 135/* ---- Begin more 'specific' memory functions for cx_like products --- */
142 136
143static inline void pcxem_memwinon(struct board_info *b, unsigned int win); 137static void pcxem_memwinon(struct board_info *b, unsigned int win);
144static inline void pcxem_memwinoff(struct board_info *b, unsigned int win); 138static void pcxem_memwinoff(struct board_info *b, unsigned int win);
145static inline void pcxem_globalwinon(struct channel *ch); 139static void pcxem_globalwinon(struct channel *ch);
146static inline void pcxem_rxwinon(struct channel *ch); 140static void pcxem_rxwinon(struct channel *ch);
147static inline void pcxem_txwinon(struct channel *ch); 141static void pcxem_txwinon(struct channel *ch);
148static inline void pcxem_memoff(struct channel *ch); 142static void pcxem_memoff(struct channel *ch);
149 143
150/* ------ Begin more 'specific' memory functions for the pcxe ------- */ 144/* ------ Begin more 'specific' memory functions for the pcxe ------- */
151 145
152static inline void pcxe_memwinon(struct board_info *b, unsigned int win); 146static void pcxe_memwinon(struct board_info *b, unsigned int win);
153static inline void pcxe_memwinoff(struct board_info *b, unsigned int win); 147static void pcxe_memwinoff(struct board_info *b, unsigned int win);
154static inline void pcxe_globalwinon(struct channel *ch); 148static void pcxe_globalwinon(struct channel *ch);
155static inline void pcxe_rxwinon(struct channel *ch); 149static void pcxe_rxwinon(struct channel *ch);
156static inline void pcxe_txwinon(struct channel *ch); 150static void pcxe_txwinon(struct channel *ch);
157static inline void pcxe_memoff(struct channel *ch); 151static void pcxe_memoff(struct channel *ch);
158 152
159/* ---- Begin more 'specific' memory functions for the pc64xe and pcxi ---- */ 153/* ---- Begin more 'specific' memory functions for the pc64xe and pcxi ---- */
160/* Note : pc64xe and pcxi share the same windowing routines */ 154/* Note : pc64xe and pcxi share the same windowing routines */
161 155
162static inline void pcxi_memwinon(struct board_info *b, unsigned int win); 156static void pcxi_memwinon(struct board_info *b, unsigned int win);
163static inline void pcxi_memwinoff(struct board_info *b, unsigned int win); 157static void pcxi_memwinoff(struct board_info *b, unsigned int win);
164static inline void pcxi_globalwinon(struct channel *ch); 158static void pcxi_globalwinon(struct channel *ch);
165static inline void pcxi_rxwinon(struct channel *ch); 159static void pcxi_rxwinon(struct channel *ch);
166static inline void pcxi_txwinon(struct channel *ch); 160static void pcxi_txwinon(struct channel *ch);
167static inline void pcxi_memoff(struct channel *ch); 161static void pcxi_memoff(struct channel *ch);
168 162
169/* - Begin 'specific' do nothing memory functions needed for some cards - */ 163/* - Begin 'specific' do nothing memory functions needed for some cards - */
170 164
171static inline void dummy_memwinon(struct board_info *b, unsigned int win); 165static void dummy_memwinon(struct board_info *b, unsigned int win);
172static inline void dummy_memwinoff(struct board_info *b, unsigned int win); 166static void dummy_memwinoff(struct board_info *b, unsigned int win);
173static inline void dummy_globalwinon(struct channel *ch); 167static void dummy_globalwinon(struct channel *ch);
174static inline void dummy_rxwinon(struct channel *ch); 168static void dummy_rxwinon(struct channel *ch);
175static inline void dummy_txwinon(struct channel *ch); 169static void dummy_txwinon(struct channel *ch);
176static inline void dummy_memoff(struct channel *ch); 170static void dummy_memoff(struct channel *ch);
177static inline void dummy_assertgwinon(struct channel *ch); 171static void dummy_assertgwinon(struct channel *ch);
178static inline void dummy_assertmemoff(struct channel *ch); 172static void dummy_assertmemoff(struct channel *ch);
179 173
180/* ------------------- Begin declare functions ----------------------- */ 174/* ------------------- Begin declare functions ----------------------- */
181 175
182static inline struct channel *verifyChannel(register struct tty_struct *); 176static struct channel *verifyChannel(struct tty_struct *);
183static inline void pc_sched_event(struct channel *, int); 177static void pc_sched_event(struct channel *, int);
184static void epca_error(int, char *); 178static void epca_error(int, char *);
185static void pc_close(struct tty_struct *, struct file *); 179static void pc_close(struct tty_struct *, struct file *);
186static void shutdown(struct channel *); 180static void shutdown(struct channel *);
@@ -215,15 +209,11 @@ static void pc_unthrottle(struct tty_struct *tty);
215static void digi_send_break(struct channel *ch, int msec); 209static void digi_send_break(struct channel *ch, int msec);
216static void setup_empty_event(struct tty_struct *tty, struct channel *ch); 210static void setup_empty_event(struct tty_struct *tty, struct channel *ch);
217void epca_setup(char *, int *); 211void epca_setup(char *, int *);
218void console_print(const char *);
219 212
220static int get_termio(struct tty_struct *, struct termio __user *); 213static int get_termio(struct tty_struct *, struct termio __user *);
221static int pc_write(struct tty_struct *, const unsigned char *, int); 214static int pc_write(struct tty_struct *, const unsigned char *, int);
222int pc_init(void); 215static int pc_init(void);
223
224#ifdef ENABLE_PCI
225static int init_PCI(void); 216static int init_PCI(void);
226#endif /* ENABLE_PCI */
227 217
228 218
229/* ------------------------------------------------------------------ 219/* ------------------------------------------------------------------
@@ -237,41 +227,41 @@ static int init_PCI(void);
237 making direct calls deserves what they get. 227 making direct calls deserves what they get.
238-------------------------------------------------------------------- */ 228-------------------------------------------------------------------- */
239 229
240static inline void memwinon(struct board_info *b, unsigned int win) 230static void memwinon(struct board_info *b, unsigned int win)
241{ 231{
242 (b->memwinon)(b, win); 232 (b->memwinon)(b, win);
243} 233}
244 234
245static inline void memwinoff(struct board_info *b, unsigned int win) 235static void memwinoff(struct board_info *b, unsigned int win)
246{ 236{
247 (b->memwinoff)(b, win); 237 (b->memwinoff)(b, win);
248} 238}
249 239
250static inline void globalwinon(struct channel *ch) 240static void globalwinon(struct channel *ch)
251{ 241{
252 (ch->board->globalwinon)(ch); 242 (ch->board->globalwinon)(ch);
253} 243}
254 244
255static inline void rxwinon(struct channel *ch) 245static void rxwinon(struct channel *ch)
256{ 246{
257 (ch->board->rxwinon)(ch); 247 (ch->board->rxwinon)(ch);
258} 248}
259 249
260static inline void txwinon(struct channel *ch) 250static void txwinon(struct channel *ch)
261{ 251{
262 (ch->board->txwinon)(ch); 252 (ch->board->txwinon)(ch);
263} 253}
264 254
265static inline void memoff(struct channel *ch) 255static void memoff(struct channel *ch)
266{ 256{
267 (ch->board->memoff)(ch); 257 (ch->board->memoff)(ch);
268} 258}
269static inline void assertgwinon(struct channel *ch) 259static void assertgwinon(struct channel *ch)
270{ 260{
271 (ch->board->assertgwinon)(ch); 261 (ch->board->assertgwinon)(ch);
272} 262}
273 263
274static inline void assertmemoff(struct channel *ch) 264static void assertmemoff(struct channel *ch)
275{ 265{
276 (ch->board->assertmemoff)(ch); 266 (ch->board->assertmemoff)(ch);
277} 267}
@@ -281,66 +271,66 @@ static inline void assertmemoff(struct channel *ch)
281 and CX series cards. 271 and CX series cards.
282------------------------------------------------------------ */ 272------------------------------------------------------------ */
283 273
284static inline void pcxem_memwinon(struct board_info *b, unsigned int win) 274static void pcxem_memwinon(struct board_info *b, unsigned int win)
285{ 275{
286 outb_p(FEPWIN|win, (int)b->port + 1); 276 outb_p(FEPWIN|win, b->port + 1);
287} 277}
288 278
289static inline void pcxem_memwinoff(struct board_info *b, unsigned int win) 279static void pcxem_memwinoff(struct board_info *b, unsigned int win)
290{ 280{
291 outb_p(0, (int)b->port + 1); 281 outb_p(0, b->port + 1);
292} 282}
293 283
294static inline void pcxem_globalwinon(struct channel *ch) 284static void pcxem_globalwinon(struct channel *ch)
295{ 285{
296 outb_p( FEPWIN, (int)ch->board->port + 1); 286 outb_p( FEPWIN, (int)ch->board->port + 1);
297} 287}
298 288
299static inline void pcxem_rxwinon(struct channel *ch) 289static void pcxem_rxwinon(struct channel *ch)
300{ 290{
301 outb_p(ch->rxwin, (int)ch->board->port + 1); 291 outb_p(ch->rxwin, (int)ch->board->port + 1);
302} 292}
303 293
304static inline void pcxem_txwinon(struct channel *ch) 294static void pcxem_txwinon(struct channel *ch)
305{ 295{
306 outb_p(ch->txwin, (int)ch->board->port + 1); 296 outb_p(ch->txwin, (int)ch->board->port + 1);
307} 297}
308 298
309static inline void pcxem_memoff(struct channel *ch) 299static void pcxem_memoff(struct channel *ch)
310{ 300{
311 outb_p(0, (int)ch->board->port + 1); 301 outb_p(0, (int)ch->board->port + 1);
312} 302}
313 303
314/* ----------------- Begin pcxe memory window stuff ------------------ */ 304/* ----------------- Begin pcxe memory window stuff ------------------ */
315 305
316static inline void pcxe_memwinon(struct board_info *b, unsigned int win) 306static void pcxe_memwinon(struct board_info *b, unsigned int win)
317{ 307{
318 outb_p(FEPWIN | win, (int)b->port + 1); 308 outb_p(FEPWIN | win, b->port + 1);
319} 309}
320 310
321static inline void pcxe_memwinoff(struct board_info *b, unsigned int win) 311static void pcxe_memwinoff(struct board_info *b, unsigned int win)
322{ 312{
323 outb_p(inb((int)b->port) & ~FEPMEM, 313 outb_p(inb(b->port) & ~FEPMEM,
324 (int)b->port + 1); 314 b->port + 1);
325 outb_p(0, (int)b->port + 1); 315 outb_p(0, b->port + 1);
326} 316}
327 317
328static inline void pcxe_globalwinon(struct channel *ch) 318static void pcxe_globalwinon(struct channel *ch)
329{ 319{
330 outb_p( FEPWIN, (int)ch->board->port + 1); 320 outb_p( FEPWIN, (int)ch->board->port + 1);
331} 321}
332 322
333static inline void pcxe_rxwinon(struct channel *ch) 323static void pcxe_rxwinon(struct channel *ch)
334{ 324{
335 outb_p(ch->rxwin, (int)ch->board->port + 1); 325 outb_p(ch->rxwin, (int)ch->board->port + 1);
336} 326}
337 327
338static inline void pcxe_txwinon(struct channel *ch) 328static void pcxe_txwinon(struct channel *ch)
339{ 329{
340 outb_p(ch->txwin, (int)ch->board->port + 1); 330 outb_p(ch->txwin, (int)ch->board->port + 1);
341} 331}
342 332
343static inline void pcxe_memoff(struct channel *ch) 333static void pcxe_memoff(struct channel *ch)
344{ 334{
345 outb_p(0, (int)ch->board->port); 335 outb_p(0, (int)ch->board->port);
346 outb_p(0, (int)ch->board->port + 1); 336 outb_p(0, (int)ch->board->port + 1);
@@ -348,44 +338,44 @@ static inline void pcxe_memoff(struct channel *ch)
348 338
349/* ------------- Begin pc64xe and pcxi memory window stuff -------------- */ 339/* ------------- Begin pc64xe and pcxi memory window stuff -------------- */
350 340
351static inline void pcxi_memwinon(struct board_info *b, unsigned int win) 341static void pcxi_memwinon(struct board_info *b, unsigned int win)
352{ 342{
353 outb_p(inb((int)b->port) | FEPMEM, (int)b->port); 343 outb_p(inb(b->port) | FEPMEM, b->port);
354} 344}
355 345
356static inline void pcxi_memwinoff(struct board_info *b, unsigned int win) 346static void pcxi_memwinoff(struct board_info *b, unsigned int win)
357{ 347{
358 outb_p(inb((int)b->port) & ~FEPMEM, (int)b->port); 348 outb_p(inb(b->port) & ~FEPMEM, b->port);
359} 349}
360 350
361static inline void pcxi_globalwinon(struct channel *ch) 351static void pcxi_globalwinon(struct channel *ch)
362{ 352{
363 outb_p(FEPMEM, (int)ch->board->port); 353 outb_p(FEPMEM, ch->board->port);
364} 354}
365 355
366static inline void pcxi_rxwinon(struct channel *ch) 356static void pcxi_rxwinon(struct channel *ch)
367{ 357{
368 outb_p(FEPMEM, (int)ch->board->port); 358 outb_p(FEPMEM, ch->board->port);
369} 359}
370 360
371static inline void pcxi_txwinon(struct channel *ch) 361static void pcxi_txwinon(struct channel *ch)
372{ 362{
373 outb_p(FEPMEM, (int)ch->board->port); 363 outb_p(FEPMEM, ch->board->port);
374} 364}
375 365
376static inline void pcxi_memoff(struct channel *ch) 366static void pcxi_memoff(struct channel *ch)
377{ 367{
378 outb_p(0, (int)ch->board->port); 368 outb_p(0, ch->board->port);
379} 369}
380 370
381static inline void pcxi_assertgwinon(struct channel *ch) 371static void pcxi_assertgwinon(struct channel *ch)
382{ 372{
383 epcaassert(inb((int)ch->board->port) & FEPMEM, "Global memory off"); 373 epcaassert(inb(ch->board->port) & FEPMEM, "Global memory off");
384} 374}
385 375
386static inline void pcxi_assertmemoff(struct channel *ch) 376static void pcxi_assertmemoff(struct channel *ch)
387{ 377{
388 epcaassert(!(inb((int)ch->board->port) & FEPMEM), "Memory on"); 378 epcaassert(!(inb(ch->board->port) & FEPMEM), "Memory on");
389} 379}
390 380
391 381
@@ -398,185 +388,143 @@ static inline void pcxi_assertmemoff(struct channel *ch)
398 may or may not do anything. 388 may or may not do anything.
399---------------------------------------------------------------------------*/ 389---------------------------------------------------------------------------*/
400 390
401static inline void dummy_memwinon(struct board_info *b, unsigned int win) 391static void dummy_memwinon(struct board_info *b, unsigned int win)
402{ 392{
403} 393}
404 394
405static inline void dummy_memwinoff(struct board_info *b, unsigned int win) 395static void dummy_memwinoff(struct board_info *b, unsigned int win)
406{ 396{
407} 397}
408 398
409static inline void dummy_globalwinon(struct channel *ch) 399static void dummy_globalwinon(struct channel *ch)
410{ 400{
411} 401}
412 402
413static inline void dummy_rxwinon(struct channel *ch) 403static void dummy_rxwinon(struct channel *ch)
414{ 404{
415} 405}
416 406
417static inline void dummy_txwinon(struct channel *ch) 407static void dummy_txwinon(struct channel *ch)
418{ 408{
419} 409}
420 410
421static inline void dummy_memoff(struct channel *ch) 411static void dummy_memoff(struct channel *ch)
422{ 412{
423} 413}
424 414
425static inline void dummy_assertgwinon(struct channel *ch) 415static void dummy_assertgwinon(struct channel *ch)
426{ 416{
427} 417}
428 418
429static inline void dummy_assertmemoff(struct channel *ch) 419static void dummy_assertmemoff(struct channel *ch)
430{ 420{
431} 421}
432 422
433/* ----------------- Begin verifyChannel function ----------------------- */ 423/* ----------------- Begin verifyChannel function ----------------------- */
434static inline struct channel *verifyChannel(register struct tty_struct *tty) 424static struct channel *verifyChannel(struct tty_struct *tty)
435{ /* Begin verifyChannel */ 425{ /* Begin verifyChannel */
436
437 /* -------------------------------------------------------------------- 426 /* --------------------------------------------------------------------
438 This routine basically provides a sanity check. It insures that 427 This routine basically provides a sanity check. It insures that
439 the channel returned is within the proper range of addresses as 428 the channel returned is within the proper range of addresses as
440 well as properly initialized. If some bogus info gets passed in 429 well as properly initialized. If some bogus info gets passed in
441 through tty->driver_data this should catch it. 430 through tty->driver_data this should catch it.
442 --------------------------------------------------------------------- */ 431 --------------------------------------------------------------------- */
443 432 if (tty) {
444 if (tty) 433 struct channel *ch = (struct channel *)tty->driver_data;
445 { /* Begin if tty */ 434 if ((ch >= &digi_channels[0]) && (ch < &digi_channels[nbdevs])) {
446
447 register struct channel *ch = (struct channel *)tty->driver_data;
448
449 if ((ch >= &digi_channels[0]) && (ch < &digi_channels[nbdevs]))
450 {
451 if (ch->magic == EPCA_MAGIC) 435 if (ch->magic == EPCA_MAGIC)
452 return ch; 436 return ch;
453 } 437 }
454 438 }
455 } /* End if tty */
456
457 /* Else return a NULL for invalid */
458 return NULL; 439 return NULL;
459 440
460} /* End verifyChannel */ 441} /* End verifyChannel */
461 442
462/* ------------------ Begin pc_sched_event ------------------------- */ 443/* ------------------ Begin pc_sched_event ------------------------- */
463 444
464static inline void pc_sched_event(struct channel *ch, int event) 445static void pc_sched_event(struct channel *ch, int event)
465{ /* Begin pc_sched_event */ 446{
466
467
468 /* ---------------------------------------------------------------------- 447 /* ----------------------------------------------------------------------
469 We call this to schedule interrupt processing on some event. The 448 We call this to schedule interrupt processing on some event. The
470 kernel sees our request and calls the related routine in OUR driver. 449 kernel sees our request and calls the related routine in OUR driver.
471 -------------------------------------------------------------------------*/ 450 -------------------------------------------------------------------------*/
472
473 ch->event |= 1 << event; 451 ch->event |= 1 << event;
474 schedule_work(&ch->tqueue); 452 schedule_work(&ch->tqueue);
475
476
477} /* End pc_sched_event */ 453} /* End pc_sched_event */
478 454
479/* ------------------ Begin epca_error ------------------------- */ 455/* ------------------ Begin epca_error ------------------------- */
480 456
481static void epca_error(int line, char *msg) 457static void epca_error(int line, char *msg)
482{ /* Begin epca_error */ 458{
483
484 printk(KERN_ERR "epca_error (Digi): line = %d %s\n",line,msg); 459 printk(KERN_ERR "epca_error (Digi): line = %d %s\n",line,msg);
485 return; 460}
486
487} /* End epca_error */
488 461
489/* ------------------ Begin pc_close ------------------------- */ 462/* ------------------ Begin pc_close ------------------------- */
490static void pc_close(struct tty_struct * tty, struct file * filp) 463static void pc_close(struct tty_struct * tty, struct file * filp)
491{ /* Begin pc_close */ 464{
492
493 struct channel *ch; 465 struct channel *ch;
494 unsigned long flags; 466 unsigned long flags;
495
496 /* --------------------------------------------------------- 467 /* ---------------------------------------------------------
497 verifyChannel returns the channel from the tty struct 468 verifyChannel returns the channel from the tty struct
498 if it is valid. This serves as a sanity check. 469 if it is valid. This serves as a sanity check.
499 ------------------------------------------------------------- */ 470 ------------------------------------------------------------- */
500 471 if ((ch = verifyChannel(tty)) != NULL) { /* Begin if ch != NULL */
501 if ((ch = verifyChannel(tty)) != NULL) 472 spin_lock_irqsave(&epca_lock, flags);
502 { /* Begin if ch != NULL */ 473 if (tty_hung_up_p(filp)) {
503 474 spin_unlock_irqrestore(&epca_lock, flags);
504 save_flags(flags);
505 cli();
506
507 if (tty_hung_up_p(filp))
508 {
509 restore_flags(flags);
510 return; 475 return;
511 } 476 }
512
513 /* Check to see if the channel is open more than once */ 477 /* Check to see if the channel is open more than once */
514 if (ch->count-- > 1) 478 if (ch->count-- > 1) {
515 { /* Begin channel is open more than once */ 479 /* Begin channel is open more than once */
516
517 /* ------------------------------------------------------------- 480 /* -------------------------------------------------------------
518 Return without doing anything. Someone might still be using 481 Return without doing anything. Someone might still be using
519 the channel. 482 the channel.
520 ---------------------------------------------------------------- */ 483 ---------------------------------------------------------------- */
521 484 spin_unlock_irqrestore(&epca_lock, flags);
522 restore_flags(flags);
523 return; 485 return;
524 } /* End channel is open more than once */ 486 } /* End channel is open more than once */
525 487
526 /* Port open only once go ahead with shutdown & reset */ 488 /* Port open only once go ahead with shutdown & reset */
527 489 if (ch->count < 0)
528 if (ch->count < 0) 490 BUG();
529 {
530 ch->count = 0;
531 }
532 491
533 /* --------------------------------------------------------------- 492 /* ---------------------------------------------------------------
534 Let the rest of the driver know the channel is being closed. 493 Let the rest of the driver know the channel is being closed.
535 This becomes important if an open is attempted before close 494 This becomes important if an open is attempted before close
536 is finished. 495 is finished.
537 ------------------------------------------------------------------ */ 496 ------------------------------------------------------------------ */
538
539 ch->asyncflags |= ASYNC_CLOSING; 497 ch->asyncflags |= ASYNC_CLOSING;
540
541 tty->closing = 1; 498 tty->closing = 1;
542 499
543 if (ch->asyncflags & ASYNC_INITIALIZED) 500 spin_unlock_irqrestore(&epca_lock, flags);
544 { 501
502 if (ch->asyncflags & ASYNC_INITIALIZED) {
545 /* Setup an event to indicate when the transmit buffer empties */ 503 /* Setup an event to indicate when the transmit buffer empties */
546 setup_empty_event(tty, ch); 504 setup_empty_event(tty, ch);
547 tty_wait_until_sent(tty, 3000); /* 30 seconds timeout */ 505 tty_wait_until_sent(tty, 3000); /* 30 seconds timeout */
548 } 506 }
549
550 if (tty->driver->flush_buffer) 507 if (tty->driver->flush_buffer)
551 tty->driver->flush_buffer(tty); 508 tty->driver->flush_buffer(tty);
552 509
553 tty_ldisc_flush(tty); 510 tty_ldisc_flush(tty);
554 shutdown(ch); 511 shutdown(ch);
512
513 spin_lock_irqsave(&epca_lock, flags);
555 tty->closing = 0; 514 tty->closing = 0;
556 ch->event = 0; 515 ch->event = 0;
557 ch->tty = NULL; 516 ch->tty = NULL;
517 spin_unlock_irqrestore(&epca_lock, flags);
558 518
559 if (ch->blocked_open) 519 if (ch->blocked_open) { /* Begin if blocked_open */
560 { /* Begin if blocked_open */
561
562 if (ch->close_delay) 520 if (ch->close_delay)
563 {
564 msleep_interruptible(jiffies_to_msecs(ch->close_delay)); 521 msleep_interruptible(jiffies_to_msecs(ch->close_delay));
565 }
566
567 wake_up_interruptible(&ch->open_wait); 522 wake_up_interruptible(&ch->open_wait);
568
569 } /* End if blocked_open */ 523 } /* End if blocked_open */
570
571 ch->asyncflags &= ~(ASYNC_NORMAL_ACTIVE | ASYNC_INITIALIZED | 524 ch->asyncflags &= ~(ASYNC_NORMAL_ACTIVE | ASYNC_INITIALIZED |
572 ASYNC_CLOSING); 525 ASYNC_CLOSING);
573 wake_up_interruptible(&ch->close_wait); 526 wake_up_interruptible(&ch->close_wait);
574
575
576 restore_flags(flags);
577
578 } /* End if ch != NULL */ 527 } /* End if ch != NULL */
579
580} /* End pc_close */ 528} /* End pc_close */
581 529
582/* ------------------ Begin shutdown ------------------------- */ 530/* ------------------ Begin shutdown ------------------------- */
@@ -586,15 +534,14 @@ static void shutdown(struct channel *ch)
586 534
587 unsigned long flags; 535 unsigned long flags;
588 struct tty_struct *tty; 536 struct tty_struct *tty;
589 volatile struct board_chan *bc; 537 struct board_chan *bc;
590 538
591 if (!(ch->asyncflags & ASYNC_INITIALIZED)) 539 if (!(ch->asyncflags & ASYNC_INITIALIZED))
592 return; 540 return;
593 541
594 save_flags(flags); 542 spin_lock_irqsave(&epca_lock, flags);
595 cli();
596 globalwinon(ch);
597 543
544 globalwinon(ch);
598 bc = ch->brdchan; 545 bc = ch->brdchan;
599 546
600 /* ------------------------------------------------------------------ 547 /* ------------------------------------------------------------------
@@ -604,20 +551,17 @@ static void shutdown(struct channel *ch)
604 --------------------------------------------------------------------- */ 551 --------------------------------------------------------------------- */
605 552
606 if (bc) 553 if (bc)
607 bc->idata = 0; 554 writeb(0, &bc->idata);
608
609 tty = ch->tty; 555 tty = ch->tty;
610 556
611 /* ---------------------------------------------------------------- 557 /* ----------------------------------------------------------------
612 If we're a modem control device and HUPCL is on, drop RTS & DTR. 558 If we're a modem control device and HUPCL is on, drop RTS & DTR.
613 ------------------------------------------------------------------ */ 559 ------------------------------------------------------------------ */
614 560
615 if (tty->termios->c_cflag & HUPCL) 561 if (tty->termios->c_cflag & HUPCL) {
616 {
617 ch->omodem &= ~(ch->m_rts | ch->m_dtr); 562 ch->omodem &= ~(ch->m_rts | ch->m_dtr);
618 fepcmd(ch, SETMODEM, 0, ch->m_dtr | ch->m_rts, 10, 1); 563 fepcmd(ch, SETMODEM, 0, ch->m_dtr | ch->m_rts, 10, 1);
619 } 564 }
620
621 memoff(ch); 565 memoff(ch);
622 566
623 /* ------------------------------------------------------------------ 567 /* ------------------------------------------------------------------
@@ -628,7 +572,7 @@ static void shutdown(struct channel *ch)
628 /* Prevent future Digi programmed interrupts from coming active */ 572 /* Prevent future Digi programmed interrupts from coming active */
629 573
630 ch->asyncflags &= ~ASYNC_INITIALIZED; 574 ch->asyncflags &= ~ASYNC_INITIALIZED;
631 restore_flags(flags); 575 spin_unlock_irqrestore(&epca_lock, flags);
632 576
633} /* End shutdown */ 577} /* End shutdown */
634 578
@@ -636,7 +580,6 @@ static void shutdown(struct channel *ch)
636 580
637static void pc_hangup(struct tty_struct *tty) 581static void pc_hangup(struct tty_struct *tty)
638{ /* Begin pc_hangup */ 582{ /* Begin pc_hangup */
639
640 struct channel *ch; 583 struct channel *ch;
641 584
642 /* --------------------------------------------------------- 585 /* ---------------------------------------------------------
@@ -644,25 +587,21 @@ static void pc_hangup(struct tty_struct *tty)
644 if it is valid. This serves as a sanity check. 587 if it is valid. This serves as a sanity check.
645 ------------------------------------------------------------- */ 588 ------------------------------------------------------------- */
646 589
647 if ((ch = verifyChannel(tty)) != NULL) 590 if ((ch = verifyChannel(tty)) != NULL) { /* Begin if ch != NULL */
648 { /* Begin if ch != NULL */
649
650 unsigned long flags; 591 unsigned long flags;
651 592
652 save_flags(flags);
653 cli();
654 if (tty->driver->flush_buffer) 593 if (tty->driver->flush_buffer)
655 tty->driver->flush_buffer(tty); 594 tty->driver->flush_buffer(tty);
656 tty_ldisc_flush(tty); 595 tty_ldisc_flush(tty);
657 shutdown(ch); 596 shutdown(ch);
658 597
598 spin_lock_irqsave(&epca_lock, flags);
659 ch->tty = NULL; 599 ch->tty = NULL;
660 ch->event = 0; 600 ch->event = 0;
661 ch->count = 0; 601 ch->count = 0;
662 restore_flags(flags);
663 ch->asyncflags &= ~(ASYNC_NORMAL_ACTIVE | ASYNC_INITIALIZED); 602 ch->asyncflags &= ~(ASYNC_NORMAL_ACTIVE | ASYNC_INITIALIZED);
603 spin_unlock_irqrestore(&epca_lock, flags);
664 wake_up_interruptible(&ch->open_wait); 604 wake_up_interruptible(&ch->open_wait);
665
666 } /* End if ch != NULL */ 605 } /* End if ch != NULL */
667 606
668} /* End pc_hangup */ 607} /* End pc_hangup */
@@ -672,18 +611,14 @@ static void pc_hangup(struct tty_struct *tty)
672static int pc_write(struct tty_struct * tty, 611static int pc_write(struct tty_struct * tty,
673 const unsigned char *buf, int bytesAvailable) 612 const unsigned char *buf, int bytesAvailable)
674{ /* Begin pc_write */ 613{ /* Begin pc_write */
675 614 unsigned int head, tail;
676 register unsigned int head, tail; 615 int dataLen;
677 register int dataLen; 616 int size;
678 register int size; 617 int amountCopied;
679 register int amountCopied;
680
681
682 struct channel *ch; 618 struct channel *ch;
683 unsigned long flags; 619 unsigned long flags;
684 int remain; 620 int remain;
685 volatile struct board_chan *bc; 621 struct board_chan *bc;
686
687 622
688 /* ---------------------------------------------------------------- 623 /* ----------------------------------------------------------------
689 pc_write is primarily called directly by the kernel routine 624 pc_write is primarily called directly by the kernel routine
@@ -706,24 +641,20 @@ static int pc_write(struct tty_struct * tty,
706 641
707 bc = ch->brdchan; 642 bc = ch->brdchan;
708 size = ch->txbufsize; 643 size = ch->txbufsize;
709
710 amountCopied = 0; 644 amountCopied = 0;
711 save_flags(flags);
712 cli();
713 645
646 spin_lock_irqsave(&epca_lock, flags);
714 globalwinon(ch); 647 globalwinon(ch);
715 648
716 head = bc->tin & (size - 1); 649 head = readw(&bc->tin) & (size - 1);
717 tail = bc->tout; 650 tail = readw(&bc->tout);
718 651
719 if (tail != bc->tout) 652 if (tail != readw(&bc->tout))
720 tail = bc->tout; 653 tail = readw(&bc->tout);
721 tail &= (size - 1); 654 tail &= (size - 1);
722 655
723 /* If head >= tail, head has not wrapped around. */ 656 /* If head >= tail, head has not wrapped around. */
724 if (head >= tail) 657 if (head >= tail) { /* Begin head has not wrapped */
725 { /* Begin head has not wrapped */
726
727 /* --------------------------------------------------------------- 658 /* ---------------------------------------------------------------
728 remain (much like dataLen above) represents the total amount of 659 remain (much like dataLen above) represents the total amount of
729 space available on the card for data. Here dataLen represents 660 space available on the card for data. Here dataLen represents
@@ -731,26 +662,19 @@ static int pc_write(struct tty_struct * tty,
731 buffer. This is important because a memcpy cannot be told to 662 buffer. This is important because a memcpy cannot be told to
732 automatically wrap around when it hits the buffer end. 663 automatically wrap around when it hits the buffer end.
733 ------------------------------------------------------------------ */ 664 ------------------------------------------------------------------ */
734
735 dataLen = size - head; 665 dataLen = size - head;
736 remain = size - (head - tail) - 1; 666 remain = size - (head - tail) - 1;
737 667 } else { /* Begin head has wrapped around */
738 } /* End head has not wrapped */
739 else
740 { /* Begin head has wrapped around */
741 668
742 remain = tail - head - 1; 669 remain = tail - head - 1;
743 dataLen = remain; 670 dataLen = remain;
744 671
745 } /* End head has wrapped around */ 672 } /* End head has wrapped around */
746
747 /* ------------------------------------------------------------------- 673 /* -------------------------------------------------------------------
748 Check the space on the card. If we have more data than 674 Check the space on the card. If we have more data than
749 space; reduce the amount of data to fit the space. 675 space; reduce the amount of data to fit the space.
750 ---------------------------------------------------------------------- */ 676 ---------------------------------------------------------------------- */
751
752 bytesAvailable = min(remain, bytesAvailable); 677 bytesAvailable = min(remain, bytesAvailable);
753
754 txwinon(ch); 678 txwinon(ch);
755 while (bytesAvailable > 0) 679 while (bytesAvailable > 0)
756 { /* Begin while there is data to copy onto card */ 680 { /* Begin while there is data to copy onto card */
@@ -767,26 +691,21 @@ static int pc_write(struct tty_struct * tty,
767 amountCopied += dataLen; 691 amountCopied += dataLen;
768 bytesAvailable -= dataLen; 692 bytesAvailable -= dataLen;
769 693
770 if (head >= size) 694 if (head >= size) {
771 {
772 head = 0; 695 head = 0;
773 dataLen = tail; 696 dataLen = tail;
774 } 697 }
775
776 } /* End while there is data to copy onto card */ 698 } /* End while there is data to copy onto card */
777
778 ch->statusflags |= TXBUSY; 699 ch->statusflags |= TXBUSY;
779 globalwinon(ch); 700 globalwinon(ch);
780 bc->tin = head; 701 writew(head, &bc->tin);
781 702
782 if ((ch->statusflags & LOWWAIT) == 0) 703 if ((ch->statusflags & LOWWAIT) == 0) {
783 {
784 ch->statusflags |= LOWWAIT; 704 ch->statusflags |= LOWWAIT;
785 bc->ilow = 1; 705 writeb(1, &bc->ilow);
786 } 706 }
787 memoff(ch); 707 memoff(ch);
788 restore_flags(flags); 708 spin_unlock_irqrestore(&epca_lock, flags);
789
790 return(amountCopied); 709 return(amountCopied);
791 710
792} /* End pc_write */ 711} /* End pc_write */
@@ -795,11 +714,7 @@ static int pc_write(struct tty_struct * tty,
795 714
796static void pc_put_char(struct tty_struct *tty, unsigned char c) 715static void pc_put_char(struct tty_struct *tty, unsigned char c)
797{ /* Begin pc_put_char */ 716{ /* Begin pc_put_char */
798
799
800 pc_write(tty, &c, 1); 717 pc_write(tty, &c, 1);
801 return;
802
803} /* End pc_put_char */ 718} /* End pc_put_char */
804 719
805/* ------------------ Begin pc_write_room ------------------------- */ 720/* ------------------ Begin pc_write_room ------------------------- */
@@ -811,7 +726,7 @@ static int pc_write_room(struct tty_struct *tty)
811 struct channel *ch; 726 struct channel *ch;
812 unsigned long flags; 727 unsigned long flags;
813 unsigned int head, tail; 728 unsigned int head, tail;
814 volatile struct board_chan *bc; 729 struct board_chan *bc;
815 730
816 remain = 0; 731 remain = 0;
817 732
@@ -820,33 +735,29 @@ static int pc_write_room(struct tty_struct *tty)
820 if it is valid. This serves as a sanity check. 735 if it is valid. This serves as a sanity check.
821 ------------------------------------------------------------- */ 736 ------------------------------------------------------------- */
822 737
823 if ((ch = verifyChannel(tty)) != NULL) 738 if ((ch = verifyChannel(tty)) != NULL) {
824 { 739 spin_lock_irqsave(&epca_lock, flags);
825 save_flags(flags);
826 cli();
827 globalwinon(ch); 740 globalwinon(ch);
828 741
829 bc = ch->brdchan; 742 bc = ch->brdchan;
830 head = bc->tin & (ch->txbufsize - 1); 743 head = readw(&bc->tin) & (ch->txbufsize - 1);
831 tail = bc->tout; 744 tail = readw(&bc->tout);
832 745
833 if (tail != bc->tout) 746 if (tail != readw(&bc->tout))
834 tail = bc->tout; 747 tail = readw(&bc->tout);
835 /* Wrap tail if necessary */ 748 /* Wrap tail if necessary */
836 tail &= (ch->txbufsize - 1); 749 tail &= (ch->txbufsize - 1);
837 750
838 if ((remain = tail - head - 1) < 0 ) 751 if ((remain = tail - head - 1) < 0 )
839 remain += ch->txbufsize; 752 remain += ch->txbufsize;
840 753
841 if (remain && (ch->statusflags & LOWWAIT) == 0) 754 if (remain && (ch->statusflags & LOWWAIT) == 0) {
842 {
843 ch->statusflags |= LOWWAIT; 755 ch->statusflags |= LOWWAIT;
844 bc->ilow = 1; 756 writeb(1, &bc->ilow);
845 } 757 }
846 memoff(ch); 758 memoff(ch);
847 restore_flags(flags); 759 spin_unlock_irqrestore(&epca_lock, flags);
848 } 760 }
849
850 /* Return how much room is left on card */ 761 /* Return how much room is left on card */
851 return remain; 762 return remain;
852 763
@@ -862,8 +773,7 @@ static int pc_chars_in_buffer(struct tty_struct *tty)
862 int remain; 773 int remain;
863 unsigned long flags; 774 unsigned long flags;
864 struct channel *ch; 775 struct channel *ch;
865 volatile struct board_chan *bc; 776 struct board_chan *bc;
866
867 777
868 /* --------------------------------------------------------- 778 /* ---------------------------------------------------------
869 verifyChannel returns the channel from the tty struct 779 verifyChannel returns the channel from the tty struct
@@ -873,34 +783,27 @@ static int pc_chars_in_buffer(struct tty_struct *tty)
873 if ((ch = verifyChannel(tty)) == NULL) 783 if ((ch = verifyChannel(tty)) == NULL)
874 return(0); 784 return(0);
875 785
876 save_flags(flags); 786 spin_lock_irqsave(&epca_lock, flags);
877 cli();
878 globalwinon(ch); 787 globalwinon(ch);
879 788
880 bc = ch->brdchan; 789 bc = ch->brdchan;
881 tail = bc->tout; 790 tail = readw(&bc->tout);
882 head = bc->tin; 791 head = readw(&bc->tin);
883 ctail = ch->mailbox->cout; 792 ctail = readw(&ch->mailbox->cout);
884 793
885 if (tail == head && ch->mailbox->cin == ctail && bc->tbusy == 0) 794 if (tail == head && readw(&ch->mailbox->cin) == ctail && readb(&bc->tbusy) == 0)
886 chars = 0; 795 chars = 0;
887 else 796 else { /* Begin if some space on the card has been used */
888 { /* Begin if some space on the card has been used */ 797 head = readw(&bc->tin) & (ch->txbufsize - 1);
889
890 head = bc->tin & (ch->txbufsize - 1);
891 tail &= (ch->txbufsize - 1); 798 tail &= (ch->txbufsize - 1);
892
893 /* -------------------------------------------------------------- 799 /* --------------------------------------------------------------
894 The logic here is basically opposite of the above pc_write_room 800 The logic here is basically opposite of the above pc_write_room
895 here we are finding the amount of bytes in the buffer filled. 801 here we are finding the amount of bytes in the buffer filled.
896 Not the amount of bytes empty. 802 Not the amount of bytes empty.
897 ------------------------------------------------------------------- */ 803 ------------------------------------------------------------------- */
898
899 if ((remain = tail - head - 1) < 0 ) 804 if ((remain = tail - head - 1) < 0 )
900 remain += ch->txbufsize; 805 remain += ch->txbufsize;
901
902 chars = (int)(ch->txbufsize - remain); 806 chars = (int)(ch->txbufsize - remain);
903
904 /* ------------------------------------------------------------- 807 /* -------------------------------------------------------------
905 Make it possible to wakeup anything waiting for output 808 Make it possible to wakeup anything waiting for output
906 in tty_ioctl.c, etc. 809 in tty_ioctl.c, etc.
@@ -908,15 +811,12 @@ static int pc_chars_in_buffer(struct tty_struct *tty)
908 If not already set. Setup an event to indicate when the 811 If not already set. Setup an event to indicate when the
909 transmit buffer empties 812 transmit buffer empties
910 ----------------------------------------------------------------- */ 813 ----------------------------------------------------------------- */
911
912 if (!(ch->statusflags & EMPTYWAIT)) 814 if (!(ch->statusflags & EMPTYWAIT))
913 setup_empty_event(tty,ch); 815 setup_empty_event(tty,ch);
914 816
915 } /* End if some space on the card has been used */ 817 } /* End if some space on the card has been used */
916
917 memoff(ch); 818 memoff(ch);
918 restore_flags(flags); 819 spin_unlock_irqrestore(&epca_lock, flags);
919
920 /* Return number of characters residing on card. */ 820 /* Return number of characters residing on card. */
921 return(chars); 821 return(chars);
922 822
@@ -930,67 +830,46 @@ static void pc_flush_buffer(struct tty_struct *tty)
930 unsigned int tail; 830 unsigned int tail;
931 unsigned long flags; 831 unsigned long flags;
932 struct channel *ch; 832 struct channel *ch;
933 volatile struct board_chan *bc; 833 struct board_chan *bc;
934
935
936 /* --------------------------------------------------------- 834 /* ---------------------------------------------------------
937 verifyChannel returns the channel from the tty struct 835 verifyChannel returns the channel from the tty struct
938 if it is valid. This serves as a sanity check. 836 if it is valid. This serves as a sanity check.
939 ------------------------------------------------------------- */ 837 ------------------------------------------------------------- */
940
941 if ((ch = verifyChannel(tty)) == NULL) 838 if ((ch = verifyChannel(tty)) == NULL)
942 return; 839 return;
943 840
944 save_flags(flags); 841 spin_lock_irqsave(&epca_lock, flags);
945 cli();
946
947 globalwinon(ch); 842 globalwinon(ch);
948
949 bc = ch->brdchan; 843 bc = ch->brdchan;
950 tail = bc->tout; 844 tail = readw(&bc->tout);
951
952 /* Have FEP move tout pointer; effectively flushing transmit buffer */ 845 /* Have FEP move tout pointer; effectively flushing transmit buffer */
953
954 fepcmd(ch, STOUT, (unsigned) tail, 0, 0, 0); 846 fepcmd(ch, STOUT, (unsigned) tail, 0, 0, 0);
955
956 memoff(ch); 847 memoff(ch);
957 restore_flags(flags); 848 spin_unlock_irqrestore(&epca_lock, flags);
958
959 wake_up_interruptible(&tty->write_wait); 849 wake_up_interruptible(&tty->write_wait);
960 tty_wakeup(tty); 850 tty_wakeup(tty);
961
962} /* End pc_flush_buffer */ 851} /* End pc_flush_buffer */
963 852
964/* ------------------ Begin pc_flush_chars ---------------------- */ 853/* ------------------ Begin pc_flush_chars ---------------------- */
965 854
966static void pc_flush_chars(struct tty_struct *tty) 855static void pc_flush_chars(struct tty_struct *tty)
967{ /* Begin pc_flush_chars */ 856{ /* Begin pc_flush_chars */
968
969 struct channel * ch; 857 struct channel * ch;
970
971 /* --------------------------------------------------------- 858 /* ---------------------------------------------------------
972 verifyChannel returns the channel from the tty struct 859 verifyChannel returns the channel from the tty struct
973 if it is valid. This serves as a sanity check. 860 if it is valid. This serves as a sanity check.
974 ------------------------------------------------------------- */ 861 ------------------------------------------------------------- */
975 862 if ((ch = verifyChannel(tty)) != NULL) {
976 if ((ch = verifyChannel(tty)) != NULL)
977 {
978 unsigned long flags; 863 unsigned long flags;
979 864 spin_lock_irqsave(&epca_lock, flags);
980 save_flags(flags);
981 cli();
982
983 /* ---------------------------------------------------------------- 865 /* ----------------------------------------------------------------
984 If not already set and the transmitter is busy setup an event 866 If not already set and the transmitter is busy setup an event
985 to indicate when the transmit empties. 867 to indicate when the transmit empties.
986 ------------------------------------------------------------------- */ 868 ------------------------------------------------------------------- */
987
988 if ((ch->statusflags & TXBUSY) && !(ch->statusflags & EMPTYWAIT)) 869 if ((ch->statusflags & TXBUSY) && !(ch->statusflags & EMPTYWAIT))
989 setup_empty_event(tty,ch); 870 setup_empty_event(tty,ch);
990 871 spin_unlock_irqrestore(&epca_lock, flags);
991 restore_flags(flags);
992 } 872 }
993
994} /* End pc_flush_chars */ 873} /* End pc_flush_chars */
995 874
996/* ------------------ Begin block_til_ready ---------------------- */ 875/* ------------------ Begin block_til_ready ---------------------- */
@@ -998,14 +877,11 @@ static void pc_flush_chars(struct tty_struct *tty)
998static int block_til_ready(struct tty_struct *tty, 877static int block_til_ready(struct tty_struct *tty,
999 struct file *filp, struct channel *ch) 878 struct file *filp, struct channel *ch)
1000{ /* Begin block_til_ready */ 879{ /* Begin block_til_ready */
1001
1002 DECLARE_WAITQUEUE(wait,current); 880 DECLARE_WAITQUEUE(wait,current);
1003 int retval, do_clocal = 0; 881 int retval, do_clocal = 0;
1004 unsigned long flags; 882 unsigned long flags;
1005 883
1006 884 if (tty_hung_up_p(filp)) {
1007 if (tty_hung_up_p(filp))
1008 {
1009 if (ch->asyncflags & ASYNC_HUP_NOTIFY) 885 if (ch->asyncflags & ASYNC_HUP_NOTIFY)
1010 retval = -EAGAIN; 886 retval = -EAGAIN;
1011 else 887 else
@@ -1017,8 +893,7 @@ static int block_til_ready(struct tty_struct *tty,
1017 If the device is in the middle of being closed, then block 893 If the device is in the middle of being closed, then block
1018 until it's done, and then try again. 894 until it's done, and then try again.
1019 -------------------------------------------------------------------- */ 895 -------------------------------------------------------------------- */
1020 if (ch->asyncflags & ASYNC_CLOSING) 896 if (ch->asyncflags & ASYNC_CLOSING) {
1021 {
1022 interruptible_sleep_on(&ch->close_wait); 897 interruptible_sleep_on(&ch->close_wait);
1023 898
1024 if (ch->asyncflags & ASYNC_HUP_NOTIFY) 899 if (ch->asyncflags & ASYNC_HUP_NOTIFY)
@@ -1027,43 +902,29 @@ static int block_til_ready(struct tty_struct *tty,
1027 return -ERESTARTSYS; 902 return -ERESTARTSYS;
1028 } 903 }
1029 904
1030 if (filp->f_flags & O_NONBLOCK) 905 if (filp->f_flags & O_NONBLOCK) {
1031 {
1032 /* ----------------------------------------------------------------- 906 /* -----------------------------------------------------------------
1033 If non-blocking mode is set, then make the check up front 907 If non-blocking mode is set, then make the check up front
1034 and then exit. 908 and then exit.
1035 -------------------------------------------------------------------- */ 909 -------------------------------------------------------------------- */
1036
1037 ch->asyncflags |= ASYNC_NORMAL_ACTIVE; 910 ch->asyncflags |= ASYNC_NORMAL_ACTIVE;
1038
1039 return 0; 911 return 0;
1040 } 912 }
1041
1042
1043 if (tty->termios->c_cflag & CLOCAL) 913 if (tty->termios->c_cflag & CLOCAL)
1044 do_clocal = 1; 914 do_clocal = 1;
1045 915 /* Block waiting for the carrier detect and the line to become free */
1046 /* Block waiting for the carrier detect and the line to become free */
1047 916
1048 retval = 0; 917 retval = 0;
1049 add_wait_queue(&ch->open_wait, &wait); 918 add_wait_queue(&ch->open_wait, &wait);
1050 save_flags(flags);
1051 cli();
1052
1053 919
920 spin_lock_irqsave(&epca_lock, flags);
1054 /* We dec count so that pc_close will know when to free things */ 921 /* We dec count so that pc_close will know when to free things */
1055 if (!tty_hung_up_p(filp)) 922 if (!tty_hung_up_p(filp))
1056 ch->count--; 923 ch->count--;
1057
1058 restore_flags(flags);
1059
1060 ch->blocked_open++; 924 ch->blocked_open++;
1061
1062 while(1) 925 while(1)
1063 { /* Begin forever while */ 926 { /* Begin forever while */
1064
1065 set_current_state(TASK_INTERRUPTIBLE); 927 set_current_state(TASK_INTERRUPTIBLE);
1066
1067 if (tty_hung_up_p(filp) || 928 if (tty_hung_up_p(filp) ||
1068 !(ch->asyncflags & ASYNC_INITIALIZED)) 929 !(ch->asyncflags & ASYNC_INITIALIZED))
1069 { 930 {
@@ -1073,17 +934,14 @@ static int block_til_ready(struct tty_struct *tty,
1073 retval = -ERESTARTSYS; 934 retval = -ERESTARTSYS;
1074 break; 935 break;
1075 } 936 }
1076
1077 if (!(ch->asyncflags & ASYNC_CLOSING) && 937 if (!(ch->asyncflags & ASYNC_CLOSING) &&
1078 (do_clocal || (ch->imodem & ch->dcd))) 938 (do_clocal || (ch->imodem & ch->dcd)))
1079 break; 939 break;
1080 940 if (signal_pending(current)) {
1081 if (signal_pending(current))
1082 {
1083 retval = -ERESTARTSYS; 941 retval = -ERESTARTSYS;
1084 break; 942 break;
1085 } 943 }
1086 944 spin_unlock_irqrestore(&epca_lock, flags);
1087 /* --------------------------------------------------------------- 945 /* ---------------------------------------------------------------
1088 Allow someone else to be scheduled. We will occasionally go 946 Allow someone else to be scheduled. We will occasionally go
1089 through this loop until one of the above conditions change. 947 through this loop until one of the above conditions change.
@@ -1091,25 +949,23 @@ static int block_til_ready(struct tty_struct *tty,
1091 prevent this loop from hogging the cpu. 949 prevent this loop from hogging the cpu.
1092 ------------------------------------------------------------------ */ 950 ------------------------------------------------------------------ */
1093 schedule(); 951 schedule();
952 spin_lock_irqsave(&epca_lock, flags);
1094 953
1095 } /* End forever while */ 954 } /* End forever while */
1096 955
1097 current->state = TASK_RUNNING; 956 current->state = TASK_RUNNING;
1098 remove_wait_queue(&ch->open_wait, &wait); 957 remove_wait_queue(&ch->open_wait, &wait);
1099 cli();
1100 if (!tty_hung_up_p(filp)) 958 if (!tty_hung_up_p(filp))
1101 ch->count++; 959 ch->count++;
1102 restore_flags(flags);
1103
1104 ch->blocked_open--; 960 ch->blocked_open--;
1105 961
962 spin_unlock_irqrestore(&epca_lock, flags);
963
1106 if (retval) 964 if (retval)
1107 return retval; 965 return retval;
1108 966
1109 ch->asyncflags |= ASYNC_NORMAL_ACTIVE; 967 ch->asyncflags |= ASYNC_NORMAL_ACTIVE;
1110
1111 return 0; 968 return 0;
1112
1113} /* End block_til_ready */ 969} /* End block_til_ready */
1114 970
1115/* ------------------ Begin pc_open ---------------------- */ 971/* ------------------ Begin pc_open ---------------------- */
@@ -1120,17 +976,12 @@ static int pc_open(struct tty_struct *tty, struct file * filp)
1120 struct channel *ch; 976 struct channel *ch;
1121 unsigned long flags; 977 unsigned long flags;
1122 int line, retval, boardnum; 978 int line, retval, boardnum;
1123 volatile struct board_chan *bc; 979 struct board_chan *bc;
1124 volatile unsigned int head; 980 unsigned int head;
1125 981
1126 line = tty->index; 982 line = tty->index;
1127 if (line < 0 || line >= nbdevs) 983 if (line < 0 || line >= nbdevs)
1128 { 984 return -ENODEV;
1129 printk(KERN_ERR "<Error> - pc_open : line out of range in pc_open\n");
1130 tty->driver_data = NULL;
1131 return(-ENODEV);
1132 }
1133
1134 985
1135 ch = &digi_channels[line]; 986 ch = &digi_channels[line];
1136 boardnum = ch->boardnum; 987 boardnum = ch->boardnum;
@@ -1143,66 +994,49 @@ static int pc_open(struct tty_struct *tty, struct file * filp)
1143 goes here. 994 goes here.
1144 ---------------------------------------------------------------------- */ 995 ---------------------------------------------------------------------- */
1145 996
1146 if (invalid_lilo_config) 997 if (invalid_lilo_config) {
1147 {
1148 if (setup_error_code & INVALID_BOARD_TYPE) 998 if (setup_error_code & INVALID_BOARD_TYPE)
1149 printk(KERN_ERR "<Error> - pc_open: Invalid board type specified in LILO command\n"); 999 printk(KERN_ERR "epca: pc_open: Invalid board type specified in kernel options.\n");
1150
1151 if (setup_error_code & INVALID_NUM_PORTS) 1000 if (setup_error_code & INVALID_NUM_PORTS)
1152 printk(KERN_ERR "<Error> - pc_open: Invalid number of ports specified in LILO command\n"); 1001 printk(KERN_ERR "epca: pc_open: Invalid number of ports specified in kernel options.\n");
1153
1154 if (setup_error_code & INVALID_MEM_BASE) 1002 if (setup_error_code & INVALID_MEM_BASE)
1155 printk(KERN_ERR "<Error> - pc_open: Invalid board memory address specified in LILO command\n"); 1003 printk(KERN_ERR "epca: pc_open: Invalid board memory address specified in kernel options.\n");
1156
1157 if (setup_error_code & INVALID_PORT_BASE) 1004 if (setup_error_code & INVALID_PORT_BASE)
1158 printk(KERN_ERR "<Error> - pc_open: Invalid board port address specified in LILO command\n"); 1005 printk(KERN_ERR "epca; pc_open: Invalid board port address specified in kernel options.\n");
1159
1160 if (setup_error_code & INVALID_BOARD_STATUS) 1006 if (setup_error_code & INVALID_BOARD_STATUS)
1161 printk(KERN_ERR "<Error> - pc_open: Invalid board status specified in LILO command\n"); 1007 printk(KERN_ERR "epca: pc_open: Invalid board status specified in kernel options.\n");
1162
1163 if (setup_error_code & INVALID_ALTPIN) 1008 if (setup_error_code & INVALID_ALTPIN)
1164 printk(KERN_ERR "<Error> - pc_open: Invalid board altpin specified in LILO command\n"); 1009 printk(KERN_ERR "epca: pc_open: Invalid board altpin specified in kernel options;\n");
1165
1166 tty->driver_data = NULL; /* Mark this device as 'down' */ 1010 tty->driver_data = NULL; /* Mark this device as 'down' */
1167 return(-ENODEV); 1011 return -ENODEV;
1168 } 1012 }
1169 1013 if (boardnum >= num_cards || boards[boardnum].status == DISABLED) {
1170 if ((boardnum >= num_cards) || (boards[boardnum].status == DISABLED))
1171 {
1172 tty->driver_data = NULL; /* Mark this device as 'down' */ 1014 tty->driver_data = NULL; /* Mark this device as 'down' */
1173 return(-ENODEV); 1015 return(-ENODEV);
1174 } 1016 }
1175 1017
1176 if (( bc = ch->brdchan) == 0) 1018 if ((bc = ch->brdchan) == 0) {
1177 {
1178 tty->driver_data = NULL; 1019 tty->driver_data = NULL;
1179 return(-ENODEV); 1020 return -ENODEV;
1180 } 1021 }
1181 1022
1023 spin_lock_irqsave(&epca_lock, flags);
1182 /* ------------------------------------------------------------------ 1024 /* ------------------------------------------------------------------
1183 Every time a channel is opened, increment a counter. This is 1025 Every time a channel is opened, increment a counter. This is
1184 necessary because we do not wish to flush and shutdown the channel 1026 necessary because we do not wish to flush and shutdown the channel
1185 until the last app holding the channel open, closes it. 1027 until the last app holding the channel open, closes it.
1186 --------------------------------------------------------------------- */ 1028 --------------------------------------------------------------------- */
1187
1188 ch->count++; 1029 ch->count++;
1189
1190 /* ---------------------------------------------------------------- 1030 /* ----------------------------------------------------------------
1191 Set a kernel structures pointer to our local channel 1031 Set a kernel structures pointer to our local channel
1192 structure. This way we can get to it when passed only 1032 structure. This way we can get to it when passed only
1193 a tty struct. 1033 a tty struct.
1194 ------------------------------------------------------------------ */ 1034 ------------------------------------------------------------------ */
1195
1196 tty->driver_data = ch; 1035 tty->driver_data = ch;
1197
1198 /* ---------------------------------------------------------------- 1036 /* ----------------------------------------------------------------
1199 If this is the first time the channel has been opened, initialize 1037 If this is the first time the channel has been opened, initialize
1200 the tty->termios struct otherwise let pc_close handle it. 1038 the tty->termios struct otherwise let pc_close handle it.
1201 -------------------------------------------------------------------- */ 1039 -------------------------------------------------------------------- */
1202
1203 save_flags(flags);
1204 cli();
1205
1206 globalwinon(ch); 1040 globalwinon(ch);
1207 ch->statusflags = 0; 1041 ch->statusflags = 0;
1208 1042
@@ -1213,8 +1047,8 @@ static int pc_open(struct tty_struct *tty, struct file * filp)
1213 Set receive head and tail ptrs to each other. This indicates 1047 Set receive head and tail ptrs to each other. This indicates
1214 no data available to read. 1048 no data available to read.
1215 ----------------------------------------------------------------- */ 1049 ----------------------------------------------------------------- */
1216 head = bc->rin; 1050 head = readw(&bc->rin);
1217 bc->rout = head; 1051 writew(head, &bc->rout);
1218 1052
1219 /* Set the channels associated tty structure */ 1053 /* Set the channels associated tty structure */
1220 ch->tty = tty; 1054 ch->tty = tty;
@@ -1224,122 +1058,74 @@ static int pc_open(struct tty_struct *tty, struct file * filp)
1224 issues, etc.... It effect both control flags and input flags. 1058 issues, etc.... It effect both control flags and input flags.
1225 -------------------------------------------------------------------- */ 1059 -------------------------------------------------------------------- */
1226 epcaparam(tty,ch); 1060 epcaparam(tty,ch);
1227
1228 ch->asyncflags |= ASYNC_INITIALIZED; 1061 ch->asyncflags |= ASYNC_INITIALIZED;
1229 memoff(ch); 1062 memoff(ch);
1230 1063 spin_unlock_irqrestore(&epca_lock, flags);
1231 restore_flags(flags);
1232 1064
1233 retval = block_til_ready(tty, filp, ch); 1065 retval = block_til_ready(tty, filp, ch);
1234 if (retval) 1066 if (retval)
1235 {
1236 return retval; 1067 return retval;
1237 }
1238
1239 /* ------------------------------------------------------------- 1068 /* -------------------------------------------------------------
1240 Set this again in case a hangup set it to zero while this 1069 Set this again in case a hangup set it to zero while this
1241 open() was waiting for the line... 1070 open() was waiting for the line...
1242 --------------------------------------------------------------- */ 1071 --------------------------------------------------------------- */
1072 spin_lock_irqsave(&epca_lock, flags);
1243 ch->tty = tty; 1073 ch->tty = tty;
1244
1245 save_flags(flags);
1246 cli();
1247 globalwinon(ch); 1074 globalwinon(ch);
1248
1249 /* Enable Digi Data events */ 1075 /* Enable Digi Data events */
1250 bc->idata = 1; 1076 writeb(1, &bc->idata);
1251
1252 memoff(ch); 1077 memoff(ch);
1253 restore_flags(flags); 1078 spin_unlock_irqrestore(&epca_lock, flags);
1254
1255 return 0; 1079 return 0;
1256
1257} /* End pc_open */ 1080} /* End pc_open */
1258 1081
1259#ifdef MODULE
1260static int __init epca_module_init(void) 1082static int __init epca_module_init(void)
1261{ /* Begin init_module */ 1083{ /* Begin init_module */
1262 1084 return pc_init();
1263 unsigned long flags;
1264
1265 save_flags(flags);
1266 cli();
1267
1268 pc_init();
1269
1270 restore_flags(flags);
1271
1272 return(0);
1273} 1085}
1274 1086
1275module_init(epca_module_init); 1087module_init(epca_module_init);
1276#endif
1277 1088
1278#ifdef ENABLE_PCI
1279static struct pci_driver epca_driver; 1089static struct pci_driver epca_driver;
1280#endif
1281
1282#ifdef MODULE
1283/* -------------------- Begin cleanup_module ---------------------- */
1284 1090
1285static void __exit epca_module_exit(void) 1091static void __exit epca_module_exit(void)
1286{ 1092{
1287
1288 int count, crd; 1093 int count, crd;
1289 struct board_info *bd; 1094 struct board_info *bd;
1290 struct channel *ch; 1095 struct channel *ch;
1291 unsigned long flags;
1292 1096
1293 del_timer_sync(&epca_timer); 1097 del_timer_sync(&epca_timer);
1294 1098
1295 save_flags(flags);
1296 cli();
1297
1298 if ((tty_unregister_driver(pc_driver)) || 1099 if ((tty_unregister_driver(pc_driver)) ||
1299 (tty_unregister_driver(pc_info))) 1100 (tty_unregister_driver(pc_info)))
1300 { 1101 {
1301 printk(KERN_WARNING "<Error> - DIGI : cleanup_module failed to un-register tty driver\n"); 1102 printk(KERN_WARNING "epca: cleanup_module failed to un-register tty driver\n");
1302 restore_flags(flags);
1303 return; 1103 return;
1304 } 1104 }
1305 put_tty_driver(pc_driver); 1105 put_tty_driver(pc_driver);
1306 put_tty_driver(pc_info); 1106 put_tty_driver(pc_info);
1307 1107
1308 for (crd = 0; crd < num_cards; crd++) 1108 for (crd = 0; crd < num_cards; crd++) { /* Begin for each card */
1309 { /* Begin for each card */
1310
1311 bd = &boards[crd]; 1109 bd = &boards[crd];
1312
1313 if (!bd) 1110 if (!bd)
1314 { /* Begin sanity check */ 1111 { /* Begin sanity check */
1315 printk(KERN_ERR "<Error> - Digi : cleanup_module failed\n"); 1112 printk(KERN_ERR "<Error> - Digi : cleanup_module failed\n");
1316 return; 1113 return;
1317 } /* End sanity check */ 1114 } /* End sanity check */
1318 1115 ch = card_ptr[crd];
1319 ch = card_ptr[crd];
1320
1321 for (count = 0; count < bd->numports; count++, ch++) 1116 for (count = 0; count < bd->numports; count++, ch++)
1322 { /* Begin for each port */ 1117 { /* Begin for each port */
1323 1118 if (ch) {
1324 if (ch)
1325 {
1326 if (ch->tty) 1119 if (ch->tty)
1327 tty_hangup(ch->tty); 1120 tty_hangup(ch->tty);
1328 kfree(ch->tmp_buf); 1121 kfree(ch->tmp_buf);
1329 } 1122 }
1330
1331 } /* End for each port */ 1123 } /* End for each port */
1332 } /* End for each card */ 1124 } /* End for each card */
1333
1334#ifdef ENABLE_PCI
1335 pci_unregister_driver (&epca_driver); 1125 pci_unregister_driver (&epca_driver);
1336#endif
1337
1338 restore_flags(flags);
1339
1340} 1126}
1127
1341module_exit(epca_module_exit); 1128module_exit(epca_module_exit);
1342#endif /* MODULE */
1343 1129
1344static struct tty_operations pc_ops = { 1130static struct tty_operations pc_ops = {
1345 .open = pc_open, 1131 .open = pc_open,
@@ -1371,34 +1157,15 @@ static struct tty_operations info_ops = {
1371 1157
1372/* ------------------ Begin pc_init ---------------------- */ 1158/* ------------------ Begin pc_init ---------------------- */
1373 1159
1374int __init pc_init(void) 1160static int __init pc_init(void)
1375{ /* Begin pc_init */ 1161{ /* Begin pc_init */
1376
1377 /* ----------------------------------------------------------------
1378 pc_init is called by the operating system during boot up prior to
1379 any open calls being made. In the older versions of Linux (Prior
1380 to 2.0.0) an entry is made into tty_io.c. A pointer to the last
1381 memory location (from kernel space) used (kmem_start) is passed
1382 to pc_init. It is pc_inits responsibility to modify this value
1383 for any memory that the Digi driver might need and then return
1384 this value to the operating system. For example if the driver
1385 wishes to allocate 1K of kernel memory, pc_init would return
1386 (kmem_start + 1024). This memory (Between kmem_start and kmem_start
1387 + 1024) would then be available for use exclusively by the driver.
1388 In this case our driver does not allocate any of this kernel
1389 memory.
1390 ------------------------------------------------------------------*/
1391
1392 ulong flags;
1393 int crd; 1162 int crd;
1394 struct board_info *bd; 1163 struct board_info *bd;
1395 unsigned char board_id = 0; 1164 unsigned char board_id = 0;
1396 1165
1397#ifdef ENABLE_PCI
1398 int pci_boards_found, pci_count; 1166 int pci_boards_found, pci_count;
1399 1167
1400 pci_count = 0; 1168 pci_count = 0;
1401#endif /* ENABLE_PCI */
1402 1169
1403 pc_driver = alloc_tty_driver(MAX_ALLOC); 1170 pc_driver = alloc_tty_driver(MAX_ALLOC);
1404 if (!pc_driver) 1171 if (!pc_driver)
@@ -1416,8 +1183,7 @@ int __init pc_init(void)
1416 Note : If LILO has ran epca_setup then epca_setup will handle defining 1183 Note : If LILO has ran epca_setup then epca_setup will handle defining
1417 num_cards as well as copying the data into the board structure. 1184 num_cards as well as copying the data into the board structure.
1418 -------------------------------------------------------------------------- */ 1185 -------------------------------------------------------------------------- */
1419 if (!liloconfig) 1186 if (!liloconfig) { /* Begin driver has been configured via. epcaconfig */
1420 { /* Begin driver has been configured via. epcaconfig */
1421 1187
1422 nbdevs = NBDEVS; 1188 nbdevs = NBDEVS;
1423 num_cards = NUMCARDS; 1189 num_cards = NUMCARDS;
@@ -1440,8 +1206,6 @@ int __init pc_init(void)
1440 1206
1441 printk(KERN_INFO "DIGI epca driver version %s loaded.\n",VERSION); 1207 printk(KERN_INFO "DIGI epca driver version %s loaded.\n",VERSION);
1442 1208
1443#ifdef ENABLE_PCI
1444
1445 /* ------------------------------------------------------------------ 1209 /* ------------------------------------------------------------------
1446 NOTE : This code assumes that the number of ports found in 1210 NOTE : This code assumes that the number of ports found in
1447 the boards array is correct. This could be wrong if 1211 the boards array is correct. This could be wrong if
@@ -1467,8 +1231,6 @@ int __init pc_init(void)
1467 pci_boards_found += init_PCI(); 1231 pci_boards_found += init_PCI();
1468 num_cards += pci_boards_found; 1232 num_cards += pci_boards_found;
1469 1233
1470#endif /* ENABLE_PCI */
1471
1472 pc_driver->owner = THIS_MODULE; 1234 pc_driver->owner = THIS_MODULE;
1473 pc_driver->name = "ttyD"; 1235 pc_driver->name = "ttyD";
1474 pc_driver->devfs_name = "tts/D"; 1236 pc_driver->devfs_name = "tts/D";
@@ -1499,9 +1261,6 @@ int __init pc_init(void)
1499 tty_set_operations(pc_info, &info_ops); 1261 tty_set_operations(pc_info, &info_ops);
1500 1262
1501 1263
1502 save_flags(flags);
1503 cli();
1504
1505 for (crd = 0; crd < num_cards; crd++) 1264 for (crd = 0; crd < num_cards; crd++)
1506 { /* Begin for each card */ 1265 { /* Begin for each card */
1507 1266
@@ -1610,11 +1369,7 @@ int __init pc_init(void)
1610 if ((board_id & 0x30) == 0x30) 1369 if ((board_id & 0x30) == 0x30)
1611 bd->memory_seg = 0x8000; 1370 bd->memory_seg = 0x8000;
1612 1371
1613 } /* End it is an XI card */ 1372 } else printk(KERN_ERR "epca: Board at 0x%x doesn't appear to be an XI\n",(int)bd->port);
1614 else
1615 {
1616 printk(KERN_ERR "<Error> - Board at 0x%x doesn't appear to be an XI\n",(int)bd->port);
1617 }
1618 break; 1373 break;
1619 1374
1620 } /* End switch on bd->type */ 1375 } /* End switch on bd->type */
@@ -1634,9 +1389,6 @@ int __init pc_init(void)
1634 init_timer(&epca_timer); 1389 init_timer(&epca_timer);
1635 epca_timer.function = epcapoll; 1390 epca_timer.function = epcapoll;
1636 mod_timer(&epca_timer, jiffies + HZ/25); 1391 mod_timer(&epca_timer, jiffies + HZ/25);
1637
1638 restore_flags(flags);
1639
1640 return 0; 1392 return 0;
1641 1393
1642} /* End pc_init */ 1394} /* End pc_init */
@@ -1647,10 +1399,10 @@ static void post_fep_init(unsigned int crd)
1647{ /* Begin post_fep_init */ 1399{ /* Begin post_fep_init */
1648 1400
1649 int i; 1401 int i;
1650 unchar *memaddr; 1402 unsigned char *memaddr;
1651 volatile struct global_data *gd; 1403 struct global_data *gd;
1652 struct board_info *bd; 1404 struct board_info *bd;
1653 volatile struct board_chan *bc; 1405 struct board_chan *bc;
1654 struct channel *ch; 1406 struct channel *ch;
1655 int shrinkmem = 0, lowwater ; 1407 int shrinkmem = 0, lowwater ;
1656 1408
@@ -1669,9 +1421,7 @@ static void post_fep_init(unsigned int crd)
1669 after DIGI_INIT has been called will return the proper values. 1421 after DIGI_INIT has been called will return the proper values.
1670 ------------------------------------------------------------------- */ 1422 ------------------------------------------------------------------- */
1671 1423
1672 if (bd->type >= PCIXEM) /* If the board in question is PCI */ 1424 if (bd->type >= PCIXEM) { /* Begin get PCI number of ports */
1673 { /* Begin get PCI number of ports */
1674
1675 /* -------------------------------------------------------------------- 1425 /* --------------------------------------------------------------------
1676 Below we use XEMPORTS as a memory offset regardless of which PCI 1426 Below we use XEMPORTS as a memory offset regardless of which PCI
1677 card it is. This is because all of the supported PCI cards have 1427 card it is. This is because all of the supported PCI cards have
@@ -1685,15 +1435,15 @@ static void post_fep_init(unsigned int crd)
1685 (FYI - The id should be located at 0x1ac (And may use up to 4 bytes 1435 (FYI - The id should be located at 0x1ac (And may use up to 4 bytes
1686 if the box in question is a XEM or CX)). 1436 if the box in question is a XEM or CX)).
1687 ------------------------------------------------------------------------ */ 1437 ------------------------------------------------------------------------ */
1688 1438 /* PCI cards are already remapped at this point ISA are not */
1689 bd->numports = (unsigned short)*(unsigned char *)bus_to_virt((unsigned long) 1439 bd->numports = readw(bd->re_map_membase + XEMPORTS);
1690 (bd->re_map_membase + XEMPORTS));
1691
1692
1693 epcaassert(bd->numports <= 64,"PCI returned a invalid number of ports"); 1440 epcaassert(bd->numports <= 64,"PCI returned a invalid number of ports");
1694 nbdevs += (bd->numports); 1441 nbdevs += (bd->numports);
1695 1442 } else {
1696 } /* End get PCI number of ports */ 1443 /* Fix up the mappings for ISA/EISA etc */
1444 /* FIXME: 64K - can we be smarter ? */
1445 bd->re_map_membase = ioremap(bd->membase, 0x10000);
1446 }
1697 1447
1698 if (crd != 0) 1448 if (crd != 0)
1699 card_ptr[crd] = card_ptr[crd-1] + boards[crd-1].numports; 1449 card_ptr[crd] = card_ptr[crd-1] + boards[crd-1].numports;
@@ -1701,19 +1451,9 @@ static void post_fep_init(unsigned int crd)
1701 card_ptr[crd] = &digi_channels[crd]; /* <- For card 0 only */ 1451 card_ptr[crd] = &digi_channels[crd]; /* <- For card 0 only */
1702 1452
1703 ch = card_ptr[crd]; 1453 ch = card_ptr[crd];
1704
1705
1706 epcaassert(ch <= &digi_channels[nbdevs - 1], "ch out of range"); 1454 epcaassert(ch <= &digi_channels[nbdevs - 1], "ch out of range");
1707 1455
1708 memaddr = (unchar *)bd->re_map_membase; 1456 memaddr = bd->re_map_membase;
1709
1710 /*
1711 The below command is necessary because newer kernels (2.1.x and
1712 up) do not have a 1:1 virtual to physical mapping. The below
1713 call adjust for that.
1714 */
1715
1716 memaddr = (unsigned char *)bus_to_virt((unsigned long)memaddr);
1717 1457
1718 /* ----------------------------------------------------------------- 1458 /* -----------------------------------------------------------------
1719 The below assignment will set bc to point at the BEGINING of 1459 The below assignment will set bc to point at the BEGINING of
@@ -1721,7 +1461,7 @@ static void post_fep_init(unsigned int crd)
1721 8 and 64 of these structures. 1461 8 and 64 of these structures.
1722 -------------------------------------------------------------------- */ 1462 -------------------------------------------------------------------- */
1723 1463
1724 bc = (volatile struct board_chan *)((ulong)memaddr + CHANSTRUCT); 1464 bc = (struct board_chan *)(memaddr + CHANSTRUCT);
1725 1465
1726 /* ------------------------------------------------------------------- 1466 /* -------------------------------------------------------------------
1727 The below assignment will set gd to point at the BEGINING of 1467 The below assignment will set gd to point at the BEGINING of
@@ -1730,20 +1470,18 @@ static void post_fep_init(unsigned int crd)
1730 pointer begins at 0xd10. 1470 pointer begins at 0xd10.
1731 ---------------------------------------------------------------------- */ 1471 ---------------------------------------------------------------------- */
1732 1472
1733 gd = (volatile struct global_data *)((ulong)memaddr + GLOBAL); 1473 gd = (struct global_data *)(memaddr + GLOBAL);
1734 1474
1735 /* -------------------------------------------------------------------- 1475 /* --------------------------------------------------------------------
1736 XEPORTS (address 0xc22) points at the number of channels the 1476 XEPORTS (address 0xc22) points at the number of channels the
1737 card supports. (For 64XE, XI, XEM, and XR use 0xc02) 1477 card supports. (For 64XE, XI, XEM, and XR use 0xc02)
1738 ----------------------------------------------------------------------- */ 1478 ----------------------------------------------------------------------- */
1739 1479
1740 if (((bd->type == PCXEVE) | (bd->type == PCXE)) && 1480 if ((bd->type == PCXEVE || bd->type == PCXE) && (readw(memaddr + XEPORTS) < 3))
1741 (*(ushort *)((ulong)memaddr + XEPORTS) < 3))
1742 shrinkmem = 1; 1481 shrinkmem = 1;
1743 if (bd->type < PCIXEM) 1482 if (bd->type < PCIXEM)
1744 if (!request_region((int)bd->port, 4, board_desc[bd->type])) 1483 if (!request_region((int)bd->port, 4, board_desc[bd->type]))
1745 return; 1484 return;
1746
1747 memwinon(bd, 0); 1485 memwinon(bd, 0);
1748 1486
1749 /* -------------------------------------------------------------------- 1487 /* --------------------------------------------------------------------
@@ -1753,17 +1491,16 @@ static void post_fep_init(unsigned int crd)
1753 1491
1754 /* For every port on the card do ..... */ 1492 /* For every port on the card do ..... */
1755 1493
1756 for (i = 0; i < bd->numports; i++, ch++, bc++) 1494 for (i = 0; i < bd->numports; i++, ch++, bc++) { /* Begin for each port */
1757 { /* Begin for each port */ 1495 unsigned long flags;
1758 1496
1759 ch->brdchan = bc; 1497 ch->brdchan = bc;
1760 ch->mailbox = gd; 1498 ch->mailbox = gd;
1761 INIT_WORK(&ch->tqueue, do_softint, ch); 1499 INIT_WORK(&ch->tqueue, do_softint, ch);
1762 ch->board = &boards[crd]; 1500 ch->board = &boards[crd];
1763 1501
1764 switch (bd->type) 1502 spin_lock_irqsave(&epca_lock, flags);
1765 { /* Begin switch bd->type */ 1503 switch (bd->type) {
1766
1767 /* ---------------------------------------------------------------- 1504 /* ----------------------------------------------------------------
1768 Since some of the boards use different bitmaps for their 1505 Since some of the boards use different bitmaps for their
1769 control signals we cannot hard code these values and retain 1506 control signals we cannot hard code these values and retain
@@ -1796,14 +1533,12 @@ static void post_fep_init(unsigned int crd)
1796 1533
1797 } /* End switch bd->type */ 1534 } /* End switch bd->type */
1798 1535
1799 if (boards[crd].altpin) 1536 if (boards[crd].altpin) {
1800 {
1801 ch->dsr = ch->m_dcd; 1537 ch->dsr = ch->m_dcd;
1802 ch->dcd = ch->m_dsr; 1538 ch->dcd = ch->m_dsr;
1803 ch->digiext.digi_flags |= DIGI_ALTPIN; 1539 ch->digiext.digi_flags |= DIGI_ALTPIN;
1804 } 1540 }
1805 else 1541 else {
1806 {
1807 ch->dcd = ch->m_dcd; 1542 ch->dcd = ch->m_dcd;
1808 ch->dsr = ch->m_dsr; 1543 ch->dsr = ch->m_dsr;
1809 } 1544 }
@@ -1813,14 +1548,12 @@ static void post_fep_init(unsigned int crd)
1813 ch->magic = EPCA_MAGIC; 1548 ch->magic = EPCA_MAGIC;
1814 ch->tty = NULL; 1549 ch->tty = NULL;
1815 1550
1816 if (shrinkmem) 1551 if (shrinkmem) {
1817 {
1818 fepcmd(ch, SETBUFFER, 32, 0, 0, 0); 1552 fepcmd(ch, SETBUFFER, 32, 0, 0, 0);
1819 shrinkmem = 0; 1553 shrinkmem = 0;
1820 } 1554 }
1821 1555
1822 switch (bd->type) 1556 switch (bd->type) {
1823 { /* Begin switch bd->type */
1824 1557
1825 case PCIXEM: 1558 case PCIXEM:
1826 case PCIXRJ: 1559 case PCIXRJ:
@@ -1878,13 +1611,13 @@ static void post_fep_init(unsigned int crd)
1878 1611
1879 fepcmd(ch, SRXHWATER, (3 * ch->rxbufsize / 4), 0, 10, 0); 1612 fepcmd(ch, SRXHWATER, (3 * ch->rxbufsize / 4), 0, 10, 0);
1880 1613
1881 bc->edelay = 100; 1614 writew(100, &bc->edelay);
1882 bc->idata = 1; 1615 writeb(1, &bc->idata);
1883 1616
1884 ch->startc = bc->startc; 1617 ch->startc = readb(&bc->startc);
1885 ch->stopc = bc->stopc; 1618 ch->stopc = readb(&bc->stopc);
1886 ch->startca = bc->startca; 1619 ch->startca = readb(&bc->startca);
1887 ch->stopca = bc->stopca; 1620 ch->stopca = readb(&bc->stopca);
1888 1621
1889 ch->fepcflag = 0; 1622 ch->fepcflag = 0;
1890 ch->fepiflag = 0; 1623 ch->fepiflag = 0;
@@ -1899,27 +1632,23 @@ static void post_fep_init(unsigned int crd)
1899 ch->blocked_open = 0; 1632 ch->blocked_open = 0;
1900 init_waitqueue_head(&ch->open_wait); 1633 init_waitqueue_head(&ch->open_wait);
1901 init_waitqueue_head(&ch->close_wait); 1634 init_waitqueue_head(&ch->close_wait);
1635
1636 spin_unlock_irqrestore(&epca_lock, flags);
1637
1902 ch->tmp_buf = kmalloc(ch->txbufsize,GFP_KERNEL); 1638 ch->tmp_buf = kmalloc(ch->txbufsize,GFP_KERNEL);
1903 if (!(ch->tmp_buf)) 1639 if (!ch->tmp_buf) {
1904 {
1905 printk(KERN_ERR "POST FEP INIT : kmalloc failed for port 0x%x\n",i); 1640 printk(KERN_ERR "POST FEP INIT : kmalloc failed for port 0x%x\n",i);
1906 release_region((int)bd->port, 4); 1641 release_region((int)bd->port, 4);
1907 while(i-- > 0) 1642 while(i-- > 0)
1908 kfree((ch--)->tmp_buf); 1643 kfree((ch--)->tmp_buf);
1909 return; 1644 return;
1910 } 1645 } else
1911 else
1912 memset((void *)ch->tmp_buf,0,ch->txbufsize); 1646 memset((void *)ch->tmp_buf,0,ch->txbufsize);
1913 } /* End for each port */ 1647 } /* End for each port */
1914 1648
1915 printk(KERN_INFO 1649 printk(KERN_INFO
1916 "Digi PC/Xx Driver V%s: %s I/O = 0x%lx Mem = 0x%lx Ports = %d\n", 1650 "Digi PC/Xx Driver V%s: %s I/O = 0x%lx Mem = 0x%lx Ports = %d\n",
1917 VERSION, board_desc[bd->type], (long)bd->port, (long)bd->membase, bd->numports); 1651 VERSION, board_desc[bd->type], (long)bd->port, (long)bd->membase, bd->numports);
1918 sprintf(mesg,
1919 "Digi PC/Xx Driver V%s: %s I/O = 0x%lx Mem = 0x%lx Ports = %d\n",
1920 VERSION, board_desc[bd->type], (long)bd->port, (long)bd->membase, bd->numports);
1921 console_print(mesg);
1922
1923 memwinoff(bd, 0); 1652 memwinoff(bd, 0);
1924 1653
1925} /* End post_fep_init */ 1654} /* End post_fep_init */
@@ -1943,9 +1672,6 @@ static void epcapoll(unsigned long ignored)
1943 buffer empty) and acts on those events. 1672 buffer empty) and acts on those events.
1944 ----------------------------------------------------------------------- */ 1673 ----------------------------------------------------------------------- */
1945 1674
1946 save_flags(flags);
1947 cli();
1948
1949 for (crd = 0; crd < num_cards; crd++) 1675 for (crd = 0; crd < num_cards; crd++)
1950 { /* Begin for each card */ 1676 { /* Begin for each card */
1951 1677
@@ -1961,6 +1687,8 @@ static void epcapoll(unsigned long ignored)
1961 some legacy boards. 1687 some legacy boards.
1962 ---------------------------------------------------------------- */ 1688 ---------------------------------------------------------------- */
1963 1689
1690 spin_lock_irqsave(&epca_lock, flags);
1691
1964 assertmemoff(ch); 1692 assertmemoff(ch);
1965 1693
1966 globalwinon(ch); 1694 globalwinon(ch);
@@ -1970,21 +1698,19 @@ static void epcapoll(unsigned long ignored)
1970 the transmit or receive queue. 1698 the transmit or receive queue.
1971 ------------------------------------------------------------------- */ 1699 ------------------------------------------------------------------- */
1972 1700
1973 head = ch->mailbox->ein; 1701 head = readw(&ch->mailbox->ein);
1974 tail = ch->mailbox->eout; 1702 tail = readw(&ch->mailbox->eout);
1975 1703
1976 /* If head isn't equal to tail we have an event */ 1704 /* If head isn't equal to tail we have an event */
1977 1705
1978 if (head != tail) 1706 if (head != tail)
1979 doevent(crd); 1707 doevent(crd);
1980
1981 memoff(ch); 1708 memoff(ch);
1982 1709
1983 } /* End for each card */ 1710 spin_unlock_irqrestore(&epca_lock, flags);
1984 1711
1712 } /* End for each card */
1985 mod_timer(&epca_timer, jiffies + (HZ / 25)); 1713 mod_timer(&epca_timer, jiffies + (HZ / 25));
1986
1987 restore_flags(flags);
1988} /* End epcapoll */ 1714} /* End epcapoll */
1989 1715
1990/* --------------------- Begin doevent ------------------------ */ 1716/* --------------------- Begin doevent ------------------------ */
@@ -1992,53 +1718,42 @@ static void epcapoll(unsigned long ignored)
1992static void doevent(int crd) 1718static void doevent(int crd)
1993{ /* Begin doevent */ 1719{ /* Begin doevent */
1994 1720
1995 volatile unchar *eventbuf; 1721 void *eventbuf;
1996 struct channel *ch, *chan0; 1722 struct channel *ch, *chan0;
1997 static struct tty_struct *tty; 1723 static struct tty_struct *tty;
1998 volatile struct board_info *bd; 1724 struct board_info *bd;
1999 volatile struct board_chan *bc; 1725 struct board_chan *bc;
2000 register volatile unsigned int tail, head; 1726 unsigned int tail, head;
2001 register int event, channel; 1727 int event, channel;
2002 register int mstat, lstat; 1728 int mstat, lstat;
2003 1729
2004 /* ------------------------------------------------------------------- 1730 /* -------------------------------------------------------------------
2005 This subroutine is called by epcapoll when an event is detected 1731 This subroutine is called by epcapoll when an event is detected
2006 in the event queue. This routine responds to those events. 1732 in the event queue. This routine responds to those events.
2007 --------------------------------------------------------------------- */ 1733 --------------------------------------------------------------------- */
2008
2009 bd = &boards[crd]; 1734 bd = &boards[crd];
2010 1735
2011 chan0 = card_ptr[crd]; 1736 chan0 = card_ptr[crd];
2012 epcaassert(chan0 <= &digi_channels[nbdevs - 1], "ch out of range"); 1737 epcaassert(chan0 <= &digi_channels[nbdevs - 1], "ch out of range");
2013
2014 assertgwinon(chan0); 1738 assertgwinon(chan0);
2015 1739 while ((tail = readw(&chan0->mailbox->eout)) != (head = readw(&chan0->mailbox->ein)))
2016 while ((tail = chan0->mailbox->eout) != (head = chan0->mailbox->ein))
2017 { /* Begin while something in event queue */ 1740 { /* Begin while something in event queue */
2018
2019 assertgwinon(chan0); 1741 assertgwinon(chan0);
2020 1742 eventbuf = bd->re_map_membase + tail + ISTART;
2021 eventbuf = (volatile unchar *)bus_to_virt((ulong)(bd->re_map_membase + tail + ISTART));
2022
2023 /* Get the channel the event occurred on */ 1743 /* Get the channel the event occurred on */
2024 channel = eventbuf[0]; 1744 channel = readb(eventbuf);
2025
2026 /* Get the actual event code that occurred */ 1745 /* Get the actual event code that occurred */
2027 event = eventbuf[1]; 1746 event = readb(eventbuf + 1);
2028
2029 /* ---------------------------------------------------------------- 1747 /* ----------------------------------------------------------------
2030 The two assignments below get the current modem status (mstat) 1748 The two assignments below get the current modem status (mstat)
2031 and the previous modem status (lstat). These are useful becuase 1749 and the previous modem status (lstat). These are useful becuase
2032 an event could signal a change in modem signals itself. 1750 an event could signal a change in modem signals itself.
2033 ------------------------------------------------------------------- */ 1751 ------------------------------------------------------------------- */
2034 1752 mstat = readb(eventbuf + 2);
2035 mstat = eventbuf[2]; 1753 lstat = readb(eventbuf + 3);
2036 lstat = eventbuf[3];
2037 1754
2038 ch = chan0 + channel; 1755 ch = chan0 + channel;
2039 1756 if ((unsigned)channel >= bd->numports || !ch) {
2040 if ((unsigned)channel >= bd->numports || !ch)
2041 {
2042 if (channel >= bd->numports) 1757 if (channel >= bd->numports)
2043 ch = chan0; 1758 ch = chan0;
2044 bc = ch->brdchan; 1759 bc = ch->brdchan;
@@ -2048,97 +1763,53 @@ static void doevent(int crd)
2048 if ((bc = ch->brdchan) == NULL) 1763 if ((bc = ch->brdchan) == NULL)
2049 goto next; 1764 goto next;
2050 1765
2051 if (event & DATA_IND) 1766 if (event & DATA_IND) { /* Begin DATA_IND */
2052 { /* Begin DATA_IND */
2053
2054 receive_data(ch); 1767 receive_data(ch);
2055 assertgwinon(ch); 1768 assertgwinon(ch);
2056
2057 } /* End DATA_IND */ 1769 } /* End DATA_IND */
2058 /* else *//* Fix for DCD transition missed bug */ 1770 /* else *//* Fix for DCD transition missed bug */
2059 if (event & MODEMCHG_IND) 1771 if (event & MODEMCHG_IND) { /* Begin MODEMCHG_IND */
2060 { /* Begin MODEMCHG_IND */
2061
2062 /* A modem signal change has been indicated */ 1772 /* A modem signal change has been indicated */
2063
2064 ch->imodem = mstat; 1773 ch->imodem = mstat;
2065 1774 if (ch->asyncflags & ASYNC_CHECK_CD) {
2066 if (ch->asyncflags & ASYNC_CHECK_CD)
2067 {
2068 if (mstat & ch->dcd) /* We are now receiving dcd */ 1775 if (mstat & ch->dcd) /* We are now receiving dcd */
2069 wake_up_interruptible(&ch->open_wait); 1776 wake_up_interruptible(&ch->open_wait);
2070 else 1777 else
2071 pc_sched_event(ch, EPCA_EVENT_HANGUP); /* No dcd; hangup */ 1778 pc_sched_event(ch, EPCA_EVENT_HANGUP); /* No dcd; hangup */
2072 } 1779 }
2073
2074 } /* End MODEMCHG_IND */ 1780 } /* End MODEMCHG_IND */
2075
2076 tty = ch->tty; 1781 tty = ch->tty;
2077 if (tty) 1782 if (tty) { /* Begin if valid tty */
2078 { /* Begin if valid tty */ 1783 if (event & BREAK_IND) { /* Begin if BREAK_IND */
2079
2080 if (event & BREAK_IND)
2081 { /* Begin if BREAK_IND */
2082
2083 /* A break has been indicated */ 1784 /* A break has been indicated */
2084
2085 tty->flip.count++; 1785 tty->flip.count++;
2086 *tty->flip.flag_buf_ptr++ = TTY_BREAK; 1786 *tty->flip.flag_buf_ptr++ = TTY_BREAK;
2087
2088 *tty->flip.char_buf_ptr++ = 0; 1787 *tty->flip.char_buf_ptr++ = 0;
2089
2090 tty_schedule_flip(tty); 1788 tty_schedule_flip(tty);
2091 1789 } else if (event & LOWTX_IND) { /* Begin LOWTX_IND */
2092 } /* End if BREAK_IND */
2093 else
2094 if (event & LOWTX_IND)
2095 { /* Begin LOWTX_IND */
2096
2097 if (ch->statusflags & LOWWAIT) 1790 if (ch->statusflags & LOWWAIT)
2098 { /* Begin if LOWWAIT */ 1791 { /* Begin if LOWWAIT */
2099
2100 ch->statusflags &= ~LOWWAIT; 1792 ch->statusflags &= ~LOWWAIT;
2101 tty_wakeup(tty); 1793 tty_wakeup(tty);
2102 wake_up_interruptible(&tty->write_wait); 1794 wake_up_interruptible(&tty->write_wait);
2103
2104 } /* End if LOWWAIT */ 1795 } /* End if LOWWAIT */
2105 1796 } else if (event & EMPTYTX_IND) { /* Begin EMPTYTX_IND */
2106 } /* End LOWTX_IND */
2107 else
2108 if (event & EMPTYTX_IND)
2109 { /* Begin EMPTYTX_IND */
2110
2111 /* This event is generated by setup_empty_event */ 1797 /* This event is generated by setup_empty_event */
2112
2113 ch->statusflags &= ~TXBUSY; 1798 ch->statusflags &= ~TXBUSY;
2114 if (ch->statusflags & EMPTYWAIT) 1799 if (ch->statusflags & EMPTYWAIT) { /* Begin if EMPTYWAIT */
2115 { /* Begin if EMPTYWAIT */
2116
2117 ch->statusflags &= ~EMPTYWAIT; 1800 ch->statusflags &= ~EMPTYWAIT;
2118 tty_wakeup(tty); 1801 tty_wakeup(tty);
2119
2120 wake_up_interruptible(&tty->write_wait); 1802 wake_up_interruptible(&tty->write_wait);
2121
2122 } /* End if EMPTYWAIT */ 1803 } /* End if EMPTYWAIT */
2123
2124 } /* End EMPTYTX_IND */ 1804 } /* End EMPTYTX_IND */
2125
2126 } /* End if valid tty */ 1805 } /* End if valid tty */
2127
2128
2129 next: 1806 next:
2130 globalwinon(ch); 1807 globalwinon(ch);
2131 1808 BUG_ON(!bc);
2132 if (!bc) 1809 writew(1, &bc->idata);
2133 printk(KERN_ERR "<Error> - bc == NULL in doevent!\n"); 1810 writew((tail + 4) & (IMAX - ISTART - 4), &chan0->mailbox->eout);
2134 else
2135 bc->idata = 1;
2136
2137 chan0->mailbox->eout = (tail + 4) & (IMAX - ISTART - 4);
2138 globalwinon(chan0); 1811 globalwinon(chan0);
2139
2140 } /* End while something in event queue */ 1812 } /* End while something in event queue */
2141
2142} /* End doevent */ 1813} /* End doevent */
2143 1814
2144/* --------------------- Begin fepcmd ------------------------ */ 1815/* --------------------- Begin fepcmd ------------------------ */
@@ -2146,7 +1817,6 @@ static void doevent(int crd)
2146static void fepcmd(struct channel *ch, int cmd, int word_or_byte, 1817static void fepcmd(struct channel *ch, int cmd, int word_or_byte,
2147 int byte2, int ncmds, int bytecmd) 1818 int byte2, int ncmds, int bytecmd)
2148{ /* Begin fepcmd */ 1819{ /* Begin fepcmd */
2149
2150 unchar *memaddr; 1820 unchar *memaddr;
2151 unsigned int head, cmdTail, cmdStart, cmdMax; 1821 unsigned int head, cmdTail, cmdStart, cmdMax;
2152 long count; 1822 long count;
@@ -2155,93 +1825,57 @@ static void fepcmd(struct channel *ch, int cmd, int word_or_byte,
2155 /* This is the routine in which commands may be passed to the card. */ 1825 /* This is the routine in which commands may be passed to the card. */
2156 1826
2157 if (ch->board->status == DISABLED) 1827 if (ch->board->status == DISABLED)
2158 {
2159 return; 1828 return;
2160 }
2161
2162 assertgwinon(ch); 1829 assertgwinon(ch);
2163
2164 /* Remember head (As well as max) is just an offset not a base addr */ 1830 /* Remember head (As well as max) is just an offset not a base addr */
2165 head = ch->mailbox->cin; 1831 head = readw(&ch->mailbox->cin);
2166
2167 /* cmdStart is a base address */ 1832 /* cmdStart is a base address */
2168 cmdStart = ch->mailbox->cstart; 1833 cmdStart = readw(&ch->mailbox->cstart);
2169
2170 /* ------------------------------------------------------------------ 1834 /* ------------------------------------------------------------------
2171 We do the addition below because we do not want a max pointer 1835 We do the addition below because we do not want a max pointer
2172 relative to cmdStart. We want a max pointer that points at the 1836 relative to cmdStart. We want a max pointer that points at the
2173 physical end of the command queue. 1837 physical end of the command queue.
2174 -------------------------------------------------------------------- */ 1838 -------------------------------------------------------------------- */
2175 1839 cmdMax = (cmdStart + 4 + readw(&ch->mailbox->cmax));
2176 cmdMax = (cmdStart + 4 + (ch->mailbox->cmax));
2177
2178 memaddr = ch->board->re_map_membase; 1840 memaddr = ch->board->re_map_membase;
2179 1841
2180 /* 1842 if (head >= (cmdMax - cmdStart) || (head & 03)) {
2181 The below command is necessary because newer kernels (2.1.x and 1843 printk(KERN_ERR "line %d: Out of range, cmd = %x, head = %x\n", __LINE__, cmd, head);
2182 up) do not have a 1:1 virtual to physical mapping. The below 1844 printk(KERN_ERR "line %d: Out of range, cmdMax = %x, cmdStart = %x\n", __LINE__, cmdMax, cmdStart);
2183 call adjust for that.
2184 */
2185
2186 memaddr = (unsigned char *)bus_to_virt((unsigned long)memaddr);
2187
2188 if (head >= (cmdMax - cmdStart) || (head & 03))
2189 {
2190 printk(KERN_ERR "line %d: Out of range, cmd = %x, head = %x\n", __LINE__,
2191 cmd, head);
2192 printk(KERN_ERR "line %d: Out of range, cmdMax = %x, cmdStart = %x\n", __LINE__,
2193 cmdMax, cmdStart);
2194 return; 1845 return;
2195 } 1846 }
2196 1847 if (bytecmd) {
2197 if (bytecmd) 1848 writeb(cmd, memaddr + head + cmdStart + 0);
2198 { 1849 writeb(ch->channelnum, memaddr + head + cmdStart + 1);
2199 *(volatile unchar *)(memaddr + head + cmdStart + 0) = (unchar)cmd;
2200
2201 *(volatile unchar *)(memaddr + head + cmdStart + 1) = (unchar)ch->channelnum;
2202 /* Below word_or_byte is bits to set */ 1850 /* Below word_or_byte is bits to set */
2203 *(volatile unchar *)(memaddr + head + cmdStart + 2) = (unchar)word_or_byte; 1851 writeb(word_or_byte, memaddr + head + cmdStart + 2);
2204 /* Below byte2 is bits to reset */ 1852 /* Below byte2 is bits to reset */
2205 *(volatile unchar *)(memaddr + head + cmdStart + 3) = (unchar)byte2; 1853 writeb(byte2, memaddr + head + cmdStart + 3);
2206 1854 } else {
2207 } 1855 writeb(cmd, memaddr + head + cmdStart + 0);
2208 else 1856 writeb(ch->channelnum, memaddr + head + cmdStart + 1);
2209 { 1857 writeb(word_or_byte, memaddr + head + cmdStart + 2);
2210 *(volatile unchar *)(memaddr + head + cmdStart + 0) = (unchar)cmd;
2211 *(volatile unchar *)(memaddr + head + cmdStart + 1) = (unchar)ch->channelnum;
2212 *(volatile ushort*)(memaddr + head + cmdStart + 2) = (ushort)word_or_byte;
2213 } 1858 }
2214
2215 head = (head + 4) & (cmdMax - cmdStart - 4); 1859 head = (head + 4) & (cmdMax - cmdStart - 4);
2216 ch->mailbox->cin = head; 1860 writew(head, &ch->mailbox->cin);
2217
2218 count = FEPTIMEOUT; 1861 count = FEPTIMEOUT;
2219 1862
2220 for (;;) 1863 for (;;) { /* Begin forever loop */
2221 { /* Begin forever loop */
2222
2223 count--; 1864 count--;
2224 if (count == 0) 1865 if (count == 0) {
2225 {
2226 printk(KERN_ERR "<Error> - Fep not responding in fepcmd()\n"); 1866 printk(KERN_ERR "<Error> - Fep not responding in fepcmd()\n");
2227 return; 1867 return;
2228 } 1868 }
2229 1869 head = readw(&ch->mailbox->cin);
2230 head = ch->mailbox->cin; 1870 cmdTail = readw(&ch->mailbox->cout);
2231 cmdTail = ch->mailbox->cout;
2232
2233 n = (head - cmdTail) & (cmdMax - cmdStart - 4); 1871 n = (head - cmdTail) & (cmdMax - cmdStart - 4);
2234
2235 /* ---------------------------------------------------------- 1872 /* ----------------------------------------------------------
2236 Basically this will break when the FEP acknowledges the 1873 Basically this will break when the FEP acknowledges the
2237 command by incrementing cmdTail (Making it equal to head). 1874 command by incrementing cmdTail (Making it equal to head).
2238 ------------------------------------------------------------- */ 1875 ------------------------------------------------------------- */
2239
2240 if (n <= ncmds * (sizeof(short) * 4)) 1876 if (n <= ncmds * (sizeof(short) * 4))
2241 break; /* Well nearly forever :-) */ 1877 break; /* Well nearly forever :-) */
2242
2243 } /* End forever loop */ 1878 } /* End forever loop */
2244
2245} /* End fepcmd */ 1879} /* End fepcmd */
2246 1880
2247/* --------------------------------------------------------------------- 1881/* ---------------------------------------------------------------------
@@ -2255,11 +1889,9 @@ static void fepcmd(struct channel *ch, int cmd, int word_or_byte,
2255 1889
2256static unsigned termios2digi_h(struct channel *ch, unsigned cflag) 1890static unsigned termios2digi_h(struct channel *ch, unsigned cflag)
2257{ /* Begin termios2digi_h */ 1891{ /* Begin termios2digi_h */
2258
2259 unsigned res = 0; 1892 unsigned res = 0;
2260 1893
2261 if (cflag & CRTSCTS) 1894 if (cflag & CRTSCTS) {
2262 {
2263 ch->digiext.digi_flags |= (RTSPACE | CTSPACE); 1895 ch->digiext.digi_flags |= (RTSPACE | CTSPACE);
2264 res |= ((ch->m_cts) | (ch->m_rts)); 1896 res |= ((ch->m_cts) | (ch->m_rts));
2265 } 1897 }
@@ -2295,7 +1927,6 @@ static unsigned termios2digi_i(struct channel *ch, unsigned iflag)
2295 1927
2296 unsigned res = iflag & (IGNBRK | BRKINT | IGNPAR | PARMRK | 1928 unsigned res = iflag & (IGNBRK | BRKINT | IGNPAR | PARMRK |
2297 INPCK | ISTRIP|IXON|IXANY|IXOFF); 1929 INPCK | ISTRIP|IXON|IXANY|IXOFF);
2298
2299 if (ch->digiext.digi_flags & DIGI_AIXON) 1930 if (ch->digiext.digi_flags & DIGI_AIXON)
2300 res |= IAIXON; 1931 res |= IAIXON;
2301 return res; 1932 return res;
@@ -2308,28 +1939,15 @@ static unsigned termios2digi_c(struct channel *ch, unsigned cflag)
2308{ /* Begin termios2digi_c */ 1939{ /* Begin termios2digi_c */
2309 1940
2310 unsigned res = 0; 1941 unsigned res = 0;
2311 1942 if (cflag & CBAUDEX) { /* Begin detected CBAUDEX */
2312#ifdef SPEED_HACK
2313 /* CL: HACK to force 115200 at 38400 and 57600 at 19200 Baud */
2314 if ((cflag & CBAUD)== B38400) cflag=cflag - B38400 + B115200;
2315 if ((cflag & CBAUD)== B19200) cflag=cflag - B19200 + B57600;
2316#endif /* SPEED_HACK */
2317
2318 if (cflag & CBAUDEX)
2319 { /* Begin detected CBAUDEX */
2320
2321 ch->digiext.digi_flags |= DIGI_FAST; 1943 ch->digiext.digi_flags |= DIGI_FAST;
2322
2323 /* ------------------------------------------------------------- 1944 /* -------------------------------------------------------------
2324 HUPCL bit is used by FEP to indicate fast baud 1945 HUPCL bit is used by FEP to indicate fast baud
2325 table is to be used. 1946 table is to be used.
2326 ----------------------------------------------------------------- */ 1947 ----------------------------------------------------------------- */
2327
2328 res |= FEP_HUPCL; 1948 res |= FEP_HUPCL;
2329
2330 } /* End detected CBAUDEX */ 1949 } /* End detected CBAUDEX */
2331 else ch->digiext.digi_flags &= ~DIGI_FAST; 1950 else ch->digiext.digi_flags &= ~DIGI_FAST;
2332
2333 /* ------------------------------------------------------------------- 1951 /* -------------------------------------------------------------------
2334 CBAUD has bit position 0x1000 set these days to indicate Linux 1952 CBAUD has bit position 0x1000 set these days to indicate Linux
2335 baud rate remap. Digi hardware can't handle the bit assignment. 1953 baud rate remap. Digi hardware can't handle the bit assignment.
@@ -2337,7 +1955,6 @@ static unsigned termios2digi_c(struct channel *ch, unsigned cflag)
2337 bit out. 1955 bit out.
2338 ---------------------------------------------------------------------- */ 1956 ---------------------------------------------------------------------- */
2339 res |= cflag & ((CBAUD ^ CBAUDEX) | PARODD | PARENB | CSTOPB | CSIZE); 1957 res |= cflag & ((CBAUD ^ CBAUDEX) | PARODD | PARENB | CSTOPB | CSIZE);
2340
2341 /* ------------------------------------------------------------- 1958 /* -------------------------------------------------------------
2342 This gets a little confusing. The Digi cards have their own 1959 This gets a little confusing. The Digi cards have their own
2343 representation of c_cflags controling baud rate. For the most 1960 representation of c_cflags controling baud rate. For the most
@@ -2357,10 +1974,8 @@ static unsigned termios2digi_c(struct channel *ch, unsigned cflag)
2357 should be checked for a screened out prior to termios2digi_c 1974 should be checked for a screened out prior to termios2digi_c
2358 returning. Since CLOCAL isn't used by the board this can be 1975 returning. Since CLOCAL isn't used by the board this can be
2359 ignored as long as the returned value is used only by Digi hardware. 1976 ignored as long as the returned value is used only by Digi hardware.
2360 ----------------------------------------------------------------- */ 1977 ----------------------------------------------------------------- */
2361 1978 if (cflag & CBAUDEX) {
2362 if (cflag & CBAUDEX)
2363 {
2364 /* ------------------------------------------------------------- 1979 /* -------------------------------------------------------------
2365 The below code is trying to guarantee that only baud rates 1980 The below code is trying to guarantee that only baud rates
2366 115200 and 230400 are remapped. We use exclusive or because 1981 115200 and 230400 are remapped. We use exclusive or because
@@ -2371,138 +1986,96 @@ static unsigned termios2digi_c(struct channel *ch, unsigned cflag)
2371 1986
2372 if ((!((cflag & 0x7) ^ (B115200 & ~CBAUDEX))) || 1987 if ((!((cflag & 0x7) ^ (B115200 & ~CBAUDEX))) ||
2373 (!((cflag & 0x7) ^ (B230400 & ~CBAUDEX)))) 1988 (!((cflag & 0x7) ^ (B230400 & ~CBAUDEX))))
2374 {
2375 res += 1; 1989 res += 1;
2376 }
2377 } 1990 }
2378
2379 return res; 1991 return res;
2380 1992
2381} /* End termios2digi_c */ 1993} /* End termios2digi_c */
2382 1994
2383/* --------------------- Begin epcaparam ----------------------- */ 1995/* --------------------- Begin epcaparam ----------------------- */
2384 1996
1997/* Caller must hold the locks */
2385static void epcaparam(struct tty_struct *tty, struct channel *ch) 1998static void epcaparam(struct tty_struct *tty, struct channel *ch)
2386{ /* Begin epcaparam */ 1999{ /* Begin epcaparam */
2387 2000
2388 unsigned int cmdHead; 2001 unsigned int cmdHead;
2389 struct termios *ts; 2002 struct termios *ts;
2390 volatile struct board_chan *bc; 2003 struct board_chan *bc;
2391 unsigned mval, hflow, cflag, iflag; 2004 unsigned mval, hflow, cflag, iflag;
2392 2005
2393 bc = ch->brdchan; 2006 bc = ch->brdchan;
2394 epcaassert(bc !=0, "bc out of range"); 2007 epcaassert(bc !=0, "bc out of range");
2395 2008
2396 assertgwinon(ch); 2009 assertgwinon(ch);
2397
2398 ts = tty->termios; 2010 ts = tty->termios;
2399 2011 if ((ts->c_cflag & CBAUD) == 0) { /* Begin CBAUD detected */
2400 if ((ts->c_cflag & CBAUD) == 0) 2012 cmdHead = readw(&bc->rin);
2401 { /* Begin CBAUD detected */
2402
2403 cmdHead = bc->rin;
2404 bc->rout = cmdHead; 2013 bc->rout = cmdHead;
2405 cmdHead = bc->tin; 2014 cmdHead = readw(&bc->tin);
2406
2407 /* Changing baud in mid-stream transmission can be wonderful */ 2015 /* Changing baud in mid-stream transmission can be wonderful */
2408 /* --------------------------------------------------------------- 2016 /* ---------------------------------------------------------------
2409 Flush current transmit buffer by setting cmdTail pointer (tout) 2017 Flush current transmit buffer by setting cmdTail pointer (tout)
2410 to cmdHead pointer (tin). Hopefully the transmit buffer is empty. 2018 to cmdHead pointer (tin). Hopefully the transmit buffer is empty.
2411 ----------------------------------------------------------------- */ 2019 ----------------------------------------------------------------- */
2412
2413 fepcmd(ch, STOUT, (unsigned) cmdHead, 0, 0, 0); 2020 fepcmd(ch, STOUT, (unsigned) cmdHead, 0, 0, 0);
2414 mval = 0; 2021 mval = 0;
2415 2022 } else { /* Begin CBAUD not detected */
2416 } /* End CBAUD detected */
2417 else
2418 { /* Begin CBAUD not detected */
2419
2420 /* ------------------------------------------------------------------- 2023 /* -------------------------------------------------------------------
2421 c_cflags have changed but that change had nothing to do with BAUD. 2024 c_cflags have changed but that change had nothing to do with BAUD.
2422 Propagate the change to the card. 2025 Propagate the change to the card.
2423 ---------------------------------------------------------------------- */ 2026 ---------------------------------------------------------------------- */
2424
2425 cflag = termios2digi_c(ch, ts->c_cflag); 2027 cflag = termios2digi_c(ch, ts->c_cflag);
2426 2028 if (cflag != ch->fepcflag) {
2427 if (cflag != ch->fepcflag)
2428 {
2429 ch->fepcflag = cflag; 2029 ch->fepcflag = cflag;
2430 /* Set baud rate, char size, stop bits, parity */ 2030 /* Set baud rate, char size, stop bits, parity */
2431 fepcmd(ch, SETCTRLFLAGS, (unsigned) cflag, 0, 0, 0); 2031 fepcmd(ch, SETCTRLFLAGS, (unsigned) cflag, 0, 0, 0);
2432 } 2032 }
2433
2434
2435 /* ---------------------------------------------------------------- 2033 /* ----------------------------------------------------------------
2436 If the user has not forced CLOCAL and if the device is not a 2034 If the user has not forced CLOCAL and if the device is not a
2437 CALLOUT device (Which is always CLOCAL) we set flags such that 2035 CALLOUT device (Which is always CLOCAL) we set flags such that
2438 the driver will wait on carrier detect. 2036 the driver will wait on carrier detect.
2439 ------------------------------------------------------------------- */ 2037 ------------------------------------------------------------------- */
2440
2441 if (ts->c_cflag & CLOCAL) 2038 if (ts->c_cflag & CLOCAL)
2442 { /* Begin it is a cud device or a ttyD device with CLOCAL on */
2443 ch->asyncflags &= ~ASYNC_CHECK_CD; 2039 ch->asyncflags &= ~ASYNC_CHECK_CD;
2444 } /* End it is a cud device or a ttyD device with CLOCAL on */
2445 else 2040 else
2446 { /* Begin it is a ttyD device */
2447 ch->asyncflags |= ASYNC_CHECK_CD; 2041 ch->asyncflags |= ASYNC_CHECK_CD;
2448 } /* End it is a ttyD device */
2449
2450 mval = ch->m_dtr | ch->m_rts; 2042 mval = ch->m_dtr | ch->m_rts;
2451
2452 } /* End CBAUD not detected */ 2043 } /* End CBAUD not detected */
2453
2454 iflag = termios2digi_i(ch, ts->c_iflag); 2044 iflag = termios2digi_i(ch, ts->c_iflag);
2455
2456 /* Check input mode flags */ 2045 /* Check input mode flags */
2457 2046 if (iflag != ch->fepiflag) {
2458 if (iflag != ch->fepiflag)
2459 {
2460 ch->fepiflag = iflag; 2047 ch->fepiflag = iflag;
2461
2462 /* --------------------------------------------------------------- 2048 /* ---------------------------------------------------------------
2463 Command sets channels iflag structure on the board. Such things 2049 Command sets channels iflag structure on the board. Such things
2464 as input soft flow control, handling of parity errors, and 2050 as input soft flow control, handling of parity errors, and
2465 break handling are all set here. 2051 break handling are all set here.
2466 ------------------------------------------------------------------- */ 2052 ------------------------------------------------------------------- */
2467
2468 /* break handling, parity handling, input stripping, flow control chars */ 2053 /* break handling, parity handling, input stripping, flow control chars */
2469 fepcmd(ch, SETIFLAGS, (unsigned int) ch->fepiflag, 0, 0, 0); 2054 fepcmd(ch, SETIFLAGS, (unsigned int) ch->fepiflag, 0, 0, 0);
2470 } 2055 }
2471
2472 /* --------------------------------------------------------------- 2056 /* ---------------------------------------------------------------
2473 Set the board mint value for this channel. This will cause hardware 2057 Set the board mint value for this channel. This will cause hardware
2474 events to be generated each time the DCD signal (Described in mint) 2058 events to be generated each time the DCD signal (Described in mint)
2475 changes. 2059 changes.
2476 ------------------------------------------------------------------- */ 2060 ------------------------------------------------------------------- */
2477 bc->mint = ch->dcd; 2061 writeb(ch->dcd, &bc->mint);
2478
2479 if ((ts->c_cflag & CLOCAL) || (ch->digiext.digi_flags & DIGI_FORCEDCD)) 2062 if ((ts->c_cflag & CLOCAL) || (ch->digiext.digi_flags & DIGI_FORCEDCD))
2480 if (ch->digiext.digi_flags & DIGI_FORCEDCD) 2063 if (ch->digiext.digi_flags & DIGI_FORCEDCD)
2481 bc->mint = 0; 2064 writeb(0, &bc->mint);
2482 2065 ch->imodem = readb(&bc->mstat);
2483 ch->imodem = bc->mstat;
2484
2485 hflow = termios2digi_h(ch, ts->c_cflag); 2066 hflow = termios2digi_h(ch, ts->c_cflag);
2486 2067 if (hflow != ch->hflow) {
2487 if (hflow != ch->hflow)
2488 {
2489 ch->hflow = hflow; 2068 ch->hflow = hflow;
2490
2491 /* -------------------------------------------------------------- 2069 /* --------------------------------------------------------------
2492 Hard flow control has been selected but the board is not 2070 Hard flow control has been selected but the board is not
2493 using it. Activate hard flow control now. 2071 using it. Activate hard flow control now.
2494 ----------------------------------------------------------------- */ 2072 ----------------------------------------------------------------- */
2495
2496 fepcmd(ch, SETHFLOW, hflow, 0xff, 0, 1); 2073 fepcmd(ch, SETHFLOW, hflow, 0xff, 0, 1);
2497 } 2074 }
2498
2499
2500 mval ^= ch->modemfake & (mval ^ ch->modem); 2075 mval ^= ch->modemfake & (mval ^ ch->modem);
2501 2076
2502 if (ch->omodem ^ mval) 2077 if (ch->omodem ^ mval) {
2503 {
2504 ch->omodem = mval; 2078 ch->omodem = mval;
2505
2506 /* -------------------------------------------------------------- 2079 /* --------------------------------------------------------------
2507 The below command sets the DTR and RTS mstat structure. If 2080 The below command sets the DTR and RTS mstat structure. If
2508 hard flow control is NOT active these changes will drive the 2081 hard flow control is NOT active these changes will drive the
@@ -2514,87 +2087,65 @@ static void epcaparam(struct tty_struct *tty, struct channel *ch)
2514 /* First reset DTR & RTS; then set them */ 2087 /* First reset DTR & RTS; then set them */
2515 fepcmd(ch, SETMODEM, 0, ((ch->m_dtr)|(ch->m_rts)), 0, 1); 2088 fepcmd(ch, SETMODEM, 0, ((ch->m_dtr)|(ch->m_rts)), 0, 1);
2516 fepcmd(ch, SETMODEM, mval, 0, 0, 1); 2089 fepcmd(ch, SETMODEM, mval, 0, 0, 1);
2517
2518 } 2090 }
2519 2091 if (ch->startc != ch->fepstartc || ch->stopc != ch->fepstopc) {
2520 if (ch->startc != ch->fepstartc || ch->stopc != ch->fepstopc)
2521 {
2522 ch->fepstartc = ch->startc; 2092 ch->fepstartc = ch->startc;
2523 ch->fepstopc = ch->stopc; 2093 ch->fepstopc = ch->stopc;
2524
2525 /* ------------------------------------------------------------ 2094 /* ------------------------------------------------------------
2526 The XON / XOFF characters have changed; propagate these 2095 The XON / XOFF characters have changed; propagate these
2527 changes to the card. 2096 changes to the card.
2528 --------------------------------------------------------------- */ 2097 --------------------------------------------------------------- */
2529
2530 fepcmd(ch, SONOFFC, ch->fepstartc, ch->fepstopc, 0, 1); 2098 fepcmd(ch, SONOFFC, ch->fepstartc, ch->fepstopc, 0, 1);
2531 } 2099 }
2532 2100 if (ch->startca != ch->fepstartca || ch->stopca != ch->fepstopca) {
2533 if (ch->startca != ch->fepstartca || ch->stopca != ch->fepstopca)
2534 {
2535 ch->fepstartca = ch->startca; 2101 ch->fepstartca = ch->startca;
2536 ch->fepstopca = ch->stopca; 2102 ch->fepstopca = ch->stopca;
2537
2538 /* --------------------------------------------------------------- 2103 /* ---------------------------------------------------------------
2539 Similar to the above, this time the auxilarly XON / XOFF 2104 Similar to the above, this time the auxilarly XON / XOFF
2540 characters have changed; propagate these changes to the card. 2105 characters have changed; propagate these changes to the card.
2541 ------------------------------------------------------------------ */ 2106 ------------------------------------------------------------------ */
2542
2543 fepcmd(ch, SAUXONOFFC, ch->fepstartca, ch->fepstopca, 0, 1); 2107 fepcmd(ch, SAUXONOFFC, ch->fepstartca, ch->fepstopca, 0, 1);
2544 } 2108 }
2545
2546} /* End epcaparam */ 2109} /* End epcaparam */
2547 2110
2548/* --------------------- Begin receive_data ----------------------- */ 2111/* --------------------- Begin receive_data ----------------------- */
2549 2112/* Caller holds lock */
2550static void receive_data(struct channel *ch) 2113static void receive_data(struct channel *ch)
2551{ /* Begin receive_data */ 2114{ /* Begin receive_data */
2552 2115
2553 unchar *rptr; 2116 unchar *rptr;
2554 struct termios *ts = NULL; 2117 struct termios *ts = NULL;
2555 struct tty_struct *tty; 2118 struct tty_struct *tty;
2556 volatile struct board_chan *bc; 2119 struct board_chan *bc;
2557 register int dataToRead, wrapgap, bytesAvailable; 2120 int dataToRead, wrapgap, bytesAvailable;
2558 register unsigned int tail, head; 2121 unsigned int tail, head;
2559 unsigned int wrapmask; 2122 unsigned int wrapmask;
2560 int rc; 2123 int rc;
2561 2124
2562
2563 /* --------------------------------------------------------------- 2125 /* ---------------------------------------------------------------
2564 This routine is called by doint when a receive data event 2126 This routine is called by doint when a receive data event
2565 has taken place. 2127 has taken place.
2566 ------------------------------------------------------------------- */ 2128 ------------------------------------------------------------------- */
2567 2129
2568 globalwinon(ch); 2130 globalwinon(ch);
2569
2570 if (ch->statusflags & RXSTOPPED) 2131 if (ch->statusflags & RXSTOPPED)
2571 return; 2132 return;
2572
2573 tty = ch->tty; 2133 tty = ch->tty;
2574 if (tty) 2134 if (tty)
2575 ts = tty->termios; 2135 ts = tty->termios;
2576
2577 bc = ch->brdchan; 2136 bc = ch->brdchan;
2578 2137 BUG_ON(!bc);
2579 if (!bc)
2580 {
2581 printk(KERN_ERR "<Error> - bc is NULL in receive_data!\n");
2582 return;
2583 }
2584
2585 wrapmask = ch->rxbufsize - 1; 2138 wrapmask = ch->rxbufsize - 1;
2586 2139
2587 /* --------------------------------------------------------------------- 2140 /* ---------------------------------------------------------------------
2588 Get the head and tail pointers to the receiver queue. Wrap the 2141 Get the head and tail pointers to the receiver queue. Wrap the
2589 head pointer if it has reached the end of the buffer. 2142 head pointer if it has reached the end of the buffer.
2590 ------------------------------------------------------------------------ */ 2143 ------------------------------------------------------------------------ */
2591 2144 head = readw(&bc->rin);
2592 head = bc->rin;
2593 head &= wrapmask; 2145 head &= wrapmask;
2594 tail = bc->rout & wrapmask; 2146 tail = readw(&bc->rout) & wrapmask;
2595 2147
2596 bytesAvailable = (head - tail) & wrapmask; 2148 bytesAvailable = (head - tail) & wrapmask;
2597
2598 if (bytesAvailable == 0) 2149 if (bytesAvailable == 0)
2599 return; 2150 return;
2600 2151
@@ -2602,8 +2153,7 @@ static void receive_data(struct channel *ch)
2602 If CREAD bit is off or device not open, set TX tail to head 2153 If CREAD bit is off or device not open, set TX tail to head
2603 --------------------------------------------------------------------- */ 2154 --------------------------------------------------------------------- */
2604 2155
2605 if (!tty || !ts || !(ts->c_cflag & CREAD)) 2156 if (!tty || !ts || !(ts->c_cflag & CREAD)) {
2606 {
2607 bc->rout = head; 2157 bc->rout = head;
2608 return; 2158 return;
2609 } 2159 }
@@ -2611,64 +2161,45 @@ static void receive_data(struct channel *ch)
2611 if (tty->flip.count == TTY_FLIPBUF_SIZE) 2161 if (tty->flip.count == TTY_FLIPBUF_SIZE)
2612 return; 2162 return;
2613 2163
2614 if (bc->orun) 2164 if (readb(&bc->orun)) {
2615 { 2165 writeb(0, &bc->orun);
2616 bc->orun = 0; 2166 printk(KERN_WARNING "epca; overrun! DigiBoard device %s\n",tty->name);
2617 printk(KERN_WARNING "overrun! DigiBoard device %s\n",tty->name);
2618 } 2167 }
2619
2620 rxwinon(ch); 2168 rxwinon(ch);
2621 rptr = tty->flip.char_buf_ptr; 2169 rptr = tty->flip.char_buf_ptr;
2622 rc = tty->flip.count; 2170 rc = tty->flip.count;
2623 2171 while (bytesAvailable > 0) { /* Begin while there is data on the card */
2624 while (bytesAvailable > 0)
2625 { /* Begin while there is data on the card */
2626
2627 wrapgap = (head >= tail) ? head - tail : ch->rxbufsize - tail; 2172 wrapgap = (head >= tail) ? head - tail : ch->rxbufsize - tail;
2628
2629 /* --------------------------------------------------------------- 2173 /* ---------------------------------------------------------------
2630 Even if head has wrapped around only report the amount of 2174 Even if head has wrapped around only report the amount of
2631 data to be equal to the size - tail. Remember memcpy can't 2175 data to be equal to the size - tail. Remember memcpy can't
2632 automaticly wrap around the receive buffer. 2176 automaticly wrap around the receive buffer.
2633 ----------------------------------------------------------------- */ 2177 ----------------------------------------------------------------- */
2634
2635 dataToRead = (wrapgap < bytesAvailable) ? wrapgap : bytesAvailable; 2178 dataToRead = (wrapgap < bytesAvailable) ? wrapgap : bytesAvailable;
2636
2637 /* -------------------------------------------------------------- 2179 /* --------------------------------------------------------------
2638 Make sure we don't overflow the buffer 2180 Make sure we don't overflow the buffer
2639 ----------------------------------------------------------------- */ 2181 ----------------------------------------------------------------- */
2640
2641 if ((rc + dataToRead) > TTY_FLIPBUF_SIZE) 2182 if ((rc + dataToRead) > TTY_FLIPBUF_SIZE)
2642 dataToRead = TTY_FLIPBUF_SIZE - rc; 2183 dataToRead = TTY_FLIPBUF_SIZE - rc;
2643
2644 if (dataToRead == 0) 2184 if (dataToRead == 0)
2645 break; 2185 break;
2646
2647 /* --------------------------------------------------------------- 2186 /* ---------------------------------------------------------------
2648 Move data read from our card into the line disciplines buffer 2187 Move data read from our card into the line disciplines buffer
2649 for translation if necessary. 2188 for translation if necessary.
2650 ------------------------------------------------------------------ */ 2189 ------------------------------------------------------------------ */
2651 2190 memcpy_fromio(rptr, ch->rxptr + tail, dataToRead);
2652 if ((memcpy(rptr, ch->rxptr + tail, dataToRead)) != rptr)
2653 printk(KERN_ERR "<Error> - receive_data : memcpy failed\n");
2654
2655 rc += dataToRead; 2191 rc += dataToRead;
2656 rptr += dataToRead; 2192 rptr += dataToRead;
2657 tail = (tail + dataToRead) & wrapmask; 2193 tail = (tail + dataToRead) & wrapmask;
2658 bytesAvailable -= dataToRead; 2194 bytesAvailable -= dataToRead;
2659
2660 } /* End while there is data on the card */ 2195 } /* End while there is data on the card */
2661
2662
2663 tty->flip.count = rc; 2196 tty->flip.count = rc;
2664 tty->flip.char_buf_ptr = rptr; 2197 tty->flip.char_buf_ptr = rptr;
2665 globalwinon(ch); 2198 globalwinon(ch);
2666 bc->rout = tail; 2199 writew(tail, &bc->rout);
2667
2668 /* Must be called with global data */ 2200 /* Must be called with global data */
2669 tty_schedule_flip(ch->tty); 2201 tty_schedule_flip(ch->tty);
2670 return; 2202 return;
2671
2672} /* End receive_data */ 2203} /* End receive_data */
2673 2204
2674static int info_ioctl(struct tty_struct *tty, struct file * file, 2205static int info_ioctl(struct tty_struct *tty, struct file * file,
@@ -2676,17 +2207,15 @@ static int info_ioctl(struct tty_struct *tty, struct file * file,
2676{ 2207{
2677 switch (cmd) 2208 switch (cmd)
2678 { /* Begin switch cmd */ 2209 { /* Begin switch cmd */
2679
2680 case DIGI_GETINFO: 2210 case DIGI_GETINFO:
2681 { /* Begin case DIGI_GETINFO */ 2211 { /* Begin case DIGI_GETINFO */
2682
2683 struct digi_info di ; 2212 struct digi_info di ;
2684 int brd; 2213 int brd;
2685 2214
2686 getUser(brd, (unsigned int __user *)arg); 2215 if(get_user(brd, (unsigned int __user *)arg))
2687 2216 return -EFAULT;
2688 if ((brd < 0) || (brd >= num_cards) || (num_cards == 0)) 2217 if (brd < 0 || brd >= num_cards || num_cards == 0)
2689 return (-ENODEV); 2218 return -ENODEV;
2690 2219
2691 memset(&di, 0, sizeof(di)); 2220 memset(&di, 0, sizeof(di));
2692 2221
@@ -2694,8 +2223,9 @@ static int info_ioctl(struct tty_struct *tty, struct file * file,
2694 di.status = boards[brd].status; 2223 di.status = boards[brd].status;
2695 di.type = boards[brd].type ; 2224 di.type = boards[brd].type ;
2696 di.numports = boards[brd].numports ; 2225 di.numports = boards[brd].numports ;
2697 di.port = boards[brd].port ; 2226 /* Legacy fixups - just move along nothing to see */
2698 di.membase = boards[brd].membase ; 2227 di.port = (unsigned char *)boards[brd].port ;
2228 di.membase = (unsigned char *)boards[brd].membase ;
2699 2229
2700 if (copy_to_user((void __user *)arg, &di, sizeof (di))) 2230 if (copy_to_user((void __user *)arg, &di, sizeof (di)))
2701 return -EFAULT; 2231 return -EFAULT;
@@ -2709,39 +2239,29 @@ static int info_ioctl(struct tty_struct *tty, struct file * file,
2709 int brd = arg & 0xff000000 >> 16 ; 2239 int brd = arg & 0xff000000 >> 16 ;
2710 unsigned char state = arg & 0xff ; 2240 unsigned char state = arg & 0xff ;
2711 2241
2712 if ((brd < 0) || (brd >= num_cards)) 2242 if (brd < 0 || brd >= num_cards) {
2713 { 2243 printk(KERN_ERR "epca: DIGI POLLER : brd not valid!\n");
2714 printk(KERN_ERR "<Error> - DIGI POLLER : brd not valid!\n");
2715 return (-ENODEV); 2244 return (-ENODEV);
2716 } 2245 }
2717
2718 digi_poller_inhibited = state ; 2246 digi_poller_inhibited = state ;
2719 break ; 2247 break ;
2720
2721 } /* End case DIGI_POLLER */ 2248 } /* End case DIGI_POLLER */
2722 2249
2723 case DIGI_INIT: 2250 case DIGI_INIT:
2724 { /* Begin case DIGI_INIT */ 2251 { /* Begin case DIGI_INIT */
2725
2726 /* ------------------------------------------------------------ 2252 /* ------------------------------------------------------------
2727 This call is made by the apps to complete the initilization 2253 This call is made by the apps to complete the initilization
2728 of the board(s). This routine is responsible for setting 2254 of the board(s). This routine is responsible for setting
2729 the card to its initial state and setting the drivers control 2255 the card to its initial state and setting the drivers control
2730 fields to the sutianle settings for the card in question. 2256 fields to the sutianle settings for the card in question.
2731 ---------------------------------------------------------------- */ 2257 ---------------------------------------------------------------- */
2732
2733 int crd ; 2258 int crd ;
2734 for (crd = 0; crd < num_cards; crd++) 2259 for (crd = 0; crd < num_cards; crd++)
2735 post_fep_init (crd); 2260 post_fep_init (crd);
2736
2737 break ; 2261 break ;
2738
2739 } /* End case DIGI_INIT */ 2262 } /* End case DIGI_INIT */
2740
2741
2742 default: 2263 default:
2743 return -ENOIOCTLCMD; 2264 return -ENOTTY;
2744
2745 } /* End switch cmd */ 2265 } /* End switch cmd */
2746 return (0) ; 2266 return (0) ;
2747} 2267}
@@ -2750,43 +2270,33 @@ static int info_ioctl(struct tty_struct *tty, struct file * file,
2750static int pc_tiocmget(struct tty_struct *tty, struct file *file) 2270static int pc_tiocmget(struct tty_struct *tty, struct file *file)
2751{ 2271{
2752 struct channel *ch = (struct channel *) tty->driver_data; 2272 struct channel *ch = (struct channel *) tty->driver_data;
2753 volatile struct board_chan *bc; 2273 struct board_chan *bc;
2754 unsigned int mstat, mflag = 0; 2274 unsigned int mstat, mflag = 0;
2755 unsigned long flags; 2275 unsigned long flags;
2756 2276
2757 if (ch) 2277 if (ch)
2758 bc = ch->brdchan; 2278 bc = ch->brdchan;
2759 else 2279 else
2760 { 2280 return -EINVAL;
2761 printk(KERN_ERR "<Error> - ch is NULL in pc_tiocmget!\n");
2762 return(-EINVAL);
2763 }
2764 2281
2765 save_flags(flags); 2282 spin_lock_irqsave(&epca_lock, flags);
2766 cli();
2767 globalwinon(ch); 2283 globalwinon(ch);
2768 mstat = bc->mstat; 2284 mstat = readb(&bc->mstat);
2769 memoff(ch); 2285 memoff(ch);
2770 restore_flags(flags); 2286 spin_unlock_irqrestore(&epca_lock, flags);
2771 2287
2772 if (mstat & ch->m_dtr) 2288 if (mstat & ch->m_dtr)
2773 mflag |= TIOCM_DTR; 2289 mflag |= TIOCM_DTR;
2774
2775 if (mstat & ch->m_rts) 2290 if (mstat & ch->m_rts)
2776 mflag |= TIOCM_RTS; 2291 mflag |= TIOCM_RTS;
2777
2778 if (mstat & ch->m_cts) 2292 if (mstat & ch->m_cts)
2779 mflag |= TIOCM_CTS; 2293 mflag |= TIOCM_CTS;
2780
2781 if (mstat & ch->dsr) 2294 if (mstat & ch->dsr)
2782 mflag |= TIOCM_DSR; 2295 mflag |= TIOCM_DSR;
2783
2784 if (mstat & ch->m_ri) 2296 if (mstat & ch->m_ri)
2785 mflag |= TIOCM_RI; 2297 mflag |= TIOCM_RI;
2786
2787 if (mstat & ch->dcd) 2298 if (mstat & ch->dcd)
2788 mflag |= TIOCM_CD; 2299 mflag |= TIOCM_CD;
2789
2790 return mflag; 2300 return mflag;
2791} 2301}
2792 2302
@@ -2796,13 +2306,10 @@ static int pc_tiocmset(struct tty_struct *tty, struct file *file,
2796 struct channel *ch = (struct channel *) tty->driver_data; 2306 struct channel *ch = (struct channel *) tty->driver_data;
2797 unsigned long flags; 2307 unsigned long flags;
2798 2308
2799 if (!ch) { 2309 if (!ch)
2800 printk(KERN_ERR "<Error> - ch is NULL in pc_tiocmset!\n"); 2310 return -EINVAL;
2801 return(-EINVAL);
2802 }
2803 2311
2804 save_flags(flags); 2312 spin_lock_irqsave(&epca_lock, flags);
2805 cli();
2806 /* 2313 /*
2807 * I think this modemfake stuff is broken. It doesn't 2314 * I think this modemfake stuff is broken. It doesn't
2808 * correctly reflect the behaviour desired by the TIOCM* 2315 * correctly reflect the behaviour desired by the TIOCM*
@@ -2824,17 +2331,14 @@ static int pc_tiocmset(struct tty_struct *tty, struct file *file,
2824 ch->modemfake |= ch->m_dtr; 2331 ch->modemfake |= ch->m_dtr;
2825 ch->modem &= ~ch->m_dtr; 2332 ch->modem &= ~ch->m_dtr;
2826 } 2333 }
2827
2828 globalwinon(ch); 2334 globalwinon(ch);
2829
2830 /* -------------------------------------------------------------- 2335 /* --------------------------------------------------------------
2831 The below routine generally sets up parity, baud, flow control 2336 The below routine generally sets up parity, baud, flow control
2832 issues, etc.... It effect both control flags and input flags. 2337 issues, etc.... It effect both control flags and input flags.
2833 ------------------------------------------------------------------ */ 2338 ------------------------------------------------------------------ */
2834
2835 epcaparam(tty,ch); 2339 epcaparam(tty,ch);
2836 memoff(ch); 2340 memoff(ch);
2837 restore_flags(flags); 2341 spin_unlock_irqrestore(&epca_lock, flags);
2838 return 0; 2342 return 0;
2839} 2343}
2840 2344
@@ -2847,19 +2351,14 @@ static int pc_ioctl(struct tty_struct *tty, struct file * file,
2847 unsigned long flags; 2351 unsigned long flags;
2848 unsigned int mflag, mstat; 2352 unsigned int mflag, mstat;
2849 unsigned char startc, stopc; 2353 unsigned char startc, stopc;
2850 volatile struct board_chan *bc; 2354 struct board_chan *bc;
2851 struct channel *ch = (struct channel *) tty->driver_data; 2355 struct channel *ch = (struct channel *) tty->driver_data;
2852 void __user *argp = (void __user *)arg; 2356 void __user *argp = (void __user *)arg;
2853 2357
2854 if (ch) 2358 if (ch)
2855 bc = ch->brdchan; 2359 bc = ch->brdchan;
2856 else 2360 else
2857 { 2361 return -EINVAL;
2858 printk(KERN_ERR "<Error> - ch is NULL in pc_ioctl!\n");
2859 return(-EINVAL);
2860 }
2861
2862 save_flags(flags);
2863 2362
2864 /* ------------------------------------------------------------------- 2363 /* -------------------------------------------------------------------
2865 For POSIX compliance we need to add more ioctls. See tty_ioctl.c 2364 For POSIX compliance we need to add more ioctls. See tty_ioctl.c
@@ -2871,46 +2370,39 @@ static int pc_ioctl(struct tty_struct *tty, struct file * file,
2871 { /* Begin switch cmd */ 2370 { /* Begin switch cmd */
2872 2371
2873 case TCGETS: 2372 case TCGETS:
2874 if (copy_to_user(argp, 2373 if (copy_to_user(argp, tty->termios, sizeof(struct termios)))
2875 tty->termios, sizeof(struct termios)))
2876 return -EFAULT; 2374 return -EFAULT;
2877 return(0); 2375 return 0;
2878
2879 case TCGETA: 2376 case TCGETA:
2880 return get_termio(tty, argp); 2377 return get_termio(tty, argp);
2881
2882 case TCSBRK: /* SVID version: non-zero arg --> no break */ 2378 case TCSBRK: /* SVID version: non-zero arg --> no break */
2883
2884 retval = tty_check_change(tty); 2379 retval = tty_check_change(tty);
2885 if (retval) 2380 if (retval)
2886 return retval; 2381 return retval;
2887
2888 /* Setup an event to indicate when the transmit buffer empties */ 2382 /* Setup an event to indicate when the transmit buffer empties */
2889 2383 spin_lock_irqsave(&epca_lock, flags);
2890 setup_empty_event(tty,ch); 2384 setup_empty_event(tty,ch);
2385 spin_unlock_irqrestore(&epca_lock, flags);
2891 tty_wait_until_sent(tty, 0); 2386 tty_wait_until_sent(tty, 0);
2892 if (!arg) 2387 if (!arg)
2893 digi_send_break(ch, HZ/4); /* 1/4 second */ 2388 digi_send_break(ch, HZ/4); /* 1/4 second */
2894 return 0; 2389 return 0;
2895
2896 case TCSBRKP: /* support for POSIX tcsendbreak() */ 2390 case TCSBRKP: /* support for POSIX tcsendbreak() */
2897
2898 retval = tty_check_change(tty); 2391 retval = tty_check_change(tty);
2899 if (retval) 2392 if (retval)
2900 return retval; 2393 return retval;
2901 2394
2902 /* Setup an event to indicate when the transmit buffer empties */ 2395 /* Setup an event to indicate when the transmit buffer empties */
2903 2396 spin_lock_irqsave(&epca_lock, flags);
2904 setup_empty_event(tty,ch); 2397 setup_empty_event(tty,ch);
2398 spin_unlock_irqrestore(&epca_lock, flags);
2905 tty_wait_until_sent(tty, 0); 2399 tty_wait_until_sent(tty, 0);
2906 digi_send_break(ch, arg ? arg*(HZ/10) : HZ/4); 2400 digi_send_break(ch, arg ? arg*(HZ/10) : HZ/4);
2907 return 0; 2401 return 0;
2908
2909 case TIOCGSOFTCAR: 2402 case TIOCGSOFTCAR:
2910 if (put_user(C_CLOCAL(tty)?1:0, (unsigned long __user *)arg)) 2403 if (put_user(C_CLOCAL(tty)?1:0, (unsigned long __user *)arg))
2911 return -EFAULT; 2404 return -EFAULT;
2912 return 0; 2405 return 0;
2913
2914 case TIOCSSOFTCAR: 2406 case TIOCSSOFTCAR:
2915 { 2407 {
2916 unsigned int value; 2408 unsigned int value;
@@ -2922,75 +2414,63 @@ static int pc_ioctl(struct tty_struct *tty, struct file * file,
2922 (value ? CLOCAL : 0)); 2414 (value ? CLOCAL : 0));
2923 return 0; 2415 return 0;
2924 } 2416 }
2925
2926 case TIOCMODG: 2417 case TIOCMODG:
2927 mflag = pc_tiocmget(tty, file); 2418 mflag = pc_tiocmget(tty, file);
2928 if (put_user(mflag, (unsigned long __user *)argp)) 2419 if (put_user(mflag, (unsigned long __user *)argp))
2929 return -EFAULT; 2420 return -EFAULT;
2930 break; 2421 break;
2931
2932 case TIOCMODS: 2422 case TIOCMODS:
2933 if (get_user(mstat, (unsigned __user *)argp)) 2423 if (get_user(mstat, (unsigned __user *)argp))
2934 return -EFAULT; 2424 return -EFAULT;
2935 return pc_tiocmset(tty, file, mstat, ~mstat); 2425 return pc_tiocmset(tty, file, mstat, ~mstat);
2936
2937 case TIOCSDTR: 2426 case TIOCSDTR:
2427 spin_lock_irqsave(&epca_lock, flags);
2938 ch->omodem |= ch->m_dtr; 2428 ch->omodem |= ch->m_dtr;
2939 cli();
2940 globalwinon(ch); 2429 globalwinon(ch);
2941 fepcmd(ch, SETMODEM, ch->m_dtr, 0, 10, 1); 2430 fepcmd(ch, SETMODEM, ch->m_dtr, 0, 10, 1);
2942 memoff(ch); 2431 memoff(ch);
2943 restore_flags(flags); 2432 spin_unlock_irqrestore(&epca_lock, flags);
2944 break; 2433 break;
2945 2434
2946 case TIOCCDTR: 2435 case TIOCCDTR:
2436 spin_lock_irqsave(&epca_lock, flags);
2947 ch->omodem &= ~ch->m_dtr; 2437 ch->omodem &= ~ch->m_dtr;
2948 cli();
2949 globalwinon(ch); 2438 globalwinon(ch);
2950 fepcmd(ch, SETMODEM, 0, ch->m_dtr, 10, 1); 2439 fepcmd(ch, SETMODEM, 0, ch->m_dtr, 10, 1);
2951 memoff(ch); 2440 memoff(ch);
2952 restore_flags(flags); 2441 spin_unlock_irqrestore(&epca_lock, flags);
2953 break; 2442 break;
2954
2955 case DIGI_GETA: 2443 case DIGI_GETA:
2956 if (copy_to_user(argp, &ch->digiext, sizeof(digi_t))) 2444 if (copy_to_user(argp, &ch->digiext, sizeof(digi_t)))
2957 return -EFAULT; 2445 return -EFAULT;
2958 break; 2446 break;
2959
2960 case DIGI_SETAW: 2447 case DIGI_SETAW:
2961 case DIGI_SETAF: 2448 case DIGI_SETAF:
2962 if ((cmd) == (DIGI_SETAW)) 2449 if (cmd == DIGI_SETAW) {
2963 {
2964 /* Setup an event to indicate when the transmit buffer empties */ 2450 /* Setup an event to indicate when the transmit buffer empties */
2965 2451 spin_lock_irqsave(&epca_lock, flags);
2966 setup_empty_event(tty,ch); 2452 setup_empty_event(tty,ch);
2453 spin_unlock_irqrestore(&epca_lock, flags);
2967 tty_wait_until_sent(tty, 0); 2454 tty_wait_until_sent(tty, 0);
2968 } 2455 } else {
2969 else
2970 {
2971 /* ldisc lock already held in ioctl */ 2456 /* ldisc lock already held in ioctl */
2972 if (tty->ldisc.flush_buffer) 2457 if (tty->ldisc.flush_buffer)
2973 tty->ldisc.flush_buffer(tty); 2458 tty->ldisc.flush_buffer(tty);
2974 } 2459 }
2975
2976 /* Fall Thru */ 2460 /* Fall Thru */
2977
2978 case DIGI_SETA: 2461 case DIGI_SETA:
2979 if (copy_from_user(&ch->digiext, argp, sizeof(digi_t))) 2462 if (copy_from_user(&ch->digiext, argp, sizeof(digi_t)))
2980 return -EFAULT; 2463 return -EFAULT;
2981 2464
2982 if (ch->digiext.digi_flags & DIGI_ALTPIN) 2465 if (ch->digiext.digi_flags & DIGI_ALTPIN) {
2983 {
2984 ch->dcd = ch->m_dsr; 2466 ch->dcd = ch->m_dsr;
2985 ch->dsr = ch->m_dcd; 2467 ch->dsr = ch->m_dcd;
2986 } 2468 } else {
2987 else
2988 {
2989 ch->dcd = ch->m_dcd; 2469 ch->dcd = ch->m_dcd;
2990 ch->dsr = ch->m_dsr; 2470 ch->dsr = ch->m_dsr;
2991 } 2471 }
2992 2472
2993 cli(); 2473 spin_lock_irqsave(&epca_lock, flags);
2994 globalwinon(ch); 2474 globalwinon(ch);
2995 2475
2996 /* ----------------------------------------------------------------- 2476 /* -----------------------------------------------------------------
@@ -3000,25 +2480,22 @@ static int pc_ioctl(struct tty_struct *tty, struct file * file,
3000 2480
3001 epcaparam(tty,ch); 2481 epcaparam(tty,ch);
3002 memoff(ch); 2482 memoff(ch);
3003 restore_flags(flags); 2483 spin_unlock_irqrestore(&epca_lock, flags);
3004 break; 2484 break;
3005 2485
3006 case DIGI_GETFLOW: 2486 case DIGI_GETFLOW:
3007 case DIGI_GETAFLOW: 2487 case DIGI_GETAFLOW:
3008 cli(); 2488 spin_lock_irqsave(&epca_lock, flags);
3009 globalwinon(ch); 2489 globalwinon(ch);
3010 if ((cmd) == (DIGI_GETFLOW)) 2490 if (cmd == DIGI_GETFLOW) {
3011 { 2491 dflow.startc = readb(&bc->startc);
3012 dflow.startc = bc->startc; 2492 dflow.stopc = readb(&bc->stopc);
3013 dflow.stopc = bc->stopc; 2493 } else {
3014 } 2494 dflow.startc = readb(&bc->startca);
3015 else 2495 dflow.stopc = readb(&bc->stopca);
3016 {
3017 dflow.startc = bc->startca;
3018 dflow.stopc = bc->stopca;
3019 } 2496 }
3020 memoff(ch); 2497 memoff(ch);
3021 restore_flags(flags); 2498 spin_unlock_irqrestore(&epca_lock, flags);
3022 2499
3023 if (copy_to_user(argp, &dflow, sizeof(dflow))) 2500 if (copy_to_user(argp, &dflow, sizeof(dflow)))
3024 return -EFAULT; 2501 return -EFAULT;
@@ -3026,13 +2503,10 @@ static int pc_ioctl(struct tty_struct *tty, struct file * file,
3026 2503
3027 case DIGI_SETAFLOW: 2504 case DIGI_SETAFLOW:
3028 case DIGI_SETFLOW: 2505 case DIGI_SETFLOW:
3029 if ((cmd) == (DIGI_SETFLOW)) 2506 if (cmd == DIGI_SETFLOW) {
3030 {
3031 startc = ch->startc; 2507 startc = ch->startc;
3032 stopc = ch->stopc; 2508 stopc = ch->stopc;
3033 } 2509 } else {
3034 else
3035 {
3036 startc = ch->startca; 2510 startc = ch->startca;
3037 stopc = ch->stopca; 2511 stopc = ch->stopca;
3038 } 2512 }
@@ -3040,40 +2514,31 @@ static int pc_ioctl(struct tty_struct *tty, struct file * file,
3040 if (copy_from_user(&dflow, argp, sizeof(dflow))) 2514 if (copy_from_user(&dflow, argp, sizeof(dflow)))
3041 return -EFAULT; 2515 return -EFAULT;
3042 2516
3043 if (dflow.startc != startc || dflow.stopc != stopc) 2517 if (dflow.startc != startc || dflow.stopc != stopc) { /* Begin if setflow toggled */
3044 { /* Begin if setflow toggled */ 2518 spin_lock_irqsave(&epca_lock, flags);
3045 cli();
3046 globalwinon(ch); 2519 globalwinon(ch);
3047 2520
3048 if ((cmd) == (DIGI_SETFLOW)) 2521 if (cmd == DIGI_SETFLOW) {
3049 {
3050 ch->fepstartc = ch->startc = dflow.startc; 2522 ch->fepstartc = ch->startc = dflow.startc;
3051 ch->fepstopc = ch->stopc = dflow.stopc; 2523 ch->fepstopc = ch->stopc = dflow.stopc;
3052 fepcmd(ch, SONOFFC, ch->fepstartc, ch->fepstopc, 0, 1); 2524 fepcmd(ch, SONOFFC, ch->fepstartc, ch->fepstopc, 0, 1);
3053 } 2525 } else {
3054 else
3055 {
3056 ch->fepstartca = ch->startca = dflow.startc; 2526 ch->fepstartca = ch->startca = dflow.startc;
3057 ch->fepstopca = ch->stopca = dflow.stopc; 2527 ch->fepstopca = ch->stopca = dflow.stopc;
3058 fepcmd(ch, SAUXONOFFC, ch->fepstartca, ch->fepstopca, 0, 1); 2528 fepcmd(ch, SAUXONOFFC, ch->fepstartca, ch->fepstopca, 0, 1);
3059 } 2529 }
3060 2530
3061 if (ch->statusflags & TXSTOPPED) 2531 if (ch->statusflags & TXSTOPPED)
3062 pc_start(tty); 2532 pc_start(tty);
3063 2533
3064 memoff(ch); 2534 memoff(ch);
3065 restore_flags(flags); 2535 spin_unlock_irqrestore(&epca_lock, flags);
3066
3067 } /* End if setflow toggled */ 2536 } /* End if setflow toggled */
3068 break; 2537 break;
3069
3070 default: 2538 default:
3071 return -ENOIOCTLCMD; 2539 return -ENOIOCTLCMD;
3072
3073 } /* End switch cmd */ 2540 } /* End switch cmd */
3074
3075 return 0; 2541 return 0;
3076
3077} /* End pc_ioctl */ 2542} /* End pc_ioctl */
3078 2543
3079/* --------------------- Begin pc_set_termios ----------------------- */ 2544/* --------------------- Begin pc_set_termios ----------------------- */
@@ -3083,20 +2548,16 @@ static void pc_set_termios(struct tty_struct *tty, struct termios *old_termios)
3083 2548
3084 struct channel *ch; 2549 struct channel *ch;
3085 unsigned long flags; 2550 unsigned long flags;
3086
3087 /* --------------------------------------------------------- 2551 /* ---------------------------------------------------------
3088 verifyChannel returns the channel from the tty struct 2552 verifyChannel returns the channel from the tty struct
3089 if it is valid. This serves as a sanity check. 2553 if it is valid. This serves as a sanity check.
3090 ------------------------------------------------------------- */ 2554 ------------------------------------------------------------- */
3091 2555 if ((ch = verifyChannel(tty)) != NULL) { /* Begin if channel valid */
3092 if ((ch = verifyChannel(tty)) != NULL) 2556 spin_lock_irqsave(&epca_lock, flags);
3093 { /* Begin if channel valid */
3094
3095 save_flags(flags);
3096 cli();
3097 globalwinon(ch); 2557 globalwinon(ch);
3098 epcaparam(tty, ch); 2558 epcaparam(tty, ch);
3099 memoff(ch); 2559 memoff(ch);
2560 spin_unlock_irqrestore(&epca_lock, flags);
3100 2561
3101 if ((old_termios->c_cflag & CRTSCTS) && 2562 if ((old_termios->c_cflag & CRTSCTS) &&
3102 ((tty->termios->c_cflag & CRTSCTS) == 0)) 2563 ((tty->termios->c_cflag & CRTSCTS) == 0))
@@ -3106,8 +2567,6 @@ static void pc_set_termios(struct tty_struct *tty, struct termios *old_termios)
3106 (tty->termios->c_cflag & CLOCAL)) 2567 (tty->termios->c_cflag & CLOCAL))
3107 wake_up_interruptible(&ch->open_wait); 2568 wake_up_interruptible(&ch->open_wait);
3108 2569
3109 restore_flags(flags);
3110
3111 } /* End if channel valid */ 2570 } /* End if channel valid */
3112 2571
3113} /* End pc_set_termios */ 2572} /* End pc_set_termios */
@@ -3116,29 +2575,18 @@ static void pc_set_termios(struct tty_struct *tty, struct termios *old_termios)
3116 2575
3117static void do_softint(void *private_) 2576static void do_softint(void *private_)
3118{ /* Begin do_softint */ 2577{ /* Begin do_softint */
3119
3120 struct channel *ch = (struct channel *) private_; 2578 struct channel *ch = (struct channel *) private_;
3121
3122
3123 /* Called in response to a modem change event */ 2579 /* Called in response to a modem change event */
3124 2580 if (ch && ch->magic == EPCA_MAGIC) { /* Begin EPCA_MAGIC */
3125 if (ch && ch->magic == EPCA_MAGIC)
3126 { /* Begin EPCA_MAGIC */
3127
3128 struct tty_struct *tty = ch->tty; 2581 struct tty_struct *tty = ch->tty;
3129 2582
3130 if (tty && tty->driver_data) 2583 if (tty && tty->driver_data) {
3131 { 2584 if (test_and_clear_bit(EPCA_EVENT_HANGUP, &ch->event)) { /* Begin if clear_bit */
3132 if (test_and_clear_bit(EPCA_EVENT_HANGUP, &ch->event))
3133 { /* Begin if clear_bit */
3134
3135 tty_hangup(tty); /* FIXME: module removal race here - AKPM */ 2585 tty_hangup(tty); /* FIXME: module removal race here - AKPM */
3136 wake_up_interruptible(&ch->open_wait); 2586 wake_up_interruptible(&ch->open_wait);
3137 ch->asyncflags &= ~ASYNC_NORMAL_ACTIVE; 2587 ch->asyncflags &= ~ASYNC_NORMAL_ACTIVE;
3138
3139 } /* End if clear_bit */ 2588 } /* End if clear_bit */
3140 } 2589 }
3141
3142 } /* End EPCA_MAGIC */ 2590 } /* End EPCA_MAGIC */
3143} /* End do_softint */ 2591} /* End do_softint */
3144 2592
@@ -3154,82 +2602,49 @@ static void pc_stop(struct tty_struct *tty)
3154 2602
3155 struct channel *ch; 2603 struct channel *ch;
3156 unsigned long flags; 2604 unsigned long flags;
3157
3158 /* --------------------------------------------------------- 2605 /* ---------------------------------------------------------
3159 verifyChannel returns the channel from the tty struct 2606 verifyChannel returns the channel from the tty struct
3160 if it is valid. This serves as a sanity check. 2607 if it is valid. This serves as a sanity check.
3161 ------------------------------------------------------------- */ 2608 ------------------------------------------------------------- */
3162 2609 if ((ch = verifyChannel(tty)) != NULL) { /* Begin if valid channel */
3163 if ((ch = verifyChannel(tty)) != NULL) 2610 spin_lock_irqsave(&epca_lock, flags);
3164 { /* Begin if valid channel */ 2611 if ((ch->statusflags & TXSTOPPED) == 0) { /* Begin if transmit stop requested */
3165
3166 save_flags(flags);
3167 cli();
3168
3169 if ((ch->statusflags & TXSTOPPED) == 0)
3170 { /* Begin if transmit stop requested */
3171
3172 globalwinon(ch); 2612 globalwinon(ch);
3173
3174 /* STOP transmitting now !! */ 2613 /* STOP transmitting now !! */
3175
3176 fepcmd(ch, PAUSETX, 0, 0, 0, 0); 2614 fepcmd(ch, PAUSETX, 0, 0, 0, 0);
3177
3178 ch->statusflags |= TXSTOPPED; 2615 ch->statusflags |= TXSTOPPED;
3179 memoff(ch); 2616 memoff(ch);
3180
3181 } /* End if transmit stop requested */ 2617 } /* End if transmit stop requested */
3182 2618 spin_unlock_irqrestore(&epca_lock, flags);
3183 restore_flags(flags);
3184
3185 } /* End if valid channel */ 2619 } /* End if valid channel */
3186
3187} /* End pc_stop */ 2620} /* End pc_stop */
3188 2621
3189/* --------------------- Begin pc_start ----------------------- */ 2622/* --------------------- Begin pc_start ----------------------- */
3190 2623
3191static void pc_start(struct tty_struct *tty) 2624static void pc_start(struct tty_struct *tty)
3192{ /* Begin pc_start */ 2625{ /* Begin pc_start */
3193
3194 struct channel *ch; 2626 struct channel *ch;
3195
3196 /* --------------------------------------------------------- 2627 /* ---------------------------------------------------------
3197 verifyChannel returns the channel from the tty struct 2628 verifyChannel returns the channel from the tty struct
3198 if it is valid. This serves as a sanity check. 2629 if it is valid. This serves as a sanity check.
3199 ------------------------------------------------------------- */ 2630 ------------------------------------------------------------- */
3200 2631 if ((ch = verifyChannel(tty)) != NULL) { /* Begin if channel valid */
3201 if ((ch = verifyChannel(tty)) != NULL)
3202 { /* Begin if channel valid */
3203
3204 unsigned long flags; 2632 unsigned long flags;
3205 2633 spin_lock_irqsave(&epca_lock, flags);
3206 save_flags(flags);
3207 cli();
3208
3209 /* Just in case output was resumed because of a change in Digi-flow */ 2634 /* Just in case output was resumed because of a change in Digi-flow */
3210 if (ch->statusflags & TXSTOPPED) 2635 if (ch->statusflags & TXSTOPPED) { /* Begin transmit resume requested */
3211 { /* Begin transmit resume requested */ 2636 struct board_chan *bc;
3212
3213 volatile struct board_chan *bc;
3214
3215 globalwinon(ch); 2637 globalwinon(ch);
3216 bc = ch->brdchan; 2638 bc = ch->brdchan;
3217 if (ch->statusflags & LOWWAIT) 2639 if (ch->statusflags & LOWWAIT)
3218 bc->ilow = 1; 2640 writeb(1, &bc->ilow);
3219
3220 /* Okay, you can start transmitting again... */ 2641 /* Okay, you can start transmitting again... */
3221
3222 fepcmd(ch, RESUMETX, 0, 0, 0, 0); 2642 fepcmd(ch, RESUMETX, 0, 0, 0, 0);
3223
3224 ch->statusflags &= ~TXSTOPPED; 2643 ch->statusflags &= ~TXSTOPPED;
3225 memoff(ch); 2644 memoff(ch);
3226
3227 } /* End transmit resume requested */ 2645 } /* End transmit resume requested */
3228 2646 spin_unlock_irqrestore(&epca_lock, flags);
3229 restore_flags(flags);
3230
3231 } /* End if channel valid */ 2647 } /* End if channel valid */
3232
3233} /* End pc_start */ 2648} /* End pc_start */
3234 2649
3235/* ------------------------------------------------------------------ 2650/* ------------------------------------------------------------------
@@ -3244,86 +2659,55 @@ ______________________________________________________________________ */
3244 2659
3245static void pc_throttle(struct tty_struct * tty) 2660static void pc_throttle(struct tty_struct * tty)
3246{ /* Begin pc_throttle */ 2661{ /* Begin pc_throttle */
3247
3248 struct channel *ch; 2662 struct channel *ch;
3249 unsigned long flags; 2663 unsigned long flags;
3250
3251 /* --------------------------------------------------------- 2664 /* ---------------------------------------------------------
3252 verifyChannel returns the channel from the tty struct 2665 verifyChannel returns the channel from the tty struct
3253 if it is valid. This serves as a sanity check. 2666 if it is valid. This serves as a sanity check.
3254 ------------------------------------------------------------- */ 2667 ------------------------------------------------------------- */
3255 2668 if ((ch = verifyChannel(tty)) != NULL) { /* Begin if channel valid */
3256 if ((ch = verifyChannel(tty)) != NULL) 2669 spin_lock_irqsave(&epca_lock, flags);
3257 { /* Begin if channel valid */ 2670 if ((ch->statusflags & RXSTOPPED) == 0) {
3258
3259
3260 save_flags(flags);
3261 cli();
3262
3263 if ((ch->statusflags & RXSTOPPED) == 0)
3264 {
3265 globalwinon(ch); 2671 globalwinon(ch);
3266 fepcmd(ch, PAUSERX, 0, 0, 0, 0); 2672 fepcmd(ch, PAUSERX, 0, 0, 0, 0);
3267
3268 ch->statusflags |= RXSTOPPED; 2673 ch->statusflags |= RXSTOPPED;
3269 memoff(ch); 2674 memoff(ch);
3270 } 2675 }
3271 restore_flags(flags); 2676 spin_unlock_irqrestore(&epca_lock, flags);
3272
3273 } /* End if channel valid */ 2677 } /* End if channel valid */
3274
3275} /* End pc_throttle */ 2678} /* End pc_throttle */
3276 2679
3277/* --------------------- Begin unthrottle ----------------------- */ 2680/* --------------------- Begin unthrottle ----------------------- */
3278 2681
3279static void pc_unthrottle(struct tty_struct *tty) 2682static void pc_unthrottle(struct tty_struct *tty)
3280{ /* Begin pc_unthrottle */ 2683{ /* Begin pc_unthrottle */
3281
3282 struct channel *ch; 2684 struct channel *ch;
3283 unsigned long flags; 2685 unsigned long flags;
3284 volatile struct board_chan *bc;
3285
3286
3287 /* --------------------------------------------------------- 2686 /* ---------------------------------------------------------
3288 verifyChannel returns the channel from the tty struct 2687 verifyChannel returns the channel from the tty struct
3289 if it is valid. This serves as a sanity check. 2688 if it is valid. This serves as a sanity check.
3290 ------------------------------------------------------------- */ 2689 ------------------------------------------------------------- */
3291 2690 if ((ch = verifyChannel(tty)) != NULL) { /* Begin if channel valid */
3292 if ((ch = verifyChannel(tty)) != NULL)
3293 { /* Begin if channel valid */
3294
3295
3296 /* Just in case output was resumed because of a change in Digi-flow */ 2691 /* Just in case output was resumed because of a change in Digi-flow */
3297 save_flags(flags); 2692 spin_lock_irqsave(&epca_lock, flags);
3298 cli(); 2693 if (ch->statusflags & RXSTOPPED) {
3299
3300 if (ch->statusflags & RXSTOPPED)
3301 {
3302
3303 globalwinon(ch); 2694 globalwinon(ch);
3304 bc = ch->brdchan;
3305 fepcmd(ch, RESUMERX, 0, 0, 0, 0); 2695 fepcmd(ch, RESUMERX, 0, 0, 0, 0);
3306
3307 ch->statusflags &= ~RXSTOPPED; 2696 ch->statusflags &= ~RXSTOPPED;
3308 memoff(ch); 2697 memoff(ch);
3309 } 2698 }
3310 restore_flags(flags); 2699 spin_unlock_irqrestore(&epca_lock, flags);
3311
3312 } /* End if channel valid */ 2700 } /* End if channel valid */
3313
3314} /* End pc_unthrottle */ 2701} /* End pc_unthrottle */
3315 2702
3316/* --------------------- Begin digi_send_break ----------------------- */ 2703/* --------------------- Begin digi_send_break ----------------------- */
3317 2704
3318void digi_send_break(struct channel *ch, int msec) 2705void digi_send_break(struct channel *ch, int msec)
3319{ /* Begin digi_send_break */ 2706{ /* Begin digi_send_break */
3320
3321 unsigned long flags; 2707 unsigned long flags;
3322 2708
3323 save_flags(flags); 2709 spin_lock_irqsave(&epca_lock, flags);
3324 cli();
3325 globalwinon(ch); 2710 globalwinon(ch);
3326
3327 /* -------------------------------------------------------------------- 2711 /* --------------------------------------------------------------------
3328 Maybe I should send an infinite break here, schedule() for 2712 Maybe I should send an infinite break here, schedule() for
3329 msec amount of time, and then stop the break. This way, 2713 msec amount of time, and then stop the break. This way,
@@ -3331,36 +2715,28 @@ void digi_send_break(struct channel *ch, int msec)
3331 to be called (i.e. via an ioctl()) more than once in msec amount 2715 to be called (i.e. via an ioctl()) more than once in msec amount
3332 of time. Try this for now... 2716 of time. Try this for now...
3333 ------------------------------------------------------------------------ */ 2717 ------------------------------------------------------------------------ */
3334
3335 fepcmd(ch, SENDBREAK, msec, 0, 10, 0); 2718 fepcmd(ch, SENDBREAK, msec, 0, 10, 0);
3336 memoff(ch); 2719 memoff(ch);
3337 2720 spin_unlock_irqrestore(&epca_lock, flags);
3338 restore_flags(flags);
3339
3340} /* End digi_send_break */ 2721} /* End digi_send_break */
3341 2722
3342/* --------------------- Begin setup_empty_event ----------------------- */ 2723/* --------------------- Begin setup_empty_event ----------------------- */
3343 2724
2725/* Caller MUST hold the lock */
2726
3344static void setup_empty_event(struct tty_struct *tty, struct channel *ch) 2727static void setup_empty_event(struct tty_struct *tty, struct channel *ch)
3345{ /* Begin setup_empty_event */ 2728{ /* Begin setup_empty_event */
3346 2729
3347 volatile struct board_chan *bc = ch->brdchan; 2730 struct board_chan *bc = ch->brdchan;
3348 unsigned long int flags;
3349 2731
3350 save_flags(flags);
3351 cli();
3352 globalwinon(ch); 2732 globalwinon(ch);
3353 ch->statusflags |= EMPTYWAIT; 2733 ch->statusflags |= EMPTYWAIT;
3354
3355 /* ------------------------------------------------------------------ 2734 /* ------------------------------------------------------------------
3356 When set the iempty flag request a event to be generated when the 2735 When set the iempty flag request a event to be generated when the
3357 transmit buffer is empty (If there is no BREAK in progress). 2736 transmit buffer is empty (If there is no BREAK in progress).
3358 --------------------------------------------------------------------- */ 2737 --------------------------------------------------------------------- */
3359 2738 writeb(1, &bc->iempty);
3360 bc->iempty = 1;
3361 memoff(ch); 2739 memoff(ch);
3362 restore_flags(flags);
3363
3364} /* End setup_empty_event */ 2740} /* End setup_empty_event */
3365 2741
3366/* --------------------- Begin get_termio ----------------------- */ 2742/* --------------------- Begin get_termio ----------------------- */
@@ -3369,10 +2745,10 @@ static int get_termio(struct tty_struct * tty, struct termio __user * termio)
3369{ /* Begin get_termio */ 2745{ /* Begin get_termio */
3370 return kernel_termios_to_user_termio(termio, tty->termios); 2746 return kernel_termios_to_user_termio(termio, tty->termios);
3371} /* End get_termio */ 2747} /* End get_termio */
2748
3372/* ---------------------- Begin epca_setup -------------------------- */ 2749/* ---------------------- Begin epca_setup -------------------------- */
3373void epca_setup(char *str, int *ints) 2750void epca_setup(char *str, int *ints)
3374{ /* Begin epca_setup */ 2751{ /* Begin epca_setup */
3375
3376 struct board_info board; 2752 struct board_info board;
3377 int index, loop, last; 2753 int index, loop, last;
3378 char *temp, *t2; 2754 char *temp, *t2;
@@ -3394,49 +2770,41 @@ void epca_setup(char *str, int *ints)
3394 for (last = 0, index = 1; index <= ints[0]; index++) 2770 for (last = 0, index = 1; index <= ints[0]; index++)
3395 switch(index) 2771 switch(index)
3396 { /* Begin parse switch */ 2772 { /* Begin parse switch */
3397
3398 case 1: 2773 case 1:
3399 board.status = ints[index]; 2774 board.status = ints[index];
3400
3401 /* --------------------------------------------------------- 2775 /* ---------------------------------------------------------
3402 We check for 2 (As opposed to 1; because 2 is a flag 2776 We check for 2 (As opposed to 1; because 2 is a flag
3403 instructing the driver to ignore epcaconfig.) For this 2777 instructing the driver to ignore epcaconfig.) For this
3404 reason we check for 2. 2778 reason we check for 2.
3405 ------------------------------------------------------------ */ 2779 ------------------------------------------------------------ */
3406 if (board.status == 2) 2780 if (board.status == 2) { /* Begin ignore epcaconfig as well as lilo cmd line */
3407 { /* Begin ignore epcaconfig as well as lilo cmd line */
3408 nbdevs = 0; 2781 nbdevs = 0;
3409 num_cards = 0; 2782 num_cards = 0;
3410 return; 2783 return;
3411 } /* End ignore epcaconfig as well as lilo cmd line */ 2784 } /* End ignore epcaconfig as well as lilo cmd line */
3412 2785
3413 if (board.status > 2) 2786 if (board.status > 2) {
3414 { 2787 printk(KERN_ERR "epca_setup: Invalid board status 0x%x\n", board.status);
3415 printk(KERN_ERR "<Error> - epca_setup: Invalid board status 0x%x\n", board.status);
3416 invalid_lilo_config = 1; 2788 invalid_lilo_config = 1;
3417 setup_error_code |= INVALID_BOARD_STATUS; 2789 setup_error_code |= INVALID_BOARD_STATUS;
3418 return; 2790 return;
3419 } 2791 }
3420 last = index; 2792 last = index;
3421 break; 2793 break;
3422
3423 case 2: 2794 case 2:
3424 board.type = ints[index]; 2795 board.type = ints[index];
3425 if (board.type >= PCIXEM) 2796 if (board.type >= PCIXEM) {
3426 { 2797 printk(KERN_ERR "epca_setup: Invalid board type 0x%x\n", board.type);
3427 printk(KERN_ERR "<Error> - epca_setup: Invalid board type 0x%x\n", board.type);
3428 invalid_lilo_config = 1; 2798 invalid_lilo_config = 1;
3429 setup_error_code |= INVALID_BOARD_TYPE; 2799 setup_error_code |= INVALID_BOARD_TYPE;
3430 return; 2800 return;
3431 } 2801 }
3432 last = index; 2802 last = index;
3433 break; 2803 break;
3434
3435 case 3: 2804 case 3:
3436 board.altpin = ints[index]; 2805 board.altpin = ints[index];
3437 if (board.altpin > 1) 2806 if (board.altpin > 1) {
3438 { 2807 printk(KERN_ERR "epca_setup: Invalid board altpin 0x%x\n", board.altpin);
3439 printk(KERN_ERR "<Error> - epca_setup: Invalid board altpin 0x%x\n", board.altpin);
3440 invalid_lilo_config = 1; 2808 invalid_lilo_config = 1;
3441 setup_error_code |= INVALID_ALTPIN; 2809 setup_error_code |= INVALID_ALTPIN;
3442 return; 2810 return;
@@ -3446,9 +2814,8 @@ void epca_setup(char *str, int *ints)
3446 2814
3447 case 4: 2815 case 4:
3448 board.numports = ints[index]; 2816 board.numports = ints[index];
3449 if ((board.numports < 2) || (board.numports > 256)) 2817 if (board.numports < 2 || board.numports > 256) {
3450 { 2818 printk(KERN_ERR "epca_setup: Invalid board numports 0x%x\n", board.numports);
3451 printk(KERN_ERR "<Error> - epca_setup: Invalid board numports 0x%x\n", board.numports);
3452 invalid_lilo_config = 1; 2819 invalid_lilo_config = 1;
3453 setup_error_code |= INVALID_NUM_PORTS; 2820 setup_error_code |= INVALID_NUM_PORTS;
3454 return; 2821 return;
@@ -3458,10 +2825,9 @@ void epca_setup(char *str, int *ints)
3458 break; 2825 break;
3459 2826
3460 case 5: 2827 case 5:
3461 board.port = (unsigned char *)ints[index]; 2828 board.port = ints[index];
3462 if (ints[index] <= 0) 2829 if (ints[index] <= 0) {
3463 { 2830 printk(KERN_ERR "epca_setup: Invalid io port 0x%x\n", (unsigned int)board.port);
3464 printk(KERN_ERR "<Error> - epca_setup: Invalid io port 0x%x\n", (unsigned int)board.port);
3465 invalid_lilo_config = 1; 2831 invalid_lilo_config = 1;
3466 setup_error_code |= INVALID_PORT_BASE; 2832 setup_error_code |= INVALID_PORT_BASE;
3467 return; 2833 return;
@@ -3470,10 +2836,9 @@ void epca_setup(char *str, int *ints)
3470 break; 2836 break;
3471 2837
3472 case 6: 2838 case 6:
3473 board.membase = (unsigned char *)ints[index]; 2839 board.membase = ints[index];
3474 if (ints[index] <= 0) 2840 if (ints[index] <= 0) {
3475 { 2841 printk(KERN_ERR "epca_setup: Invalid memory base 0x%x\n",(unsigned int)board.membase);
3476 printk(KERN_ERR "<Error> - epca_setup: Invalid memory base 0x%x\n",(unsigned int)board.membase);
3477 invalid_lilo_config = 1; 2842 invalid_lilo_config = 1;
3478 setup_error_code |= INVALID_MEM_BASE; 2843 setup_error_code |= INVALID_MEM_BASE;
3479 return; 2844 return;
@@ -3487,21 +2852,16 @@ void epca_setup(char *str, int *ints)
3487 2852
3488 } /* End parse switch */ 2853 } /* End parse switch */
3489 2854
3490 while (str && *str) 2855 while (str && *str) { /* Begin while there is a string arg */
3491 { /* Begin while there is a string arg */
3492
3493 /* find the next comma or terminator */ 2856 /* find the next comma or terminator */
3494 temp = str; 2857 temp = str;
3495
3496 /* While string is not null, and a comma hasn't been found */ 2858 /* While string is not null, and a comma hasn't been found */
3497 while (*temp && (*temp != ',')) 2859 while (*temp && (*temp != ','))
3498 temp++; 2860 temp++;
3499
3500 if (!*temp) 2861 if (!*temp)
3501 temp = NULL; 2862 temp = NULL;
3502 else 2863 else
3503 *temp++ = 0; 2864 *temp++ = 0;
3504
3505 /* Set index to the number of args + 1 */ 2865 /* Set index to the number of args + 1 */
3506 index = last + 1; 2866 index = last + 1;
3507 2867
@@ -3511,12 +2871,10 @@ void epca_setup(char *str, int *ints)
3511 len = strlen(str); 2871 len = strlen(str);
3512 if (strncmp("Disable", str, len) == 0) 2872 if (strncmp("Disable", str, len) == 0)
3513 board.status = 0; 2873 board.status = 0;
3514 else 2874 else if (strncmp("Enable", str, len) == 0)
3515 if (strncmp("Enable", str, len) == 0)
3516 board.status = 1; 2875 board.status = 1;
3517 else 2876 else {
3518 { 2877 printk(KERN_ERR "epca_setup: Invalid status %s\n", str);
3519 printk(KERN_ERR "<Error> - epca_setup: Invalid status %s\n", str);
3520 invalid_lilo_config = 1; 2878 invalid_lilo_config = 1;
3521 setup_error_code |= INVALID_BOARD_STATUS; 2879 setup_error_code |= INVALID_BOARD_STATUS;
3522 return; 2880 return;
@@ -3525,22 +2883,17 @@ void epca_setup(char *str, int *ints)
3525 break; 2883 break;
3526 2884
3527 case 2: 2885 case 2:
3528
3529 for(loop = 0; loop < EPCA_NUM_TYPES; loop++) 2886 for(loop = 0; loop < EPCA_NUM_TYPES; loop++)
3530 if (strcmp(board_desc[loop], str) == 0) 2887 if (strcmp(board_desc[loop], str) == 0)
3531 break; 2888 break;
3532
3533
3534 /* --------------------------------------------------------------- 2889 /* ---------------------------------------------------------------
3535 If the index incremented above refers to a legitamate board 2890 If the index incremented above refers to a legitamate board
3536 type set it here. 2891 type set it here.
3537 ------------------------------------------------------------------*/ 2892 ------------------------------------------------------------------*/
3538
3539 if (index < EPCA_NUM_TYPES) 2893 if (index < EPCA_NUM_TYPES)
3540 board.type = loop; 2894 board.type = loop;
3541 else 2895 else {
3542 { 2896 printk(KERN_ERR "epca_setup: Invalid board type: %s\n", str);
3543 printk(KERN_ERR "<Error> - epca_setup: Invalid board type: %s\n", str);
3544 invalid_lilo_config = 1; 2897 invalid_lilo_config = 1;
3545 setup_error_code |= INVALID_BOARD_TYPE; 2898 setup_error_code |= INVALID_BOARD_TYPE;
3546 return; 2899 return;
@@ -3552,12 +2905,10 @@ void epca_setup(char *str, int *ints)
3552 len = strlen(str); 2905 len = strlen(str);
3553 if (strncmp("Disable", str, len) == 0) 2906 if (strncmp("Disable", str, len) == 0)
3554 board.altpin = 0; 2907 board.altpin = 0;
3555 else 2908 else if (strncmp("Enable", str, len) == 0)
3556 if (strncmp("Enable", str, len) == 0)
3557 board.altpin = 1; 2909 board.altpin = 1;
3558 else 2910 else {
3559 { 2911 printk(KERN_ERR "epca_setup: Invalid altpin %s\n", str);
3560 printk(KERN_ERR "<Error> - epca_setup: Invalid altpin %s\n", str);
3561 invalid_lilo_config = 1; 2912 invalid_lilo_config = 1;
3562 setup_error_code |= INVALID_ALTPIN; 2913 setup_error_code |= INVALID_ALTPIN;
3563 return; 2914 return;
@@ -3570,9 +2921,8 @@ void epca_setup(char *str, int *ints)
3570 while (isdigit(*t2)) 2921 while (isdigit(*t2))
3571 t2++; 2922 t2++;
3572 2923
3573 if (*t2) 2924 if (*t2) {
3574 { 2925 printk(KERN_ERR "epca_setup: Invalid port count %s\n", str);
3575 printk(KERN_ERR "<Error> - epca_setup: Invalid port count %s\n", str);
3576 invalid_lilo_config = 1; 2926 invalid_lilo_config = 1;
3577 setup_error_code |= INVALID_NUM_PORTS; 2927 setup_error_code |= INVALID_NUM_PORTS;
3578 return; 2928 return;
@@ -3601,15 +2951,14 @@ void epca_setup(char *str, int *ints)
3601 while (isxdigit(*t2)) 2951 while (isxdigit(*t2))
3602 t2++; 2952 t2++;
3603 2953
3604 if (*t2) 2954 if (*t2) {
3605 { 2955 printk(KERN_ERR "epca_setup: Invalid i/o address %s\n", str);
3606 printk(KERN_ERR "<Error> - epca_setup: Invalid i/o address %s\n", str);
3607 invalid_lilo_config = 1; 2956 invalid_lilo_config = 1;
3608 setup_error_code |= INVALID_PORT_BASE; 2957 setup_error_code |= INVALID_PORT_BASE;
3609 return; 2958 return;
3610 } 2959 }
3611 2960
3612 board.port = (unsigned char *)simple_strtoul(str, NULL, 16); 2961 board.port = simple_strtoul(str, NULL, 16);
3613 last = index; 2962 last = index;
3614 break; 2963 break;
3615 2964
@@ -3618,52 +2967,38 @@ void epca_setup(char *str, int *ints)
3618 while (isxdigit(*t2)) 2967 while (isxdigit(*t2))
3619 t2++; 2968 t2++;
3620 2969
3621 if (*t2) 2970 if (*t2) {
3622 { 2971 printk(KERN_ERR "epca_setup: Invalid memory base %s\n",str);
3623 printk(KERN_ERR "<Error> - epca_setup: Invalid memory base %s\n",str);
3624 invalid_lilo_config = 1; 2972 invalid_lilo_config = 1;
3625 setup_error_code |= INVALID_MEM_BASE; 2973 setup_error_code |= INVALID_MEM_BASE;
3626 return; 2974 return;
3627 } 2975 }
3628 2976 board.membase = simple_strtoul(str, NULL, 16);
3629 board.membase = (unsigned char *)simple_strtoul(str, NULL, 16);
3630 last = index; 2977 last = index;
3631 break; 2978 break;
3632
3633 default: 2979 default:
3634 printk(KERN_ERR "PC/Xx: Too many string parms\n"); 2980 printk(KERN_ERR "epca: Too many string parms\n");
3635 return; 2981 return;
3636 } 2982 }
3637 str = temp; 2983 str = temp;
3638
3639 } /* End while there is a string arg */ 2984 } /* End while there is a string arg */
3640 2985
3641 2986 if (last < 6) {
3642 if (last < 6) 2987 printk(KERN_ERR "epca: Insufficient parms specified\n");
3643 {
3644 printk(KERN_ERR "PC/Xx: Insufficient parms specified\n");
3645 return; 2988 return;
3646 } 2989 }
3647 2990
3648 /* I should REALLY validate the stuff here */ 2991 /* I should REALLY validate the stuff here */
3649
3650 /* Copies our local copy of board into boards */ 2992 /* Copies our local copy of board into boards */
3651 memcpy((void *)&boards[num_cards],(void *)&board, sizeof(board)); 2993 memcpy((void *)&boards[num_cards],(void *)&board, sizeof(board));
3652
3653
3654 /* Does this get called once per lilo arg are what ? */ 2994 /* Does this get called once per lilo arg are what ? */
3655
3656 printk(KERN_INFO "PC/Xx: Added board %i, %s %i ports at 0x%4.4X base 0x%6.6X\n", 2995 printk(KERN_INFO "PC/Xx: Added board %i, %s %i ports at 0x%4.4X base 0x%6.6X\n",
3657 num_cards, board_desc[board.type], 2996 num_cards, board_desc[board.type],
3658 board.numports, (int)board.port, (unsigned int) board.membase); 2997 board.numports, (int)board.port, (unsigned int) board.membase);
3659
3660 num_cards++; 2998 num_cards++;
3661
3662} /* End epca_setup */ 2999} /* End epca_setup */
3663 3000
3664 3001
3665
3666#ifdef ENABLE_PCI
3667/* ------------------------ Begin init_PCI --------------------------- */ 3002/* ------------------------ Begin init_PCI --------------------------- */
3668 3003
3669enum epic_board_types { 3004enum epic_board_types {
@@ -3685,7 +3020,6 @@ static struct {
3685 { PCIXRJ, 2, }, 3020 { PCIXRJ, 2, },
3686}; 3021};
3687 3022
3688
3689static int __devinit epca_init_one (struct pci_dev *pdev, 3023static int __devinit epca_init_one (struct pci_dev *pdev,
3690 const struct pci_device_id *ent) 3024 const struct pci_device_id *ent)
3691{ 3025{
@@ -3711,10 +3045,8 @@ static int __devinit epca_init_one (struct pci_dev *pdev,
3711 boards[board_idx].status = ENABLED; 3045 boards[board_idx].status = ENABLED;
3712 boards[board_idx].type = epca_info_tbl[info_idx].board_type; 3046 boards[board_idx].type = epca_info_tbl[info_idx].board_type;
3713 boards[board_idx].numports = 0x0; 3047 boards[board_idx].numports = 0x0;
3714 boards[board_idx].port = 3048 boards[board_idx].port = addr + PCI_IO_OFFSET;
3715 (unsigned char *)((char *) addr + PCI_IO_OFFSET); 3049 boards[board_idx].membase = addr;
3716 boards[board_idx].membase =
3717 (unsigned char *)((char *) addr);
3718 3050
3719 if (!request_mem_region (addr + PCI_IO_OFFSET, 0x200000, "epca")) { 3051 if (!request_mem_region (addr + PCI_IO_OFFSET, 0x200000, "epca")) {
3720 printk (KERN_ERR PFX "resource 0x%x @ 0x%lx unavailable\n", 3052 printk (KERN_ERR PFX "resource 0x%x @ 0x%lx unavailable\n",
@@ -3775,15 +3107,13 @@ static struct pci_device_id epca_pci_tbl[] = {
3775MODULE_DEVICE_TABLE(pci, epca_pci_tbl); 3107MODULE_DEVICE_TABLE(pci, epca_pci_tbl);
3776 3108
3777int __init init_PCI (void) 3109int __init init_PCI (void)
3778{ /* Begin init_PCI */ 3110{ /* Begin init_PCI */
3779 memset (&epca_driver, 0, sizeof (epca_driver)); 3111 memset (&epca_driver, 0, sizeof (epca_driver));
3780 epca_driver.name = "epca"; 3112 epca_driver.name = "epca";
3781 epca_driver.id_table = epca_pci_tbl; 3113 epca_driver.id_table = epca_pci_tbl;
3782 epca_driver.probe = epca_init_one; 3114 epca_driver.probe = epca_init_one;
3783 3115
3784 return pci_register_driver(&epca_driver); 3116 return pci_register_driver(&epca_driver);
3785} /* End init_PCI */ 3117}
3786
3787#endif /* ENABLE_PCI */
3788 3118
3789MODULE_LICENSE("GPL"); 3119MODULE_LICENSE("GPL");
diff --git a/drivers/char/epca.h b/drivers/char/epca.h
index 52205ef7131..20eeb5a70e1 100644
--- a/drivers/char/epca.h
+++ b/drivers/char/epca.h
@@ -85,73 +85,73 @@ static char *board_desc[] =
85struct channel 85struct channel
86{ 86{
87 long magic; 87 long magic;
88 unchar boardnum; 88 unsigned char boardnum;
89 unchar channelnum; 89 unsigned char channelnum;
90 unchar omodem; /* FEP output modem status */ 90 unsigned char omodem; /* FEP output modem status */
91 unchar imodem; /* FEP input modem status */ 91 unsigned char imodem; /* FEP input modem status */
92 unchar modemfake; /* Modem values to be forced */ 92 unsigned char modemfake; /* Modem values to be forced */
93 unchar modem; /* Force values */ 93 unsigned char modem; /* Force values */
94 unchar hflow; 94 unsigned char hflow;
95 unchar dsr; 95 unsigned char dsr;
96 unchar dcd; 96 unsigned char dcd;
97 unchar m_rts ; /* The bits used in whatever FEP */ 97 unsigned char m_rts ; /* The bits used in whatever FEP */
98 unchar m_dcd ; /* is indiginous to this board to */ 98 unsigned char m_dcd ; /* is indiginous to this board to */
99 unchar m_dsr ; /* represent each of the physical */ 99 unsigned char m_dsr ; /* represent each of the physical */
100 unchar m_cts ; /* handshake lines */ 100 unsigned char m_cts ; /* handshake lines */
101 unchar m_ri ; 101 unsigned char m_ri ;
102 unchar m_dtr ; 102 unsigned char m_dtr ;
103 unchar stopc; 103 unsigned char stopc;
104 unchar startc; 104 unsigned char startc;
105 unchar stopca; 105 unsigned char stopca;
106 unchar startca; 106 unsigned char startca;
107 unchar fepstopc; 107 unsigned char fepstopc;
108 unchar fepstartc; 108 unsigned char fepstartc;
109 unchar fepstopca; 109 unsigned char fepstopca;
110 unchar fepstartca; 110 unsigned char fepstartca;
111 unchar txwin; 111 unsigned char txwin;
112 unchar rxwin; 112 unsigned char rxwin;
113 ushort fepiflag; 113 unsigned short fepiflag;
114 ushort fepcflag; 114 unsigned short fepcflag;
115 ushort fepoflag; 115 unsigned short fepoflag;
116 ushort txbufhead; 116 unsigned short txbufhead;
117 ushort txbufsize; 117 unsigned short txbufsize;
118 ushort rxbufhead; 118 unsigned short rxbufhead;
119 ushort rxbufsize; 119 unsigned short rxbufsize;
120 int close_delay; 120 int close_delay;
121 int count; 121 int count;
122 int blocked_open; 122 int blocked_open;
123 ulong event; 123 unsigned long event;
124 int asyncflags; 124 int asyncflags;
125 uint dev; 125 uint dev;
126 ulong statusflags; 126 unsigned long statusflags;
127 ulong c_iflag; 127 unsigned long c_iflag;
128 ulong c_cflag; 128 unsigned long c_cflag;
129 ulong c_lflag; 129 unsigned long c_lflag;
130 ulong c_oflag; 130 unsigned long c_oflag;
131 unchar *txptr; 131 unsigned char *txptr;
132 unchar *rxptr; 132 unsigned char *rxptr;
133 unchar *tmp_buf; 133 unsigned char *tmp_buf;
134 struct board_info *board; 134 struct board_info *board;
135 volatile struct board_chan *brdchan; 135 struct board_chan *brdchan;
136 struct digi_struct digiext; 136 struct digi_struct digiext;
137 struct tty_struct *tty; 137 struct tty_struct *tty;
138 wait_queue_head_t open_wait; 138 wait_queue_head_t open_wait;
139 wait_queue_head_t close_wait; 139 wait_queue_head_t close_wait;
140 struct work_struct tqueue; 140 struct work_struct tqueue;
141 volatile struct global_data *mailbox; 141 struct global_data *mailbox;
142}; 142};
143 143
144struct board_info 144struct board_info
145{ 145{
146 unchar status; 146 unsigned char status;
147 unchar type; 147 unsigned char type;
148 unchar altpin; 148 unsigned char altpin;
149 ushort numports; 149 unsigned short numports;
150 unchar *port; 150 unsigned long port;
151 unchar *membase; 151 unsigned long membase;
152 unchar __iomem *re_map_port; 152 unsigned char __iomem *re_map_port;
153 unchar *re_map_membase; 153 unsigned char *re_map_membase;
154 ulong memory_seg; 154 unsigned long memory_seg;
155 void ( * memwinon ) (struct board_info *, unsigned int) ; 155 void ( * memwinon ) (struct board_info *, unsigned int) ;
156 void ( * memwinoff ) (struct board_info *, unsigned int) ; 156 void ( * memwinoff ) (struct board_info *, unsigned int) ;
157 void ( * globalwinon ) (struct channel *) ; 157 void ( * globalwinon ) (struct channel *) ;
@@ -160,6 +160,6 @@ struct board_info
160 void ( * memoff ) (struct channel *) ; 160 void ( * memoff ) (struct channel *) ;
161 void ( * assertgwinon ) (struct channel *) ; 161 void ( * assertgwinon ) (struct channel *) ;
162 void ( * assertmemoff ) (struct channel *) ; 162 void ( * assertmemoff ) (struct channel *) ;
163 unchar poller_inhibited ; 163 unsigned char poller_inhibited ;
164}; 164};
165 165
diff --git a/drivers/char/hpet.c b/drivers/char/hpet.c
index 97feb7f7024..5fe8461271f 100644
--- a/drivers/char/hpet.c
+++ b/drivers/char/hpet.c
@@ -44,7 +44,7 @@
44/* 44/*
45 * The High Precision Event Timer driver. 45 * The High Precision Event Timer driver.
46 * This driver is closely modelled after the rtc.c driver. 46 * This driver is closely modelled after the rtc.c driver.
47 * http://www.intel.com/labs/platcomp/hpet/hpetspec.htm 47 * http://www.intel.com/hardwaredesign/hpetspec.htm
48 */ 48 */
49#define HPET_USER_FREQ (64) 49#define HPET_USER_FREQ (64)
50#define HPET_DRIFT (500) 50#define HPET_DRIFT (500)
@@ -712,7 +712,7 @@ static void hpet_register_interpolator(struct hpets *hpetp)
712 ti->shift = 10; 712 ti->shift = 10;
713 ti->addr = &hpetp->hp_hpet->hpet_mc; 713 ti->addr = &hpetp->hp_hpet->hpet_mc;
714 ti->frequency = hpet_time_div(hpets->hp_period); 714 ti->frequency = hpet_time_div(hpets->hp_period);
715 ti->drift = ti->frequency * HPET_DRIFT / 1000000; 715 ti->drift = HPET_DRIFT;
716 ti->mask = -1; 716 ti->mask = -1;
717 717
718 hpetp->hp_interpolator = ti; 718 hpetp->hp_interpolator = ti;
diff --git a/drivers/char/ipmi/ipmi_bt_sm.c b/drivers/char/ipmi/ipmi_bt_sm.c
index 5ce9c626903..33862670e28 100644
--- a/drivers/char/ipmi/ipmi_bt_sm.c
+++ b/drivers/char/ipmi/ipmi_bt_sm.c
@@ -31,8 +31,6 @@
31#include <linux/ipmi_msgdefs.h> /* for completion codes */ 31#include <linux/ipmi_msgdefs.h> /* for completion codes */
32#include "ipmi_si_sm.h" 32#include "ipmi_si_sm.h"
33 33
34#define IPMI_BT_VERSION "v33"
35
36static int bt_debug = 0x00; /* Production value 0, see following flags */ 34static int bt_debug = 0x00; /* Production value 0, see following flags */
37 35
38#define BT_DEBUG_ENABLE 1 36#define BT_DEBUG_ENABLE 1
@@ -163,7 +161,8 @@ static int bt_start_transaction(struct si_sm_data *bt,
163{ 161{
164 unsigned int i; 162 unsigned int i;
165 163
166 if ((size < 2) || (size > IPMI_MAX_MSG_LENGTH)) return -1; 164 if ((size < 2) || (size > IPMI_MAX_MSG_LENGTH))
165 return -1;
167 166
168 if ((bt->state != BT_STATE_IDLE) && (bt->state != BT_STATE_HOSED)) 167 if ((bt->state != BT_STATE_IDLE) && (bt->state != BT_STATE_HOSED))
169 return -2; 168 return -2;
@@ -171,7 +170,8 @@ static int bt_start_transaction(struct si_sm_data *bt,
171 if (bt_debug & BT_DEBUG_MSG) { 170 if (bt_debug & BT_DEBUG_MSG) {
172 printk(KERN_WARNING "+++++++++++++++++++++++++++++++++++++\n"); 171 printk(KERN_WARNING "+++++++++++++++++++++++++++++++++++++\n");
173 printk(KERN_WARNING "BT: write seq=0x%02X:", bt->seq); 172 printk(KERN_WARNING "BT: write seq=0x%02X:", bt->seq);
174 for (i = 0; i < size; i ++) printk (" %02x", data[i]); 173 for (i = 0; i < size; i ++)
174 printk (" %02x", data[i]);
175 printk("\n"); 175 printk("\n");
176 } 176 }
177 bt->write_data[0] = size + 1; /* all data plus seq byte */ 177 bt->write_data[0] = size + 1; /* all data plus seq byte */
@@ -210,15 +210,18 @@ static int bt_get_result(struct si_sm_data *bt,
210 } else { 210 } else {
211 data[0] = bt->read_data[1]; 211 data[0] = bt->read_data[1];
212 data[1] = bt->read_data[3]; 212 data[1] = bt->read_data[3];
213 if (length < msg_len) bt->truncated = 1; 213 if (length < msg_len)
214 bt->truncated = 1;
214 if (bt->truncated) { /* can be set in read_all_bytes() */ 215 if (bt->truncated) { /* can be set in read_all_bytes() */
215 data[2] = IPMI_ERR_MSG_TRUNCATED; 216 data[2] = IPMI_ERR_MSG_TRUNCATED;
216 msg_len = 3; 217 msg_len = 3;
217 } else memcpy(data + 2, bt->read_data + 4, msg_len - 2); 218 } else
219 memcpy(data + 2, bt->read_data + 4, msg_len - 2);
218 220
219 if (bt_debug & BT_DEBUG_MSG) { 221 if (bt_debug & BT_DEBUG_MSG) {
220 printk (KERN_WARNING "BT: res (raw)"); 222 printk (KERN_WARNING "BT: res (raw)");
221 for (i = 0; i < msg_len; i++) printk(" %02x", data[i]); 223 for (i = 0; i < msg_len; i++)
224 printk(" %02x", data[i]);
222 printk ("\n"); 225 printk ("\n");
223 } 226 }
224 } 227 }
@@ -231,8 +234,10 @@ static int bt_get_result(struct si_sm_data *bt,
231 234
232static void reset_flags(struct si_sm_data *bt) 235static void reset_flags(struct si_sm_data *bt)
233{ 236{
234 if (BT_STATUS & BT_H_BUSY) BT_CONTROL(BT_H_BUSY); 237 if (BT_STATUS & BT_H_BUSY)
235 if (BT_STATUS & BT_B_BUSY) BT_CONTROL(BT_B_BUSY); 238 BT_CONTROL(BT_H_BUSY);
239 if (BT_STATUS & BT_B_BUSY)
240 BT_CONTROL(BT_B_BUSY);
236 BT_CONTROL(BT_CLR_WR_PTR); 241 BT_CONTROL(BT_CLR_WR_PTR);
237 BT_CONTROL(BT_SMS_ATN); 242 BT_CONTROL(BT_SMS_ATN);
238#ifdef DEVELOPMENT_ONLY_NOT_FOR_PRODUCTION 243#ifdef DEVELOPMENT_ONLY_NOT_FOR_PRODUCTION
@@ -241,7 +246,8 @@ static void reset_flags(struct si_sm_data *bt)
241 BT_CONTROL(BT_H_BUSY); 246 BT_CONTROL(BT_H_BUSY);
242 BT_CONTROL(BT_B2H_ATN); 247 BT_CONTROL(BT_B2H_ATN);
243 BT_CONTROL(BT_CLR_RD_PTR); 248 BT_CONTROL(BT_CLR_RD_PTR);
244 for (i = 0; i < IPMI_MAX_MSG_LENGTH + 2; i++) BMC2HOST; 249 for (i = 0; i < IPMI_MAX_MSG_LENGTH + 2; i++)
250 BMC2HOST;
245 BT_CONTROL(BT_H_BUSY); 251 BT_CONTROL(BT_H_BUSY);
246 } 252 }
247#endif 253#endif
@@ -258,7 +264,8 @@ static inline void write_all_bytes(struct si_sm_data *bt)
258 printk (" %02x", bt->write_data[i]); 264 printk (" %02x", bt->write_data[i]);
259 printk ("\n"); 265 printk ("\n");
260 } 266 }
261 for (i = 0; i < bt->write_count; i++) HOST2BMC(bt->write_data[i]); 267 for (i = 0; i < bt->write_count; i++)
268 HOST2BMC(bt->write_data[i]);
262} 269}
263 270
264static inline int read_all_bytes(struct si_sm_data *bt) 271static inline int read_all_bytes(struct si_sm_data *bt)
@@ -278,7 +285,8 @@ static inline int read_all_bytes(struct si_sm_data *bt)
278 bt->truncated = 1; 285 bt->truncated = 1;
279 return 1; /* let next XACTION START clean it up */ 286 return 1; /* let next XACTION START clean it up */
280 } 287 }
281 for (i = 1; i <= bt->read_count; i++) bt->read_data[i] = BMC2HOST; 288 for (i = 1; i <= bt->read_count; i++)
289 bt->read_data[i] = BMC2HOST;
282 bt->read_count++; /* account for the length byte */ 290 bt->read_count++; /* account for the length byte */
283 291
284 if (bt_debug & BT_DEBUG_MSG) { 292 if (bt_debug & BT_DEBUG_MSG) {
@@ -295,7 +303,8 @@ static inline int read_all_bytes(struct si_sm_data *bt)
295 ((bt->read_data[1] & 0xF8) == (bt->write_data[1] & 0xF8))) 303 ((bt->read_data[1] & 0xF8) == (bt->write_data[1] & 0xF8)))
296 return 1; 304 return 1;
297 305
298 if (bt_debug & BT_DEBUG_MSG) printk(KERN_WARNING "BT: bad packet: " 306 if (bt_debug & BT_DEBUG_MSG)
307 printk(KERN_WARNING "BT: bad packet: "
299 "want 0x(%02X, %02X, %02X) got (%02X, %02X, %02X)\n", 308 "want 0x(%02X, %02X, %02X) got (%02X, %02X, %02X)\n",
300 bt->write_data[1], bt->write_data[2], bt->write_data[3], 309 bt->write_data[1], bt->write_data[2], bt->write_data[3],
301 bt->read_data[1], bt->read_data[2], bt->read_data[3]); 310 bt->read_data[1], bt->read_data[2], bt->read_data[3]);
@@ -359,7 +368,8 @@ static enum si_sm_result bt_event(struct si_sm_data *bt, long time)
359 time); 368 time);
360 bt->last_state = bt->state; 369 bt->last_state = bt->state;
361 370
362 if (bt->state == BT_STATE_HOSED) return SI_SM_HOSED; 371 if (bt->state == BT_STATE_HOSED)
372 return SI_SM_HOSED;
363 373
364 if (bt->state != BT_STATE_IDLE) { /* do timeout test */ 374 if (bt->state != BT_STATE_IDLE) { /* do timeout test */
365 375
@@ -371,7 +381,8 @@ static enum si_sm_result bt_event(struct si_sm_data *bt, long time)
371 /* FIXME: bt_event is sometimes called with time > BT_NORMAL_TIMEOUT 381 /* FIXME: bt_event is sometimes called with time > BT_NORMAL_TIMEOUT
372 (noticed in ipmi_smic_sm.c January 2004) */ 382 (noticed in ipmi_smic_sm.c January 2004) */
373 383
374 if ((time <= 0) || (time >= BT_NORMAL_TIMEOUT)) time = 100; 384 if ((time <= 0) || (time >= BT_NORMAL_TIMEOUT))
385 time = 100;
375 bt->timeout -= time; 386 bt->timeout -= time;
376 if ((bt->timeout < 0) && (bt->state < BT_STATE_RESET1)) { 387 if ((bt->timeout < 0) && (bt->state < BT_STATE_RESET1)) {
377 error_recovery(bt, "timed out"); 388 error_recovery(bt, "timed out");
@@ -393,12 +404,14 @@ static enum si_sm_result bt_event(struct si_sm_data *bt, long time)
393 BT_CONTROL(BT_H_BUSY); 404 BT_CONTROL(BT_H_BUSY);
394 break; 405 break;
395 } 406 }
396 if (status & BT_B2H_ATN) break; 407 if (status & BT_B2H_ATN)
408 break;
397 bt->state = BT_STATE_WRITE_BYTES; 409 bt->state = BT_STATE_WRITE_BYTES;
398 return SI_SM_CALL_WITHOUT_DELAY; /* for logging */ 410 return SI_SM_CALL_WITHOUT_DELAY; /* for logging */
399 411
400 case BT_STATE_WRITE_BYTES: 412 case BT_STATE_WRITE_BYTES:
401 if (status & (BT_B_BUSY | BT_H2B_ATN)) break; 413 if (status & (BT_B_BUSY | BT_H2B_ATN))
414 break;
402 BT_CONTROL(BT_CLR_WR_PTR); 415 BT_CONTROL(BT_CLR_WR_PTR);
403 write_all_bytes(bt); 416 write_all_bytes(bt);
404 BT_CONTROL(BT_H2B_ATN); /* clears too fast to catch? */ 417 BT_CONTROL(BT_H2B_ATN); /* clears too fast to catch? */
@@ -406,7 +419,8 @@ static enum si_sm_result bt_event(struct si_sm_data *bt, long time)
406 return SI_SM_CALL_WITHOUT_DELAY; /* it MIGHT sail through */ 419 return SI_SM_CALL_WITHOUT_DELAY; /* it MIGHT sail through */
407 420
408 case BT_STATE_WRITE_CONSUME: /* BMCs usually blow right thru here */ 421 case BT_STATE_WRITE_CONSUME: /* BMCs usually blow right thru here */
409 if (status & (BT_H2B_ATN | BT_B_BUSY)) break; 422 if (status & (BT_H2B_ATN | BT_B_BUSY))
423 break;
410 bt->state = BT_STATE_B2H_WAIT; 424 bt->state = BT_STATE_B2H_WAIT;
411 /* fall through with status */ 425 /* fall through with status */
412 426
@@ -415,15 +429,18 @@ static enum si_sm_result bt_event(struct si_sm_data *bt, long time)
415 generation of B2H_ATN so ALWAYS return CALL_WITH_DELAY. */ 429 generation of B2H_ATN so ALWAYS return CALL_WITH_DELAY. */
416 430
417 case BT_STATE_B2H_WAIT: 431 case BT_STATE_B2H_WAIT:
418 if (!(status & BT_B2H_ATN)) break; 432 if (!(status & BT_B2H_ATN))
433 break;
419 434
420 /* Assume ordered, uncached writes: no need to wait */ 435 /* Assume ordered, uncached writes: no need to wait */
421 if (!(status & BT_H_BUSY)) BT_CONTROL(BT_H_BUSY); /* set */ 436 if (!(status & BT_H_BUSY))
437 BT_CONTROL(BT_H_BUSY); /* set */
422 BT_CONTROL(BT_B2H_ATN); /* clear it, ACK to the BMC */ 438 BT_CONTROL(BT_B2H_ATN); /* clear it, ACK to the BMC */
423 BT_CONTROL(BT_CLR_RD_PTR); /* reset the queue */ 439 BT_CONTROL(BT_CLR_RD_PTR); /* reset the queue */
424 i = read_all_bytes(bt); 440 i = read_all_bytes(bt);
425 BT_CONTROL(BT_H_BUSY); /* clear */ 441 BT_CONTROL(BT_H_BUSY); /* clear */
426 if (!i) break; /* Try this state again */ 442 if (!i) /* Try this state again */
443 break;
427 bt->state = BT_STATE_READ_END; 444 bt->state = BT_STATE_READ_END;
428 return SI_SM_CALL_WITHOUT_DELAY; /* for logging */ 445 return SI_SM_CALL_WITHOUT_DELAY; /* for logging */
429 446
@@ -436,7 +453,8 @@ static enum si_sm_result bt_event(struct si_sm_data *bt, long time)
436 453
437#ifdef MAKE_THIS_TRUE_IF_NECESSARY 454#ifdef MAKE_THIS_TRUE_IF_NECESSARY
438 455
439 if (status & BT_H_BUSY) break; 456 if (status & BT_H_BUSY)
457 break;
440#endif 458#endif
441 bt->seq++; 459 bt->seq++;
442 bt->state = BT_STATE_IDLE; 460 bt->state = BT_STATE_IDLE;
@@ -459,7 +477,8 @@ static enum si_sm_result bt_event(struct si_sm_data *bt, long time)
459 break; 477 break;
460 478
461 case BT_STATE_RESET3: 479 case BT_STATE_RESET3:
462 if (bt->timeout > 0) return SI_SM_CALL_WITH_DELAY; 480 if (bt->timeout > 0)
481 return SI_SM_CALL_WITH_DELAY;
463 bt->state = BT_STATE_RESTART; /* printk in debug modes */ 482 bt->state = BT_STATE_RESTART; /* printk in debug modes */
464 break; 483 break;
465 484
@@ -485,7 +504,8 @@ static int bt_detect(struct si_sm_data *bt)
485 but that's what you get from reading a bogus address, so we 504 but that's what you get from reading a bogus address, so we
486 test that first. The calling routine uses negative logic. */ 505 test that first. The calling routine uses negative logic. */
487 506
488 if ((BT_STATUS == 0xFF) && (BT_INTMASK_R == 0xFF)) return 1; 507 if ((BT_STATUS == 0xFF) && (BT_INTMASK_R == 0xFF))
508 return 1;
489 reset_flags(bt); 509 reset_flags(bt);
490 return 0; 510 return 0;
491} 511}
@@ -501,7 +521,6 @@ static int bt_size(void)
501 521
502struct si_sm_handlers bt_smi_handlers = 522struct si_sm_handlers bt_smi_handlers =
503{ 523{
504 .version = IPMI_BT_VERSION,
505 .init_data = bt_init_data, 524 .init_data = bt_init_data,
506 .start_transaction = bt_start_transaction, 525 .start_transaction = bt_start_transaction,
507 .get_result = bt_get_result, 526 .get_result = bt_get_result,
diff --git a/drivers/char/ipmi/ipmi_devintf.c b/drivers/char/ipmi/ipmi_devintf.c
index e0a53570fea..883ac4352be 100644
--- a/drivers/char/ipmi/ipmi_devintf.c
+++ b/drivers/char/ipmi/ipmi_devintf.c
@@ -47,8 +47,6 @@
47#include <linux/device.h> 47#include <linux/device.h>
48#include <linux/compat.h> 48#include <linux/compat.h>
49 49
50#define IPMI_DEVINTF_VERSION "v33"
51
52struct ipmi_file_private 50struct ipmi_file_private
53{ 51{
54 ipmi_user_t user; 52 ipmi_user_t user;
@@ -411,6 +409,7 @@ static int ipmi_ioctl(struct inode *inode,
411 break; 409 break;
412 } 410 }
413 411
412 /* The next four are legacy, not per-channel. */
414 case IPMICTL_SET_MY_ADDRESS_CMD: 413 case IPMICTL_SET_MY_ADDRESS_CMD:
415 { 414 {
416 unsigned int val; 415 unsigned int val;
@@ -420,22 +419,25 @@ static int ipmi_ioctl(struct inode *inode,
420 break; 419 break;
421 } 420 }
422 421
423 ipmi_set_my_address(priv->user, val); 422 rv = ipmi_set_my_address(priv->user, 0, val);
424 rv = 0;
425 break; 423 break;
426 } 424 }
427 425
428 case IPMICTL_GET_MY_ADDRESS_CMD: 426 case IPMICTL_GET_MY_ADDRESS_CMD:
429 { 427 {
430 unsigned int val; 428 unsigned int val;
429 unsigned char rval;
430
431 rv = ipmi_get_my_address(priv->user, 0, &rval);
432 if (rv)
433 break;
431 434
432 val = ipmi_get_my_address(priv->user); 435 val = rval;
433 436
434 if (copy_to_user(arg, &val, sizeof(val))) { 437 if (copy_to_user(arg, &val, sizeof(val))) {
435 rv = -EFAULT; 438 rv = -EFAULT;
436 break; 439 break;
437 } 440 }
438 rv = 0;
439 break; 441 break;
440 } 442 }
441 443
@@ -448,24 +450,94 @@ static int ipmi_ioctl(struct inode *inode,
448 break; 450 break;
449 } 451 }
450 452
451 ipmi_set_my_LUN(priv->user, val); 453 rv = ipmi_set_my_LUN(priv->user, 0, val);
452 rv = 0;
453 break; 454 break;
454 } 455 }
455 456
456 case IPMICTL_GET_MY_LUN_CMD: 457 case IPMICTL_GET_MY_LUN_CMD:
457 { 458 {
458 unsigned int val; 459 unsigned int val;
460 unsigned char rval;
459 461
460 val = ipmi_get_my_LUN(priv->user); 462 rv = ipmi_get_my_LUN(priv->user, 0, &rval);
463 if (rv)
464 break;
465
466 val = rval;
467
468 if (copy_to_user(arg, &val, sizeof(val))) {
469 rv = -EFAULT;
470 break;
471 }
472 break;
473 }
474
475 case IPMICTL_SET_MY_CHANNEL_ADDRESS_CMD:
476 {
477 struct ipmi_channel_lun_address_set val;
478
479 if (copy_from_user(&val, arg, sizeof(val))) {
480 rv = -EFAULT;
481 break;
482 }
483
484 return ipmi_set_my_address(priv->user, val.channel, val.value);
485 break;
486 }
487
488 case IPMICTL_GET_MY_CHANNEL_ADDRESS_CMD:
489 {
490 struct ipmi_channel_lun_address_set val;
491
492 if (copy_from_user(&val, arg, sizeof(val))) {
493 rv = -EFAULT;
494 break;
495 }
496
497 rv = ipmi_get_my_address(priv->user, val.channel, &val.value);
498 if (rv)
499 break;
500
501 if (copy_to_user(arg, &val, sizeof(val))) {
502 rv = -EFAULT;
503 break;
504 }
505 break;
506 }
507
508 case IPMICTL_SET_MY_CHANNEL_LUN_CMD:
509 {
510 struct ipmi_channel_lun_address_set val;
511
512 if (copy_from_user(&val, arg, sizeof(val))) {
513 rv = -EFAULT;
514 break;
515 }
516
517 rv = ipmi_set_my_LUN(priv->user, val.channel, val.value);
518 break;
519 }
520
521 case IPMICTL_GET_MY_CHANNEL_LUN_CMD:
522 {
523 struct ipmi_channel_lun_address_set val;
524
525 if (copy_from_user(&val, arg, sizeof(val))) {
526 rv = -EFAULT;
527 break;
528 }
529
530 rv = ipmi_get_my_LUN(priv->user, val.channel, &val.value);
531 if (rv)
532 break;
461 533
462 if (copy_to_user(arg, &val, sizeof(val))) { 534 if (copy_to_user(arg, &val, sizeof(val))) {
463 rv = -EFAULT; 535 rv = -EFAULT;
464 break; 536 break;
465 } 537 }
466 rv = 0;
467 break; 538 break;
468 } 539 }
540
469 case IPMICTL_SET_TIMING_PARMS_CMD: 541 case IPMICTL_SET_TIMING_PARMS_CMD:
470 { 542 {
471 struct ipmi_timing_parms parms; 543 struct ipmi_timing_parms parms;
@@ -748,8 +820,7 @@ static __init int init_ipmi_devintf(void)
748 if (ipmi_major < 0) 820 if (ipmi_major < 0)
749 return -EINVAL; 821 return -EINVAL;
750 822
751 printk(KERN_INFO "ipmi device interface version " 823 printk(KERN_INFO "ipmi device interface\n");
752 IPMI_DEVINTF_VERSION "\n");
753 824
754 ipmi_class = class_create(THIS_MODULE, "ipmi"); 825 ipmi_class = class_create(THIS_MODULE, "ipmi");
755 if (IS_ERR(ipmi_class)) { 826 if (IS_ERR(ipmi_class)) {
@@ -792,3 +863,5 @@ static __exit void cleanup_ipmi(void)
792module_exit(cleanup_ipmi); 863module_exit(cleanup_ipmi);
793 864
794MODULE_LICENSE("GPL"); 865MODULE_LICENSE("GPL");
866MODULE_AUTHOR("Corey Minyard <minyard@mvista.com>");
867MODULE_DESCRIPTION("Linux device interface for the IPMI message handler.");
diff --git a/drivers/char/ipmi/ipmi_kcs_sm.c b/drivers/char/ipmi/ipmi_kcs_sm.c
index 48cce24329b..d21853a594a 100644
--- a/drivers/char/ipmi/ipmi_kcs_sm.c
+++ b/drivers/char/ipmi/ipmi_kcs_sm.c
@@ -42,8 +42,6 @@
42#include <linux/ipmi_msgdefs.h> /* for completion codes */ 42#include <linux/ipmi_msgdefs.h> /* for completion codes */
43#include "ipmi_si_sm.h" 43#include "ipmi_si_sm.h"
44 44
45#define IPMI_KCS_VERSION "v33"
46
47/* Set this if you want a printout of why the state machine was hosed 45/* Set this if you want a printout of why the state machine was hosed
48 when it gets hosed. */ 46 when it gets hosed. */
49#define DEBUG_HOSED_REASON 47#define DEBUG_HOSED_REASON
@@ -489,7 +487,6 @@ static void kcs_cleanup(struct si_sm_data *kcs)
489 487
490struct si_sm_handlers kcs_smi_handlers = 488struct si_sm_handlers kcs_smi_handlers =
491{ 489{
492 .version = IPMI_KCS_VERSION,
493 .init_data = init_kcs_data, 490 .init_data = init_kcs_data,
494 .start_transaction = start_kcs_transaction, 491 .start_transaction = start_kcs_transaction,
495 .get_result = get_kcs_result, 492 .get_result = get_kcs_result,
diff --git a/drivers/char/ipmi/ipmi_msghandler.c b/drivers/char/ipmi/ipmi_msghandler.c
index e16c13fe698..463351d4f94 100644
--- a/drivers/char/ipmi/ipmi_msghandler.c
+++ b/drivers/char/ipmi/ipmi_msghandler.c
@@ -47,7 +47,8 @@
47#include <linux/proc_fs.h> 47#include <linux/proc_fs.h>
48 48
49#define PFX "IPMI message handler: " 49#define PFX "IPMI message handler: "
50#define IPMI_MSGHANDLER_VERSION "v33" 50
51#define IPMI_DRIVER_VERSION "36.0"
51 52
52static struct ipmi_recv_msg *ipmi_alloc_recv_msg(void); 53static struct ipmi_recv_msg *ipmi_alloc_recv_msg(void);
53static int ipmi_init_msghandler(void); 54static int ipmi_init_msghandler(void);
@@ -116,7 +117,7 @@ struct seq_table
116 do { \ 117 do { \
117 seq = ((msgid >> 26) & 0x3f); \ 118 seq = ((msgid >> 26) & 0x3f); \
118 seqid = (msgid & 0x3fffff); \ 119 seqid = (msgid & 0x3fffff); \
119 } while(0) 120 } while (0)
120 121
121#define NEXT_SEQID(seqid) (((seqid) + 1) & 0x3fffff) 122#define NEXT_SEQID(seqid) (((seqid) + 1) & 0x3fffff)
122 123
@@ -124,6 +125,14 @@ struct ipmi_channel
124{ 125{
125 unsigned char medium; 126 unsigned char medium;
126 unsigned char protocol; 127 unsigned char protocol;
128
129 /* My slave address. This is initialized to IPMI_BMC_SLAVE_ADDR,
130 but may be changed by the user. */
131 unsigned char address;
132
133 /* My LUN. This should generally stay the SMS LUN, but just in
134 case... */
135 unsigned char lun;
127}; 136};
128 137
129#ifdef CONFIG_PROC_FS 138#ifdef CONFIG_PROC_FS
@@ -135,7 +144,7 @@ struct ipmi_proc_entry
135#endif 144#endif
136 145
137#define IPMI_IPMB_NUM_SEQ 64 146#define IPMI_IPMB_NUM_SEQ 64
138#define IPMI_MAX_CHANNELS 8 147#define IPMI_MAX_CHANNELS 16
139struct ipmi_smi 148struct ipmi_smi
140{ 149{
141 /* What interface number are we? */ 150 /* What interface number are we? */
@@ -193,20 +202,6 @@ struct ipmi_smi
193 struct list_head waiting_events; 202 struct list_head waiting_events;
194 unsigned int waiting_events_count; /* How many events in queue? */ 203 unsigned int waiting_events_count; /* How many events in queue? */
195 204
196 /* This will be non-null if someone registers to receive all
197 IPMI commands (this is for interface emulation). There
198 may not be any things in the cmd_rcvrs list above when
199 this is registered. */
200 ipmi_user_t all_cmd_rcvr;
201
202 /* My slave address. This is initialized to IPMI_BMC_SLAVE_ADDR,
203 but may be changed by the user. */
204 unsigned char my_address;
205
206 /* My LUN. This should generally stay the SMS LUN, but just in
207 case... */
208 unsigned char my_lun;
209
210 /* The event receiver for my BMC, only really used at panic 205 /* The event receiver for my BMC, only really used at panic
211 shutdown as a place to store this. */ 206 shutdown as a place to store this. */
212 unsigned char event_receiver; 207 unsigned char event_receiver;
@@ -218,7 +213,7 @@ struct ipmi_smi
218 interface comes in with a NULL user, call this routine with 213 interface comes in with a NULL user, call this routine with
219 it. Note that the message will still be freed by the 214 it. Note that the message will still be freed by the
220 caller. This only works on the system interface. */ 215 caller. This only works on the system interface. */
221 void (*null_user_handler)(ipmi_smi_t intf, struct ipmi_smi_msg *msg); 216 void (*null_user_handler)(ipmi_smi_t intf, struct ipmi_recv_msg *msg);
222 217
223 /* When we are scanning the channels for an SMI, this will 218 /* When we are scanning the channels for an SMI, this will
224 tell which channel we are scanning. */ 219 tell which channel we are scanning. */
@@ -325,7 +320,7 @@ int ipmi_smi_watcher_register(struct ipmi_smi_watcher *watcher)
325 down_read(&interfaces_sem); 320 down_read(&interfaces_sem);
326 down_write(&smi_watchers_sem); 321 down_write(&smi_watchers_sem);
327 list_add(&(watcher->link), &smi_watchers); 322 list_add(&(watcher->link), &smi_watchers);
328 for (i=0; i<MAX_IPMI_INTERFACES; i++) { 323 for (i = 0; i < MAX_IPMI_INTERFACES; i++) {
329 if (ipmi_interfaces[i] != NULL) { 324 if (ipmi_interfaces[i] != NULL) {
330 watcher->new_smi(i); 325 watcher->new_smi(i);
331 } 326 }
@@ -458,7 +453,27 @@ unsigned int ipmi_addr_length(int addr_type)
458 453
459static void deliver_response(struct ipmi_recv_msg *msg) 454static void deliver_response(struct ipmi_recv_msg *msg)
460{ 455{
461 msg->user->handler->ipmi_recv_hndl(msg, msg->user->handler_data); 456 if (! msg->user) {
457 ipmi_smi_t intf = msg->user_msg_data;
458 unsigned long flags;
459
460 /* Special handling for NULL users. */
461 if (intf->null_user_handler) {
462 intf->null_user_handler(intf, msg);
463 spin_lock_irqsave(&intf->counter_lock, flags);
464 intf->handled_local_responses++;
465 spin_unlock_irqrestore(&intf->counter_lock, flags);
466 } else {
467 /* No handler, so give up. */
468 spin_lock_irqsave(&intf->counter_lock, flags);
469 intf->unhandled_local_responses++;
470 spin_unlock_irqrestore(&intf->counter_lock, flags);
471 }
472 ipmi_free_recv_msg(msg);
473 } else {
474 msg->user->handler->ipmi_recv_hndl(msg,
475 msg->user->handler_data);
476 }
462} 477}
463 478
464/* Find the next sequence number not being used and add the given 479/* Find the next sequence number not being used and add the given
@@ -475,9 +490,9 @@ static int intf_next_seq(ipmi_smi_t intf,
475 int rv = 0; 490 int rv = 0;
476 unsigned int i; 491 unsigned int i;
477 492
478 for (i=intf->curr_seq; 493 for (i = intf->curr_seq;
479 (i+1)%IPMI_IPMB_NUM_SEQ != intf->curr_seq; 494 (i+1)%IPMI_IPMB_NUM_SEQ != intf->curr_seq;
480 i=(i+1)%IPMI_IPMB_NUM_SEQ) 495 i = (i+1)%IPMI_IPMB_NUM_SEQ)
481 { 496 {
482 if (! intf->seq_table[i].inuse) 497 if (! intf->seq_table[i].inuse)
483 break; 498 break;
@@ -712,7 +727,7 @@ static int ipmi_destroy_user_nolock(ipmi_user_t user)
712 727
713 /* Remove the user from the interfaces sequence table. */ 728 /* Remove the user from the interfaces sequence table. */
714 spin_lock_irqsave(&(user->intf->seq_lock), flags); 729 spin_lock_irqsave(&(user->intf->seq_lock), flags);
715 for (i=0; i<IPMI_IPMB_NUM_SEQ; i++) { 730 for (i = 0; i < IPMI_IPMB_NUM_SEQ; i++) {
716 if (user->intf->seq_table[i].inuse 731 if (user->intf->seq_table[i].inuse
717 && (user->intf->seq_table[i].recv_msg->user == user)) 732 && (user->intf->seq_table[i].recv_msg->user == user))
718 { 733 {
@@ -766,26 +781,44 @@ void ipmi_get_version(ipmi_user_t user,
766 *minor = user->intf->version_minor; 781 *minor = user->intf->version_minor;
767} 782}
768 783
769void ipmi_set_my_address(ipmi_user_t user, 784int ipmi_set_my_address(ipmi_user_t user,
770 unsigned char address) 785 unsigned int channel,
786 unsigned char address)
771{ 787{
772 user->intf->my_address = address; 788 if (channel >= IPMI_MAX_CHANNELS)
789 return -EINVAL;
790 user->intf->channels[channel].address = address;
791 return 0;
773} 792}
774 793
775unsigned char ipmi_get_my_address(ipmi_user_t user) 794int ipmi_get_my_address(ipmi_user_t user,
795 unsigned int channel,
796 unsigned char *address)
776{ 797{
777 return user->intf->my_address; 798 if (channel >= IPMI_MAX_CHANNELS)
799 return -EINVAL;
800 *address = user->intf->channels[channel].address;
801 return 0;
778} 802}
779 803
780void ipmi_set_my_LUN(ipmi_user_t user, 804int ipmi_set_my_LUN(ipmi_user_t user,
781 unsigned char LUN) 805 unsigned int channel,
806 unsigned char LUN)
782{ 807{
783 user->intf->my_lun = LUN & 0x3; 808 if (channel >= IPMI_MAX_CHANNELS)
809 return -EINVAL;
810 user->intf->channels[channel].lun = LUN & 0x3;
811 return 0;
784} 812}
785 813
786unsigned char ipmi_get_my_LUN(ipmi_user_t user) 814int ipmi_get_my_LUN(ipmi_user_t user,
815 unsigned int channel,
816 unsigned char *address)
787{ 817{
788 return user->intf->my_lun; 818 if (channel >= IPMI_MAX_CHANNELS)
819 return -EINVAL;
820 *address = user->intf->channels[channel].lun;
821 return 0;
789} 822}
790 823
791int ipmi_set_gets_events(ipmi_user_t user, int val) 824int ipmi_set_gets_events(ipmi_user_t user, int val)
@@ -828,11 +861,6 @@ int ipmi_register_for_cmd(ipmi_user_t user,
828 861
829 read_lock(&(user->intf->users_lock)); 862 read_lock(&(user->intf->users_lock));
830 write_lock_irqsave(&(user->intf->cmd_rcvr_lock), flags); 863 write_lock_irqsave(&(user->intf->cmd_rcvr_lock), flags);
831 if (user->intf->all_cmd_rcvr != NULL) {
832 rv = -EBUSY;
833 goto out_unlock;
834 }
835
836 /* Make sure the command/netfn is not already registered. */ 864 /* Make sure the command/netfn is not already registered. */
837 list_for_each_entry(cmp, &(user->intf->cmd_rcvrs), link) { 865 list_for_each_entry(cmp, &(user->intf->cmd_rcvrs), link) {
838 if ((cmp->netfn == netfn) && (cmp->cmd == cmd)) { 866 if ((cmp->netfn == netfn) && (cmp->cmd == cmd)) {
@@ -847,7 +875,7 @@ int ipmi_register_for_cmd(ipmi_user_t user,
847 rcvr->user = user; 875 rcvr->user = user;
848 list_add_tail(&(rcvr->link), &(user->intf->cmd_rcvrs)); 876 list_add_tail(&(rcvr->link), &(user->intf->cmd_rcvrs));
849 } 877 }
850 out_unlock: 878
851 write_unlock_irqrestore(&(user->intf->cmd_rcvr_lock), flags); 879 write_unlock_irqrestore(&(user->intf->cmd_rcvr_lock), flags);
852 read_unlock(&(user->intf->users_lock)); 880 read_unlock(&(user->intf->users_lock));
853 881
@@ -1213,7 +1241,7 @@ static inline int i_ipmi_request(ipmi_user_t user,
1213 unsigned char ipmb_seq; 1241 unsigned char ipmb_seq;
1214 long seqid; 1242 long seqid;
1215 1243
1216 if (addr->channel > IPMI_NUM_CHANNELS) { 1244 if (addr->channel >= IPMI_NUM_CHANNELS) {
1217 spin_lock_irqsave(&intf->counter_lock, flags); 1245 spin_lock_irqsave(&intf->counter_lock, flags);
1218 intf->sent_invalid_commands++; 1246 intf->sent_invalid_commands++;
1219 spin_unlock_irqrestore(&intf->counter_lock, flags); 1247 spin_unlock_irqrestore(&intf->counter_lock, flags);
@@ -1331,7 +1359,7 @@ static inline int i_ipmi_request(ipmi_user_t user,
1331#ifdef DEBUG_MSGING 1359#ifdef DEBUG_MSGING
1332 { 1360 {
1333 int m; 1361 int m;
1334 for (m=0; m<smi_msg->data_size; m++) 1362 for (m = 0; m < smi_msg->data_size; m++)
1335 printk(" %2.2x", smi_msg->data[m]); 1363 printk(" %2.2x", smi_msg->data[m]);
1336 printk("\n"); 1364 printk("\n");
1337 } 1365 }
@@ -1346,6 +1374,18 @@ static inline int i_ipmi_request(ipmi_user_t user,
1346 return rv; 1374 return rv;
1347} 1375}
1348 1376
1377static int check_addr(ipmi_smi_t intf,
1378 struct ipmi_addr *addr,
1379 unsigned char *saddr,
1380 unsigned char *lun)
1381{
1382 if (addr->channel >= IPMI_MAX_CHANNELS)
1383 return -EINVAL;
1384 *lun = intf->channels[addr->channel].lun;
1385 *saddr = intf->channels[addr->channel].address;
1386 return 0;
1387}
1388
1349int ipmi_request_settime(ipmi_user_t user, 1389int ipmi_request_settime(ipmi_user_t user,
1350 struct ipmi_addr *addr, 1390 struct ipmi_addr *addr,
1351 long msgid, 1391 long msgid,
@@ -1355,6 +1395,14 @@ int ipmi_request_settime(ipmi_user_t user,
1355 int retries, 1395 int retries,
1356 unsigned int retry_time_ms) 1396 unsigned int retry_time_ms)
1357{ 1397{
1398 unsigned char saddr, lun;
1399 int rv;
1400
1401 if (! user)
1402 return -EINVAL;
1403 rv = check_addr(user->intf, addr, &saddr, &lun);
1404 if (rv)
1405 return rv;
1358 return i_ipmi_request(user, 1406 return i_ipmi_request(user,
1359 user->intf, 1407 user->intf,
1360 addr, 1408 addr,
@@ -1363,8 +1411,8 @@ int ipmi_request_settime(ipmi_user_t user,
1363 user_msg_data, 1411 user_msg_data,
1364 NULL, NULL, 1412 NULL, NULL,
1365 priority, 1413 priority,
1366 user->intf->my_address, 1414 saddr,
1367 user->intf->my_lun, 1415 lun,
1368 retries, 1416 retries,
1369 retry_time_ms); 1417 retry_time_ms);
1370} 1418}
@@ -1378,6 +1426,14 @@ int ipmi_request_supply_msgs(ipmi_user_t user,
1378 struct ipmi_recv_msg *supplied_recv, 1426 struct ipmi_recv_msg *supplied_recv,
1379 int priority) 1427 int priority)
1380{ 1428{
1429 unsigned char saddr, lun;
1430 int rv;
1431
1432 if (! user)
1433 return -EINVAL;
1434 rv = check_addr(user->intf, addr, &saddr, &lun);
1435 if (rv)
1436 return rv;
1381 return i_ipmi_request(user, 1437 return i_ipmi_request(user,
1382 user->intf, 1438 user->intf,
1383 addr, 1439 addr,
@@ -1387,8 +1443,8 @@ int ipmi_request_supply_msgs(ipmi_user_t user,
1387 supplied_smi, 1443 supplied_smi,
1388 supplied_recv, 1444 supplied_recv,
1389 priority, 1445 priority,
1390 user->intf->my_address, 1446 saddr,
1391 user->intf->my_lun, 1447 lun,
1392 -1, 0); 1448 -1, 0);
1393} 1449}
1394 1450
@@ -1397,8 +1453,15 @@ static int ipmb_file_read_proc(char *page, char **start, off_t off,
1397{ 1453{
1398 char *out = (char *) page; 1454 char *out = (char *) page;
1399 ipmi_smi_t intf = data; 1455 ipmi_smi_t intf = data;
1456 int i;
1457 int rv= 0;
1400 1458
1401 return sprintf(out, "%x\n", intf->my_address); 1459 for (i = 0; i < IPMI_MAX_CHANNELS; i++)
1460 rv += sprintf(out+rv, "%x ", intf->channels[i].address);
1461 out[rv-1] = '\n'; /* Replace the final space with a newline */
1462 out[rv] = '\0';
1463 rv++;
1464 return rv;
1402} 1465}
1403 1466
1404static int version_file_read_proc(char *page, char **start, off_t off, 1467static int version_file_read_proc(char *page, char **start, off_t off,
@@ -1588,29 +1651,30 @@ send_channel_info_cmd(ipmi_smi_t intf, int chan)
1588 (struct ipmi_addr *) &si, 1651 (struct ipmi_addr *) &si,
1589 0, 1652 0,
1590 &msg, 1653 &msg,
1591 NULL, 1654 intf,
1592 NULL, 1655 NULL,
1593 NULL, 1656 NULL,
1594 0, 1657 0,
1595 intf->my_address, 1658 intf->channels[0].address,
1596 intf->my_lun, 1659 intf->channels[0].lun,
1597 -1, 0); 1660 -1, 0);
1598} 1661}
1599 1662
1600static void 1663static void
1601channel_handler(ipmi_smi_t intf, struct ipmi_smi_msg *msg) 1664channel_handler(ipmi_smi_t intf, struct ipmi_recv_msg *msg)
1602{ 1665{
1603 int rv = 0; 1666 int rv = 0;
1604 int chan; 1667 int chan;
1605 1668
1606 if ((msg->rsp[0] == (IPMI_NETFN_APP_RESPONSE << 2)) 1669 if ((msg->addr.addr_type == IPMI_SYSTEM_INTERFACE_ADDR_TYPE)
1607 && (msg->rsp[1] == IPMI_GET_CHANNEL_INFO_CMD)) 1670 && (msg->msg.netfn == IPMI_NETFN_APP_RESPONSE)
1671 && (msg->msg.cmd == IPMI_GET_CHANNEL_INFO_CMD))
1608 { 1672 {
1609 /* It's the one we want */ 1673 /* It's the one we want */
1610 if (msg->rsp[2] != 0) { 1674 if (msg->msg.data[0] != 0) {
1611 /* Got an error from the channel, just go on. */ 1675 /* Got an error from the channel, just go on. */
1612 1676
1613 if (msg->rsp[2] == IPMI_INVALID_COMMAND_ERR) { 1677 if (msg->msg.data[0] == IPMI_INVALID_COMMAND_ERR) {
1614 /* If the MC does not support this 1678 /* If the MC does not support this
1615 command, that is legal. We just 1679 command, that is legal. We just
1616 assume it has one IPMB at channel 1680 assume it has one IPMB at channel
@@ -1627,13 +1691,13 @@ channel_handler(ipmi_smi_t intf, struct ipmi_smi_msg *msg)
1627 } 1691 }
1628 goto next_channel; 1692 goto next_channel;
1629 } 1693 }
1630 if (msg->rsp_size < 6) { 1694 if (msg->msg.data_len < 4) {
1631 /* Message not big enough, just go on. */ 1695 /* Message not big enough, just go on. */
1632 goto next_channel; 1696 goto next_channel;
1633 } 1697 }
1634 chan = intf->curr_channel; 1698 chan = intf->curr_channel;
1635 intf->channels[chan].medium = msg->rsp[4] & 0x7f; 1699 intf->channels[chan].medium = msg->msg.data[2] & 0x7f;
1636 intf->channels[chan].protocol = msg->rsp[5] & 0x1f; 1700 intf->channels[chan].protocol = msg->msg.data[3] & 0x1f;
1637 1701
1638 next_channel: 1702 next_channel:
1639 intf->curr_channel++; 1703 intf->curr_channel++;
@@ -1691,22 +1755,24 @@ int ipmi_register_smi(struct ipmi_smi_handlers *handlers,
1691 rv = -ENOMEM; 1755 rv = -ENOMEM;
1692 1756
1693 down_write(&interfaces_sem); 1757 down_write(&interfaces_sem);
1694 for (i=0; i<MAX_IPMI_INTERFACES; i++) { 1758 for (i = 0; i < MAX_IPMI_INTERFACES; i++) {
1695 if (ipmi_interfaces[i] == NULL) { 1759 if (ipmi_interfaces[i] == NULL) {
1696 new_intf->intf_num = i; 1760 new_intf->intf_num = i;
1697 new_intf->version_major = version_major; 1761 new_intf->version_major = version_major;
1698 new_intf->version_minor = version_minor; 1762 new_intf->version_minor = version_minor;
1699 if (slave_addr == 0) 1763 for (j = 0; j < IPMI_MAX_CHANNELS; j++) {
1700 new_intf->my_address = IPMI_BMC_SLAVE_ADDR; 1764 new_intf->channels[j].address
1701 else 1765 = IPMI_BMC_SLAVE_ADDR;
1702 new_intf->my_address = slave_addr; 1766 new_intf->channels[j].lun = 2;
1703 new_intf->my_lun = 2; /* the SMS LUN. */ 1767 }
1768 if (slave_addr != 0)
1769 new_intf->channels[0].address = slave_addr;
1704 rwlock_init(&(new_intf->users_lock)); 1770 rwlock_init(&(new_intf->users_lock));
1705 INIT_LIST_HEAD(&(new_intf->users)); 1771 INIT_LIST_HEAD(&(new_intf->users));
1706 new_intf->handlers = handlers; 1772 new_intf->handlers = handlers;
1707 new_intf->send_info = send_info; 1773 new_intf->send_info = send_info;
1708 spin_lock_init(&(new_intf->seq_lock)); 1774 spin_lock_init(&(new_intf->seq_lock));
1709 for (j=0; j<IPMI_IPMB_NUM_SEQ; j++) { 1775 for (j = 0; j < IPMI_IPMB_NUM_SEQ; j++) {
1710 new_intf->seq_table[j].inuse = 0; 1776 new_intf->seq_table[j].inuse = 0;
1711 new_intf->seq_table[j].seqid = 0; 1777 new_intf->seq_table[j].seqid = 0;
1712 } 1778 }
@@ -1722,7 +1788,6 @@ int ipmi_register_smi(struct ipmi_smi_handlers *handlers,
1722 rwlock_init(&(new_intf->cmd_rcvr_lock)); 1788 rwlock_init(&(new_intf->cmd_rcvr_lock));
1723 init_waitqueue_head(&new_intf->waitq); 1789 init_waitqueue_head(&new_intf->waitq);
1724 INIT_LIST_HEAD(&(new_intf->cmd_rcvrs)); 1790 INIT_LIST_HEAD(&(new_intf->cmd_rcvrs));
1725 new_intf->all_cmd_rcvr = NULL;
1726 1791
1727 spin_lock_init(&(new_intf->counter_lock)); 1792 spin_lock_init(&(new_intf->counter_lock));
1728 1793
@@ -1814,7 +1879,7 @@ static void clean_up_interface_data(ipmi_smi_t intf)
1814 free_recv_msg_list(&(intf->waiting_events)); 1879 free_recv_msg_list(&(intf->waiting_events));
1815 free_cmd_rcvr_list(&(intf->cmd_rcvrs)); 1880 free_cmd_rcvr_list(&(intf->cmd_rcvrs));
1816 1881
1817 for (i=0; i<IPMI_IPMB_NUM_SEQ; i++) { 1882 for (i = 0; i < IPMI_IPMB_NUM_SEQ; i++) {
1818 if ((intf->seq_table[i].inuse) 1883 if ((intf->seq_table[i].inuse)
1819 && (intf->seq_table[i].recv_msg)) 1884 && (intf->seq_table[i].recv_msg))
1820 { 1885 {
@@ -1833,7 +1898,7 @@ int ipmi_unregister_smi(ipmi_smi_t intf)
1833 down_write(&interfaces_sem); 1898 down_write(&interfaces_sem);
1834 if (list_empty(&(intf->users))) 1899 if (list_empty(&(intf->users)))
1835 { 1900 {
1836 for (i=0; i<MAX_IPMI_INTERFACES; i++) { 1901 for (i = 0; i < MAX_IPMI_INTERFACES; i++) {
1837 if (ipmi_interfaces[i] == intf) { 1902 if (ipmi_interfaces[i] == intf) {
1838 remove_proc_entries(intf); 1903 remove_proc_entries(intf);
1839 spin_lock_irqsave(&interfaces_lock, flags); 1904 spin_lock_irqsave(&interfaces_lock, flags);
@@ -1960,15 +2025,11 @@ static int handle_ipmb_get_msg_cmd(ipmi_smi_t intf,
1960 2025
1961 read_lock(&(intf->cmd_rcvr_lock)); 2026 read_lock(&(intf->cmd_rcvr_lock));
1962 2027
1963 if (intf->all_cmd_rcvr) { 2028 /* Find the command/netfn. */
1964 user = intf->all_cmd_rcvr; 2029 list_for_each_entry(rcvr, &(intf->cmd_rcvrs), link) {
1965 } else { 2030 if ((rcvr->netfn == netfn) && (rcvr->cmd == cmd)) {
1966 /* Find the command/netfn. */ 2031 user = rcvr->user;
1967 list_for_each_entry(rcvr, &(intf->cmd_rcvrs), link) { 2032 break;
1968 if ((rcvr->netfn == netfn) && (rcvr->cmd == cmd)) {
1969 user = rcvr->user;
1970 break;
1971 }
1972 } 2033 }
1973 } 2034 }
1974 read_unlock(&(intf->cmd_rcvr_lock)); 2035 read_unlock(&(intf->cmd_rcvr_lock));
@@ -1985,7 +2046,7 @@ static int handle_ipmb_get_msg_cmd(ipmi_smi_t intf,
1985 msg->data[3] = msg->rsp[6]; 2046 msg->data[3] = msg->rsp[6];
1986 msg->data[4] = ((netfn + 1) << 2) | (msg->rsp[7] & 0x3); 2047 msg->data[4] = ((netfn + 1) << 2) | (msg->rsp[7] & 0x3);
1987 msg->data[5] = ipmb_checksum(&(msg->data[3]), 2); 2048 msg->data[5] = ipmb_checksum(&(msg->data[3]), 2);
1988 msg->data[6] = intf->my_address; 2049 msg->data[6] = intf->channels[msg->rsp[3] & 0xf].address;
1989 /* rqseq/lun */ 2050 /* rqseq/lun */
1990 msg->data[7] = (msg->rsp[7] & 0xfc) | (msg->rsp[4] & 0x3); 2051 msg->data[7] = (msg->rsp[7] & 0xfc) | (msg->rsp[4] & 0x3);
1991 msg->data[8] = msg->rsp[8]; /* cmd */ 2052 msg->data[8] = msg->rsp[8]; /* cmd */
@@ -1997,7 +2058,7 @@ static int handle_ipmb_get_msg_cmd(ipmi_smi_t intf,
1997 { 2058 {
1998 int m; 2059 int m;
1999 printk("Invalid command:"); 2060 printk("Invalid command:");
2000 for (m=0; m<msg->data_size; m++) 2061 for (m = 0; m < msg->data_size; m++)
2001 printk(" %2.2x", msg->data[m]); 2062 printk(" %2.2x", msg->data[m]);
2002 printk("\n"); 2063 printk("\n");
2003 } 2064 }
@@ -2145,15 +2206,11 @@ static int handle_lan_get_msg_cmd(ipmi_smi_t intf,
2145 2206
2146 read_lock(&(intf->cmd_rcvr_lock)); 2207 read_lock(&(intf->cmd_rcvr_lock));
2147 2208
2148 if (intf->all_cmd_rcvr) { 2209 /* Find the command/netfn. */
2149 user = intf->all_cmd_rcvr; 2210 list_for_each_entry(rcvr, &(intf->cmd_rcvrs), link) {
2150 } else { 2211 if ((rcvr->netfn == netfn) && (rcvr->cmd == cmd)) {
2151 /* Find the command/netfn. */ 2212 user = rcvr->user;
2152 list_for_each_entry(rcvr, &(intf->cmd_rcvrs), link) { 2213 break;
2153 if ((rcvr->netfn == netfn) && (rcvr->cmd == cmd)) {
2154 user = rcvr->user;
2155 break;
2156 }
2157 } 2214 }
2158 } 2215 }
2159 read_unlock(&(intf->cmd_rcvr_lock)); 2216 read_unlock(&(intf->cmd_rcvr_lock));
@@ -2330,6 +2387,14 @@ static int handle_bmc_rsp(ipmi_smi_t intf,
2330 unsigned long flags; 2387 unsigned long flags;
2331 2388
2332 recv_msg = (struct ipmi_recv_msg *) msg->user_data; 2389 recv_msg = (struct ipmi_recv_msg *) msg->user_data;
2390 if (recv_msg == NULL)
2391 {
2392 printk(KERN_WARNING"IPMI message received with no owner. This\n"
2393 "could be because of a malformed message, or\n"
2394 "because of a hardware error. Contact your\n"
2395 "hardware vender for assistance\n");
2396 return 0;
2397 }
2333 2398
2334 /* Make sure the user still exists. */ 2399 /* Make sure the user still exists. */
2335 list_for_each_entry(user, &(intf->users), link) { 2400 list_for_each_entry(user, &(intf->users), link) {
@@ -2340,19 +2405,11 @@ static int handle_bmc_rsp(ipmi_smi_t intf,
2340 } 2405 }
2341 } 2406 }
2342 2407
2343 if (!found) { 2408 if ((! found) && recv_msg->user) {
2344 /* Special handling for NULL users. */ 2409 /* The user for the message went away, so give up. */
2345 if (!recv_msg->user && intf->null_user_handler){ 2410 spin_lock_irqsave(&intf->counter_lock, flags);
2346 intf->null_user_handler(intf, msg); 2411 intf->unhandled_local_responses++;
2347 spin_lock_irqsave(&intf->counter_lock, flags); 2412 spin_unlock_irqrestore(&intf->counter_lock, flags);
2348 intf->handled_local_responses++;
2349 spin_unlock_irqrestore(&intf->counter_lock, flags);
2350 }else{
2351 /* The user for the message went away, so give up. */
2352 spin_lock_irqsave(&intf->counter_lock, flags);
2353 intf->unhandled_local_responses++;
2354 spin_unlock_irqrestore(&intf->counter_lock, flags);
2355 }
2356 ipmi_free_recv_msg(recv_msg); 2413 ipmi_free_recv_msg(recv_msg);
2357 } else { 2414 } else {
2358 struct ipmi_system_interface_addr *smi_addr; 2415 struct ipmi_system_interface_addr *smi_addr;
@@ -2392,7 +2449,7 @@ static int handle_new_recv_msg(ipmi_smi_t intf,
2392#ifdef DEBUG_MSGING 2449#ifdef DEBUG_MSGING
2393 int m; 2450 int m;
2394 printk("Recv:"); 2451 printk("Recv:");
2395 for (m=0; m<msg->rsp_size; m++) 2452 for (m = 0; m < msg->rsp_size; m++)
2396 printk(" %2.2x", msg->rsp[m]); 2453 printk(" %2.2x", msg->rsp[m]);
2397 printk("\n"); 2454 printk("\n");
2398#endif 2455#endif
@@ -2626,7 +2683,7 @@ smi_from_recv_msg(ipmi_smi_t intf, struct ipmi_recv_msg *recv_msg,
2626 { 2683 {
2627 int m; 2684 int m;
2628 printk("Resend: "); 2685 printk("Resend: ");
2629 for (m=0; m<smi_msg->data_size; m++) 2686 for (m = 0; m < smi_msg->data_size; m++)
2630 printk(" %2.2x", smi_msg->data[m]); 2687 printk(" %2.2x", smi_msg->data[m]);
2631 printk("\n"); 2688 printk("\n");
2632 } 2689 }
@@ -2647,7 +2704,7 @@ ipmi_timeout_handler(long timeout_period)
2647 INIT_LIST_HEAD(&timeouts); 2704 INIT_LIST_HEAD(&timeouts);
2648 2705
2649 spin_lock(&interfaces_lock); 2706 spin_lock(&interfaces_lock);
2650 for (i=0; i<MAX_IPMI_INTERFACES; i++) { 2707 for (i = 0; i < MAX_IPMI_INTERFACES; i++) {
2651 intf = ipmi_interfaces[i]; 2708 intf = ipmi_interfaces[i];
2652 if (intf == NULL) 2709 if (intf == NULL)
2653 continue; 2710 continue;
@@ -2672,7 +2729,7 @@ ipmi_timeout_handler(long timeout_period)
2672 have timed out, putting them in the timeouts 2729 have timed out, putting them in the timeouts
2673 list. */ 2730 list. */
2674 spin_lock_irqsave(&(intf->seq_lock), flags); 2731 spin_lock_irqsave(&(intf->seq_lock), flags);
2675 for (j=0; j<IPMI_IPMB_NUM_SEQ; j++) { 2732 for (j = 0; j < IPMI_IPMB_NUM_SEQ; j++) {
2676 struct seq_table *ent = &(intf->seq_table[j]); 2733 struct seq_table *ent = &(intf->seq_table[j]);
2677 if (!ent->inuse) 2734 if (!ent->inuse)
2678 continue; 2735 continue;
@@ -2712,7 +2769,7 @@ ipmi_timeout_handler(long timeout_period)
2712 spin_unlock(&intf->counter_lock); 2769 spin_unlock(&intf->counter_lock);
2713 smi_msg = smi_from_recv_msg(intf, 2770 smi_msg = smi_from_recv_msg(intf,
2714 ent->recv_msg, j, ent->seqid); 2771 ent->recv_msg, j, ent->seqid);
2715 if(!smi_msg) 2772 if (! smi_msg)
2716 continue; 2773 continue;
2717 2774
2718 spin_unlock_irqrestore(&(intf->seq_lock),flags); 2775 spin_unlock_irqrestore(&(intf->seq_lock),flags);
@@ -2743,7 +2800,7 @@ static void ipmi_request_event(void)
2743 int i; 2800 int i;
2744 2801
2745 spin_lock(&interfaces_lock); 2802 spin_lock(&interfaces_lock);
2746 for (i=0; i<MAX_IPMI_INTERFACES; i++) { 2803 for (i = 0; i < MAX_IPMI_INTERFACES; i++) {
2747 intf = ipmi_interfaces[i]; 2804 intf = ipmi_interfaces[i];
2748 if (intf == NULL) 2805 if (intf == NULL)
2749 continue; 2806 continue;
@@ -2838,28 +2895,30 @@ static void dummy_recv_done_handler(struct ipmi_recv_msg *msg)
2838} 2895}
2839 2896
2840#ifdef CONFIG_IPMI_PANIC_STRING 2897#ifdef CONFIG_IPMI_PANIC_STRING
2841static void event_receiver_fetcher(ipmi_smi_t intf, struct ipmi_smi_msg *msg) 2898static void event_receiver_fetcher(ipmi_smi_t intf, struct ipmi_recv_msg *msg)
2842{ 2899{
2843 if ((msg->rsp[0] == (IPMI_NETFN_SENSOR_EVENT_RESPONSE << 2)) 2900 if ((msg->addr.addr_type == IPMI_SYSTEM_INTERFACE_ADDR_TYPE)
2844 && (msg->rsp[1] == IPMI_GET_EVENT_RECEIVER_CMD) 2901 && (msg->msg.netfn == IPMI_NETFN_SENSOR_EVENT_RESPONSE)
2845 && (msg->rsp[2] == IPMI_CC_NO_ERROR)) 2902 && (msg->msg.cmd == IPMI_GET_EVENT_RECEIVER_CMD)
2903 && (msg->msg.data[0] == IPMI_CC_NO_ERROR))
2846 { 2904 {
2847 /* A get event receiver command, save it. */ 2905 /* A get event receiver command, save it. */
2848 intf->event_receiver = msg->rsp[3]; 2906 intf->event_receiver = msg->msg.data[1];
2849 intf->event_receiver_lun = msg->rsp[4] & 0x3; 2907 intf->event_receiver_lun = msg->msg.data[2] & 0x3;
2850 } 2908 }
2851} 2909}
2852 2910
2853static void device_id_fetcher(ipmi_smi_t intf, struct ipmi_smi_msg *msg) 2911static void device_id_fetcher(ipmi_smi_t intf, struct ipmi_recv_msg *msg)
2854{ 2912{
2855 if ((msg->rsp[0] == (IPMI_NETFN_APP_RESPONSE << 2)) 2913 if ((msg->addr.addr_type == IPMI_SYSTEM_INTERFACE_ADDR_TYPE)
2856 && (msg->rsp[1] == IPMI_GET_DEVICE_ID_CMD) 2914 && (msg->msg.netfn == IPMI_NETFN_APP_RESPONSE)
2857 && (msg->rsp[2] == IPMI_CC_NO_ERROR)) 2915 && (msg->msg.cmd == IPMI_GET_DEVICE_ID_CMD)
2916 && (msg->msg.data[0] == IPMI_CC_NO_ERROR))
2858 { 2917 {
2859 /* A get device id command, save if we are an event 2918 /* A get device id command, save if we are an event
2860 receiver or generator. */ 2919 receiver or generator. */
2861 intf->local_sel_device = (msg->rsp[8] >> 2) & 1; 2920 intf->local_sel_device = (msg->msg.data[6] >> 2) & 1;
2862 intf->local_event_generator = (msg->rsp[8] >> 5) & 1; 2921 intf->local_event_generator = (msg->msg.data[6] >> 5) & 1;
2863 } 2922 }
2864} 2923}
2865#endif 2924#endif
@@ -2903,7 +2962,7 @@ static void send_panic_events(char *str)
2903 recv_msg.done = dummy_recv_done_handler; 2962 recv_msg.done = dummy_recv_done_handler;
2904 2963
2905 /* For every registered interface, send the event. */ 2964 /* For every registered interface, send the event. */
2906 for (i=0; i<MAX_IPMI_INTERFACES; i++) { 2965 for (i = 0; i < MAX_IPMI_INTERFACES; i++) {
2907 intf = ipmi_interfaces[i]; 2966 intf = ipmi_interfaces[i];
2908 if (intf == NULL) 2967 if (intf == NULL)
2909 continue; 2968 continue;
@@ -2915,12 +2974,12 @@ static void send_panic_events(char *str)
2915 &addr, 2974 &addr,
2916 0, 2975 0,
2917 &msg, 2976 &msg,
2918 NULL, 2977 intf,
2919 &smi_msg, 2978 &smi_msg,
2920 &recv_msg, 2979 &recv_msg,
2921 0, 2980 0,
2922 intf->my_address, 2981 intf->channels[0].address,
2923 intf->my_lun, 2982 intf->channels[0].lun,
2924 0, 1); /* Don't retry, and don't wait. */ 2983 0, 1); /* Don't retry, and don't wait. */
2925 } 2984 }
2926 2985
@@ -2930,7 +2989,7 @@ static void send_panic_events(char *str)
2930 if (!str) 2989 if (!str)
2931 return; 2990 return;
2932 2991
2933 for (i=0; i<MAX_IPMI_INTERFACES; i++) { 2992 for (i = 0; i < MAX_IPMI_INTERFACES; i++) {
2934 char *p = str; 2993 char *p = str;
2935 struct ipmi_ipmb_addr *ipmb; 2994 struct ipmi_ipmb_addr *ipmb;
2936 int j; 2995 int j;
@@ -2961,12 +3020,12 @@ static void send_panic_events(char *str)
2961 &addr, 3020 &addr,
2962 0, 3021 0,
2963 &msg, 3022 &msg,
2964 NULL, 3023 intf,
2965 &smi_msg, 3024 &smi_msg,
2966 &recv_msg, 3025 &recv_msg,
2967 0, 3026 0,
2968 intf->my_address, 3027 intf->channels[0].address,
2969 intf->my_lun, 3028 intf->channels[0].lun,
2970 0, 1); /* Don't retry, and don't wait. */ 3029 0, 1); /* Don't retry, and don't wait. */
2971 3030
2972 if (intf->local_event_generator) { 3031 if (intf->local_event_generator) {
@@ -2981,12 +3040,12 @@ static void send_panic_events(char *str)
2981 &addr, 3040 &addr,
2982 0, 3041 0,
2983 &msg, 3042 &msg,
2984 NULL, 3043 intf,
2985 &smi_msg, 3044 &smi_msg,
2986 &recv_msg, 3045 &recv_msg,
2987 0, 3046 0,
2988 intf->my_address, 3047 intf->channels[0].address,
2989 intf->my_lun, 3048 intf->channels[0].lun,
2990 0, 1); /* no retry, and no wait. */ 3049 0, 1); /* no retry, and no wait. */
2991 } 3050 }
2992 intf->null_user_handler = NULL; 3051 intf->null_user_handler = NULL;
@@ -2996,7 +3055,7 @@ static void send_panic_events(char *str)
2996 be zero, and it must not be my address. */ 3055 be zero, and it must not be my address. */
2997 if (((intf->event_receiver & 1) == 0) 3056 if (((intf->event_receiver & 1) == 0)
2998 && (intf->event_receiver != 0) 3057 && (intf->event_receiver != 0)
2999 && (intf->event_receiver != intf->my_address)) 3058 && (intf->event_receiver != intf->channels[0].address))
3000 { 3059 {
3001 /* The event receiver is valid, send an IPMB 3060 /* The event receiver is valid, send an IPMB
3002 message. */ 3061 message. */
@@ -3031,7 +3090,7 @@ static void send_panic_events(char *str)
3031 data[0] = 0; 3090 data[0] = 0;
3032 data[1] = 0; 3091 data[1] = 0;
3033 data[2] = 0xf0; /* OEM event without timestamp. */ 3092 data[2] = 0xf0; /* OEM event without timestamp. */
3034 data[3] = intf->my_address; 3093 data[3] = intf->channels[0].address;
3035 data[4] = j++; /* sequence # */ 3094 data[4] = j++; /* sequence # */
3036 /* Always give 11 bytes, so strncpy will fill 3095 /* Always give 11 bytes, so strncpy will fill
3037 it with zeroes for me. */ 3096 it with zeroes for me. */
@@ -3043,12 +3102,12 @@ static void send_panic_events(char *str)
3043 &addr, 3102 &addr,
3044 0, 3103 0,
3045 &msg, 3104 &msg,
3046 NULL, 3105 intf,
3047 &smi_msg, 3106 &smi_msg,
3048 &recv_msg, 3107 &recv_msg,
3049 0, 3108 0,
3050 intf->my_address, 3109 intf->channels[0].address,
3051 intf->my_lun, 3110 intf->channels[0].lun,
3052 0, 1); /* no retry, and no wait. */ 3111 0, 1); /* no retry, and no wait. */
3053 } 3112 }
3054 } 3113 }
@@ -3070,7 +3129,7 @@ static int panic_event(struct notifier_block *this,
3070 has_paniced = 1; 3129 has_paniced = 1;
3071 3130
3072 /* For every registered interface, set it to run to completion. */ 3131 /* For every registered interface, set it to run to completion. */
3073 for (i=0; i<MAX_IPMI_INTERFACES; i++) { 3132 for (i = 0; i < MAX_IPMI_INTERFACES; i++) {
3074 intf = ipmi_interfaces[i]; 3133 intf = ipmi_interfaces[i];
3075 if (intf == NULL) 3134 if (intf == NULL)
3076 continue; 3135 continue;
@@ -3099,9 +3158,9 @@ static int ipmi_init_msghandler(void)
3099 return 0; 3158 return 0;
3100 3159
3101 printk(KERN_INFO "ipmi message handler version " 3160 printk(KERN_INFO "ipmi message handler version "
3102 IPMI_MSGHANDLER_VERSION "\n"); 3161 IPMI_DRIVER_VERSION "\n");
3103 3162
3104 for (i=0; i<MAX_IPMI_INTERFACES; i++) { 3163 for (i = 0; i < MAX_IPMI_INTERFACES; i++) {
3105 ipmi_interfaces[i] = NULL; 3164 ipmi_interfaces[i] = NULL;
3106 } 3165 }
3107 3166
@@ -3171,6 +3230,9 @@ module_exit(cleanup_ipmi);
3171 3230
3172module_init(ipmi_init_msghandler_mod); 3231module_init(ipmi_init_msghandler_mod);
3173MODULE_LICENSE("GPL"); 3232MODULE_LICENSE("GPL");
3233MODULE_AUTHOR("Corey Minyard <minyard@mvista.com>");
3234MODULE_DESCRIPTION("Incoming and outgoing message routing for an IPMI interface.");
3235MODULE_VERSION(IPMI_DRIVER_VERSION);
3174 3236
3175EXPORT_SYMBOL(ipmi_create_user); 3237EXPORT_SYMBOL(ipmi_create_user);
3176EXPORT_SYMBOL(ipmi_destroy_user); 3238EXPORT_SYMBOL(ipmi_destroy_user);
diff --git a/drivers/char/ipmi/ipmi_poweroff.c b/drivers/char/ipmi/ipmi_poweroff.c
index f951c30236c..e82a96ba396 100644
--- a/drivers/char/ipmi/ipmi_poweroff.c
+++ b/drivers/char/ipmi/ipmi_poweroff.c
@@ -42,7 +42,6 @@
42#include <linux/ipmi_smi.h> 42#include <linux/ipmi_smi.h>
43 43
44#define PFX "IPMI poweroff: " 44#define PFX "IPMI poweroff: "
45#define IPMI_POWEROFF_VERSION "v33"
46 45
47/* Where to we insert our poweroff function? */ 46/* Where to we insert our poweroff function? */
48extern void (*pm_power_off)(void); 47extern void (*pm_power_off)(void);
@@ -53,16 +52,17 @@ extern void (*pm_power_off)(void);
53#define IPMI_CHASSIS_POWER_CYCLE 0x02 /* power cycle */ 52#define IPMI_CHASSIS_POWER_CYCLE 0x02 /* power cycle */
54 53
55/* the IPMI data command */ 54/* the IPMI data command */
56static int poweroff_control = IPMI_CHASSIS_POWER_DOWN; 55static int poweroff_powercycle;
57 56
58/* parameter definition to allow user to flag power cycle */ 57/* parameter definition to allow user to flag power cycle */
59module_param(poweroff_control, int, IPMI_CHASSIS_POWER_DOWN); 58module_param(poweroff_powercycle, int, 0);
60MODULE_PARM_DESC(poweroff_control, " Set to 2 to enable power cycle instead of power down. Power cycle is contingent on hardware support, otherwise it defaults back to power down."); 59MODULE_PARM_DESC(poweroff_powercycles, " Set to non-zero to enable power cycle instead of power down. Power cycle is contingent on hardware support, otherwise it defaults back to power down.");
61 60
62/* Stuff from the get device id command. */ 61/* Stuff from the get device id command. */
63static unsigned int mfg_id; 62static unsigned int mfg_id;
64static unsigned int prod_id; 63static unsigned int prod_id;
65static unsigned char capabilities; 64static unsigned char capabilities;
65static unsigned char ipmi_version;
66 66
67/* We use our own messages for this operation, we don't let the system 67/* We use our own messages for this operation, we don't let the system
68 allocate them, since we may be in a panic situation. The whole 68 allocate them, since we may be in a panic situation. The whole
@@ -338,6 +338,25 @@ static void ipmi_poweroff_cpi1 (ipmi_user_t user)
338} 338}
339 339
340/* 340/*
341 * ipmi_dell_chassis_detect()
342 * Dell systems with IPMI < 1.5 don't set the chassis capability bit
343 * but they can handle a chassis poweroff or powercycle command.
344 */
345
346#define DELL_IANA_MFR_ID {0xA2, 0x02, 0x00}
347static int ipmi_dell_chassis_detect (ipmi_user_t user)
348{
349 const char ipmi_version_major = ipmi_version & 0xF;
350 const char ipmi_version_minor = (ipmi_version >> 4) & 0xF;
351 const char mfr[3]=DELL_IANA_MFR_ID;
352 if (!memcmp(mfr, &mfg_id, sizeof(mfr)) &&
353 ipmi_version_major <= 1 &&
354 ipmi_version_minor < 5)
355 return 1;
356 return 0;
357}
358
359/*
341 * Standard chassis support 360 * Standard chassis support
342 */ 361 */
343 362
@@ -366,37 +385,34 @@ static void ipmi_poweroff_chassis (ipmi_user_t user)
366 385
367 powercyclefailed: 386 powercyclefailed:
368 printk(KERN_INFO PFX "Powering %s via IPMI chassis control command\n", 387 printk(KERN_INFO PFX "Powering %s via IPMI chassis control command\n",
369 ((poweroff_control != IPMI_CHASSIS_POWER_CYCLE) ? "down" : "cycle")); 388 (poweroff_powercycle ? "cycle" : "down"));
370 389
371 /* 390 /*
372 * Power down 391 * Power down
373 */ 392 */
374 send_msg.netfn = IPMI_NETFN_CHASSIS_REQUEST; 393 send_msg.netfn = IPMI_NETFN_CHASSIS_REQUEST;
375 send_msg.cmd = IPMI_CHASSIS_CONTROL_CMD; 394 send_msg.cmd = IPMI_CHASSIS_CONTROL_CMD;
376 data[0] = poweroff_control; 395 if (poweroff_powercycle)
396 data[0] = IPMI_CHASSIS_POWER_CYCLE;
397 else
398 data[0] = IPMI_CHASSIS_POWER_DOWN;
377 send_msg.data = data; 399 send_msg.data = data;
378 send_msg.data_len = sizeof(data); 400 send_msg.data_len = sizeof(data);
379 rv = ipmi_request_in_rc_mode(user, 401 rv = ipmi_request_in_rc_mode(user,
380 (struct ipmi_addr *) &smi_addr, 402 (struct ipmi_addr *) &smi_addr,
381 &send_msg); 403 &send_msg);
382 if (rv) { 404 if (rv) {
383 switch (poweroff_control) { 405 if (poweroff_powercycle) {
384 case IPMI_CHASSIS_POWER_CYCLE: 406 /* power cycle failed, default to power down */
385 /* power cycle failed, default to power down */ 407 printk(KERN_ERR PFX "Unable to send chassis power " \
386 printk(KERN_ERR PFX "Unable to send chassis power " \ 408 "cycle message, IPMI error 0x%x\n", rv);
387 "cycle message, IPMI error 0x%x\n", rv); 409 poweroff_powercycle = 0;
388 poweroff_control = IPMI_CHASSIS_POWER_DOWN; 410 goto powercyclefailed;
389 goto powercyclefailed;
390
391 case IPMI_CHASSIS_POWER_DOWN:
392 default:
393 printk(KERN_ERR PFX "Unable to send chassis power " \
394 "down message, IPMI error 0x%x\n", rv);
395 break;
396 } 411 }
397 }
398 412
399 return; 413 printk(KERN_ERR PFX "Unable to send chassis power " \
414 "down message, IPMI error 0x%x\n", rv);
415 }
400} 416}
401 417
402 418
@@ -414,6 +430,9 @@ static struct poweroff_function poweroff_functions[] = {
414 { .platform_type = "CPI1", 430 { .platform_type = "CPI1",
415 .detect = ipmi_cpi1_detect, 431 .detect = ipmi_cpi1_detect,
416 .poweroff_func = ipmi_poweroff_cpi1 }, 432 .poweroff_func = ipmi_poweroff_cpi1 },
433 { .platform_type = "chassis",
434 .detect = ipmi_dell_chassis_detect,
435 .poweroff_func = ipmi_poweroff_chassis },
417 /* Chassis should generally be last, other things should override 436 /* Chassis should generally be last, other things should override
418 it. */ 437 it. */
419 { .platform_type = "chassis", 438 { .platform_type = "chassis",
@@ -499,10 +518,11 @@ static void ipmi_po_new_smi(int if_num)
499 prod_id = (halt_recv_msg.msg.data[10] 518 prod_id = (halt_recv_msg.msg.data[10]
500 | (halt_recv_msg.msg.data[11] << 8)); 519 | (halt_recv_msg.msg.data[11] << 8));
501 capabilities = halt_recv_msg.msg.data[6]; 520 capabilities = halt_recv_msg.msg.data[6];
521 ipmi_version = halt_recv_msg.msg.data[5];
502 522
503 523
504 /* Scan for a poweroff method */ 524 /* Scan for a poweroff method */
505 for (i=0; i<NUM_PO_FUNCS; i++) { 525 for (i = 0; i < NUM_PO_FUNCS; i++) {
506 if (poweroff_functions[i].detect(ipmi_user)) 526 if (poweroff_functions[i].detect(ipmi_user))
507 goto found; 527 goto found;
508 } 528 }
@@ -538,39 +558,35 @@ static struct ipmi_smi_watcher smi_watcher =
538 558
539 559
540#ifdef CONFIG_PROC_FS 560#ifdef CONFIG_PROC_FS
541/* displays properties to proc */ 561#include <linux/sysctl.h>
542static int proc_read_chassctrl(char *page, char **start, off_t off, int count, 562
543 int *eof, void *data) 563static ctl_table ipmi_table[] = {
544{ 564 { .ctl_name = DEV_IPMI_POWEROFF_POWERCYCLE,
545 return sprintf(page, "%d\t[ 0=powerdown 2=powercycle ]\n", 565 .procname = "poweroff_powercycle",
546 poweroff_control); 566 .data = &poweroff_powercycle,
547} 567 .maxlen = sizeof(poweroff_powercycle),
568 .mode = 0644,
569 .proc_handler = &proc_dointvec },
570 { }
571};
548 572
549/* process property writes from proc */ 573static ctl_table ipmi_dir_table[] = {
550static int proc_write_chassctrl(struct file *file, const char *buffer, 574 { .ctl_name = DEV_IPMI,
551 unsigned long count, void *data) 575 .procname = "ipmi",
552{ 576 .mode = 0555,
553 int rv = count; 577 .child = ipmi_table },
554 unsigned int newval = 0; 578 { }
555 579};
556 sscanf(buffer, "%d", &newval);
557 switch (newval) {
558 case IPMI_CHASSIS_POWER_CYCLE:
559 printk(KERN_INFO PFX "power cycle is now enabled\n");
560 poweroff_control = newval;
561 break;
562
563 case IPMI_CHASSIS_POWER_DOWN:
564 poweroff_control = IPMI_CHASSIS_POWER_DOWN;
565 break;
566
567 default:
568 rv = -EINVAL;
569 break;
570 }
571 580
572 return rv; 581static ctl_table ipmi_root_table[] = {
573} 582 { .ctl_name = CTL_DEV,
583 .procname = "dev",
584 .mode = 0555,
585 .child = ipmi_dir_table },
586 { }
587};
588
589static struct ctl_table_header *ipmi_table_header;
574#endif /* CONFIG_PROC_FS */ 590#endif /* CONFIG_PROC_FS */
575 591
576/* 592/*
@@ -578,42 +594,32 @@ static int proc_write_chassctrl(struct file *file, const char *buffer,
578 */ 594 */
579static int ipmi_poweroff_init (void) 595static int ipmi_poweroff_init (void)
580{ 596{
581 int rv; 597 int rv;
582 struct proc_dir_entry *file;
583 598
584 printk ("Copyright (C) 2004 MontaVista Software -" 599 printk ("Copyright (C) 2004 MontaVista Software -"
585 " IPMI Powerdown via sys_reboot version " 600 " IPMI Powerdown via sys_reboot.\n");
586 IPMI_POWEROFF_VERSION ".\n"); 601
587 602 if (poweroff_powercycle)
588 switch (poweroff_control) { 603 printk(KERN_INFO PFX "Power cycle is enabled.\n");
589 case IPMI_CHASSIS_POWER_CYCLE: 604
590 printk(KERN_INFO PFX "Power cycle is enabled.\n"); 605#ifdef CONFIG_PROC_FS
591 break; 606 ipmi_table_header = register_sysctl_table(ipmi_root_table, 1);
592 607 if (!ipmi_table_header) {
593 case IPMI_CHASSIS_POWER_DOWN: 608 printk(KERN_ERR PFX "Unable to register powercycle sysctl\n");
594 default: 609 rv = -ENOMEM;
595 poweroff_control = IPMI_CHASSIS_POWER_DOWN; 610 goto out_err;
596 break;
597 } 611 }
612#endif
598 613
614#ifdef CONFIG_PROC_FS
599 rv = ipmi_smi_watcher_register(&smi_watcher); 615 rv = ipmi_smi_watcher_register(&smi_watcher);
616#endif
600 if (rv) { 617 if (rv) {
618 unregister_sysctl_table(ipmi_table_header);
601 printk(KERN_ERR PFX "Unable to register SMI watcher: %d\n", rv); 619 printk(KERN_ERR PFX "Unable to register SMI watcher: %d\n", rv);
602 goto out_err; 620 goto out_err;
603 } 621 }
604 622
605#ifdef CONFIG_PROC_FS
606 file = create_proc_entry("poweroff_control", 0, proc_ipmi_root);
607 if (!file) {
608 printk(KERN_ERR PFX "Unable to create proc power control\n");
609 } else {
610 file->nlink = 1;
611 file->read_proc = proc_read_chassctrl;
612 file->write_proc = proc_write_chassctrl;
613 file->owner = THIS_MODULE;
614 }
615#endif
616
617 out_err: 623 out_err:
618 return rv; 624 return rv;
619} 625}
@@ -624,7 +630,7 @@ static __exit void ipmi_poweroff_cleanup(void)
624 int rv; 630 int rv;
625 631
626#ifdef CONFIG_PROC_FS 632#ifdef CONFIG_PROC_FS
627 remove_proc_entry("poweroff_control", proc_ipmi_root); 633 unregister_sysctl_table(ipmi_table_header);
628#endif 634#endif
629 635
630 ipmi_smi_watcher_unregister(&smi_watcher); 636 ipmi_smi_watcher_unregister(&smi_watcher);
@@ -642,3 +648,5 @@ module_exit(ipmi_poweroff_cleanup);
642 648
643module_init(ipmi_poweroff_init); 649module_init(ipmi_poweroff_init);
644MODULE_LICENSE("GPL"); 650MODULE_LICENSE("GPL");
651MODULE_AUTHOR("Corey Minyard <minyard@mvista.com>");
652MODULE_DESCRIPTION("IPMI Poweroff extension to sys_reboot");
diff --git a/drivers/char/ipmi/ipmi_si_intf.c b/drivers/char/ipmi/ipmi_si_intf.c
index adbec73b80a..278f8410499 100644
--- a/drivers/char/ipmi/ipmi_si_intf.c
+++ b/drivers/char/ipmi/ipmi_si_intf.c
@@ -61,11 +61,11 @@
61# endif 61# endif
62static inline void add_usec_to_timer(struct timer_list *t, long v) 62static inline void add_usec_to_timer(struct timer_list *t, long v)
63{ 63{
64 t->sub_expires += nsec_to_arch_cycle(v * 1000); 64 t->arch_cycle_expires += nsec_to_arch_cycle(v * 1000);
65 while (t->sub_expires >= arch_cycles_per_jiffy) 65 while (t->arch_cycle_expires >= arch_cycles_per_jiffy)
66 { 66 {
67 t->expires++; 67 t->expires++;
68 t->sub_expires -= arch_cycles_per_jiffy; 68 t->arch_cycle_expires -= arch_cycles_per_jiffy;
69 } 69 }
70} 70}
71#endif 71#endif
@@ -75,8 +75,7 @@ static inline void add_usec_to_timer(struct timer_list *t, long v)
75#include <asm/io.h> 75#include <asm/io.h>
76#include "ipmi_si_sm.h" 76#include "ipmi_si_sm.h"
77#include <linux/init.h> 77#include <linux/init.h>
78 78#include <linux/dmi.h>
79#define IPMI_SI_VERSION "v33"
80 79
81/* Measure times between events in the driver. */ 80/* Measure times between events in the driver. */
82#undef DEBUG_TIMING 81#undef DEBUG_TIMING
@@ -109,6 +108,21 @@ enum si_type {
109 SI_KCS, SI_SMIC, SI_BT 108 SI_KCS, SI_SMIC, SI_BT
110}; 109};
111 110
111struct ipmi_device_id {
112 unsigned char device_id;
113 unsigned char device_revision;
114 unsigned char firmware_revision_1;
115 unsigned char firmware_revision_2;
116 unsigned char ipmi_version;
117 unsigned char additional_device_support;
118 unsigned char manufacturer_id[3];
119 unsigned char product_id[2];
120 unsigned char aux_firmware_revision[4];
121} __attribute__((packed));
122
123#define ipmi_version_major(v) ((v)->ipmi_version & 0xf)
124#define ipmi_version_minor(v) ((v)->ipmi_version >> 4)
125
112struct smi_info 126struct smi_info
113{ 127{
114 ipmi_smi_t intf; 128 ipmi_smi_t intf;
@@ -131,12 +145,24 @@ struct smi_info
131 void (*irq_cleanup)(struct smi_info *info); 145 void (*irq_cleanup)(struct smi_info *info);
132 unsigned int io_size; 146 unsigned int io_size;
133 147
148 /* Per-OEM handler, called from handle_flags().
149 Returns 1 when handle_flags() needs to be re-run
150 or 0 indicating it set si_state itself.
151 */
152 int (*oem_data_avail_handler)(struct smi_info *smi_info);
153
134 /* Flags from the last GET_MSG_FLAGS command, used when an ATTN 154 /* Flags from the last GET_MSG_FLAGS command, used when an ATTN
135 is set to hold the flags until we are done handling everything 155 is set to hold the flags until we are done handling everything
136 from the flags. */ 156 from the flags. */
137#define RECEIVE_MSG_AVAIL 0x01 157#define RECEIVE_MSG_AVAIL 0x01
138#define EVENT_MSG_BUFFER_FULL 0x02 158#define EVENT_MSG_BUFFER_FULL 0x02
139#define WDT_PRE_TIMEOUT_INT 0x08 159#define WDT_PRE_TIMEOUT_INT 0x08
160#define OEM0_DATA_AVAIL 0x20
161#define OEM1_DATA_AVAIL 0x40
162#define OEM2_DATA_AVAIL 0x80
163#define OEM_DATA_AVAIL (OEM0_DATA_AVAIL | \
164 OEM1_DATA_AVAIL | \
165 OEM2_DATA_AVAIL)
140 unsigned char msg_flags; 166 unsigned char msg_flags;
141 167
142 /* If set to true, this will request events the next time the 168 /* If set to true, this will request events the next time the
@@ -175,11 +201,7 @@ struct smi_info
175 interrupts. */ 201 interrupts. */
176 int interrupt_disabled; 202 int interrupt_disabled;
177 203
178 unsigned char ipmi_si_dev_rev; 204 struct ipmi_device_id device_id;
179 unsigned char ipmi_si_fw_rev_major;
180 unsigned char ipmi_si_fw_rev_minor;
181 unsigned char ipmi_version_major;
182 unsigned char ipmi_version_minor;
183 205
184 /* Slave address, could be reported from DMI. */ 206 /* Slave address, could be reported from DMI. */
185 unsigned char slave_addr; 207 unsigned char slave_addr;
@@ -245,7 +267,7 @@ static enum si_sm_result start_next_msg(struct smi_info *smi_info)
245 entry = smi_info->xmit_msgs.next; 267 entry = smi_info->xmit_msgs.next;
246 } 268 }
247 269
248 if (!entry) { 270 if (! entry) {
249 smi_info->curr_msg = NULL; 271 smi_info->curr_msg = NULL;
250 rv = SI_SM_IDLE; 272 rv = SI_SM_IDLE;
251 } else { 273 } else {
@@ -306,7 +328,7 @@ static void start_clear_flags(struct smi_info *smi_info)
306 memory, we will re-enable the interrupt. */ 328 memory, we will re-enable the interrupt. */
307static inline void disable_si_irq(struct smi_info *smi_info) 329static inline void disable_si_irq(struct smi_info *smi_info)
308{ 330{
309 if ((smi_info->irq) && (!smi_info->interrupt_disabled)) { 331 if ((smi_info->irq) && (! smi_info->interrupt_disabled)) {
310 disable_irq_nosync(smi_info->irq); 332 disable_irq_nosync(smi_info->irq);
311 smi_info->interrupt_disabled = 1; 333 smi_info->interrupt_disabled = 1;
312 } 334 }
@@ -322,6 +344,7 @@ static inline void enable_si_irq(struct smi_info *smi_info)
322 344
323static void handle_flags(struct smi_info *smi_info) 345static void handle_flags(struct smi_info *smi_info)
324{ 346{
347 retry:
325 if (smi_info->msg_flags & WDT_PRE_TIMEOUT_INT) { 348 if (smi_info->msg_flags & WDT_PRE_TIMEOUT_INT) {
326 /* Watchdog pre-timeout */ 349 /* Watchdog pre-timeout */
327 spin_lock(&smi_info->count_lock); 350 spin_lock(&smi_info->count_lock);
@@ -336,7 +359,7 @@ static void handle_flags(struct smi_info *smi_info)
336 } else if (smi_info->msg_flags & RECEIVE_MSG_AVAIL) { 359 } else if (smi_info->msg_flags & RECEIVE_MSG_AVAIL) {
337 /* Messages available. */ 360 /* Messages available. */
338 smi_info->curr_msg = ipmi_alloc_smi_msg(); 361 smi_info->curr_msg = ipmi_alloc_smi_msg();
339 if (!smi_info->curr_msg) { 362 if (! smi_info->curr_msg) {
340 disable_si_irq(smi_info); 363 disable_si_irq(smi_info);
341 smi_info->si_state = SI_NORMAL; 364 smi_info->si_state = SI_NORMAL;
342 return; 365 return;
@@ -355,7 +378,7 @@ static void handle_flags(struct smi_info *smi_info)
355 } else if (smi_info->msg_flags & EVENT_MSG_BUFFER_FULL) { 378 } else if (smi_info->msg_flags & EVENT_MSG_BUFFER_FULL) {
356 /* Events available. */ 379 /* Events available. */
357 smi_info->curr_msg = ipmi_alloc_smi_msg(); 380 smi_info->curr_msg = ipmi_alloc_smi_msg();
358 if (!smi_info->curr_msg) { 381 if (! smi_info->curr_msg) {
359 disable_si_irq(smi_info); 382 disable_si_irq(smi_info);
360 smi_info->si_state = SI_NORMAL; 383 smi_info->si_state = SI_NORMAL;
361 return; 384 return;
@@ -371,6 +394,10 @@ static void handle_flags(struct smi_info *smi_info)
371 smi_info->curr_msg->data, 394 smi_info->curr_msg->data,
372 smi_info->curr_msg->data_size); 395 smi_info->curr_msg->data_size);
373 smi_info->si_state = SI_GETTING_EVENTS; 396 smi_info->si_state = SI_GETTING_EVENTS;
397 } else if (smi_info->msg_flags & OEM_DATA_AVAIL) {
398 if (smi_info->oem_data_avail_handler)
399 if (smi_info->oem_data_avail_handler(smi_info))
400 goto retry;
374 } else { 401 } else {
375 smi_info->si_state = SI_NORMAL; 402 smi_info->si_state = SI_NORMAL;
376 } 403 }
@@ -387,7 +414,7 @@ static void handle_transaction_done(struct smi_info *smi_info)
387#endif 414#endif
388 switch (smi_info->si_state) { 415 switch (smi_info->si_state) {
389 case SI_NORMAL: 416 case SI_NORMAL:
390 if (!smi_info->curr_msg) 417 if (! smi_info->curr_msg)
391 break; 418 break;
392 419
393 smi_info->curr_msg->rsp_size 420 smi_info->curr_msg->rsp_size
@@ -761,18 +788,20 @@ static void si_restart_short_timer(struct smi_info *smi_info)
761#if defined(CONFIG_HIGH_RES_TIMERS) 788#if defined(CONFIG_HIGH_RES_TIMERS)
762 unsigned long flags; 789 unsigned long flags;
763 unsigned long jiffies_now; 790 unsigned long jiffies_now;
791 unsigned long seq;
764 792
765 if (del_timer(&(smi_info->si_timer))) { 793 if (del_timer(&(smi_info->si_timer))) {
766 /* If we don't delete the timer, then it will go off 794 /* If we don't delete the timer, then it will go off
767 immediately, anyway. So we only process if we 795 immediately, anyway. So we only process if we
768 actually delete the timer. */ 796 actually delete the timer. */
769 797
770 /* We already have irqsave on, so no need for it 798 do {
771 here. */ 799 seq = read_seqbegin_irqsave(&xtime_lock, flags);
772 read_lock(&xtime_lock); 800 jiffies_now = jiffies;
773 jiffies_now = jiffies; 801 smi_info->si_timer.expires = jiffies_now;
774 smi_info->si_timer.expires = jiffies_now; 802 smi_info->si_timer.arch_cycle_expires
775 smi_info->si_timer.sub_expires = get_arch_cycles(jiffies_now); 803 = get_arch_cycles(jiffies_now);
804 } while (read_seqretry_irqrestore(&xtime_lock, seq, flags));
776 805
777 add_usec_to_timer(&smi_info->si_timer, SI_SHORT_TIMEOUT_USEC); 806 add_usec_to_timer(&smi_info->si_timer, SI_SHORT_TIMEOUT_USEC);
778 807
@@ -826,15 +855,19 @@ static void smi_timeout(unsigned long data)
826 /* If the state machine asks for a short delay, then shorten 855 /* If the state machine asks for a short delay, then shorten
827 the timer timeout. */ 856 the timer timeout. */
828 if (smi_result == SI_SM_CALL_WITH_DELAY) { 857 if (smi_result == SI_SM_CALL_WITH_DELAY) {
858#if defined(CONFIG_HIGH_RES_TIMERS)
859 unsigned long seq;
860#endif
829 spin_lock_irqsave(&smi_info->count_lock, flags); 861 spin_lock_irqsave(&smi_info->count_lock, flags);
830 smi_info->short_timeouts++; 862 smi_info->short_timeouts++;
831 spin_unlock_irqrestore(&smi_info->count_lock, flags); 863 spin_unlock_irqrestore(&smi_info->count_lock, flags);
832#if defined(CONFIG_HIGH_RES_TIMERS) 864#if defined(CONFIG_HIGH_RES_TIMERS)
833 read_lock(&xtime_lock); 865 do {
834 smi_info->si_timer.expires = jiffies; 866 seq = read_seqbegin_irqsave(&xtime_lock, flags);
835 smi_info->si_timer.sub_expires 867 smi_info->si_timer.expires = jiffies;
836 = get_arch_cycles(smi_info->si_timer.expires); 868 smi_info->si_timer.arch_cycle_expires
837 read_unlock(&xtime_lock); 869 = get_arch_cycles(smi_info->si_timer.expires);
870 } while (read_seqretry_irqrestore(&xtime_lock, seq, flags));
838 add_usec_to_timer(&smi_info->si_timer, SI_SHORT_TIMEOUT_USEC); 871 add_usec_to_timer(&smi_info->si_timer, SI_SHORT_TIMEOUT_USEC);
839#else 872#else
840 smi_info->si_timer.expires = jiffies + 1; 873 smi_info->si_timer.expires = jiffies + 1;
@@ -845,7 +878,7 @@ static void smi_timeout(unsigned long data)
845 spin_unlock_irqrestore(&smi_info->count_lock, flags); 878 spin_unlock_irqrestore(&smi_info->count_lock, flags);
846 smi_info->si_timer.expires = jiffies + SI_TIMEOUT_JIFFIES; 879 smi_info->si_timer.expires = jiffies + SI_TIMEOUT_JIFFIES;
847#if defined(CONFIG_HIGH_RES_TIMERS) 880#if defined(CONFIG_HIGH_RES_TIMERS)
848 smi_info->si_timer.sub_expires = 0; 881 smi_info->si_timer.arch_cycle_expires = 0;
849#endif 882#endif
850 } 883 }
851 884
@@ -1014,7 +1047,7 @@ static int std_irq_setup(struct smi_info *info)
1014{ 1047{
1015 int rv; 1048 int rv;
1016 1049
1017 if (!info->irq) 1050 if (! info->irq)
1018 return 0; 1051 return 0;
1019 1052
1020 if (info->si_type == SI_BT) { 1053 if (info->si_type == SI_BT) {
@@ -1023,7 +1056,7 @@ static int std_irq_setup(struct smi_info *info)
1023 SA_INTERRUPT, 1056 SA_INTERRUPT,
1024 DEVICE_NAME, 1057 DEVICE_NAME,
1025 info); 1058 info);
1026 if (!rv) 1059 if (! rv)
1027 /* Enable the interrupt in the BT interface. */ 1060 /* Enable the interrupt in the BT interface. */
1028 info->io.outputb(&info->io, IPMI_BT_INTMASK_REG, 1061 info->io.outputb(&info->io, IPMI_BT_INTMASK_REG,
1029 IPMI_BT_INTMASK_ENABLE_IRQ_BIT); 1062 IPMI_BT_INTMASK_ENABLE_IRQ_BIT);
@@ -1048,7 +1081,7 @@ static int std_irq_setup(struct smi_info *info)
1048 1081
1049static void std_irq_cleanup(struct smi_info *info) 1082static void std_irq_cleanup(struct smi_info *info)
1050{ 1083{
1051 if (!info->irq) 1084 if (! info->irq)
1052 return; 1085 return;
1053 1086
1054 if (info->si_type == SI_BT) 1087 if (info->si_type == SI_BT)
@@ -1121,7 +1154,7 @@ static int port_setup(struct smi_info *info)
1121 unsigned int *addr = info->io.info; 1154 unsigned int *addr = info->io.info;
1122 int mapsize; 1155 int mapsize;
1123 1156
1124 if (!addr || (!*addr)) 1157 if (! addr || (! *addr))
1125 return -ENODEV; 1158 return -ENODEV;
1126 1159
1127 info->io_cleanup = port_cleanup; 1160 info->io_cleanup = port_cleanup;
@@ -1164,15 +1197,15 @@ static int try_init_port(int intf_num, struct smi_info **new_info)
1164{ 1197{
1165 struct smi_info *info; 1198 struct smi_info *info;
1166 1199
1167 if (!ports[intf_num]) 1200 if (! ports[intf_num])
1168 return -ENODEV; 1201 return -ENODEV;
1169 1202
1170 if (!is_new_interface(intf_num, IPMI_IO_ADDR_SPACE, 1203 if (! is_new_interface(intf_num, IPMI_IO_ADDR_SPACE,
1171 ports[intf_num])) 1204 ports[intf_num]))
1172 return -ENODEV; 1205 return -ENODEV;
1173 1206
1174 info = kmalloc(sizeof(*info), GFP_KERNEL); 1207 info = kmalloc(sizeof(*info), GFP_KERNEL);
1175 if (!info) { 1208 if (! info) {
1176 printk(KERN_ERR "ipmi_si: Could not allocate SI data (1)\n"); 1209 printk(KERN_ERR "ipmi_si: Could not allocate SI data (1)\n");
1177 return -ENOMEM; 1210 return -ENOMEM;
1178 } 1211 }
@@ -1182,10 +1215,10 @@ static int try_init_port(int intf_num, struct smi_info **new_info)
1182 info->io.info = &(ports[intf_num]); 1215 info->io.info = &(ports[intf_num]);
1183 info->io.addr = NULL; 1216 info->io.addr = NULL;
1184 info->io.regspacing = regspacings[intf_num]; 1217 info->io.regspacing = regspacings[intf_num];
1185 if (!info->io.regspacing) 1218 if (! info->io.regspacing)
1186 info->io.regspacing = DEFAULT_REGSPACING; 1219 info->io.regspacing = DEFAULT_REGSPACING;
1187 info->io.regsize = regsizes[intf_num]; 1220 info->io.regsize = regsizes[intf_num];
1188 if (!info->io.regsize) 1221 if (! info->io.regsize)
1189 info->io.regsize = DEFAULT_REGSPACING; 1222 info->io.regsize = DEFAULT_REGSPACING;
1190 info->io.regshift = regshifts[intf_num]; 1223 info->io.regshift = regshifts[intf_num];
1191 info->irq = 0; 1224 info->irq = 0;
@@ -1270,7 +1303,7 @@ static int mem_setup(struct smi_info *info)
1270 unsigned long *addr = info->io.info; 1303 unsigned long *addr = info->io.info;
1271 int mapsize; 1304 int mapsize;
1272 1305
1273 if (!addr || (!*addr)) 1306 if (! addr || (! *addr))
1274 return -ENODEV; 1307 return -ENODEV;
1275 1308
1276 info->io_cleanup = mem_cleanup; 1309 info->io_cleanup = mem_cleanup;
@@ -1325,15 +1358,15 @@ static int try_init_mem(int intf_num, struct smi_info **new_info)
1325{ 1358{
1326 struct smi_info *info; 1359 struct smi_info *info;
1327 1360
1328 if (!addrs[intf_num]) 1361 if (! addrs[intf_num])
1329 return -ENODEV; 1362 return -ENODEV;
1330 1363
1331 if (!is_new_interface(intf_num, IPMI_MEM_ADDR_SPACE, 1364 if (! is_new_interface(intf_num, IPMI_MEM_ADDR_SPACE,
1332 addrs[intf_num])) 1365 addrs[intf_num]))
1333 return -ENODEV; 1366 return -ENODEV;
1334 1367
1335 info = kmalloc(sizeof(*info), GFP_KERNEL); 1368 info = kmalloc(sizeof(*info), GFP_KERNEL);
1336 if (!info) { 1369 if (! info) {
1337 printk(KERN_ERR "ipmi_si: Could not allocate SI data (2)\n"); 1370 printk(KERN_ERR "ipmi_si: Could not allocate SI data (2)\n");
1338 return -ENOMEM; 1371 return -ENOMEM;
1339 } 1372 }
@@ -1343,10 +1376,10 @@ static int try_init_mem(int intf_num, struct smi_info **new_info)
1343 info->io.info = &addrs[intf_num]; 1376 info->io.info = &addrs[intf_num];
1344 info->io.addr = NULL; 1377 info->io.addr = NULL;
1345 info->io.regspacing = regspacings[intf_num]; 1378 info->io.regspacing = regspacings[intf_num];
1346 if (!info->io.regspacing) 1379 if (! info->io.regspacing)
1347 info->io.regspacing = DEFAULT_REGSPACING; 1380 info->io.regspacing = DEFAULT_REGSPACING;
1348 info->io.regsize = regsizes[intf_num]; 1381 info->io.regsize = regsizes[intf_num];
1349 if (!info->io.regsize) 1382 if (! info->io.regsize)
1350 info->io.regsize = DEFAULT_REGSPACING; 1383 info->io.regsize = DEFAULT_REGSPACING;
1351 info->io.regshift = regshifts[intf_num]; 1384 info->io.regshift = regshifts[intf_num];
1352 info->irq = 0; 1385 info->irq = 0;
@@ -1404,7 +1437,7 @@ static int acpi_gpe_irq_setup(struct smi_info *info)
1404{ 1437{
1405 acpi_status status; 1438 acpi_status status;
1406 1439
1407 if (!info->irq) 1440 if (! info->irq)
1408 return 0; 1441 return 0;
1409 1442
1410 /* FIXME - is level triggered right? */ 1443 /* FIXME - is level triggered right? */
@@ -1428,7 +1461,7 @@ static int acpi_gpe_irq_setup(struct smi_info *info)
1428 1461
1429static void acpi_gpe_irq_cleanup(struct smi_info *info) 1462static void acpi_gpe_irq_cleanup(struct smi_info *info)
1430{ 1463{
1431 if (!info->irq) 1464 if (! info->irq)
1432 return; 1465 return;
1433 1466
1434 acpi_remove_gpe_handler(NULL, info->irq, &ipmi_acpi_gpe); 1467 acpi_remove_gpe_handler(NULL, info->irq, &ipmi_acpi_gpe);
@@ -1507,10 +1540,10 @@ static int try_init_acpi(int intf_num, struct smi_info **new_info)
1507 addr_space = IPMI_MEM_ADDR_SPACE; 1540 addr_space = IPMI_MEM_ADDR_SPACE;
1508 else 1541 else
1509 addr_space = IPMI_IO_ADDR_SPACE; 1542 addr_space = IPMI_IO_ADDR_SPACE;
1510 if (!is_new_interface(-1, addr_space, spmi->addr.address)) 1543 if (! is_new_interface(-1, addr_space, spmi->addr.address))
1511 return -ENODEV; 1544 return -ENODEV;
1512 1545
1513 if (!spmi->addr.register_bit_width) { 1546 if (! spmi->addr.register_bit_width) {
1514 acpi_failure = 1; 1547 acpi_failure = 1;
1515 return -ENODEV; 1548 return -ENODEV;
1516 } 1549 }
@@ -1537,7 +1570,7 @@ static int try_init_acpi(int intf_num, struct smi_info **new_info)
1537 } 1570 }
1538 1571
1539 info = kmalloc(sizeof(*info), GFP_KERNEL); 1572 info = kmalloc(sizeof(*info), GFP_KERNEL);
1540 if (!info) { 1573 if (! info) {
1541 printk(KERN_ERR "ipmi_si: Could not allocate SI data (3)\n"); 1574 printk(KERN_ERR "ipmi_si: Could not allocate SI data (3)\n");
1542 return -ENOMEM; 1575 return -ENOMEM;
1543 } 1576 }
@@ -1613,22 +1646,15 @@ typedef struct dmi_ipmi_data
1613static dmi_ipmi_data_t dmi_data[SI_MAX_DRIVERS]; 1646static dmi_ipmi_data_t dmi_data[SI_MAX_DRIVERS];
1614static int dmi_data_entries; 1647static int dmi_data_entries;
1615 1648
1616typedef struct dmi_header 1649static int __init decode_dmi(struct dmi_header *dm, int intf_num)
1617{
1618 u8 type;
1619 u8 length;
1620 u16 handle;
1621} dmi_header_t;
1622
1623static int decode_dmi(dmi_header_t __iomem *dm, int intf_num)
1624{ 1650{
1625 u8 __iomem *data = (u8 __iomem *)dm; 1651 u8 *data = (u8 *)dm;
1626 unsigned long base_addr; 1652 unsigned long base_addr;
1627 u8 reg_spacing; 1653 u8 reg_spacing;
1628 u8 len = readb(&dm->length); 1654 u8 len = dm->length;
1629 dmi_ipmi_data_t *ipmi_data = dmi_data+intf_num; 1655 dmi_ipmi_data_t *ipmi_data = dmi_data+intf_num;
1630 1656
1631 ipmi_data->type = readb(&data[4]); 1657 ipmi_data->type = data[4];
1632 1658
1633 memcpy(&base_addr, data+8, sizeof(unsigned long)); 1659 memcpy(&base_addr, data+8, sizeof(unsigned long));
1634 if (len >= 0x11) { 1660 if (len >= 0x11) {
@@ -1643,12 +1669,12 @@ static int decode_dmi(dmi_header_t __iomem *dm, int intf_num)
1643 } 1669 }
1644 /* If bit 4 of byte 0x10 is set, then the lsb for the address 1670 /* If bit 4 of byte 0x10 is set, then the lsb for the address
1645 is odd. */ 1671 is odd. */
1646 ipmi_data->base_addr = base_addr | ((readb(&data[0x10]) & 0x10) >> 4); 1672 ipmi_data->base_addr = base_addr | ((data[0x10] & 0x10) >> 4);
1647 1673
1648 ipmi_data->irq = readb(&data[0x11]); 1674 ipmi_data->irq = data[0x11];
1649 1675
1650 /* The top two bits of byte 0x10 hold the register spacing. */ 1676 /* The top two bits of byte 0x10 hold the register spacing. */
1651 reg_spacing = (readb(&data[0x10]) & 0xC0) >> 6; 1677 reg_spacing = (data[0x10] & 0xC0) >> 6;
1652 switch(reg_spacing){ 1678 switch(reg_spacing){
1653 case 0x00: /* Byte boundaries */ 1679 case 0x00: /* Byte boundaries */
1654 ipmi_data->offset = 1; 1680 ipmi_data->offset = 1;
@@ -1676,7 +1702,7 @@ static int decode_dmi(dmi_header_t __iomem *dm, int intf_num)
1676 ipmi_data->offset = 1; 1702 ipmi_data->offset = 1;
1677 } 1703 }
1678 1704
1679 ipmi_data->slave_addr = readb(&data[6]); 1705 ipmi_data->slave_addr = data[6];
1680 1706
1681 if (is_new_interface(-1, ipmi_data->addr_space,ipmi_data->base_addr)) { 1707 if (is_new_interface(-1, ipmi_data->addr_space,ipmi_data->base_addr)) {
1682 dmi_data_entries++; 1708 dmi_data_entries++;
@@ -1688,94 +1714,29 @@ static int decode_dmi(dmi_header_t __iomem *dm, int intf_num)
1688 return -1; 1714 return -1;
1689} 1715}
1690 1716
1691static int dmi_table(u32 base, int len, int num) 1717static void __init dmi_find_bmc(void)
1692{ 1718{
1693 u8 __iomem *buf; 1719 struct dmi_device *dev = NULL;
1694 struct dmi_header __iomem *dm;
1695 u8 __iomem *data;
1696 int i=1;
1697 int status=-1;
1698 int intf_num = 0; 1720 int intf_num = 0;
1699 1721
1700 buf = ioremap(base, len); 1722 while ((dev = dmi_find_device(DMI_DEV_TYPE_IPMI, NULL, dev))) {
1701 if(buf==NULL) 1723 if (intf_num >= SI_MAX_DRIVERS)
1702 return -1; 1724 break;
1703
1704 data = buf;
1705
1706 while(i<num && (data - buf) < len)
1707 {
1708 dm=(dmi_header_t __iomem *)data;
1709
1710 if((data-buf+readb(&dm->length)) >= len)
1711 break;
1712
1713 if (readb(&dm->type) == 38) {
1714 if (decode_dmi(dm, intf_num) == 0) {
1715 intf_num++;
1716 if (intf_num >= SI_MAX_DRIVERS)
1717 break;
1718 }
1719 }
1720
1721 data+=readb(&dm->length);
1722 while((data-buf) < len && (readb(data)||readb(data+1)))
1723 data++;
1724 data+=2;
1725 i++;
1726 }
1727 iounmap(buf);
1728
1729 return status;
1730}
1731
1732static inline int dmi_checksum(u8 *buf)
1733{
1734 u8 sum=0;
1735 int a;
1736
1737 for(a=0; a<15; a++)
1738 sum+=buf[a];
1739 return (sum==0);
1740}
1741
1742static int dmi_decode(void)
1743{
1744 u8 buf[15];
1745 u32 fp=0xF0000;
1746
1747#ifdef CONFIG_SIMNOW
1748 return -1;
1749#endif
1750
1751 while(fp < 0xFFFFF)
1752 {
1753 isa_memcpy_fromio(buf, fp, 15);
1754 if(memcmp(buf, "_DMI_", 5)==0 && dmi_checksum(buf))
1755 {
1756 u16 num=buf[13]<<8|buf[12];
1757 u16 len=buf[7]<<8|buf[6];
1758 u32 base=buf[11]<<24|buf[10]<<16|buf[9]<<8|buf[8];
1759 1725
1760 if(dmi_table(base, len, num) == 0) 1726 decode_dmi((struct dmi_header *) dev->device_data, intf_num++);
1761 return 0;
1762 }
1763 fp+=16;
1764 } 1727 }
1765
1766 return -1;
1767} 1728}
1768 1729
1769static int try_init_smbios(int intf_num, struct smi_info **new_info) 1730static int try_init_smbios(int intf_num, struct smi_info **new_info)
1770{ 1731{
1771 struct smi_info *info; 1732 struct smi_info *info;
1772 dmi_ipmi_data_t *ipmi_data = dmi_data+intf_num; 1733 dmi_ipmi_data_t *ipmi_data = dmi_data+intf_num;
1773 char *io_type; 1734 char *io_type;
1774 1735
1775 if (intf_num >= dmi_data_entries) 1736 if (intf_num >= dmi_data_entries)
1776 return -ENODEV; 1737 return -ENODEV;
1777 1738
1778 switch(ipmi_data->type) { 1739 switch (ipmi_data->type) {
1779 case 0x01: /* KCS */ 1740 case 0x01: /* KCS */
1780 si_type[intf_num] = "kcs"; 1741 si_type[intf_num] = "kcs";
1781 break; 1742 break;
@@ -1790,7 +1751,7 @@ static int try_init_smbios(int intf_num, struct smi_info **new_info)
1790 } 1751 }
1791 1752
1792 info = kmalloc(sizeof(*info), GFP_KERNEL); 1753 info = kmalloc(sizeof(*info), GFP_KERNEL);
1793 if (!info) { 1754 if (! info) {
1794 printk(KERN_ERR "ipmi_si: Could not allocate SI data (4)\n"); 1755 printk(KERN_ERR "ipmi_si: Could not allocate SI data (4)\n");
1795 return -ENOMEM; 1756 return -ENOMEM;
1796 } 1757 }
@@ -1814,7 +1775,7 @@ static int try_init_smbios(int intf_num, struct smi_info **new_info)
1814 1775
1815 regspacings[intf_num] = ipmi_data->offset; 1776 regspacings[intf_num] = ipmi_data->offset;
1816 info->io.regspacing = regspacings[intf_num]; 1777 info->io.regspacing = regspacings[intf_num];
1817 if (!info->io.regspacing) 1778 if (! info->io.regspacing)
1818 info->io.regspacing = DEFAULT_REGSPACING; 1779 info->io.regspacing = DEFAULT_REGSPACING;
1819 info->io.regsize = DEFAULT_REGSPACING; 1780 info->io.regsize = DEFAULT_REGSPACING;
1820 info->io.regshift = regshifts[intf_num]; 1781 info->io.regshift = regshifts[intf_num];
@@ -1856,14 +1817,14 @@ static int find_pci_smic(int intf_num, struct smi_info **new_info)
1856 1817
1857 pci_smic_checked = 1; 1818 pci_smic_checked = 1;
1858 1819
1859 if ((pci_dev = pci_get_device(PCI_HP_VENDOR_ID, PCI_MMC_DEVICE_ID, 1820 pci_dev = pci_get_device(PCI_HP_VENDOR_ID, PCI_MMC_DEVICE_ID, NULL);
1860 NULL))) 1821 if (! pci_dev) {
1861 ; 1822 pci_dev = pci_get_class(PCI_ERMC_CLASSCODE, NULL);
1862 else if ((pci_dev = pci_get_class(PCI_ERMC_CLASSCODE, NULL)) && 1823 if (pci_dev && (pci_dev->subsystem_vendor == PCI_HP_VENDOR_ID))
1863 pci_dev->subsystem_vendor == PCI_HP_VENDOR_ID) 1824 fe_rmc = 1;
1864 fe_rmc = 1; 1825 else
1865 else 1826 return -ENODEV;
1866 return -ENODEV; 1827 }
1867 1828
1868 error = pci_read_config_word(pci_dev, PCI_MMC_ADDR_CW, &base_addr); 1829 error = pci_read_config_word(pci_dev, PCI_MMC_ADDR_CW, &base_addr);
1869 if (error) 1830 if (error)
@@ -1876,7 +1837,7 @@ static int find_pci_smic(int intf_num, struct smi_info **new_info)
1876 } 1837 }
1877 1838
1878 /* Bit 0: 1 specifies programmed I/O, 0 specifies memory mapped I/O */ 1839 /* Bit 0: 1 specifies programmed I/O, 0 specifies memory mapped I/O */
1879 if (!(base_addr & 0x0001)) 1840 if (! (base_addr & 0x0001))
1880 { 1841 {
1881 pci_dev_put(pci_dev); 1842 pci_dev_put(pci_dev);
1882 printk(KERN_ERR 1843 printk(KERN_ERR
@@ -1886,17 +1847,17 @@ static int find_pci_smic(int intf_num, struct smi_info **new_info)
1886 } 1847 }
1887 1848
1888 base_addr &= 0xFFFE; 1849 base_addr &= 0xFFFE;
1889 if (!fe_rmc) 1850 if (! fe_rmc)
1890 /* Data register starts at base address + 1 in eRMC */ 1851 /* Data register starts at base address + 1 in eRMC */
1891 ++base_addr; 1852 ++base_addr;
1892 1853
1893 if (!is_new_interface(-1, IPMI_IO_ADDR_SPACE, base_addr)) { 1854 if (! is_new_interface(-1, IPMI_IO_ADDR_SPACE, base_addr)) {
1894 pci_dev_put(pci_dev); 1855 pci_dev_put(pci_dev);
1895 return -ENODEV; 1856 return -ENODEV;
1896 } 1857 }
1897 1858
1898 info = kmalloc(sizeof(*info), GFP_KERNEL); 1859 info = kmalloc(sizeof(*info), GFP_KERNEL);
1899 if (!info) { 1860 if (! info) {
1900 pci_dev_put(pci_dev); 1861 pci_dev_put(pci_dev);
1901 printk(KERN_ERR "ipmi_si: Could not allocate SI data (5)\n"); 1862 printk(KERN_ERR "ipmi_si: Could not allocate SI data (5)\n");
1902 return -ENOMEM; 1863 return -ENOMEM;
@@ -1907,7 +1868,7 @@ static int find_pci_smic(int intf_num, struct smi_info **new_info)
1907 ports[intf_num] = base_addr; 1868 ports[intf_num] = base_addr;
1908 info->io.info = &(ports[intf_num]); 1869 info->io.info = &(ports[intf_num]);
1909 info->io.regspacing = regspacings[intf_num]; 1870 info->io.regspacing = regspacings[intf_num];
1910 if (!info->io.regspacing) 1871 if (! info->io.regspacing)
1911 info->io.regspacing = DEFAULT_REGSPACING; 1872 info->io.regspacing = DEFAULT_REGSPACING;
1912 info->io.regsize = DEFAULT_REGSPACING; 1873 info->io.regsize = DEFAULT_REGSPACING;
1913 info->io.regshift = regshifts[intf_num]; 1874 info->io.regshift = regshifts[intf_num];
@@ -1928,7 +1889,7 @@ static int find_pci_smic(int intf_num, struct smi_info **new_info)
1928static int try_init_plug_and_play(int intf_num, struct smi_info **new_info) 1889static int try_init_plug_and_play(int intf_num, struct smi_info **new_info)
1929{ 1890{
1930#ifdef CONFIG_PCI 1891#ifdef CONFIG_PCI
1931 if (find_pci_smic(intf_num, new_info)==0) 1892 if (find_pci_smic(intf_num, new_info) == 0)
1932 return 0; 1893 return 0;
1933#endif 1894#endif
1934 /* Include other methods here. */ 1895 /* Include other methods here. */
@@ -1946,7 +1907,7 @@ static int try_get_dev_id(struct smi_info *smi_info)
1946 int rv = 0; 1907 int rv = 0;
1947 1908
1948 resp = kmalloc(IPMI_MAX_MSG_LENGTH, GFP_KERNEL); 1909 resp = kmalloc(IPMI_MAX_MSG_LENGTH, GFP_KERNEL);
1949 if (!resp) 1910 if (! resp)
1950 return -ENOMEM; 1911 return -ENOMEM;
1951 1912
1952 /* Do a Get Device ID command, since it comes back with some 1913 /* Do a Get Device ID command, since it comes back with some
@@ -1995,11 +1956,8 @@ static int try_get_dev_id(struct smi_info *smi_info)
1995 } 1956 }
1996 1957
1997 /* Record info from the get device id, in case we need it. */ 1958 /* Record info from the get device id, in case we need it. */
1998 smi_info->ipmi_si_dev_rev = resp[4] & 0xf; 1959 memcpy(&smi_info->device_id, &resp[3],
1999 smi_info->ipmi_si_fw_rev_major = resp[5] & 0x7f; 1960 min_t(unsigned long, resp_len-3, sizeof(smi_info->device_id)));
2000 smi_info->ipmi_si_fw_rev_minor = resp[6];
2001 smi_info->ipmi_version_major = resp[7] & 0xf;
2002 smi_info->ipmi_version_minor = resp[7] >> 4;
2003 1961
2004 out: 1962 out:
2005 kfree(resp); 1963 kfree(resp);
@@ -2031,7 +1989,7 @@ static int stat_file_read_proc(char *page, char **start, off_t off,
2031 struct smi_info *smi = data; 1989 struct smi_info *smi = data;
2032 1990
2033 out += sprintf(out, "interrupts_enabled: %d\n", 1991 out += sprintf(out, "interrupts_enabled: %d\n",
2034 smi->irq && !smi->interrupt_disabled); 1992 smi->irq && ! smi->interrupt_disabled);
2035 out += sprintf(out, "short_timeouts: %ld\n", 1993 out += sprintf(out, "short_timeouts: %ld\n",
2036 smi->short_timeouts); 1994 smi->short_timeouts);
2037 out += sprintf(out, "long_timeouts: %ld\n", 1995 out += sprintf(out, "long_timeouts: %ld\n",
@@ -2060,6 +2018,73 @@ static int stat_file_read_proc(char *page, char **start, off_t off,
2060 return (out - ((char *) page)); 2018 return (out - ((char *) page));
2061} 2019}
2062 2020
2021/*
2022 * oem_data_avail_to_receive_msg_avail
2023 * @info - smi_info structure with msg_flags set
2024 *
2025 * Converts flags from OEM_DATA_AVAIL to RECEIVE_MSG_AVAIL
2026 * Returns 1 indicating need to re-run handle_flags().
2027 */
2028static int oem_data_avail_to_receive_msg_avail(struct smi_info *smi_info)
2029{
2030 smi_info->msg_flags = ((smi_info->msg_flags & ~OEM_DATA_AVAIL) |
2031 RECEIVE_MSG_AVAIL);
2032 return 1;
2033}
2034
2035/*
2036 * setup_dell_poweredge_oem_data_handler
2037 * @info - smi_info.device_id must be populated
2038 *
2039 * Systems that match, but have firmware version < 1.40 may assert
2040 * OEM0_DATA_AVAIL on their own, without being told via Set Flags that
2041 * it's safe to do so. Such systems will de-assert OEM1_DATA_AVAIL
2042 * upon receipt of IPMI_GET_MSG_CMD, so we should treat these flags
2043 * as RECEIVE_MSG_AVAIL instead.
2044 *
2045 * As Dell has no plans to release IPMI 1.5 firmware that *ever*
2046 * assert the OEM[012] bits, and if it did, the driver would have to
2047 * change to handle that properly, we don't actually check for the
2048 * firmware version.
2049 * Device ID = 0x20 BMC on PowerEdge 8G servers
2050 * Device Revision = 0x80
2051 * Firmware Revision1 = 0x01 BMC version 1.40
2052 * Firmware Revision2 = 0x40 BCD encoded
2053 * IPMI Version = 0x51 IPMI 1.5
2054 * Manufacturer ID = A2 02 00 Dell IANA
2055 *
2056 */
2057#define DELL_POWEREDGE_8G_BMC_DEVICE_ID 0x20
2058#define DELL_POWEREDGE_8G_BMC_DEVICE_REV 0x80
2059#define DELL_POWEREDGE_8G_BMC_IPMI_VERSION 0x51
2060#define DELL_IANA_MFR_ID {0xA2, 0x02, 0x00}
2061static void setup_dell_poweredge_oem_data_handler(struct smi_info *smi_info)
2062{
2063 struct ipmi_device_id *id = &smi_info->device_id;
2064 const char mfr[3]=DELL_IANA_MFR_ID;
2065 if (! memcmp(mfr, id->manufacturer_id, sizeof(mfr))
2066 && (id->device_id == DELL_POWEREDGE_8G_BMC_DEVICE_ID)
2067 && (id->device_revision == DELL_POWEREDGE_8G_BMC_DEVICE_REV)
2068 && (id->ipmi_version == DELL_POWEREDGE_8G_BMC_IPMI_VERSION))
2069 {
2070 smi_info->oem_data_avail_handler =
2071 oem_data_avail_to_receive_msg_avail;
2072 }
2073}
2074
2075/*
2076 * setup_oem_data_handler
2077 * @info - smi_info.device_id must be filled in already
2078 *
2079 * Fills in smi_info.device_id.oem_data_available_handler
2080 * when we know what function to use there.
2081 */
2082
2083static void setup_oem_data_handler(struct smi_info *smi_info)
2084{
2085 setup_dell_poweredge_oem_data_handler(smi_info);
2086}
2087
2063/* Returns 0 if initialized, or negative on an error. */ 2088/* Returns 0 if initialized, or negative on an error. */
2064static int init_one_smi(int intf_num, struct smi_info **smi) 2089static int init_one_smi(int intf_num, struct smi_info **smi)
2065{ 2090{
@@ -2071,19 +2096,15 @@ static int init_one_smi(int intf_num, struct smi_info **smi)
2071 if (rv) 2096 if (rv)
2072 rv = try_init_port(intf_num, &new_smi); 2097 rv = try_init_port(intf_num, &new_smi);
2073#ifdef CONFIG_ACPI 2098#ifdef CONFIG_ACPI
2074 if ((rv) && (si_trydefaults)) { 2099 if (rv && si_trydefaults)
2075 rv = try_init_acpi(intf_num, &new_smi); 2100 rv = try_init_acpi(intf_num, &new_smi);
2076 }
2077#endif 2101#endif
2078#ifdef CONFIG_X86 2102#ifdef CONFIG_X86
2079 if ((rv) && (si_trydefaults)) { 2103 if (rv && si_trydefaults)
2080 rv = try_init_smbios(intf_num, &new_smi); 2104 rv = try_init_smbios(intf_num, &new_smi);
2081 }
2082#endif 2105#endif
2083 if ((rv) && (si_trydefaults)) { 2106 if (rv && si_trydefaults)
2084 rv = try_init_plug_and_play(intf_num, &new_smi); 2107 rv = try_init_plug_and_play(intf_num, &new_smi);
2085 }
2086
2087 2108
2088 if (rv) 2109 if (rv)
2089 return rv; 2110 return rv;
@@ -2093,7 +2114,7 @@ static int init_one_smi(int intf_num, struct smi_info **smi)
2093 new_smi->si_sm = NULL; 2114 new_smi->si_sm = NULL;
2094 new_smi->handlers = NULL; 2115 new_smi->handlers = NULL;
2095 2116
2096 if (!new_smi->irq_setup) { 2117 if (! new_smi->irq_setup) {
2097 new_smi->irq = irqs[intf_num]; 2118 new_smi->irq = irqs[intf_num];
2098 new_smi->irq_setup = std_irq_setup; 2119 new_smi->irq_setup = std_irq_setup;
2099 new_smi->irq_cleanup = std_irq_cleanup; 2120 new_smi->irq_cleanup = std_irq_cleanup;
@@ -2127,7 +2148,7 @@ static int init_one_smi(int intf_num, struct smi_info **smi)
2127 2148
2128 /* Allocate the state machine's data and initialize it. */ 2149 /* Allocate the state machine's data and initialize it. */
2129 new_smi->si_sm = kmalloc(new_smi->handlers->size(), GFP_KERNEL); 2150 new_smi->si_sm = kmalloc(new_smi->handlers->size(), GFP_KERNEL);
2130 if (!new_smi->si_sm) { 2151 if (! new_smi->si_sm) {
2131 printk(" Could not allocate state machine memory\n"); 2152 printk(" Could not allocate state machine memory\n");
2132 rv = -ENOMEM; 2153 rv = -ENOMEM;
2133 goto out_err; 2154 goto out_err;
@@ -2158,6 +2179,8 @@ static int init_one_smi(int intf_num, struct smi_info **smi)
2158 if (rv) 2179 if (rv)
2159 goto out_err; 2180 goto out_err;
2160 2181
2182 setup_oem_data_handler(new_smi);
2183
2161 /* Try to claim any interrupts. */ 2184 /* Try to claim any interrupts. */
2162 new_smi->irq_setup(new_smi); 2185 new_smi->irq_setup(new_smi);
2163 2186
@@ -2191,8 +2214,8 @@ static int init_one_smi(int intf_num, struct smi_info **smi)
2191 2214
2192 rv = ipmi_register_smi(&handlers, 2215 rv = ipmi_register_smi(&handlers,
2193 new_smi, 2216 new_smi,
2194 new_smi->ipmi_version_major, 2217 ipmi_version_major(&new_smi->device_id),
2195 new_smi->ipmi_version_minor, 2218 ipmi_version_minor(&new_smi->device_id),
2196 new_smi->slave_addr, 2219 new_smi->slave_addr,
2197 &(new_smi->intf)); 2220 &(new_smi->intf));
2198 if (rv) { 2221 if (rv) {
@@ -2233,7 +2256,7 @@ static int init_one_smi(int intf_num, struct smi_info **smi)
2233 2256
2234 /* Wait for the timer to stop. This avoids problems with race 2257 /* Wait for the timer to stop. This avoids problems with race
2235 conditions removing the timer here. */ 2258 conditions removing the timer here. */
2236 while (!new_smi->timer_stopped) { 2259 while (! new_smi->timer_stopped) {
2237 set_current_state(TASK_UNINTERRUPTIBLE); 2260 set_current_state(TASK_UNINTERRUPTIBLE);
2238 schedule_timeout(1); 2261 schedule_timeout(1);
2239 } 2262 }
@@ -2273,7 +2296,7 @@ static __init int init_ipmi_si(void)
2273 /* Parse out the si_type string into its components. */ 2296 /* Parse out the si_type string into its components. */
2274 str = si_type_str; 2297 str = si_type_str;
2275 if (*str != '\0') { 2298 if (*str != '\0') {
2276 for (i=0; (i<SI_MAX_PARMS) && (*str != '\0'); i++) { 2299 for (i = 0; (i < SI_MAX_PARMS) && (*str != '\0'); i++) {
2277 si_type[i] = str; 2300 si_type[i] = str;
2278 str = strchr(str, ','); 2301 str = strchr(str, ',');
2279 if (str) { 2302 if (str) {
@@ -2285,22 +2308,14 @@ static __init int init_ipmi_si(void)
2285 } 2308 }
2286 } 2309 }
2287 2310
2288 printk(KERN_INFO "IPMI System Interface driver version " 2311 printk(KERN_INFO "IPMI System Interface driver.\n");
2289 IPMI_SI_VERSION);
2290 if (kcs_smi_handlers.version)
2291 printk(", KCS version %s", kcs_smi_handlers.version);
2292 if (smic_smi_handlers.version)
2293 printk(", SMIC version %s", smic_smi_handlers.version);
2294 if (bt_smi_handlers.version)
2295 printk(", BT version %s", bt_smi_handlers.version);
2296 printk("\n");
2297 2312
2298#ifdef CONFIG_X86 2313#ifdef CONFIG_X86
2299 dmi_decode(); 2314 dmi_find_bmc();
2300#endif 2315#endif
2301 2316
2302 rv = init_one_smi(0, &(smi_infos[pos])); 2317 rv = init_one_smi(0, &(smi_infos[pos]));
2303 if (rv && !ports[0] && si_trydefaults) { 2318 if (rv && ! ports[0] && si_trydefaults) {
2304 /* If we are trying defaults and the initial port is 2319 /* If we are trying defaults and the initial port is
2305 not set, then set it. */ 2320 not set, then set it. */
2306 si_type[0] = "kcs"; 2321 si_type[0] = "kcs";
@@ -2322,7 +2337,7 @@ static __init int init_ipmi_si(void)
2322 if (rv == 0) 2337 if (rv == 0)
2323 pos++; 2338 pos++;
2324 2339
2325 for (i=1; i < SI_MAX_PARMS; i++) { 2340 for (i = 1; i < SI_MAX_PARMS; i++) {
2326 rv = init_one_smi(i, &(smi_infos[pos])); 2341 rv = init_one_smi(i, &(smi_infos[pos]));
2327 if (rv == 0) 2342 if (rv == 0)
2328 pos++; 2343 pos++;
@@ -2364,14 +2379,14 @@ static void __exit cleanup_one_si(struct smi_info *to_clean)
2364 2379
2365 /* Wait for the timer to stop. This avoids problems with race 2380 /* Wait for the timer to stop. This avoids problems with race
2366 conditions removing the timer here. */ 2381 conditions removing the timer here. */
2367 while (!to_clean->timer_stopped) { 2382 while (! to_clean->timer_stopped) {
2368 set_current_state(TASK_UNINTERRUPTIBLE); 2383 set_current_state(TASK_UNINTERRUPTIBLE);
2369 schedule_timeout(1); 2384 schedule_timeout(1);
2370 } 2385 }
2371 2386
2372 /* Interrupts and timeouts are stopped, now make sure the 2387 /* Interrupts and timeouts are stopped, now make sure the
2373 interface is in a clean state. */ 2388 interface is in a clean state. */
2374 while ((to_clean->curr_msg) || (to_clean->si_state != SI_NORMAL)) { 2389 while (to_clean->curr_msg || (to_clean->si_state != SI_NORMAL)) {
2375 poll(to_clean); 2390 poll(to_clean);
2376 set_current_state(TASK_UNINTERRUPTIBLE); 2391 set_current_state(TASK_UNINTERRUPTIBLE);
2377 schedule_timeout(1); 2392 schedule_timeout(1);
@@ -2395,13 +2410,15 @@ static __exit void cleanup_ipmi_si(void)
2395{ 2410{
2396 int i; 2411 int i;
2397 2412
2398 if (!initialized) 2413 if (! initialized)
2399 return; 2414 return;
2400 2415
2401 for (i=0; i<SI_MAX_DRIVERS; i++) { 2416 for (i = 0; i < SI_MAX_DRIVERS; i++) {
2402 cleanup_one_si(smi_infos[i]); 2417 cleanup_one_si(smi_infos[i]);
2403 } 2418 }
2404} 2419}
2405module_exit(cleanup_ipmi_si); 2420module_exit(cleanup_ipmi_si);
2406 2421
2407MODULE_LICENSE("GPL"); 2422MODULE_LICENSE("GPL");
2423MODULE_AUTHOR("Corey Minyard <minyard@mvista.com>");
2424MODULE_DESCRIPTION("Interface to the IPMI driver for the KCS, SMIC, and BT system interfaces.");
diff --git a/drivers/char/ipmi/ipmi_smic_sm.c b/drivers/char/ipmi/ipmi_smic_sm.c
index ae18747e670..add2aa2732f 100644
--- a/drivers/char/ipmi/ipmi_smic_sm.c
+++ b/drivers/char/ipmi/ipmi_smic_sm.c
@@ -46,8 +46,6 @@
46#include <linux/ipmi_msgdefs.h> /* for completion codes */ 46#include <linux/ipmi_msgdefs.h> /* for completion codes */
47#include "ipmi_si_sm.h" 47#include "ipmi_si_sm.h"
48 48
49#define IPMI_SMIC_VERSION "v33"
50
51/* smic_debug is a bit-field 49/* smic_debug is a bit-field
52 * SMIC_DEBUG_ENABLE - turned on for now 50 * SMIC_DEBUG_ENABLE - turned on for now
53 * SMIC_DEBUG_MSG - commands and their responses 51 * SMIC_DEBUG_MSG - commands and their responses
@@ -588,7 +586,6 @@ static int smic_size(void)
588 586
589struct si_sm_handlers smic_smi_handlers = 587struct si_sm_handlers smic_smi_handlers =
590{ 588{
591 .version = IPMI_SMIC_VERSION,
592 .init_data = init_smic_data, 589 .init_data = init_smic_data,
593 .start_transaction = start_smic_transaction, 590 .start_transaction = start_smic_transaction,
594 .get_result = smic_get_result, 591 .get_result = smic_get_result,
diff --git a/drivers/char/ipmi/ipmi_watchdog.c b/drivers/char/ipmi/ipmi_watchdog.c
index d35a953961c..e71aaae855a 100644
--- a/drivers/char/ipmi/ipmi_watchdog.c
+++ b/drivers/char/ipmi/ipmi_watchdog.c
@@ -53,8 +53,6 @@
53 53
54#define PFX "IPMI Watchdog: " 54#define PFX "IPMI Watchdog: "
55 55
56#define IPMI_WATCHDOG_VERSION "v33"
57
58/* 56/*
59 * The IPMI command/response information for the watchdog timer. 57 * The IPMI command/response information for the watchdog timer.
60 */ 58 */
@@ -259,7 +257,7 @@ static int i_ipmi_set_timeout(struct ipmi_smi_msg *smi_msg,
259 257
260 data[1] = 0; 258 data[1] = 0;
261 WDOG_SET_TIMEOUT_ACT(data[1], ipmi_watchdog_state); 259 WDOG_SET_TIMEOUT_ACT(data[1], ipmi_watchdog_state);
262 if (pretimeout > 0) { 260 if ((pretimeout > 0) && (ipmi_watchdog_state != WDOG_TIMEOUT_NONE)) {
263 WDOG_SET_PRETIMEOUT_ACT(data[1], preaction_val); 261 WDOG_SET_PRETIMEOUT_ACT(data[1], preaction_val);
264 data[2] = pretimeout; 262 data[2] = pretimeout;
265 } else { 263 } else {
@@ -659,19 +657,18 @@ static ssize_t ipmi_read(struct file *file,
659 657
660static int ipmi_open(struct inode *ino, struct file *filep) 658static int ipmi_open(struct inode *ino, struct file *filep)
661{ 659{
662 switch (iminor(ino)) 660 switch (iminor(ino)) {
663 { 661 case WATCHDOG_MINOR:
664 case WATCHDOG_MINOR: 662 if (test_and_set_bit(0, &ipmi_wdog_open))
665 if(test_and_set_bit(0, &ipmi_wdog_open))
666 return -EBUSY; 663 return -EBUSY;
667 664
668 /* Don't start the timer now, let it start on the 665 /* Don't start the timer now, let it start on the
669 first heartbeat. */ 666 first heartbeat. */
670 ipmi_start_timer_on_heartbeat = 1; 667 ipmi_start_timer_on_heartbeat = 1;
671 return nonseekable_open(ino, filep); 668 return nonseekable_open(ino, filep);
672 669
673 default: 670 default:
674 return (-ENODEV); 671 return (-ENODEV);
675 } 672 }
676} 673}
677 674
@@ -817,15 +814,19 @@ static void ipmi_register_watchdog(int ipmi_intf)
817static int 814static int
818ipmi_nmi(void *dev_id, struct pt_regs *regs, int cpu, int handled) 815ipmi_nmi(void *dev_id, struct pt_regs *regs, int cpu, int handled)
819{ 816{
817 /* If we are not expecting a timeout, ignore it. */
818 if (ipmi_watchdog_state == WDOG_TIMEOUT_NONE)
819 return NOTIFY_DONE;
820
820 /* If no one else handled the NMI, we assume it was the IPMI 821 /* If no one else handled the NMI, we assume it was the IPMI
821 watchdog. */ 822 watchdog. */
822 if ((!handled) && (preop_val == WDOG_PREOP_PANIC)) 823 if ((!handled) && (preop_val == WDOG_PREOP_PANIC)) {
824 /* On some machines, the heartbeat will give
825 an error and not work unless we re-enable
826 the timer. So do so. */
827 pretimeout_since_last_heartbeat = 1;
823 panic(PFX "pre-timeout"); 828 panic(PFX "pre-timeout");
824 829 }
825 /* On some machines, the heartbeat will give
826 an error and not work unless we re-enable
827 the timer. So do so. */
828 pretimeout_since_last_heartbeat = 1;
829 830
830 return NOTIFY_DONE; 831 return NOTIFY_DONE;
831} 832}
@@ -924,9 +925,6 @@ static int __init ipmi_wdog_init(void)
924{ 925{
925 int rv; 926 int rv;
926 927
927 printk(KERN_INFO PFX "driver version "
928 IPMI_WATCHDOG_VERSION "\n");
929
930 if (strcmp(action, "reset") == 0) { 928 if (strcmp(action, "reset") == 0) {
931 action_val = WDOG_TIMEOUT_RESET; 929 action_val = WDOG_TIMEOUT_RESET;
932 } else if (strcmp(action, "none") == 0) { 930 } else if (strcmp(action, "none") == 0) {
@@ -1011,6 +1009,8 @@ static int __init ipmi_wdog_init(void)
1011 register_reboot_notifier(&wdog_reboot_notifier); 1009 register_reboot_notifier(&wdog_reboot_notifier);
1012 notifier_chain_register(&panic_notifier_list, &wdog_panic_notifier); 1010 notifier_chain_register(&panic_notifier_list, &wdog_panic_notifier);
1013 1011
1012 printk(KERN_INFO PFX "driver initialized\n");
1013
1014 return 0; 1014 return 0;
1015} 1015}
1016 1016
@@ -1062,3 +1062,5 @@ static void __exit ipmi_wdog_exit(void)
1062module_exit(ipmi_wdog_exit); 1062module_exit(ipmi_wdog_exit);
1063module_init(ipmi_wdog_init); 1063module_init(ipmi_wdog_init);
1064MODULE_LICENSE("GPL"); 1064MODULE_LICENSE("GPL");
1065MODULE_AUTHOR("Corey Minyard <minyard@mvista.com>");
1066MODULE_DESCRIPTION("watchdog timer based upon the IPMI interface.");
diff --git a/drivers/char/mbcs.c b/drivers/char/mbcs.c
index 115dbb35334..3fa64c63110 100644
--- a/drivers/char/mbcs.c
+++ b/drivers/char/mbcs.c
@@ -750,7 +750,7 @@ static int mbcs_probe(struct cx_dev *dev, const struct cx_device_id *id)
750 750
751 dev->soft = NULL; 751 dev->soft = NULL;
752 752
753 soft = kcalloc(1, sizeof(struct mbcs_soft), GFP_KERNEL); 753 soft = kzalloc(sizeof(struct mbcs_soft), GFP_KERNEL);
754 if (soft == NULL) 754 if (soft == NULL)
755 return -ENOMEM; 755 return -ENOMEM;
756 756
diff --git a/drivers/char/mem.c b/drivers/char/mem.c
index 850a78c9c4b..f182752fe91 100644
--- a/drivers/char/mem.c
+++ b/drivers/char/mem.c
@@ -35,10 +35,6 @@
35# include <linux/efi.h> 35# include <linux/efi.h>
36#endif 36#endif
37 37
38#if defined(CONFIG_S390_TAPE) && defined(CONFIG_S390_TAPE_CHAR)
39extern void tapechar_init(void);
40#endif
41
42/* 38/*
43 * Architectures vary in how they handle caching for addresses 39 * Architectures vary in how they handle caching for addresses
44 * outside of main memory. 40 * outside of main memory.
diff --git a/drivers/char/misc.c b/drivers/char/misc.c
index 931efd58f87..0c8375165e2 100644
--- a/drivers/char/misc.c
+++ b/drivers/char/misc.c
@@ -63,8 +63,6 @@ static DECLARE_MUTEX(misc_sem);
63#define DYNAMIC_MINORS 64 /* like dynamic majors */ 63#define DYNAMIC_MINORS 64 /* like dynamic majors */
64static unsigned char misc_minors[DYNAMIC_MINORS / 8]; 64static unsigned char misc_minors[DYNAMIC_MINORS / 8];
65 65
66extern int rtc_DP8570A_init(void);
67extern int rtc_MK48T08_init(void);
68extern int pmu_device_init(void); 66extern int pmu_device_init(void);
69 67
70#ifdef CONFIG_PROC_FS 68#ifdef CONFIG_PROC_FS
@@ -303,12 +301,7 @@ static int __init misc_init(void)
303 misc_class = class_create(THIS_MODULE, "misc"); 301 misc_class = class_create(THIS_MODULE, "misc");
304 if (IS_ERR(misc_class)) 302 if (IS_ERR(misc_class))
305 return PTR_ERR(misc_class); 303 return PTR_ERR(misc_class);
306#ifdef CONFIG_MVME16x 304
307 rtc_MK48T08_init();
308#endif
309#ifdef CONFIG_BVME6000
310 rtc_DP8570A_init();
311#endif
312 if (register_chrdev(MISC_MAJOR,"misc",&misc_fops)) { 305 if (register_chrdev(MISC_MAJOR,"misc",&misc_fops)) {
313 printk("unable to get major %d for misc devices\n", 306 printk("unable to get major %d for misc devices\n",
314 MISC_MAJOR); 307 MISC_MAJOR);
diff --git a/drivers/char/moxa.c b/drivers/char/moxa.c
index 95f7046ff05..79e490ef2cf 100644
--- a/drivers/char/moxa.c
+++ b/drivers/char/moxa.c
@@ -339,7 +339,7 @@ static int __init moxa_init(void)
339 339
340 init_MUTEX(&moxaBuffSem); 340 init_MUTEX(&moxaBuffSem);
341 moxaDriver->owner = THIS_MODULE; 341 moxaDriver->owner = THIS_MODULE;
342 moxaDriver->name = "ttya"; 342 moxaDriver->name = "ttyMX";
343 moxaDriver->devfs_name = "tts/a"; 343 moxaDriver->devfs_name = "tts/a";
344 moxaDriver->major = ttymajor; 344 moxaDriver->major = ttymajor;
345 moxaDriver->minor_start = 0; 345 moxaDriver->minor_start = 0;
diff --git a/drivers/char/mxser.c b/drivers/char/mxser.c
index f022f094443..d0ef1ae4129 100644
--- a/drivers/char/mxser.c
+++ b/drivers/char/mxser.c
@@ -63,7 +63,6 @@
63#include <asm/system.h> 63#include <asm/system.h>
64#include <asm/io.h> 64#include <asm/io.h>
65#include <asm/irq.h> 65#include <asm/irq.h>
66#include <asm/segment.h>
67#include <asm/bitops.h> 66#include <asm/bitops.h>
68#include <asm/uaccess.h> 67#include <asm/uaccess.h>
69 68
diff --git a/drivers/char/rtc.c b/drivers/char/rtc.c
index cd4fe8b1709..63fff7c1244 100644
--- a/drivers/char/rtc.c
+++ b/drivers/char/rtc.c
@@ -938,10 +938,9 @@ found:
938 938
939 /* 939 /*
940 * XXX Interrupt pin #7 in Espresso is shared between RTC and 940 * XXX Interrupt pin #7 in Espresso is shared between RTC and
941 * PCI Slot 2 INTA# (and some INTx# in Slot 1). SA_INTERRUPT here 941 * PCI Slot 2 INTA# (and some INTx# in Slot 1).
942 * is asking for trouble with add-on boards. Change to SA_SHIRQ.
943 */ 942 */
944 if (request_irq(rtc_irq, rtc_interrupt, SA_INTERRUPT, "rtc", (void *)&rtc_port)) { 943 if (request_irq(rtc_irq, rtc_interrupt, SA_SHIRQ, "rtc", (void *)&rtc_port)) {
945 /* 944 /*
946 * Standard way for sparc to print irq's is to use 945 * Standard way for sparc to print irq's is to use
947 * __irq_itoa(). I think for EBus it's ok to use %d. 946 * __irq_itoa(). I think for EBus it's ok to use %d.
diff --git a/drivers/char/sonypi.c b/drivers/char/sonypi.c
index cefbe985e55..36ae9ad2598 100644
--- a/drivers/char/sonypi.c
+++ b/drivers/char/sonypi.c
@@ -98,12 +98,13 @@ MODULE_PARM_DESC(useinput,
98 98
99#define SONYPI_DEVICE_MODEL_TYPE1 1 99#define SONYPI_DEVICE_MODEL_TYPE1 1
100#define SONYPI_DEVICE_MODEL_TYPE2 2 100#define SONYPI_DEVICE_MODEL_TYPE2 2
101#define SONYPI_DEVICE_MODEL_TYPE3 3
101 102
102/* type1 models use those */ 103/* type1 models use those */
103#define SONYPI_IRQ_PORT 0x8034 104#define SONYPI_IRQ_PORT 0x8034
104#define SONYPI_IRQ_SHIFT 22 105#define SONYPI_IRQ_SHIFT 22
105#define SONYPI_BASE 0x50 106#define SONYPI_TYPE1_BASE 0x50
106#define SONYPI_G10A (SONYPI_BASE+0x14) 107#define SONYPI_G10A (SONYPI_TYPE1_BASE+0x14)
107#define SONYPI_TYPE1_REGION_SIZE 0x08 108#define SONYPI_TYPE1_REGION_SIZE 0x08
108#define SONYPI_TYPE1_EVTYPE_OFFSET 0x04 109#define SONYPI_TYPE1_EVTYPE_OFFSET 0x04
109 110
@@ -114,6 +115,13 @@ MODULE_PARM_DESC(useinput,
114#define SONYPI_TYPE2_REGION_SIZE 0x20 115#define SONYPI_TYPE2_REGION_SIZE 0x20
115#define SONYPI_TYPE2_EVTYPE_OFFSET 0x12 116#define SONYPI_TYPE2_EVTYPE_OFFSET 0x12
116 117
118/* type3 series specifics */
119#define SONYPI_TYPE3_BASE 0x40
120#define SONYPI_TYPE3_GID2 (SONYPI_TYPE3_BASE+0x48) /* 16 bits */
121#define SONYPI_TYPE3_MISC (SONYPI_TYPE3_BASE+0x6d) /* 8 bits */
122#define SONYPI_TYPE3_REGION_SIZE 0x20
123#define SONYPI_TYPE3_EVTYPE_OFFSET 0x12
124
117/* battery / brightness addresses */ 125/* battery / brightness addresses */
118#define SONYPI_BAT_FLAGS 0x81 126#define SONYPI_BAT_FLAGS 0x81
119#define SONYPI_LCD_LIGHT 0x96 127#define SONYPI_LCD_LIGHT 0x96
@@ -159,6 +167,10 @@ static struct sonypi_ioport_list sonypi_type2_ioport_list[] = {
159 { 0x0, 0x0 } 167 { 0x0, 0x0 }
160}; 168};
161 169
170/* same as in type 2 models */
171static struct sonypi_ioport_list *sonypi_type3_ioport_list =
172 sonypi_type2_ioport_list;
173
162/* The set of possible interrupts */ 174/* The set of possible interrupts */
163struct sonypi_irq_list { 175struct sonypi_irq_list {
164 u16 irq; 176 u16 irq;
@@ -180,6 +192,9 @@ static struct sonypi_irq_list sonypi_type2_irq_list[] = {
180 { 0, 0x00 } /* no IRQ, 0x00 in SIRQ in AML */ 192 { 0, 0x00 } /* no IRQ, 0x00 in SIRQ in AML */
181}; 193};
182 194
195/* same as in type2 models */
196static struct sonypi_irq_list *sonypi_type3_irq_list = sonypi_type2_irq_list;
197
183#define SONYPI_CAMERA_BRIGHTNESS 0 198#define SONYPI_CAMERA_BRIGHTNESS 0
184#define SONYPI_CAMERA_CONTRAST 1 199#define SONYPI_CAMERA_CONTRAST 1
185#define SONYPI_CAMERA_HUE 2 200#define SONYPI_CAMERA_HUE 2
@@ -223,6 +238,7 @@ static struct sonypi_irq_list sonypi_type2_irq_list[] = {
223#define SONYPI_MEYE_MASK 0x00000400 238#define SONYPI_MEYE_MASK 0x00000400
224#define SONYPI_MEMORYSTICK_MASK 0x00000800 239#define SONYPI_MEMORYSTICK_MASK 0x00000800
225#define SONYPI_BATTERY_MASK 0x00001000 240#define SONYPI_BATTERY_MASK 0x00001000
241#define SONYPI_WIRELESS_MASK 0x00002000
226 242
227struct sonypi_event { 243struct sonypi_event {
228 u8 data; 244 u8 data;
@@ -305,6 +321,13 @@ static struct sonypi_event sonypi_blueev[] = {
305 { 0, 0 } 321 { 0, 0 }
306}; 322};
307 323
324/* The set of possible wireless events */
325static struct sonypi_event sonypi_wlessev[] = {
326 { 0x59, SONYPI_EVENT_WIRELESS_ON },
327 { 0x5a, SONYPI_EVENT_WIRELESS_OFF },
328 { 0, 0 }
329};
330
308/* The set of possible back button events */ 331/* The set of possible back button events */
309static struct sonypi_event sonypi_backev[] = { 332static struct sonypi_event sonypi_backev[] = {
310 { 0x20, SONYPI_EVENT_BACK_PRESSED }, 333 { 0x20, SONYPI_EVENT_BACK_PRESSED },
@@ -383,7 +406,6 @@ static struct sonypi_eventtypes {
383 { SONYPI_DEVICE_MODEL_TYPE2, 0x31, SONYPI_BLUETOOTH_MASK, sonypi_blueev }, 406 { SONYPI_DEVICE_MODEL_TYPE2, 0x31, SONYPI_BLUETOOTH_MASK, sonypi_blueev },
384 { SONYPI_DEVICE_MODEL_TYPE2, 0x08, SONYPI_PKEY_MASK, sonypi_pkeyev }, 407 { SONYPI_DEVICE_MODEL_TYPE2, 0x08, SONYPI_PKEY_MASK, sonypi_pkeyev },
385 { SONYPI_DEVICE_MODEL_TYPE2, 0x11, SONYPI_BACK_MASK, sonypi_backev }, 408 { SONYPI_DEVICE_MODEL_TYPE2, 0x11, SONYPI_BACK_MASK, sonypi_backev },
386 { SONYPI_DEVICE_MODEL_TYPE2, 0x08, SONYPI_HELP_MASK, sonypi_helpev },
387 { SONYPI_DEVICE_MODEL_TYPE2, 0x21, SONYPI_HELP_MASK, sonypi_helpev }, 409 { SONYPI_DEVICE_MODEL_TYPE2, 0x21, SONYPI_HELP_MASK, sonypi_helpev },
388 { SONYPI_DEVICE_MODEL_TYPE2, 0x21, SONYPI_ZOOM_MASK, sonypi_zoomev }, 410 { SONYPI_DEVICE_MODEL_TYPE2, 0x21, SONYPI_ZOOM_MASK, sonypi_zoomev },
389 { SONYPI_DEVICE_MODEL_TYPE2, 0x20, SONYPI_THUMBPHRASE_MASK, sonypi_thumbphraseev }, 411 { SONYPI_DEVICE_MODEL_TYPE2, 0x20, SONYPI_THUMBPHRASE_MASK, sonypi_thumbphraseev },
@@ -391,6 +413,12 @@ static struct sonypi_eventtypes {
391 { SONYPI_DEVICE_MODEL_TYPE2, 0x41, SONYPI_BATTERY_MASK, sonypi_batteryev }, 413 { SONYPI_DEVICE_MODEL_TYPE2, 0x41, SONYPI_BATTERY_MASK, sonypi_batteryev },
392 { SONYPI_DEVICE_MODEL_TYPE2, 0x31, SONYPI_PKEY_MASK, sonypi_pkeyev }, 414 { SONYPI_DEVICE_MODEL_TYPE2, 0x31, SONYPI_PKEY_MASK, sonypi_pkeyev },
393 415
416 { SONYPI_DEVICE_MODEL_TYPE3, 0, 0xffffffff, sonypi_releaseev },
417 { SONYPI_DEVICE_MODEL_TYPE3, 0x21, SONYPI_FNKEY_MASK, sonypi_fnkeyev },
418 { SONYPI_DEVICE_MODEL_TYPE3, 0x31, SONYPI_WIRELESS_MASK, sonypi_wlessev },
419 { SONYPI_DEVICE_MODEL_TYPE3, 0x31, SONYPI_MEMORYSTICK_MASK, sonypi_memorystickev },
420 { SONYPI_DEVICE_MODEL_TYPE3, 0x41, SONYPI_BATTERY_MASK, sonypi_batteryev },
421 { SONYPI_DEVICE_MODEL_TYPE3, 0x31, SONYPI_PKEY_MASK, sonypi_pkeyev },
394 { 0 } 422 { 0 }
395}; 423};
396 424
@@ -563,6 +591,23 @@ static void sonypi_type2_srs(void)
563 udelay(10); 591 udelay(10);
564} 592}
565 593
594static void sonypi_type3_srs(void)
595{
596 u16 v16;
597 u8 v8;
598
599 /* This model type uses the same initialiazation of
600 * the embedded controller as the type2 models. */
601 sonypi_type2_srs();
602
603 /* Initialization of PCI config space of the LPC interface bridge. */
604 v16 = (sonypi_device.ioport1 & 0xFFF0) | 0x01;
605 pci_write_config_word(sonypi_device.dev, SONYPI_TYPE3_GID2, v16);
606 pci_read_config_byte(sonypi_device.dev, SONYPI_TYPE3_MISC, &v8);
607 v8 = (v8 & 0xCF) | 0x10;
608 pci_write_config_byte(sonypi_device.dev, SONYPI_TYPE3_MISC, v8);
609}
610
566/* Disables the device - this comes from the AML code in the ACPI bios */ 611/* Disables the device - this comes from the AML code in the ACPI bios */
567static void sonypi_type1_dis(void) 612static void sonypi_type1_dis(void)
568{ 613{
@@ -587,6 +632,13 @@ static void sonypi_type2_dis(void)
587 printk(KERN_WARNING "ec_write failed\n"); 632 printk(KERN_WARNING "ec_write failed\n");
588} 633}
589 634
635static void sonypi_type3_dis(void)
636{
637 sonypi_type2_dis();
638 udelay(10);
639 pci_write_config_word(sonypi_device.dev, SONYPI_TYPE3_GID2, 0);
640}
641
590static u8 sonypi_call1(u8 dev) 642static u8 sonypi_call1(u8 dev)
591{ 643{
592 u8 v1, v2; 644 u8 v1, v2;
@@ -1067,10 +1119,17 @@ static struct miscdevice sonypi_misc_device = {
1067 1119
1068static void sonypi_enable(unsigned int camera_on) 1120static void sonypi_enable(unsigned int camera_on)
1069{ 1121{
1070 if (sonypi_device.model == SONYPI_DEVICE_MODEL_TYPE2) 1122 switch (sonypi_device.model) {
1071 sonypi_type2_srs(); 1123 case SONYPI_DEVICE_MODEL_TYPE1:
1072 else
1073 sonypi_type1_srs(); 1124 sonypi_type1_srs();
1125 break;
1126 case SONYPI_DEVICE_MODEL_TYPE2:
1127 sonypi_type2_srs();
1128 break;
1129 case SONYPI_DEVICE_MODEL_TYPE3:
1130 sonypi_type3_srs();
1131 break;
1132 }
1074 1133
1075 sonypi_call1(0x82); 1134 sonypi_call1(0x82);
1076 sonypi_call2(0x81, 0xff); 1135 sonypi_call2(0x81, 0xff);
@@ -1094,10 +1153,18 @@ static int sonypi_disable(void)
1094 if (!SONYPI_ACPI_ACTIVE && fnkeyinit) 1153 if (!SONYPI_ACPI_ACTIVE && fnkeyinit)
1095 outb(0xf1, 0xb2); 1154 outb(0xf1, 0xb2);
1096 1155
1097 if (sonypi_device.model == SONYPI_DEVICE_MODEL_TYPE2) 1156 switch (sonypi_device.model) {
1098 sonypi_type2_dis(); 1157 case SONYPI_DEVICE_MODEL_TYPE1:
1099 else
1100 sonypi_type1_dis(); 1158 sonypi_type1_dis();
1159 break;
1160 case SONYPI_DEVICE_MODEL_TYPE2:
1161 sonypi_type2_dis();
1162 break;
1163 case SONYPI_DEVICE_MODEL_TYPE3:
1164 sonypi_type3_dis();
1165 break;
1166 }
1167
1101 return 0; 1168 return 0;
1102} 1169}
1103 1170
@@ -1143,12 +1210,16 @@ static int __devinit sonypi_probe(void)
1143 struct sonypi_irq_list *irq_list; 1210 struct sonypi_irq_list *irq_list;
1144 struct pci_dev *pcidev; 1211 struct pci_dev *pcidev;
1145 1212
1146 pcidev = pci_get_device(PCI_VENDOR_ID_INTEL, 1213 if ((pcidev = pci_get_device(PCI_VENDOR_ID_INTEL,
1147 PCI_DEVICE_ID_INTEL_82371AB_3, NULL); 1214 PCI_DEVICE_ID_INTEL_82371AB_3, NULL)))
1215 sonypi_device.model = SONYPI_DEVICE_MODEL_TYPE1;
1216 else if ((pcidev = pci_get_device(PCI_VENDOR_ID_INTEL,
1217 PCI_DEVICE_ID_INTEL_ICH6_1, NULL)))
1218 sonypi_device.model = SONYPI_DEVICE_MODEL_TYPE3;
1219 else
1220 sonypi_device.model = SONYPI_DEVICE_MODEL_TYPE2;
1148 1221
1149 sonypi_device.dev = pcidev; 1222 sonypi_device.dev = pcidev;
1150 sonypi_device.model = pcidev ?
1151 SONYPI_DEVICE_MODEL_TYPE1 : SONYPI_DEVICE_MODEL_TYPE2;
1152 1223
1153 spin_lock_init(&sonypi_device.fifo_lock); 1224 spin_lock_init(&sonypi_device.fifo_lock);
1154 sonypi_device.fifo = kfifo_alloc(SONYPI_BUF_SIZE, GFP_KERNEL, 1225 sonypi_device.fifo = kfifo_alloc(SONYPI_BUF_SIZE, GFP_KERNEL,
@@ -1176,16 +1247,22 @@ static int __devinit sonypi_probe(void)
1176 goto out_miscreg; 1247 goto out_miscreg;
1177 } 1248 }
1178 1249
1179 if (sonypi_device.model == SONYPI_DEVICE_MODEL_TYPE2) { 1250
1251 if (sonypi_device.model == SONYPI_DEVICE_MODEL_TYPE1) {
1252 ioport_list = sonypi_type1_ioport_list;
1253 sonypi_device.region_size = SONYPI_TYPE1_REGION_SIZE;
1254 sonypi_device.evtype_offset = SONYPI_TYPE1_EVTYPE_OFFSET;
1255 irq_list = sonypi_type1_irq_list;
1256 } else if (sonypi_device.model == SONYPI_DEVICE_MODEL_TYPE2) {
1180 ioport_list = sonypi_type2_ioport_list; 1257 ioport_list = sonypi_type2_ioport_list;
1181 sonypi_device.region_size = SONYPI_TYPE2_REGION_SIZE; 1258 sonypi_device.region_size = SONYPI_TYPE2_REGION_SIZE;
1182 sonypi_device.evtype_offset = SONYPI_TYPE2_EVTYPE_OFFSET; 1259 sonypi_device.evtype_offset = SONYPI_TYPE2_EVTYPE_OFFSET;
1183 irq_list = sonypi_type2_irq_list; 1260 irq_list = sonypi_type2_irq_list;
1184 } else { 1261 } else {
1185 ioport_list = sonypi_type1_ioport_list; 1262 ioport_list = sonypi_type3_ioport_list;
1186 sonypi_device.region_size = SONYPI_TYPE1_REGION_SIZE; 1263 sonypi_device.region_size = SONYPI_TYPE3_REGION_SIZE;
1187 sonypi_device.evtype_offset = SONYPI_TYPE1_EVTYPE_OFFSET; 1264 sonypi_device.evtype_offset = SONYPI_TYPE3_EVTYPE_OFFSET;
1188 irq_list = sonypi_type1_irq_list; 1265 irq_list = sonypi_type3_irq_list;
1189 } 1266 }
1190 1267
1191 for (i = 0; ioport_list[i].port1; i++) { 1268 for (i = 0; ioport_list[i].port1; i++) {
@@ -1274,11 +1351,10 @@ static int __devinit sonypi_probe(void)
1274 1351
1275 printk(KERN_INFO "sonypi: Sony Programmable I/O Controller Driver" 1352 printk(KERN_INFO "sonypi: Sony Programmable I/O Controller Driver"
1276 "v%s.\n", SONYPI_DRIVER_VERSION); 1353 "v%s.\n", SONYPI_DRIVER_VERSION);
1277 printk(KERN_INFO "sonypi: detected %s model, " 1354 printk(KERN_INFO "sonypi: detected type%d model, "
1278 "verbose = %d, fnkeyinit = %s, camera = %s, " 1355 "verbose = %d, fnkeyinit = %s, camera = %s, "
1279 "compat = %s, mask = 0x%08lx, useinput = %s, acpi = %s\n", 1356 "compat = %s, mask = 0x%08lx, useinput = %s, acpi = %s\n",
1280 (sonypi_device.model == SONYPI_DEVICE_MODEL_TYPE1) ? 1357 sonypi_device.model,
1281 "type1" : "type2",
1282 verbose, 1358 verbose,
1283 fnkeyinit ? "on" : "off", 1359 fnkeyinit ? "on" : "off",
1284 camera ? "on" : "off", 1360 camera ? "on" : "off",
diff --git a/drivers/char/tpm/tpm_atmel.c b/drivers/char/tpm/tpm_atmel.c
index cc2cc77fd17..c0d64914595 100644
--- a/drivers/char/tpm/tpm_atmel.c
+++ b/drivers/char/tpm/tpm_atmel.c
@@ -206,6 +206,9 @@ static struct pci_device_id tpm_pci_tbl[] __devinitdata = {
206 {PCI_DEVICE(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_82801DB_0)}, 206 {PCI_DEVICE(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_82801DB_0)},
207 {PCI_DEVICE(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_82801DB_12)}, 207 {PCI_DEVICE(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_82801DB_12)},
208 {PCI_DEVICE(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_82801EB_0)}, 208 {PCI_DEVICE(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_82801EB_0)},
209 {PCI_DEVICE(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_ICH6_0)},
210 {PCI_DEVICE(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_ICH6_1)},
211 {PCI_DEVICE(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_ICH7_0)},
209 {PCI_DEVICE(PCI_VENDOR_ID_AMD, PCI_DEVICE_ID_AMD_8111_LPC)}, 212 {PCI_DEVICE(PCI_VENDOR_ID_AMD, PCI_DEVICE_ID_AMD_8111_LPC)},
210 {PCI_DEVICE(PCI_VENDOR_ID_SERVERWORKS, PCI_DEVICE_ID_SERVERWORKS_CSB6LPC)}, 213 {PCI_DEVICE(PCI_VENDOR_ID_SERVERWORKS, PCI_DEVICE_ID_SERVERWORKS_CSB6LPC)},
211 {0,} 214 {0,}
diff --git a/drivers/char/tpm/tpm_infineon.c b/drivers/char/tpm/tpm_infineon.c
index dc8c540391f..939e51e119e 100644
--- a/drivers/char/tpm/tpm_infineon.c
+++ b/drivers/char/tpm/tpm_infineon.c
@@ -14,7 +14,6 @@
14 * License. 14 * License.
15 */ 15 */
16 16
17#include <acpi/acpi_bus.h>
18#include <linux/pnp.h> 17#include <linux/pnp.h>
19#include "tpm.h" 18#include "tpm.h"
20 19
@@ -29,9 +28,10 @@
29#define TPM_MAX_TRIES 5000 28#define TPM_MAX_TRIES 5000
30#define TPM_INFINEON_DEV_VEN_VALUE 0x15D1 29#define TPM_INFINEON_DEV_VEN_VALUE 0x15D1
31 30
32/* These values will be filled after ACPI-call */ 31/* These values will be filled after PnP-call */
33static int TPM_INF_DATA = 0; 32static int TPM_INF_DATA = 0;
34static int TPM_INF_ADDR = 0; 33static int TPM_INF_ADDR = 0;
34static int pnp_registered = 0;
35 35
36/* TPM header definitions */ 36/* TPM header definitions */
37enum infineon_tpm_header { 37enum infineon_tpm_header {
@@ -356,24 +356,26 @@ static const struct pnp_device_id tpm_pnp_tbl[] = {
356 {"IFX0102", 0}, 356 {"IFX0102", 0},
357 {"", 0} 357 {"", 0}
358}; 358};
359MODULE_DEVICE_TABLE(pnp, tpm_pnp_tbl);
359 360
360static int __devinit tpm_inf_acpi_probe(struct pnp_dev *dev, 361static int __devinit tpm_inf_pnp_probe(struct pnp_dev *dev,
361 const struct pnp_device_id *dev_id) 362 const struct pnp_device_id *dev_id)
362{ 363{
363 TPM_INF_ADDR = (pnp_port_start(dev, 0) & 0xff); 364 if (pnp_port_valid(dev, 0)) {
364 TPM_INF_DATA = ((TPM_INF_ADDR + 1) & 0xff); 365 TPM_INF_ADDR = (pnp_port_start(dev, 0) & 0xff);
365 tpm_inf.base = pnp_port_start(dev, 1); 366 TPM_INF_DATA = ((TPM_INF_ADDR + 1) & 0xff);
366 dev_info(&dev->dev, "Found %s with ID %s\n", 367 tpm_inf.base = pnp_port_start(dev, 1);
367 dev->name, dev_id->id); 368 dev_info(&dev->dev, "Found %s with ID %s\n",
368 if (!((tpm_inf.base >> 8) & 0xff)) 369 dev->name, dev_id->id);
369 tpm_inf.base = 0; 370 return 0;
370 return 0; 371 }
372 return -ENODEV;
371} 373}
372 374
373static struct pnp_driver tpm_inf_pnp = { 375static struct pnp_driver tpm_inf_pnp = {
374 .name = "tpm_inf_pnp", 376 .name = "tpm_inf_pnp",
375 .id_table = tpm_pnp_tbl, 377 .id_table = tpm_pnp_tbl,
376 .probe = tpm_inf_acpi_probe, 378 .probe = tpm_inf_pnp_probe,
377}; 379};
378 380
379static int __devinit tpm_inf_probe(struct pci_dev *pci_dev, 381static int __devinit tpm_inf_probe(struct pci_dev *pci_dev,
@@ -386,19 +388,30 @@ static int __devinit tpm_inf_probe(struct pci_dev *pci_dev,
386 int productid[2]; 388 int productid[2];
387 char chipname[20]; 389 char chipname[20];
388 390
389 if (pci_enable_device(pci_dev)) 391 rc = pci_enable_device(pci_dev);
390 return -EIO; 392 if (rc)
393 return rc;
391 394
392 dev_info(&pci_dev->dev, "LPC-bus found at 0x%x\n", pci_id->device); 395 dev_info(&pci_dev->dev, "LPC-bus found at 0x%x\n", pci_id->device);
393 396
394 /* read IO-ports from ACPI */ 397 /* read IO-ports from PnP */
395 pnp_register_driver(&tpm_inf_pnp); 398 rc = pnp_register_driver(&tpm_inf_pnp);
396 pnp_unregister_driver(&tpm_inf_pnp); 399 if (rc < 0) {
400 dev_err(&pci_dev->dev,
401 "Error %x from pnp_register_driver!\n",rc);
402 goto error2;
403 }
404 if (!rc) {
405 dev_info(&pci_dev->dev, "No Infineon TPM found!\n");
406 goto error;
407 } else {
408 pnp_registered = 1;
409 }
397 410
398 /* Make sure, we have received valid config ports */ 411 /* Make sure, we have received valid config ports */
399 if (!TPM_INF_ADDR) { 412 if (!TPM_INF_ADDR) {
400 pci_disable_device(pci_dev); 413 dev_err(&pci_dev->dev, "No valid IO-ports received!\n");
401 return -EIO; 414 goto error;
402 } 415 }
403 416
404 /* query chip for its vendor, its version number a.s.o. */ 417 /* query chip for its vendor, its version number a.s.o. */
@@ -418,23 +431,21 @@ static int __devinit tpm_inf_probe(struct pci_dev *pci_dev,
418 431
419 switch ((productid[0] << 8) | productid[1]) { 432 switch ((productid[0] << 8) | productid[1]) {
420 case 6: 433 case 6:
421 sprintf(chipname, " (SLD 9630 TT 1.1)"); 434 snprintf(chipname, sizeof(chipname), " (SLD 9630 TT 1.1)");
422 break; 435 break;
423 case 11: 436 case 11:
424 sprintf(chipname, " (SLB 9635 TT 1.2)"); 437 snprintf(chipname, sizeof(chipname), " (SLB 9635 TT 1.2)");
425 break; 438 break;
426 default: 439 default:
427 sprintf(chipname, " (unknown chip)"); 440 snprintf(chipname, sizeof(chipname), " (unknown chip)");
428 break; 441 break;
429 } 442 }
430 chipname[19] = 0;
431 443
432 if ((vendorid[0] << 8 | vendorid[1]) == (TPM_INFINEON_DEV_VEN_VALUE)) { 444 if ((vendorid[0] << 8 | vendorid[1]) == (TPM_INFINEON_DEV_VEN_VALUE)) {
433 445
434 if (tpm_inf.base == 0) { 446 if (tpm_inf.base == 0) {
435 dev_err(&pci_dev->dev, "No IO-ports found!\n"); 447 dev_err(&pci_dev->dev, "No IO-ports found!\n");
436 pci_disable_device(pci_dev); 448 goto error;
437 return -EIO;
438 } 449 }
439 /* configure TPM with IO-ports */ 450 /* configure TPM with IO-ports */
440 outb(IOLIMH, TPM_INF_ADDR); 451 outb(IOLIMH, TPM_INF_ADDR);
@@ -452,8 +463,7 @@ static int __devinit tpm_inf_probe(struct pci_dev *pci_dev,
452 dev_err(&pci_dev->dev, 463 dev_err(&pci_dev->dev,
453 "Could not set IO-ports to %04x\n", 464 "Could not set IO-ports to %04x\n",
454 tpm_inf.base); 465 tpm_inf.base);
455 pci_disable_device(pci_dev); 466 goto error;
456 return -EIO;
457 } 467 }
458 468
459 /* activate register */ 469 /* activate register */
@@ -479,14 +489,16 @@ static int __devinit tpm_inf_probe(struct pci_dev *pci_dev,
479 productid[0], productid[1], chipname); 489 productid[0], productid[1], chipname);
480 490
481 rc = tpm_register_hardware(pci_dev, &tpm_inf); 491 rc = tpm_register_hardware(pci_dev, &tpm_inf);
482 if (rc < 0) { 492 if (rc < 0)
483 pci_disable_device(pci_dev); 493 goto error;
484 return -ENODEV;
485 }
486 return 0; 494 return 0;
487 } else { 495 } else {
488 dev_info(&pci_dev->dev, "No Infineon TPM found!\n"); 496 dev_info(&pci_dev->dev, "No Infineon TPM found!\n");
497error:
498 pnp_unregister_driver(&tpm_inf_pnp);
499error2:
489 pci_disable_device(pci_dev); 500 pci_disable_device(pci_dev);
501 pnp_registered = 0;
490 return -ENODEV; 502 return -ENODEV;
491 } 503 }
492} 504}
@@ -521,6 +533,8 @@ static int __init init_inf(void)
521 533
522static void __exit cleanup_inf(void) 534static void __exit cleanup_inf(void)
523{ 535{
536 if (pnp_registered)
537 pnp_unregister_driver(&tpm_inf_pnp);
524 pci_unregister_driver(&inf_pci_driver); 538 pci_unregister_driver(&inf_pci_driver);
525} 539}
526 540
diff --git a/drivers/char/tty_io.c b/drivers/char/tty_io.c
index 6e4be3bb2d8..9d657127f31 100644
--- a/drivers/char/tty_io.c
+++ b/drivers/char/tty_io.c
@@ -153,7 +153,6 @@ static int tty_release(struct inode *, struct file *);
153int tty_ioctl(struct inode * inode, struct file * file, 153int tty_ioctl(struct inode * inode, struct file * file,
154 unsigned int cmd, unsigned long arg); 154 unsigned int cmd, unsigned long arg);
155static int tty_fasync(int fd, struct file * filp, int on); 155static int tty_fasync(int fd, struct file * filp, int on);
156extern void rs_360_init(void);
157static void release_mem(struct tty_struct *tty, int idx); 156static void release_mem(struct tty_struct *tty, int idx);
158 157
159 158
@@ -2911,11 +2910,6 @@ void __init console_init(void)
2911#ifdef CONFIG_EARLY_PRINTK 2910#ifdef CONFIG_EARLY_PRINTK
2912 disable_early_printk(); 2911 disable_early_printk();
2913#endif 2912#endif
2914#ifdef CONFIG_SERIAL_68360
2915 /* This is not a console initcall. I know not what it's doing here.
2916 So I haven't moved it. dwmw2 */
2917 rs_360_init();
2918#endif
2919 call = __con_initcall_start; 2913 call = __con_initcall_start;
2920 while (call < __con_initcall_end) { 2914 while (call < __con_initcall_end) {
2921 (*call)(); 2915 (*call)();
diff --git a/drivers/char/vt.c b/drivers/char/vt.c
index 665103ccaee..b8d0c290b0d 100644
--- a/drivers/char/vt.c
+++ b/drivers/char/vt.c
@@ -434,21 +434,25 @@ void invert_screen(struct vc_data *vc, int offset, int count, int viewed)
434/* used by selection: complement pointer position */ 434/* used by selection: complement pointer position */
435void complement_pos(struct vc_data *vc, int offset) 435void complement_pos(struct vc_data *vc, int offset)
436{ 436{
437 static unsigned short *p; 437 static int old_offset = -1;
438 static unsigned short old; 438 static unsigned short old;
439 static unsigned short oldx, oldy; 439 static unsigned short oldx, oldy;
440 440
441 WARN_CONSOLE_UNLOCKED(); 441 WARN_CONSOLE_UNLOCKED();
442 442
443 if (p) { 443 if (old_offset != -1 && old_offset >= 0 &&
444 scr_writew(old, p); 444 old_offset < vc->vc_screenbuf_size) {
445 scr_writew(old, screenpos(vc, old_offset, 1));
445 if (DO_UPDATE(vc)) 446 if (DO_UPDATE(vc))
446 vc->vc_sw->con_putc(vc, old, oldy, oldx); 447 vc->vc_sw->con_putc(vc, old, oldy, oldx);
447 } 448 }
448 if (offset == -1) 449
449 p = NULL; 450 old_offset = offset;
450 else { 451
452 if (offset != -1 && offset >= 0 &&
453 offset < vc->vc_screenbuf_size) {
451 unsigned short new; 454 unsigned short new;
455 unsigned short *p;
452 p = screenpos(vc, offset, 1); 456 p = screenpos(vc, offset, 1);
453 old = scr_readw(p); 457 old = scr_readw(p);
454 new = old ^ vc->vc_complement_mask; 458 new = old ^ vc->vc_complement_mask;
@@ -459,6 +463,7 @@ void complement_pos(struct vc_data *vc, int offset)
459 vc->vc_sw->con_putc(vc, new, oldy, oldx); 463 vc->vc_sw->con_putc(vc, new, oldy, oldx);
460 } 464 }
461 } 465 }
466
462} 467}
463 468
464static void insert_char(struct vc_data *vc, unsigned int nr) 469static void insert_char(struct vc_data *vc, unsigned int nr)
@@ -2272,7 +2277,9 @@ int tioclinux(struct tty_struct *tty, unsigned long arg)
2272 ret = paste_selection(tty); 2277 ret = paste_selection(tty);
2273 break; 2278 break;
2274 case TIOCL_UNBLANKSCREEN: 2279 case TIOCL_UNBLANKSCREEN:
2280 acquire_console_sem();
2275 unblank_screen(); 2281 unblank_screen();
2282 release_console_sem();
2276 break; 2283 break;
2277 case TIOCL_SELLOADLUT: 2284 case TIOCL_SELLOADLUT:
2278 ret = sel_loadlut(p); 2285 ret = sel_loadlut(p);
@@ -2317,8 +2324,10 @@ int tioclinux(struct tty_struct *tty, unsigned long arg)
2317 } 2324 }
2318 break; 2325 break;
2319 case TIOCL_BLANKSCREEN: /* until explicitly unblanked, not only poked */ 2326 case TIOCL_BLANKSCREEN: /* until explicitly unblanked, not only poked */
2327 acquire_console_sem();
2320 ignore_poke = 1; 2328 ignore_poke = 1;
2321 do_blank_screen(0); 2329 do_blank_screen(0);
2330 release_console_sem();
2322 break; 2331 break;
2323 case TIOCL_BLANKEDSCREEN: 2332 case TIOCL_BLANKEDSCREEN:
2324 ret = console_blanked; 2333 ret = console_blanked;
diff --git a/drivers/char/watchdog/Kconfig b/drivers/char/watchdog/Kconfig
index b53e2e2b5ae..c3898afce3a 100644
--- a/drivers/char/watchdog/Kconfig
+++ b/drivers/char/watchdog/Kconfig
@@ -346,6 +346,13 @@ config 8xx_WDT
346 tristate "MPC8xx Watchdog Timer" 346 tristate "MPC8xx Watchdog Timer"
347 depends on WATCHDOG && 8xx 347 depends on WATCHDOG && 8xx
348 348
349config BOOKE_WDT
350 tristate "PowerPC Book-E Watchdog Timer"
351 depends on WATCHDOG && (BOOKE || 4xx)
352 ---help---
353 Please see Documentation/watchdog/watchdog-api.txt for
354 more information.
355
349# MIPS Architecture 356# MIPS Architecture
350 357
351config INDYDOG 358config INDYDOG
diff --git a/drivers/char/watchdog/Makefile b/drivers/char/watchdog/Makefile
index c1838834ea7..cfeac6f1013 100644
--- a/drivers/char/watchdog/Makefile
+++ b/drivers/char/watchdog/Makefile
@@ -2,42 +2,68 @@
2# Makefile for the WatchDog device drivers. 2# Makefile for the WatchDog device drivers.
3# 3#
4 4
5# Only one watchdog can succeed. We probe the ISA/PCI/USB based
6# watchdog-cards first, then the architecture specific watchdog
7# drivers and then the architecture independant "softdog" driver.
8# This means that if your ISA/PCI/USB card isn't detected that
9# you can fall back to an architecture specific driver and if
10# that also fails then you can fall back to the software watchdog
11# to give you some cover.
12
13# ISA-based Watchdog Cards
5obj-$(CONFIG_PCWATCHDOG) += pcwd.o 14obj-$(CONFIG_PCWATCHDOG) += pcwd.o
6obj-$(CONFIG_ACQUIRE_WDT) += acquirewdt.o
7obj-$(CONFIG_ADVANTECH_WDT) += advantechwdt.o
8obj-$(CONFIG_IB700_WDT) += ib700wdt.o
9obj-$(CONFIG_MIXCOMWD) += mixcomwd.o 15obj-$(CONFIG_MIXCOMWD) += mixcomwd.o
10obj-$(CONFIG_SCx200_WDT) += scx200_wdt.o
11obj-$(CONFIG_60XX_WDT) += sbc60xxwdt.o
12obj-$(CONFIG_WDT) += wdt.o 16obj-$(CONFIG_WDT) += wdt.o
17
18# PCI-based Watchdog Cards
19obj-$(CONFIG_PCIPCWATCHDOG) += pcwd_pci.o
13obj-$(CONFIG_WDTPCI) += wdt_pci.o 20obj-$(CONFIG_WDTPCI) += wdt_pci.o
21
22# USB-based Watchdog Cards
23obj-$(CONFIG_USBPCWATCHDOG) += pcwd_usb.o
24
25# ARM Architecture
14obj-$(CONFIG_21285_WATCHDOG) += wdt285.o 26obj-$(CONFIG_21285_WATCHDOG) += wdt285.o
15obj-$(CONFIG_977_WATCHDOG) += wdt977.o 27obj-$(CONFIG_977_WATCHDOG) += wdt977.o
16obj-$(CONFIG_I8XX_TCO) += i8xx_tco.o 28obj-$(CONFIG_IXP2000_WATCHDOG) += ixp2000_wdt.o
17obj-$(CONFIG_MACHZ_WDT) += machzwd.o 29obj-$(CONFIG_IXP4XX_WATCHDOG) += ixp4xx_wdt.o
18obj-$(CONFIG_SH_WDT) += shwdt.o
19obj-$(CONFIG_S3C2410_WATCHDOG) += s3c2410_wdt.o 30obj-$(CONFIG_S3C2410_WATCHDOG) += s3c2410_wdt.o
20obj-$(CONFIG_SA1100_WATCHDOG) += sa1100_wdt.o 31obj-$(CONFIG_SA1100_WATCHDOG) += sa1100_wdt.o
21obj-$(CONFIG_EUROTECH_WDT) += eurotechwdt.o 32
22obj-$(CONFIG_W83877F_WDT) += w83877f_wdt.o 33# X86 (i386 + ia64 + x86_64) Architecture
23obj-$(CONFIG_W83627HF_WDT) += w83627hf_wdt.o 34obj-$(CONFIG_ACQUIRE_WDT) += acquirewdt.o
24obj-$(CONFIG_SC520_WDT) += sc520_wdt.o 35obj-$(CONFIG_ADVANTECH_WDT) += advantechwdt.o
25obj-$(CONFIG_ALIM7101_WDT) += alim7101_wdt.o
26obj-$(CONFIG_ALIM1535_WDT) += alim1535_wdt.o 36obj-$(CONFIG_ALIM1535_WDT) += alim1535_wdt.o
27obj-$(CONFIG_SC1200_WDT) += sc1200wdt.o 37obj-$(CONFIG_ALIM7101_WDT) += alim7101_wdt.o
38obj-$(CONFIG_SC520_WDT) += sc520_wdt.o
39obj-$(CONFIG_EUROTECH_WDT) += eurotechwdt.o
40obj-$(CONFIG_IB700_WDT) += ib700wdt.o
28obj-$(CONFIG_WAFER_WDT) += wafer5823wdt.o 41obj-$(CONFIG_WAFER_WDT) += wafer5823wdt.o
42obj-$(CONFIG_I8XX_TCO) += i8xx_tco.o
43obj-$(CONFIG_SC1200_WDT) += sc1200wdt.o
44obj-$(CONFIG_SCx200_WDT) += scx200_wdt.o
45obj-$(CONFIG_60XX_WDT) += sbc60xxwdt.o
29obj-$(CONFIG_CPU5_WDT) += cpu5wdt.o 46obj-$(CONFIG_CPU5_WDT) += cpu5wdt.o
30obj-$(CONFIG_INDYDOG) += indydog.o 47obj-$(CONFIG_W83627HF_WDT) += w83627hf_wdt.o
31obj-$(CONFIG_PCIPCWATCHDOG) += pcwd_pci.o 48obj-$(CONFIG_W83877F_WDT) += w83877f_wdt.o
32obj-$(CONFIG_USBPCWATCHDOG) += pcwd_usb.o 49obj-$(CONFIG_MACHZ_WDT) += machzwd.o
33obj-$(CONFIG_IXP4XX_WATCHDOG) += ixp4xx_wdt.o 50
34obj-$(CONFIG_IXP2000_WATCHDOG) += ixp2000_wdt.o 51# PowerPC Architecture
35obj-$(CONFIG_8xx_WDT) += mpc8xx_wdt.o 52obj-$(CONFIG_8xx_WDT) += mpc8xx_wdt.o
53
54# PPC64 Architecture
36obj-$(CONFIG_WATCHDOG_RTAS) += wdrtas.o 55obj-$(CONFIG_WATCHDOG_RTAS) += wdrtas.o
56obj-$(CONFIG_BOOKE_WDT) += booke_wdt.o
57
58# MIPS Architecture
59obj-$(CONFIG_INDYDOG) += indydog.o
60
61# S390 Architecture
62
63# SUPERH Architecture
64obj-$(CONFIG_SH_WDT) += shwdt.o
37 65
38# Only one watchdog can succeed. We probe the hardware watchdog 66# SPARC64 Architecture
39# drivers first, then the softdog driver. This means if your hardware
40# watchdog dies or is 'borrowed' for some reason the software watchdog
41# still gives you some cover.
42 67
68# Architecture Independant
43obj-$(CONFIG_SOFT_WATCHDOG) += softdog.o 69obj-$(CONFIG_SOFT_WATCHDOG) += softdog.o
diff --git a/drivers/char/watchdog/booke_wdt.c b/drivers/char/watchdog/booke_wdt.c
new file mode 100644
index 00000000000..abc30cca664
--- /dev/null
+++ b/drivers/char/watchdog/booke_wdt.c
@@ -0,0 +1,192 @@
1/*
2 * drivers/char/watchdog/booke_wdt.c
3 *
4 * Watchdog timer for PowerPC Book-E systems
5 *
6 * Author: Matthew McClintock
7 * Maintainer: Kumar Gala <kumar.gala@freescale.com>
8 *
9 * Copyright 2005 Freescale Semiconductor Inc.
10 *
11 * This program is free software; you can redistribute it and/or modify it
12 * under the terms of the GNU General Public License as published by the
13 * Free Software Foundation; either version 2 of the License, or (at your
14 * option) any later version.
15 */
16
17#include <linux/config.h>
18#include <linux/module.h>
19#include <linux/fs.h>
20#include <linux/miscdevice.h>
21#include <linux/notifier.h>
22#include <linux/watchdog.h>
23
24#include <asm/reg_booke.h>
25#include <asm/uaccess.h>
26#include <asm/system.h>
27
28/* If the kernel parameter wdt_enable=1, the watchdog will be enabled at boot.
29 * Also, the wdt_period sets the watchdog timer period timeout.
30 * For E500 cpus the wdt_period sets which bit changing from 0->1 will
31 * trigger a watchog timeout. This watchdog timeout will occur 3 times, the
32 * first time nothing will happen, the second time a watchdog exception will
33 * occur, and the final time the board will reset.
34 */
35
36#ifdef CONFIG_FSL_BOOKE
37#define WDT_PERIOD_DEFAULT 63 /* Ex. wdt_period=28 bus=333Mhz , reset=~40sec */
38#else
39#define WDT_PERIOD_DEFAULT 4 /* Refer to the PPC40x and PPC4xx manuals */
40#endif /* for timing information */
41
42u32 booke_wdt_enabled = 0;
43u32 booke_wdt_period = WDT_PERIOD_DEFAULT;
44
45#ifdef CONFIG_FSL_BOOKE
46#define WDTP(x) ((((63-x)&0x3)<<30)|(((63-x)&0x3c)<<15))
47#else
48#define WDTP(x) (TCR_WP(x))
49#endif
50
51/*
52 * booke_wdt_enable:
53 */
54static __inline__ void booke_wdt_enable(void)
55{
56 u32 val;
57
58 val = mfspr(SPRN_TCR);
59 val |= (TCR_WIE|TCR_WRC(WRC_CHIP)|WDTP(booke_wdt_period));
60
61 mtspr(SPRN_TCR, val);
62}
63
64/*
65 * booke_wdt_ping:
66 */
67static __inline__ void booke_wdt_ping(void)
68{
69 mtspr(SPRN_TSR, TSR_ENW|TSR_WIS);
70}
71
72/*
73 * booke_wdt_write:
74 */
75static ssize_t booke_wdt_write (struct file *file, const char *buf,
76 size_t count, loff_t *ppos)
77{
78 booke_wdt_ping();
79 return count;
80}
81
82static struct watchdog_info ident = {
83 .options = WDIOF_SETTIMEOUT | WDIOF_KEEPALIVEPING,
84 .firmware_version = 0,
85 .identity = "PowerPC Book-E Watchdog",
86};
87
88/*
89 * booke_wdt_ioctl:
90 */
91static int booke_wdt_ioctl (struct inode *inode, struct file *file,
92 unsigned int cmd, unsigned long arg)
93{
94 u32 tmp = 0;
95
96 switch (cmd) {
97 case WDIOC_GETSUPPORT:
98 if (copy_to_user ((struct watchdog_info *) arg, &ident,
99 sizeof(struct watchdog_info)))
100 return -EFAULT;
101 case WDIOC_GETSTATUS:
102 return put_user(ident.options, (u32 *) arg);
103 case WDIOC_GETBOOTSTATUS:
104 /* XXX: something is clearing TSR */
105 tmp = mfspr(SPRN_TSR) & TSR_WRS(3);
106 /* returns 1 if last reset was caused by the WDT */
107 return (tmp ? 1 : 0);
108 case WDIOC_KEEPALIVE:
109 booke_wdt_ping();
110 return 0;
111 case WDIOC_SETTIMEOUT:
112 if (get_user(booke_wdt_period, (u32 *) arg))
113 return -EFAULT;
114 mtspr(SPRN_TCR, (mfspr(SPRN_TCR)&~WDTP(0))|WDTP(booke_wdt_period));
115 return 0;
116 case WDIOC_GETTIMEOUT:
117 return put_user(booke_wdt_period, (u32 *) arg);
118 case WDIOC_SETOPTIONS:
119 if (get_user(tmp, (u32 *) arg))
120 return -EINVAL;
121 if (tmp == WDIOS_ENABLECARD) {
122 booke_wdt_ping();
123 break;
124 } else
125 return -EINVAL;
126 return 0;
127 default:
128 return -ENOIOCTLCMD;
129 }
130
131 return 0;
132}
133/*
134 * booke_wdt_open:
135 */
136static int booke_wdt_open (struct inode *inode, struct file *file)
137{
138 if (booke_wdt_enabled == 0) {
139 booke_wdt_enabled = 1;
140 booke_wdt_enable();
141 printk (KERN_INFO "PowerPC Book-E Watchdog Timer Enabled (wdt_period=%d)\n",
142 booke_wdt_period);
143 }
144
145 return 0;
146}
147
148static struct file_operations booke_wdt_fops = {
149 .owner = THIS_MODULE,
150 .llseek = no_llseek,
151 .write = booke_wdt_write,
152 .ioctl = booke_wdt_ioctl,
153 .open = booke_wdt_open,
154};
155
156static struct miscdevice booke_wdt_miscdev = {
157 .minor = WATCHDOG_MINOR,
158 .name = "watchdog",
159 .fops = &booke_wdt_fops,
160};
161
162static void __exit booke_wdt_exit(void)
163{
164 misc_deregister(&booke_wdt_miscdev);
165}
166
167/*
168 * booke_wdt_init:
169 */
170static int __init booke_wdt_init(void)
171{
172 int ret = 0;
173
174 printk (KERN_INFO "PowerPC Book-E Watchdog Timer Loaded\n");
175 ident.firmware_version = cpu_specs[0].pvr_value;
176
177 ret = misc_register(&booke_wdt_miscdev);
178 if (ret) {
179 printk (KERN_CRIT "Cannot register miscdev on minor=%d (err=%d)\n",
180 WATCHDOG_MINOR, ret);
181 return ret;
182 }
183
184 if (booke_wdt_enabled == 1) {
185 printk (KERN_INFO "PowerPC Book-E Watchdog Timer Enabled (wdt_period=%d)\n",
186 booke_wdt_period);
187 booke_wdt_enable();
188 }
189
190 return ret;
191}
192device_initcall(booke_wdt_init);
diff --git a/drivers/char/watchdog/ixp2000_wdt.c b/drivers/char/watchdog/ixp2000_wdt.c
index e7640bc4904..0cfb9b9c4a4 100644
--- a/drivers/char/watchdog/ixp2000_wdt.c
+++ b/drivers/char/watchdog/ixp2000_wdt.c
@@ -182,7 +182,7 @@ static struct file_operations ixp2000_wdt_fops =
182static struct miscdevice ixp2000_wdt_miscdev = 182static struct miscdevice ixp2000_wdt_miscdev =
183{ 183{
184 .minor = WATCHDOG_MINOR, 184 .minor = WATCHDOG_MINOR,
185 .name = "IXP2000 Watchdog", 185 .name = "watchdog",
186 .fops = &ixp2000_wdt_fops, 186 .fops = &ixp2000_wdt_fops,
187}; 187};
188 188
diff --git a/drivers/char/watchdog/ixp4xx_wdt.c b/drivers/char/watchdog/ixp4xx_wdt.c
index 8d916afbf4f..b5be8b11104 100644
--- a/drivers/char/watchdog/ixp4xx_wdt.c
+++ b/drivers/char/watchdog/ixp4xx_wdt.c
@@ -176,7 +176,7 @@ static struct file_operations ixp4xx_wdt_fops =
176static struct miscdevice ixp4xx_wdt_miscdev = 176static struct miscdevice ixp4xx_wdt_miscdev =
177{ 177{
178 .minor = WATCHDOG_MINOR, 178 .minor = WATCHDOG_MINOR,
179 .name = "IXP4xx Watchdog", 179 .name = "watchdog",
180 .fops = &ixp4xx_wdt_fops, 180 .fops = &ixp4xx_wdt_fops,
181}; 181};
182 182
diff --git a/drivers/char/watchdog/s3c2410_wdt.c b/drivers/char/watchdog/s3c2410_wdt.c
index f85ac898a49..8b292bf343c 100644
--- a/drivers/char/watchdog/s3c2410_wdt.c
+++ b/drivers/char/watchdog/s3c2410_wdt.c
@@ -27,7 +27,10 @@
27 * Fixed tmr_count / wdt_count confusion 27 * Fixed tmr_count / wdt_count confusion
28 * Added configurable debug 28 * Added configurable debug
29 * 29 *
30 * 11-Jan-2004 BJD Fixed divide-by-2 in timeout code 30 * 11-Jan-2005 BJD Fixed divide-by-2 in timeout code
31 *
32 * 25-Jan-2005 DA Added suspend/resume support
33 * Replaced reboot notifier with .shutdown method
31 * 34 *
32 * 10-Mar-2005 LCVR Changed S3C2410_VA to S3C24XX_VA 35 * 10-Mar-2005 LCVR Changed S3C2410_VA to S3C24XX_VA
33*/ 36*/
@@ -40,8 +43,6 @@
40#include <linux/miscdevice.h> 43#include <linux/miscdevice.h>
41#include <linux/watchdog.h> 44#include <linux/watchdog.h>
42#include <linux/fs.h> 45#include <linux/fs.h>
43#include <linux/notifier.h>
44#include <linux/reboot.h>
45#include <linux/init.h> 46#include <linux/init.h>
46#include <linux/device.h> 47#include <linux/device.h>
47#include <linux/interrupt.h> 48#include <linux/interrupt.h>
@@ -317,20 +318,6 @@ static int s3c2410wdt_ioctl(struct inode *inode, struct file *file,
317 } 318 }
318} 319}
319 320
320/*
321 * Notifier for system down
322 */
323
324static int s3c2410wdt_notify_sys(struct notifier_block *this, unsigned long code,
325 void *unused)
326{
327 if(code==SYS_DOWN || code==SYS_HALT) {
328 /* Turn the WDT off */
329 s3c2410wdt_stop();
330 }
331 return NOTIFY_DONE;
332}
333
334/* kernel interface */ 321/* kernel interface */
335 322
336static struct file_operations s3c2410wdt_fops = { 323static struct file_operations s3c2410wdt_fops = {
@@ -348,10 +335,6 @@ static struct miscdevice s3c2410wdt_miscdev = {
348 .fops = &s3c2410wdt_fops, 335 .fops = &s3c2410wdt_fops,
349}; 336};
350 337
351static struct notifier_block s3c2410wdt_notifier = {
352 .notifier_call = s3c2410wdt_notify_sys,
353};
354
355/* interrupt handler code */ 338/* interrupt handler code */
356 339
357static irqreturn_t s3c2410wdt_irq(int irqno, void *param, 340static irqreturn_t s3c2410wdt_irq(int irqno, void *param,
@@ -432,18 +415,10 @@ static int s3c2410wdt_probe(struct device *dev)
432 } 415 }
433 } 416 }
434 417
435 ret = register_reboot_notifier(&s3c2410wdt_notifier);
436 if (ret) {
437 printk (KERN_ERR PFX "cannot register reboot notifier (%d)\n",
438 ret);
439 return ret;
440 }
441
442 ret = misc_register(&s3c2410wdt_miscdev); 418 ret = misc_register(&s3c2410wdt_miscdev);
443 if (ret) { 419 if (ret) {
444 printk (KERN_ERR PFX "cannot register miscdev on minor=%d (%d)\n", 420 printk (KERN_ERR PFX "cannot register miscdev on minor=%d (%d)\n",
445 WATCHDOG_MINOR, ret); 421 WATCHDOG_MINOR, ret);
446 unregister_reboot_notifier(&s3c2410wdt_notifier);
447 return ret; 422 return ret;
448 } 423 }
449 424
@@ -479,15 +454,63 @@ static int s3c2410wdt_remove(struct device *dev)
479 return 0; 454 return 0;
480} 455}
481 456
457static void s3c2410wdt_shutdown(struct device *dev)
458{
459 s3c2410wdt_stop();
460}
461
462#ifdef CONFIG_PM
463
464static unsigned long wtcon_save;
465static unsigned long wtdat_save;
466
467static int s3c2410wdt_suspend(struct device *dev, u32 state, u32 level)
468{
469 if (level == SUSPEND_POWER_DOWN) {
470 /* Save watchdog state, and turn it off. */
471 wtcon_save = readl(wdt_base + S3C2410_WTCON);
472 wtdat_save = readl(wdt_base + S3C2410_WTDAT);
473
474 /* Note that WTCNT doesn't need to be saved. */
475 s3c2410wdt_stop();
476 }
477
478 return 0;
479}
480
481static int s3c2410wdt_resume(struct device *dev, u32 level)
482{
483 if (level == RESUME_POWER_ON) {
484 /* Restore watchdog state. */
485
486 writel(wtdat_save, wdt_base + S3C2410_WTDAT);
487 writel(wtdat_save, wdt_base + S3C2410_WTCNT); /* Reset count */
488 writel(wtcon_save, wdt_base + S3C2410_WTCON);
489
490 printk(KERN_INFO PFX "watchdog %sabled\n",
491 (wtcon_save & S3C2410_WTCON_ENABLE) ? "en" : "dis");
492 }
493
494 return 0;
495}
496
497#else
498#define s3c2410wdt_suspend NULL
499#define s3c2410wdt_resume NULL
500#endif /* CONFIG_PM */
501
502
482static struct device_driver s3c2410wdt_driver = { 503static struct device_driver s3c2410wdt_driver = {
483 .name = "s3c2410-wdt", 504 .name = "s3c2410-wdt",
484 .bus = &platform_bus_type, 505 .bus = &platform_bus_type,
485 .probe = s3c2410wdt_probe, 506 .probe = s3c2410wdt_probe,
486 .remove = s3c2410wdt_remove, 507 .remove = s3c2410wdt_remove,
508 .shutdown = s3c2410wdt_shutdown,
509 .suspend = s3c2410wdt_suspend,
510 .resume = s3c2410wdt_resume,
487}; 511};
488 512
489 513
490
491static char banner[] __initdata = KERN_INFO "S3C2410 Watchdog Timer, (c) 2004 Simtec Electronics\n"; 514static char banner[] __initdata = KERN_INFO "S3C2410 Watchdog Timer, (c) 2004 Simtec Electronics\n";
492 515
493static int __init watchdog_init(void) 516static int __init watchdog_init(void)
@@ -499,13 +522,13 @@ static int __init watchdog_init(void)
499static void __exit watchdog_exit(void) 522static void __exit watchdog_exit(void)
500{ 523{
501 driver_unregister(&s3c2410wdt_driver); 524 driver_unregister(&s3c2410wdt_driver);
502 unregister_reboot_notifier(&s3c2410wdt_notifier);
503} 525}
504 526
505module_init(watchdog_init); 527module_init(watchdog_init);
506module_exit(watchdog_exit); 528module_exit(watchdog_exit);
507 529
508MODULE_AUTHOR("Ben Dooks <ben@simtec.co.uk>"); 530MODULE_AUTHOR("Ben Dooks <ben@simtec.co.uk>, "
531 "Dimitry Andric <dimitry.andric@tomtom.com>");
509MODULE_DESCRIPTION("S3C2410 Watchdog Device Driver"); 532MODULE_DESCRIPTION("S3C2410 Watchdog Device Driver");
510MODULE_LICENSE("GPL"); 533MODULE_LICENSE("GPL");
511MODULE_ALIAS_MISCDEV(WATCHDOG_MINOR); 534MODULE_ALIAS_MISCDEV(WATCHDOG_MINOR);
diff --git a/drivers/char/watchdog/scx200_wdt.c b/drivers/char/watchdog/scx200_wdt.c
index c4568569f3a..b4a102a2d7e 100644
--- a/drivers/char/watchdog/scx200_wdt.c
+++ b/drivers/char/watchdog/scx200_wdt.c
@@ -206,7 +206,7 @@ static struct file_operations scx200_wdt_fops = {
206 206
207static struct miscdevice scx200_wdt_miscdev = { 207static struct miscdevice scx200_wdt_miscdev = {
208 .minor = WATCHDOG_MINOR, 208 .minor = WATCHDOG_MINOR,
209 .name = NAME, 209 .name = "watchdog",
210 .fops = &scx200_wdt_fops, 210 .fops = &scx200_wdt_fops,
211}; 211};
212 212
diff --git a/drivers/char/watchdog/softdog.c b/drivers/char/watchdog/softdog.c
index 4d7ed931f5c..20e5eb8667f 100644
--- a/drivers/char/watchdog/softdog.c
+++ b/drivers/char/watchdog/softdog.c
@@ -77,7 +77,7 @@ static void watchdog_fire(unsigned long);
77 77
78static struct timer_list watchdog_ticktock = 78static struct timer_list watchdog_ticktock =
79 TIMER_INITIALIZER(watchdog_fire, 0, 0); 79 TIMER_INITIALIZER(watchdog_fire, 0, 0);
80static unsigned long timer_alive; 80static unsigned long driver_open, orphan_timer;
81static char expect_close; 81static char expect_close;
82 82
83 83
@@ -87,6 +87,9 @@ static char expect_close;
87 87
88static void watchdog_fire(unsigned long data) 88static void watchdog_fire(unsigned long data)
89{ 89{
90 if (test_and_clear_bit(0, &orphan_timer))
91 module_put(THIS_MODULE);
92
90 if (soft_noboot) 93 if (soft_noboot)
91 printk(KERN_CRIT PFX "Triggered - Reboot ignored.\n"); 94 printk(KERN_CRIT PFX "Triggered - Reboot ignored.\n");
92 else 95 else
@@ -128,9 +131,9 @@ static int softdog_set_heartbeat(int t)
128 131
129static int softdog_open(struct inode *inode, struct file *file) 132static int softdog_open(struct inode *inode, struct file *file)
130{ 133{
131 if(test_and_set_bit(0, &timer_alive)) 134 if (test_and_set_bit(0, &driver_open))
132 return -EBUSY; 135 return -EBUSY;
133 if (nowayout) 136 if (!test_and_clear_bit(0, &orphan_timer))
134 __module_get(THIS_MODULE); 137 __module_get(THIS_MODULE);
135 /* 138 /*
136 * Activate timer 139 * Activate timer
@@ -147,11 +150,13 @@ static int softdog_release(struct inode *inode, struct file *file)
147 */ 150 */
148 if (expect_close == 42) { 151 if (expect_close == 42) {
149 softdog_stop(); 152 softdog_stop();
153 module_put(THIS_MODULE);
150 } else { 154 } else {
151 printk(KERN_CRIT PFX "Unexpected close, not stopping watchdog!\n"); 155 printk(KERN_CRIT PFX "Unexpected close, not stopping watchdog!\n");
156 set_bit(0, &orphan_timer);
152 softdog_keepalive(); 157 softdog_keepalive();
153 } 158 }
154 clear_bit(0, &timer_alive); 159 clear_bit(0, &driver_open);
155 expect_close = 0; 160 expect_close = 0;
156 return 0; 161 return 0;
157} 162}
diff --git a/drivers/char/watchdog/w83627hf_wdt.c b/drivers/char/watchdog/w83627hf_wdt.c
index 465e0fd0423..b5d82101542 100644
--- a/drivers/char/watchdog/w83627hf_wdt.c
+++ b/drivers/char/watchdog/w83627hf_wdt.c
@@ -93,6 +93,12 @@ w83627hf_init(void)
93 93
94 w83627hf_select_wd_register(); 94 w83627hf_select_wd_register();
95 95
96 outb_p(0xF6, WDT_EFER); /* Select CRF6 */
97 t=inb_p(WDT_EFDR); /* read CRF6 */
98 if (t != 0) {
99 printk (KERN_INFO PFX "Watchdog already running. Resetting timeout to %d sec\n", timeout);
100 outb_p(timeout, WDT_EFDR); /* Write back to CRF6 */
101 }
96 outb_p(0xF5, WDT_EFER); /* Select CRF5 */ 102 outb_p(0xF5, WDT_EFER); /* Select CRF5 */
97 t=inb_p(WDT_EFDR); /* read CRF5 */ 103 t=inb_p(WDT_EFDR); /* read CRF5 */
98 t&=~0x0C; /* set second mode & disable keyboard turning off watchdog */ 104 t&=~0x0C; /* set second mode & disable keyboard turning off watchdog */
diff --git a/drivers/firmware/Kconfig b/drivers/firmware/Kconfig
index 5b29c3b2a33..327b58e6487 100644
--- a/drivers/firmware/Kconfig
+++ b/drivers/firmware/Kconfig
@@ -58,4 +58,31 @@ config EFI_PCDP
58 58
59 See <http://www.dig64.org/specifications/DIG64_HCDPv20_042804.pdf> 59 See <http://www.dig64.org/specifications/DIG64_HCDPv20_042804.pdf>
60 60
61config DELL_RBU
62 tristate "BIOS update support for DELL systems via sysfs"
63 select FW_LOADER
64 help
65 Say m if you want to have the option of updating the BIOS for your
66 DELL system. Note you need a Dell OpenManage or Dell Update package (DUP)
67 supporting application to comunicate with the BIOS regarding the new
68 image for the image update to take effect.
69 See <file:Documentation/dell_rbu.txt> for more details on the driver.
70
71config DCDBAS
72 tristate "Dell Systems Management Base Driver"
73 depends on X86 || X86_64
74 default m
75 help
76 The Dell Systems Management Base Driver provides a sysfs interface
77 for systems management software to perform System Management
78 Interrupts (SMIs) and Host Control Actions (system power cycle or
79 power off after OS shutdown) on certain Dell systems.
80
81 See <file:Documentation/dcdbas.txt> for more details on the driver
82 and the Dell systems on which Dell systems management software makes
83 use of this driver.
84
85 Say Y or M here to enable the driver for use by Dell systems
86 management software such as Dell OpenManage.
87
61endmenu 88endmenu
diff --git a/drivers/firmware/Makefile b/drivers/firmware/Makefile
index 90fd0b26db8..85429979d0d 100644
--- a/drivers/firmware/Makefile
+++ b/drivers/firmware/Makefile
@@ -4,3 +4,5 @@
4obj-$(CONFIG_EDD) += edd.o 4obj-$(CONFIG_EDD) += edd.o
5obj-$(CONFIG_EFI_VARS) += efivars.o 5obj-$(CONFIG_EFI_VARS) += efivars.o
6obj-$(CONFIG_EFI_PCDP) += pcdp.o 6obj-$(CONFIG_EFI_PCDP) += pcdp.o
7obj-$(CONFIG_DELL_RBU) += dell_rbu.o
8obj-$(CONFIG_DCDBAS) += dcdbas.o
diff --git a/drivers/firmware/dcdbas.c b/drivers/firmware/dcdbas.c
new file mode 100644
index 00000000000..955537fe995
--- /dev/null
+++ b/drivers/firmware/dcdbas.c
@@ -0,0 +1,596 @@
1/*
2 * dcdbas.c: Dell Systems Management Base Driver
3 *
4 * The Dell Systems Management Base Driver provides a sysfs interface for
5 * systems management software to perform System Management Interrupts (SMIs)
6 * and Host Control Actions (power cycle or power off after OS shutdown) on
7 * Dell systems.
8 *
9 * See Documentation/dcdbas.txt for more information.
10 *
11 * Copyright (C) 1995-2005 Dell Inc.
12 *
13 * This program is free software; you can redistribute it and/or modify
14 * it under the terms of the GNU General Public License v2.0 as published by
15 * the Free Software Foundation.
16 *
17 * This program is distributed in the hope that it will be useful,
18 * but WITHOUT ANY WARRANTY; without even the implied warranty of
19 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20 * GNU General Public License for more details.
21 */
22
23#include <linux/device.h>
24#include <linux/dma-mapping.h>
25#include <linux/errno.h>
26#include <linux/init.h>
27#include <linux/kernel.h>
28#include <linux/mc146818rtc.h>
29#include <linux/module.h>
30#include <linux/reboot.h>
31#include <linux/sched.h>
32#include <linux/smp.h>
33#include <linux/spinlock.h>
34#include <linux/string.h>
35#include <linux/types.h>
36#include <asm/io.h>
37#include <asm/semaphore.h>
38
39#include "dcdbas.h"
40
41#define DRIVER_NAME "dcdbas"
42#define DRIVER_VERSION "5.6.0-1"
43#define DRIVER_DESCRIPTION "Dell Systems Management Base Driver"
44
45static struct platform_device *dcdbas_pdev;
46
47static u8 *smi_data_buf;
48static dma_addr_t smi_data_buf_handle;
49static unsigned long smi_data_buf_size;
50static u32 smi_data_buf_phys_addr;
51static DECLARE_MUTEX(smi_data_lock);
52
53static unsigned int host_control_action;
54static unsigned int host_control_smi_type;
55static unsigned int host_control_on_shutdown;
56
57/**
58 * smi_data_buf_free: free SMI data buffer
59 */
60static void smi_data_buf_free(void)
61{
62 if (!smi_data_buf)
63 return;
64
65 dev_dbg(&dcdbas_pdev->dev, "%s: phys: %x size: %lu\n",
66 __FUNCTION__, smi_data_buf_phys_addr, smi_data_buf_size);
67
68 dma_free_coherent(&dcdbas_pdev->dev, smi_data_buf_size, smi_data_buf,
69 smi_data_buf_handle);
70 smi_data_buf = NULL;
71 smi_data_buf_handle = 0;
72 smi_data_buf_phys_addr = 0;
73 smi_data_buf_size = 0;
74}
75
76/**
77 * smi_data_buf_realloc: grow SMI data buffer if needed
78 */
79static int smi_data_buf_realloc(unsigned long size)
80{
81 void *buf;
82 dma_addr_t handle;
83
84 if (smi_data_buf_size >= size)
85 return 0;
86
87 if (size > MAX_SMI_DATA_BUF_SIZE)
88 return -EINVAL;
89
90 /* new buffer is needed */
91 buf = dma_alloc_coherent(&dcdbas_pdev->dev, size, &handle, GFP_KERNEL);
92 if (!buf) {
93 dev_dbg(&dcdbas_pdev->dev,
94 "%s: failed to allocate memory size %lu\n",
95 __FUNCTION__, size);
96 return -ENOMEM;
97 }
98 /* memory zeroed by dma_alloc_coherent */
99
100 if (smi_data_buf)
101 memcpy(buf, smi_data_buf, smi_data_buf_size);
102
103 /* free any existing buffer */
104 smi_data_buf_free();
105
106 /* set up new buffer for use */
107 smi_data_buf = buf;
108 smi_data_buf_handle = handle;
109 smi_data_buf_phys_addr = (u32) virt_to_phys(buf);
110 smi_data_buf_size = size;
111
112 dev_dbg(&dcdbas_pdev->dev, "%s: phys: %x size: %lu\n",
113 __FUNCTION__, smi_data_buf_phys_addr, smi_data_buf_size);
114
115 return 0;
116}
117
118static ssize_t smi_data_buf_phys_addr_show(struct device *dev,
119 struct device_attribute *attr,
120 char *buf)
121{
122 return sprintf(buf, "%x\n", smi_data_buf_phys_addr);
123}
124
125static ssize_t smi_data_buf_size_show(struct device *dev,
126 struct device_attribute *attr,
127 char *buf)
128{
129 return sprintf(buf, "%lu\n", smi_data_buf_size);
130}
131
132static ssize_t smi_data_buf_size_store(struct device *dev,
133 struct device_attribute *attr,
134 const char *buf, size_t count)
135{
136 unsigned long buf_size;
137 ssize_t ret;
138
139 buf_size = simple_strtoul(buf, NULL, 10);
140
141 /* make sure SMI data buffer is at least buf_size */
142 down(&smi_data_lock);
143 ret = smi_data_buf_realloc(buf_size);
144 up(&smi_data_lock);
145 if (ret)
146 return ret;
147
148 return count;
149}
150
151static ssize_t smi_data_read(struct kobject *kobj, char *buf, loff_t pos,
152 size_t count)
153{
154 size_t max_read;
155 ssize_t ret;
156
157 down(&smi_data_lock);
158
159 if (pos >= smi_data_buf_size) {
160 ret = 0;
161 goto out;
162 }
163
164 max_read = smi_data_buf_size - pos;
165 ret = min(max_read, count);
166 memcpy(buf, smi_data_buf + pos, ret);
167out:
168 up(&smi_data_lock);
169 return ret;
170}
171
172static ssize_t smi_data_write(struct kobject *kobj, char *buf, loff_t pos,
173 size_t count)
174{
175 ssize_t ret;
176
177 down(&smi_data_lock);
178
179 ret = smi_data_buf_realloc(pos + count);
180 if (ret)
181 goto out;
182
183 memcpy(smi_data_buf + pos, buf, count);
184 ret = count;
185out:
186 up(&smi_data_lock);
187 return ret;
188}
189
190static ssize_t host_control_action_show(struct device *dev,
191 struct device_attribute *attr,
192 char *buf)
193{
194 return sprintf(buf, "%u\n", host_control_action);
195}
196
197static ssize_t host_control_action_store(struct device *dev,
198 struct device_attribute *attr,
199 const char *buf, size_t count)
200{
201 ssize_t ret;
202
203 /* make sure buffer is available for host control command */
204 down(&smi_data_lock);
205 ret = smi_data_buf_realloc(sizeof(struct apm_cmd));
206 up(&smi_data_lock);
207 if (ret)
208 return ret;
209
210 host_control_action = simple_strtoul(buf, NULL, 10);
211 return count;
212}
213
214static ssize_t host_control_smi_type_show(struct device *dev,
215 struct device_attribute *attr,
216 char *buf)
217{
218 return sprintf(buf, "%u\n", host_control_smi_type);
219}
220
221static ssize_t host_control_smi_type_store(struct device *dev,
222 struct device_attribute *attr,
223 const char *buf, size_t count)
224{
225 host_control_smi_type = simple_strtoul(buf, NULL, 10);
226 return count;
227}
228
229static ssize_t host_control_on_shutdown_show(struct device *dev,
230 struct device_attribute *attr,
231 char *buf)
232{
233 return sprintf(buf, "%u\n", host_control_on_shutdown);
234}
235
236static ssize_t host_control_on_shutdown_store(struct device *dev,
237 struct device_attribute *attr,
238 const char *buf, size_t count)
239{
240 host_control_on_shutdown = simple_strtoul(buf, NULL, 10);
241 return count;
242}
243
244/**
245 * smi_request: generate SMI request
246 *
247 * Called with smi_data_lock.
248 */
249static int smi_request(struct smi_cmd *smi_cmd)
250{
251 cpumask_t old_mask;
252 int ret = 0;
253
254 if (smi_cmd->magic != SMI_CMD_MAGIC) {
255 dev_info(&dcdbas_pdev->dev, "%s: invalid magic value\n",
256 __FUNCTION__);
257 return -EBADR;
258 }
259
260 /* SMI requires CPU 0 */
261 old_mask = current->cpus_allowed;
262 set_cpus_allowed(current, cpumask_of_cpu(0));
263 if (smp_processor_id() != 0) {
264 dev_dbg(&dcdbas_pdev->dev, "%s: failed to get CPU 0\n",
265 __FUNCTION__);
266 ret = -EBUSY;
267 goto out;
268 }
269
270 /* generate SMI */
271 asm volatile (
272 "outb %b0,%w1"
273 : /* no output args */
274 : "a" (smi_cmd->command_code),
275 "d" (smi_cmd->command_address),
276 "b" (smi_cmd->ebx),
277 "c" (smi_cmd->ecx)
278 : "memory"
279 );
280
281out:
282 set_cpus_allowed(current, old_mask);
283 return ret;
284}
285
286/**
287 * smi_request_store:
288 *
289 * The valid values are:
290 * 0: zero SMI data buffer
291 * 1: generate calling interface SMI
292 * 2: generate raw SMI
293 *
294 * User application writes smi_cmd to smi_data before telling driver
295 * to generate SMI.
296 */
297static ssize_t smi_request_store(struct device *dev,
298 struct device_attribute *attr,
299 const char *buf, size_t count)
300{
301 struct smi_cmd *smi_cmd;
302 unsigned long val = simple_strtoul(buf, NULL, 10);
303 ssize_t ret;
304
305 down(&smi_data_lock);
306
307 if (smi_data_buf_size < sizeof(struct smi_cmd)) {
308 ret = -ENODEV;
309 goto out;
310 }
311 smi_cmd = (struct smi_cmd *)smi_data_buf;
312
313 switch (val) {
314 case 2:
315 /* Raw SMI */
316 ret = smi_request(smi_cmd);
317 if (!ret)
318 ret = count;
319 break;
320 case 1:
321 /* Calling Interface SMI */
322 smi_cmd->ebx = (u32) virt_to_phys(smi_cmd->command_buffer);
323 ret = smi_request(smi_cmd);
324 if (!ret)
325 ret = count;
326 break;
327 case 0:
328 memset(smi_data_buf, 0, smi_data_buf_size);
329 ret = count;
330 break;
331 default:
332 ret = -EINVAL;
333 break;
334 }
335
336out:
337 up(&smi_data_lock);
338 return ret;
339}
340
341/**
342 * host_control_smi: generate host control SMI
343 *
344 * Caller must set up the host control command in smi_data_buf.
345 */
346static int host_control_smi(void)
347{
348 struct apm_cmd *apm_cmd;
349 u8 *data;
350 unsigned long flags;
351 u32 num_ticks;
352 s8 cmd_status;
353 u8 index;
354
355 apm_cmd = (struct apm_cmd *)smi_data_buf;
356 apm_cmd->status = ESM_STATUS_CMD_UNSUCCESSFUL;
357
358 switch (host_control_smi_type) {
359 case HC_SMITYPE_TYPE1:
360 spin_lock_irqsave(&rtc_lock, flags);
361 /* write SMI data buffer physical address */
362 data = (u8 *)&smi_data_buf_phys_addr;
363 for (index = PE1300_CMOS_CMD_STRUCT_PTR;
364 index < (PE1300_CMOS_CMD_STRUCT_PTR + 4);
365 index++, data++) {
366 outb(index,
367 (CMOS_BASE_PORT + CMOS_PAGE2_INDEX_PORT_PIIX4));
368 outb(*data,
369 (CMOS_BASE_PORT + CMOS_PAGE2_DATA_PORT_PIIX4));
370 }
371
372 /* first set status to -1 as called by spec */
373 cmd_status = ESM_STATUS_CMD_UNSUCCESSFUL;
374 outb((u8) cmd_status, PCAT_APM_STATUS_PORT);
375
376 /* generate SMM call */
377 outb(ESM_APM_CMD, PCAT_APM_CONTROL_PORT);
378 spin_unlock_irqrestore(&rtc_lock, flags);
379
380 /* wait a few to see if it executed */
381 num_ticks = TIMEOUT_USEC_SHORT_SEMA_BLOCKING;
382 while ((cmd_status = inb(PCAT_APM_STATUS_PORT))
383 == ESM_STATUS_CMD_UNSUCCESSFUL) {
384 num_ticks--;
385 if (num_ticks == EXPIRED_TIMER)
386 return -ETIME;
387 }
388 break;
389
390 case HC_SMITYPE_TYPE2:
391 case HC_SMITYPE_TYPE3:
392 spin_lock_irqsave(&rtc_lock, flags);
393 /* write SMI data buffer physical address */
394 data = (u8 *)&smi_data_buf_phys_addr;
395 for (index = PE1400_CMOS_CMD_STRUCT_PTR;
396 index < (PE1400_CMOS_CMD_STRUCT_PTR + 4);
397 index++, data++) {
398 outb(index, (CMOS_BASE_PORT + CMOS_PAGE1_INDEX_PORT));
399 outb(*data, (CMOS_BASE_PORT + CMOS_PAGE1_DATA_PORT));
400 }
401
402 /* generate SMM call */
403 if (host_control_smi_type == HC_SMITYPE_TYPE3)
404 outb(ESM_APM_CMD, PCAT_APM_CONTROL_PORT);
405 else
406 outb(ESM_APM_CMD, PE1400_APM_CONTROL_PORT);
407
408 /* restore RTC index pointer since it was written to above */
409 CMOS_READ(RTC_REG_C);
410 spin_unlock_irqrestore(&rtc_lock, flags);
411
412 /* read control port back to serialize write */
413 cmd_status = inb(PE1400_APM_CONTROL_PORT);
414
415 /* wait a few to see if it executed */
416 num_ticks = TIMEOUT_USEC_SHORT_SEMA_BLOCKING;
417 while (apm_cmd->status == ESM_STATUS_CMD_UNSUCCESSFUL) {
418 num_ticks--;
419 if (num_ticks == EXPIRED_TIMER)
420 return -ETIME;
421 }
422 break;
423
424 default:
425 dev_dbg(&dcdbas_pdev->dev, "%s: invalid SMI type %u\n",
426 __FUNCTION__, host_control_smi_type);
427 return -ENOSYS;
428 }
429
430 return 0;
431}
432
433/**
434 * dcdbas_host_control: initiate host control
435 *
436 * This function is called by the driver after the system has
437 * finished shutting down if the user application specified a
438 * host control action to perform on shutdown. It is safe to
439 * use smi_data_buf at this point because the system has finished
440 * shutting down and no userspace apps are running.
441 */
442static void dcdbas_host_control(void)
443{
444 struct apm_cmd *apm_cmd;
445 u8 action;
446
447 if (host_control_action == HC_ACTION_NONE)
448 return;
449
450 action = host_control_action;
451 host_control_action = HC_ACTION_NONE;
452
453 if (!smi_data_buf) {
454 dev_dbg(&dcdbas_pdev->dev, "%s: no SMI buffer\n", __FUNCTION__);
455 return;
456 }
457
458 if (smi_data_buf_size < sizeof(struct apm_cmd)) {
459 dev_dbg(&dcdbas_pdev->dev, "%s: SMI buffer too small\n",
460 __FUNCTION__);
461 return;
462 }
463
464 apm_cmd = (struct apm_cmd *)smi_data_buf;
465
466 /* power off takes precedence */
467 if (action & HC_ACTION_HOST_CONTROL_POWEROFF) {
468 apm_cmd->command = ESM_APM_POWER_CYCLE;
469 apm_cmd->reserved = 0;
470 *((s16 *)&apm_cmd->parameters.shortreq.parm[0]) = (s16) 0;
471 host_control_smi();
472 } else if (action & HC_ACTION_HOST_CONTROL_POWERCYCLE) {
473 apm_cmd->command = ESM_APM_POWER_CYCLE;
474 apm_cmd->reserved = 0;
475 *((s16 *)&apm_cmd->parameters.shortreq.parm[0]) = (s16) 20;
476 host_control_smi();
477 }
478}
479
480/**
481 * dcdbas_reboot_notify: handle reboot notification for host control
482 */
483static int dcdbas_reboot_notify(struct notifier_block *nb, unsigned long code,
484 void *unused)
485{
486 static unsigned int notify_cnt = 0;
487
488 switch (code) {
489 case SYS_DOWN:
490 case SYS_HALT:
491 case SYS_POWER_OFF:
492 if (host_control_on_shutdown) {
493 /* firmware is going to perform host control action */
494 if (++notify_cnt == 2) {
495 printk(KERN_WARNING
496 "Please wait for shutdown "
497 "action to complete...\n");
498 dcdbas_host_control();
499 }
500 /*
501 * register again and initiate the host control
502 * action on the second notification to allow
503 * everyone that registered to be notified
504 */
505 register_reboot_notifier(nb);
506 }
507 break;
508 }
509
510 return NOTIFY_DONE;
511}
512
513static struct notifier_block dcdbas_reboot_nb = {
514 .notifier_call = dcdbas_reboot_notify,
515 .next = NULL,
516 .priority = 0
517};
518
519static DCDBAS_BIN_ATTR_RW(smi_data);
520
521static struct bin_attribute *dcdbas_bin_attrs[] = {
522 &bin_attr_smi_data,
523 NULL
524};
525
526static DCDBAS_DEV_ATTR_RW(smi_data_buf_size);
527static DCDBAS_DEV_ATTR_RO(smi_data_buf_phys_addr);
528static DCDBAS_DEV_ATTR_WO(smi_request);
529static DCDBAS_DEV_ATTR_RW(host_control_action);
530static DCDBAS_DEV_ATTR_RW(host_control_smi_type);
531static DCDBAS_DEV_ATTR_RW(host_control_on_shutdown);
532
533static struct device_attribute *dcdbas_dev_attrs[] = {
534 &dev_attr_smi_data_buf_size,
535 &dev_attr_smi_data_buf_phys_addr,
536 &dev_attr_smi_request,
537 &dev_attr_host_control_action,
538 &dev_attr_host_control_smi_type,
539 &dev_attr_host_control_on_shutdown,
540 NULL
541};
542
543/**
544 * dcdbas_init: initialize driver
545 */
546static int __init dcdbas_init(void)
547{
548 int i;
549
550 host_control_action = HC_ACTION_NONE;
551 host_control_smi_type = HC_SMITYPE_NONE;
552
553 dcdbas_pdev = platform_device_register_simple(DRIVER_NAME, -1, NULL, 0);
554 if (IS_ERR(dcdbas_pdev))
555 return PTR_ERR(dcdbas_pdev);
556
557 /*
558 * BIOS SMI calls require buffer addresses be in 32-bit address space.
559 * This is done by setting the DMA mask below.
560 */
561 dcdbas_pdev->dev.coherent_dma_mask = DMA_32BIT_MASK;
562 dcdbas_pdev->dev.dma_mask = &dcdbas_pdev->dev.coherent_dma_mask;
563
564 register_reboot_notifier(&dcdbas_reboot_nb);
565
566 for (i = 0; dcdbas_bin_attrs[i]; i++)
567 sysfs_create_bin_file(&dcdbas_pdev->dev.kobj,
568 dcdbas_bin_attrs[i]);
569
570 for (i = 0; dcdbas_dev_attrs[i]; i++)
571 device_create_file(&dcdbas_pdev->dev, dcdbas_dev_attrs[i]);
572
573 dev_info(&dcdbas_pdev->dev, "%s (version %s)\n",
574 DRIVER_DESCRIPTION, DRIVER_VERSION);
575
576 return 0;
577}
578
579/**
580 * dcdbas_exit: perform driver cleanup
581 */
582static void __exit dcdbas_exit(void)
583{
584 platform_device_unregister(dcdbas_pdev);
585 unregister_reboot_notifier(&dcdbas_reboot_nb);
586 smi_data_buf_free();
587}
588
589module_init(dcdbas_init);
590module_exit(dcdbas_exit);
591
592MODULE_DESCRIPTION(DRIVER_DESCRIPTION " (version " DRIVER_VERSION ")");
593MODULE_VERSION(DRIVER_VERSION);
594MODULE_AUTHOR("Dell Inc.");
595MODULE_LICENSE("GPL");
596
diff --git a/drivers/firmware/dcdbas.h b/drivers/firmware/dcdbas.h
new file mode 100644
index 00000000000..58a85182b3e
--- /dev/null
+++ b/drivers/firmware/dcdbas.h
@@ -0,0 +1,107 @@
1/*
2 * dcdbas.h: Definitions for Dell Systems Management Base driver
3 *
4 * Copyright (C) 1995-2005 Dell Inc.
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 v2.0 as published by
8 * the Free Software Foundation.
9 *
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
14 */
15
16#ifndef _DCDBAS_H_
17#define _DCDBAS_H_
18
19#include <linux/device.h>
20#include <linux/input.h>
21#include <linux/sysfs.h>
22#include <linux/types.h>
23
24#define MAX_SMI_DATA_BUF_SIZE (256 * 1024)
25
26#define HC_ACTION_NONE (0)
27#define HC_ACTION_HOST_CONTROL_POWEROFF BIT(1)
28#define HC_ACTION_HOST_CONTROL_POWERCYCLE BIT(2)
29
30#define HC_SMITYPE_NONE (0)
31#define HC_SMITYPE_TYPE1 (1)
32#define HC_SMITYPE_TYPE2 (2)
33#define HC_SMITYPE_TYPE3 (3)
34
35#define ESM_APM_CMD (0x0A0)
36#define ESM_APM_POWER_CYCLE (0x10)
37#define ESM_STATUS_CMD_UNSUCCESSFUL (-1)
38
39#define CMOS_BASE_PORT (0x070)
40#define CMOS_PAGE1_INDEX_PORT (0)
41#define CMOS_PAGE1_DATA_PORT (1)
42#define CMOS_PAGE2_INDEX_PORT_PIIX4 (2)
43#define CMOS_PAGE2_DATA_PORT_PIIX4 (3)
44#define PE1400_APM_CONTROL_PORT (0x0B0)
45#define PCAT_APM_CONTROL_PORT (0x0B2)
46#define PCAT_APM_STATUS_PORT (0x0B3)
47#define PE1300_CMOS_CMD_STRUCT_PTR (0x38)
48#define PE1400_CMOS_CMD_STRUCT_PTR (0x70)
49
50#define MAX_SYSMGMT_SHORTCMD_PARMBUF_LEN (14)
51#define MAX_SYSMGMT_LONGCMD_SGENTRY_NUM (16)
52
53#define TIMEOUT_USEC_SHORT_SEMA_BLOCKING (10000)
54#define EXPIRED_TIMER (0)
55
56#define SMI_CMD_MAGIC (0x534D4931)
57
58#define DCDBAS_DEV_ATTR_RW(_name) \
59 DEVICE_ATTR(_name,0600,_name##_show,_name##_store);
60
61#define DCDBAS_DEV_ATTR_RO(_name) \
62 DEVICE_ATTR(_name,0400,_name##_show,NULL);
63
64#define DCDBAS_DEV_ATTR_WO(_name) \
65 DEVICE_ATTR(_name,0200,NULL,_name##_store);
66
67#define DCDBAS_BIN_ATTR_RW(_name) \
68struct bin_attribute bin_attr_##_name = { \
69 .attr = { .name = __stringify(_name), \
70 .mode = 0600, \
71 .owner = THIS_MODULE }, \
72 .read = _name##_read, \
73 .write = _name##_write, \
74}
75
76struct smi_cmd {
77 __u32 magic;
78 __u32 ebx;
79 __u32 ecx;
80 __u16 command_address;
81 __u8 command_code;
82 __u8 reserved;
83 __u8 command_buffer[1];
84} __attribute__ ((packed));
85
86struct apm_cmd {
87 __u8 command;
88 __s8 status;
89 __u16 reserved;
90 union {
91 struct {
92 __u8 parm[MAX_SYSMGMT_SHORTCMD_PARMBUF_LEN];
93 } __attribute__ ((packed)) shortreq;
94
95 struct {
96 __u16 num_sg_entries;
97 struct {
98 __u32 size;
99 __u64 addr;
100 } __attribute__ ((packed))
101 sglist[MAX_SYSMGMT_LONGCMD_SGENTRY_NUM];
102 } __attribute__ ((packed)) longreq;
103 } __attribute__ ((packed)) parameters;
104} __attribute__ ((packed));
105
106#endif /* _DCDBAS_H_ */
107
diff --git a/drivers/firmware/dell_rbu.c b/drivers/firmware/dell_rbu.c
new file mode 100644
index 00000000000..3b865f34a09
--- /dev/null
+++ b/drivers/firmware/dell_rbu.c
@@ -0,0 +1,634 @@
1/*
2 * dell_rbu.c
3 * Bios Update driver for Dell systems
4 * Author: Dell Inc
5 * Abhay Salunke <abhay_salunke@dell.com>
6 *
7 * Copyright (C) 2005 Dell Inc.
8 *
9 * Remote BIOS Update (rbu) driver is used for updating DELL BIOS by
10 * creating entries in the /sys file systems on Linux 2.6 and higher
11 * kernels. The driver supports two mechanism to update the BIOS namely
12 * contiguous and packetized. Both these methods still require having some
13 * application to set the CMOS bit indicating the BIOS to update itself
14 * after a reboot.
15 *
16 * Contiguous method:
17 * This driver writes the incoming data in a monolithic image by allocating
18 * contiguous physical pages large enough to accommodate the incoming BIOS
19 * image size.
20 *
21 * Packetized method:
22 * The driver writes the incoming packet image by allocating a new packet
23 * on every time the packet data is written. This driver requires an
24 * application to break the BIOS image in to fixed sized packet chunks.
25 *
26 * See Documentation/dell_rbu.txt for more info.
27 *
28 * This program is free software; you can redistribute it and/or modify
29 * it under the terms of the GNU General Public License v2.0 as published by
30 * the Free Software Foundation
31 *
32 * This program is distributed in the hope that it will be useful,
33 * but WITHOUT ANY WARRANTY; without even the implied warranty of
34 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
35 * GNU General Public License for more details.
36 */
37#include <linux/version.h>
38#include <linux/config.h>
39#include <linux/init.h>
40#include <linux/module.h>
41#include <linux/string.h>
42#include <linux/errno.h>
43#include <linux/blkdev.h>
44#include <linux/device.h>
45#include <linux/spinlock.h>
46#include <linux/moduleparam.h>
47#include <linux/firmware.h>
48#include <linux/dma-mapping.h>
49
50MODULE_AUTHOR("Abhay Salunke <abhay_salunke@dell.com>");
51MODULE_DESCRIPTION("Driver for updating BIOS image on DELL systems");
52MODULE_LICENSE("GPL");
53MODULE_VERSION("1.0");
54
55#define BIOS_SCAN_LIMIT 0xffffffff
56#define MAX_IMAGE_LENGTH 16
57static struct _rbu_data {
58 void *image_update_buffer;
59 unsigned long image_update_buffer_size;
60 unsigned long bios_image_size;
61 int image_update_ordernum;
62 int dma_alloc;
63 spinlock_t lock;
64 unsigned long packet_read_count;
65 unsigned long packet_write_count;
66 unsigned long num_packets;
67 unsigned long packetsize;
68} rbu_data;
69
70static char image_type[MAX_IMAGE_LENGTH] = "mono";
71module_param_string(image_type, image_type, sizeof(image_type), 0);
72MODULE_PARM_DESC(image_type, "BIOS image type. choose- mono or packet");
73
74struct packet_data {
75 struct list_head list;
76 size_t length;
77 void *data;
78 int ordernum;
79};
80
81static struct packet_data packet_data_head;
82
83static struct platform_device *rbu_device;
84static int context;
85static dma_addr_t dell_rbu_dmaaddr;
86
87static void init_packet_head(void)
88{
89 INIT_LIST_HEAD(&packet_data_head.list);
90 rbu_data.packet_write_count = 0;
91 rbu_data.packet_read_count = 0;
92 rbu_data.num_packets = 0;
93 rbu_data.packetsize = 0;
94}
95
96static int fill_last_packet(void *data, size_t length)
97{
98 struct list_head *ptemp_list;
99 struct packet_data *packet = NULL;
100 int packet_count = 0;
101
102 pr_debug("fill_last_packet: entry \n");
103
104 if (!rbu_data.num_packets) {
105 pr_debug("fill_last_packet: num_packets=0\n");
106 return -ENOMEM;
107 }
108
109 packet_count = rbu_data.num_packets;
110
111 ptemp_list = (&packet_data_head.list)->prev;
112
113 packet = list_entry(ptemp_list, struct packet_data, list);
114
115 if ((rbu_data.packet_write_count + length) > rbu_data.packetsize) {
116 pr_debug("dell_rbu:%s: packet size data "
117 "overrun\n", __FUNCTION__);
118 return -EINVAL;
119 }
120
121 pr_debug("fill_last_packet : buffer = %p\n", packet->data);
122
123 memcpy((packet->data + rbu_data.packet_write_count), data, length);
124
125 if ((rbu_data.packet_write_count + length) == rbu_data.packetsize) {
126 /*
127 * this was the last data chunk in the packet
128 * so reinitialize the packet data counter to zero
129 */
130 rbu_data.packet_write_count = 0;
131 } else
132 rbu_data.packet_write_count += length;
133
134 pr_debug("fill_last_packet: exit \n");
135 return 0;
136}
137
138static int create_packet(size_t length)
139{
140 struct packet_data *newpacket;
141 int ordernum = 0;
142
143 pr_debug("create_packet: entry \n");
144
145 if (!rbu_data.packetsize) {
146 pr_debug("create_packet: packetsize not specified\n");
147 return -EINVAL;
148 }
149
150 newpacket = kmalloc(sizeof(struct packet_data), GFP_KERNEL);
151 if (!newpacket) {
152 printk(KERN_WARNING
153 "dell_rbu:%s: failed to allocate new "
154 "packet\n", __FUNCTION__);
155 return -ENOMEM;
156 }
157
158 ordernum = get_order(length);
159 /*
160 * there is no upper limit on memory
161 * address for packetized mechanism
162 */
163 newpacket->data = (unsigned char *)__get_free_pages(GFP_KERNEL,
164 ordernum);
165
166 pr_debug("create_packet: newpacket %p\n", newpacket->data);
167
168 if (!newpacket->data) {
169 printk(KERN_WARNING
170 "dell_rbu:%s: failed to allocate new "
171 "packet\n", __FUNCTION__);
172 kfree(newpacket);
173 return -ENOMEM;
174 }
175
176 newpacket->ordernum = ordernum;
177 ++rbu_data.num_packets;
178 /*
179 * initialize the newly created packet headers
180 */
181 INIT_LIST_HEAD(&newpacket->list);
182 list_add_tail(&newpacket->list, &packet_data_head.list);
183 /*
184 * packets have fixed size
185 */
186 newpacket->length = rbu_data.packetsize;
187
188 pr_debug("create_packet: exit \n");
189
190 return 0;
191}
192
193static int packetize_data(void *data, size_t length)
194{
195 int rc = 0;
196
197 if (!rbu_data.packet_write_count) {
198 if ((rc = create_packet(length)))
199 return rc;
200 }
201 if ((rc = fill_last_packet(data, length)))
202 return rc;
203
204 return rc;
205}
206
207static int
208do_packet_read(char *data, struct list_head *ptemp_list,
209 int length, int bytes_read, int *list_read_count)
210{
211 void *ptemp_buf;
212 struct packet_data *newpacket = NULL;
213 int bytes_copied = 0;
214 int j = 0;
215
216 newpacket = list_entry(ptemp_list, struct packet_data, list);
217 *list_read_count += newpacket->length;
218
219 if (*list_read_count > bytes_read) {
220 /* point to the start of unread data */
221 j = newpacket->length - (*list_read_count - bytes_read);
222 /* point to the offset in the packet buffer */
223 ptemp_buf = (u8 *) newpacket->data + j;
224 /*
225 * check if there is enough room in
226 * * the incoming buffer
227 */
228 if (length > (*list_read_count - bytes_read))
229 /*
230 * copy what ever is there in this
231 * packet and move on
232 */
233 bytes_copied = (*list_read_count - bytes_read);
234 else
235 /* copy the remaining */
236 bytes_copied = length;
237 memcpy(data, ptemp_buf, bytes_copied);
238 }
239 return bytes_copied;
240}
241
242static int packet_read_list(char *data, size_t * pread_length)
243{
244 struct list_head *ptemp_list;
245 int temp_count = 0;
246 int bytes_copied = 0;
247 int bytes_read = 0;
248 int remaining_bytes = 0;
249 char *pdest = data;
250
251 /* check if we have any packets */
252 if (0 == rbu_data.num_packets)
253 return -ENOMEM;
254
255 remaining_bytes = *pread_length;
256 bytes_read = rbu_data.packet_read_count;
257
258 ptemp_list = (&packet_data_head.list)->next;
259 while (!list_empty(ptemp_list)) {
260 bytes_copied = do_packet_read(pdest, ptemp_list,
261 remaining_bytes, bytes_read,
262 &temp_count);
263 remaining_bytes -= bytes_copied;
264 bytes_read += bytes_copied;
265 pdest += bytes_copied;
266 /*
267 * check if we reached end of buffer before reaching the
268 * last packet
269 */
270 if (remaining_bytes == 0)
271 break;
272
273 ptemp_list = ptemp_list->next;
274 }
275 /*finally set the bytes read */
276 *pread_length = bytes_read - rbu_data.packet_read_count;
277 rbu_data.packet_read_count = bytes_read;
278 return 0;
279}
280
281static void packet_empty_list(void)
282{
283 struct list_head *ptemp_list;
284 struct list_head *pnext_list;
285 struct packet_data *newpacket;
286
287 ptemp_list = (&packet_data_head.list)->next;
288 while (!list_empty(ptemp_list)) {
289 newpacket =
290 list_entry(ptemp_list, struct packet_data, list);
291 pnext_list = ptemp_list->next;
292 list_del(ptemp_list);
293 ptemp_list = pnext_list;
294 /*
295 * zero out the RBU packet memory before freeing
296 * to make sure there are no stale RBU packets left in memory
297 */
298 memset(newpacket->data, 0, rbu_data.packetsize);
299 free_pages((unsigned long)newpacket->data,
300 newpacket->ordernum);
301 kfree(newpacket);
302 }
303 rbu_data.packet_write_count = 0;
304 rbu_data.packet_read_count = 0;
305 rbu_data.num_packets = 0;
306 rbu_data.packetsize = 0;
307}
308
309/*
310 * img_update_free: Frees the buffer allocated for storing BIOS image
311 * Always called with lock held and returned with lock held
312 */
313static void img_update_free(void)
314{
315 if (!rbu_data.image_update_buffer)
316 return;
317 /*
318 * zero out this buffer before freeing it to get rid of any stale
319 * BIOS image copied in memory.
320 */
321 memset(rbu_data.image_update_buffer, 0,
322 rbu_data.image_update_buffer_size);
323 if (rbu_data.dma_alloc == 1)
324 dma_free_coherent(NULL, rbu_data.bios_image_size,
325 rbu_data.image_update_buffer,
326 dell_rbu_dmaaddr);
327 else
328 free_pages((unsigned long)rbu_data.image_update_buffer,
329 rbu_data.image_update_ordernum);
330
331 /*
332 * Re-initialize the rbu_data variables after a free
333 */
334 rbu_data.image_update_ordernum = -1;
335 rbu_data.image_update_buffer = NULL;
336 rbu_data.image_update_buffer_size = 0;
337 rbu_data.bios_image_size = 0;
338 rbu_data.dma_alloc = 0;
339}
340
341/*
342 * img_update_realloc: This function allocates the contiguous pages to
343 * accommodate the requested size of data. The memory address and size
344 * values are stored globally and on every call to this function the new
345 * size is checked to see if more data is required than the existing size.
346 * If true the previous memory is freed and new allocation is done to
347 * accommodate the new size. If the incoming size is less then than the
348 * already allocated size, then that memory is reused. This function is
349 * called with lock held and returns with lock held.
350 */
351static int img_update_realloc(unsigned long size)
352{
353 unsigned char *image_update_buffer = NULL;
354 unsigned long rc;
355 unsigned long img_buf_phys_addr;
356 int ordernum;
357 int dma_alloc = 0;
358
359 /*
360 * check if the buffer of sufficient size has been
361 * already allocated
362 */
363 if (rbu_data.image_update_buffer_size >= size) {
364 /*
365 * check for corruption
366 */
367 if ((size != 0) && (rbu_data.image_update_buffer == NULL)) {
368 printk(KERN_ERR "dell_rbu:%s: corruption "
369 "check failed\n", __FUNCTION__);
370 return -EINVAL;
371 }
372 /*
373 * we have a valid pre-allocated buffer with
374 * sufficient size
375 */
376 return 0;
377 }
378
379 /*
380 * free any previously allocated buffer
381 */
382 img_update_free();
383
384 spin_unlock(&rbu_data.lock);
385
386 ordernum = get_order(size);
387 image_update_buffer =
388 (unsigned char *)__get_free_pages(GFP_KERNEL, ordernum);
389
390 img_buf_phys_addr =
391 (unsigned long)virt_to_phys(image_update_buffer);
392
393 if (img_buf_phys_addr > BIOS_SCAN_LIMIT) {
394 free_pages((unsigned long)image_update_buffer, ordernum);
395 ordernum = -1;
396 image_update_buffer = dma_alloc_coherent(NULL, size,
397 &dell_rbu_dmaaddr,
398 GFP_KERNEL);
399 dma_alloc = 1;
400 }
401
402 spin_lock(&rbu_data.lock);
403
404 if (image_update_buffer != NULL) {
405 rbu_data.image_update_buffer = image_update_buffer;
406 rbu_data.image_update_buffer_size = size;
407 rbu_data.bios_image_size =
408 rbu_data.image_update_buffer_size;
409 rbu_data.image_update_ordernum = ordernum;
410 rbu_data.dma_alloc = dma_alloc;
411 rc = 0;
412 } else {
413 pr_debug("Not enough memory for image update:"
414 "size = %ld\n", size);
415 rc = -ENOMEM;
416 }
417
418 return rc;
419}
420
421static ssize_t read_packet_data(char *buffer, loff_t pos, size_t count)
422{
423 int retval;
424 size_t bytes_left;
425 size_t data_length;
426 char *ptempBuf = buffer;
427 unsigned long imagesize;
428
429 /* check to see if we have something to return */
430 if (rbu_data.num_packets == 0) {
431 pr_debug("read_packet_data: no packets written\n");
432 retval = -ENOMEM;
433 goto read_rbu_data_exit;
434 }
435
436 imagesize = rbu_data.num_packets * rbu_data.packetsize;
437
438 if (pos > imagesize) {
439 retval = 0;
440 printk(KERN_WARNING "dell_rbu:read_packet_data: "
441 "data underrun\n");
442 goto read_rbu_data_exit;
443 }
444
445 bytes_left = imagesize - pos;
446 data_length = min(bytes_left, count);
447
448 if ((retval = packet_read_list(ptempBuf, &data_length)) < 0)
449 goto read_rbu_data_exit;
450
451 if ((pos + count) > imagesize) {
452 rbu_data.packet_read_count = 0;
453 /* this was the last copy */
454 retval = bytes_left;
455 } else
456 retval = count;
457
458 read_rbu_data_exit:
459 return retval;
460}
461
462static ssize_t read_rbu_mono_data(char *buffer, loff_t pos, size_t count)
463{
464 unsigned char *ptemp = NULL;
465 size_t bytes_left = 0;
466 size_t data_length = 0;
467 ssize_t ret_count = 0;
468
469 /* check to see if we have something to return */
470 if ((rbu_data.image_update_buffer == NULL) ||
471 (rbu_data.bios_image_size == 0)) {
472 pr_debug("read_rbu_data_mono: image_update_buffer %p ,"
473 "bios_image_size %lu\n",
474 rbu_data.image_update_buffer,
475 rbu_data.bios_image_size);
476 ret_count = -ENOMEM;
477 goto read_rbu_data_exit;
478 }
479
480 if (pos > rbu_data.bios_image_size) {
481 ret_count = 0;
482 goto read_rbu_data_exit;
483 }
484
485 bytes_left = rbu_data.bios_image_size - pos;
486 data_length = min(bytes_left, count);
487
488 ptemp = rbu_data.image_update_buffer;
489 memcpy(buffer, (ptemp + pos), data_length);
490
491 if ((pos + count) > rbu_data.bios_image_size)
492 /* this was the last copy */
493 ret_count = bytes_left;
494 else
495 ret_count = count;
496 read_rbu_data_exit:
497 return ret_count;
498}
499
500static ssize_t
501read_rbu_data(struct kobject *kobj, char *buffer, loff_t pos, size_t count)
502{
503 ssize_t ret_count = 0;
504
505 spin_lock(&rbu_data.lock);
506
507 if (!strcmp(image_type, "mono"))
508 ret_count = read_rbu_mono_data(buffer, pos, count);
509 else if (!strcmp(image_type, "packet"))
510 ret_count = read_packet_data(buffer, pos, count);
511 else
512 pr_debug("read_rbu_data: invalid image type specified\n");
513
514 spin_unlock(&rbu_data.lock);
515 return ret_count;
516}
517
518static ssize_t
519read_rbu_image_type(struct kobject *kobj, char *buffer, loff_t pos,
520 size_t count)
521{
522 int size = 0;
523 if (!pos)
524 size = sprintf(buffer, "%s\n", image_type);
525 return size;
526}
527
528static ssize_t
529write_rbu_image_type(struct kobject *kobj, char *buffer, loff_t pos,
530 size_t count)
531{
532 int rc = count;
533 spin_lock(&rbu_data.lock);
534
535 if (strlen(buffer) < MAX_IMAGE_LENGTH)
536 sscanf(buffer, "%s", image_type);
537 else
538 printk(KERN_WARNING "dell_rbu: image_type is invalid"
539 "max chars = %d, \n incoming str--%s-- \n",
540 MAX_IMAGE_LENGTH, buffer);
541
542 /* we must free all previous allocations */
543 packet_empty_list();
544 img_update_free();
545
546 spin_unlock(&rbu_data.lock);
547 return rc;
548
549}
550
551static struct bin_attribute rbu_data_attr = {
552 .attr = {.name = "data",.owner = THIS_MODULE,.mode = 0444},
553 .read = read_rbu_data,
554};
555
556static struct bin_attribute rbu_image_type_attr = {
557 .attr = {.name = "image_type",.owner = THIS_MODULE,.mode = 0644},
558 .read = read_rbu_image_type,
559 .write = write_rbu_image_type,
560};
561
562static void callbackfn_rbu(const struct firmware *fw, void *context)
563{
564 int rc = 0;
565
566 if (!fw || !fw->size)
567 return;
568
569 spin_lock(&rbu_data.lock);
570 if (!strcmp(image_type, "mono")) {
571 if (!img_update_realloc(fw->size))
572 memcpy(rbu_data.image_update_buffer,
573 fw->data, fw->size);
574 } else if (!strcmp(image_type, "packet")) {
575 if (!rbu_data.packetsize)
576 rbu_data.packetsize = fw->size;
577 else if (rbu_data.packetsize != fw->size) {
578 packet_empty_list();
579 rbu_data.packetsize = fw->size;
580 }
581 packetize_data(fw->data, fw->size);
582 } else
583 pr_debug("invalid image type specified.\n");
584 spin_unlock(&rbu_data.lock);
585
586 rc = request_firmware_nowait(THIS_MODULE, FW_ACTION_NOHOTPLUG,
587 "dell_rbu", &rbu_device->dev,
588 &context, callbackfn_rbu);
589 if (rc)
590 printk(KERN_ERR
591 "dell_rbu:%s request_firmware_nowait failed"
592 " %d\n", __FUNCTION__, rc);
593}
594
595static int __init dcdrbu_init(void)
596{
597 int rc = 0;
598 spin_lock_init(&rbu_data.lock);
599
600 init_packet_head();
601 rbu_device =
602 platform_device_register_simple("dell_rbu", -1, NULL, 0);
603 if (!rbu_device) {
604 printk(KERN_ERR
605 "dell_rbu:%s:platform_device_register_simple "
606 "failed\n", __FUNCTION__);
607 return -EIO;
608 }
609
610 sysfs_create_bin_file(&rbu_device->dev.kobj, &rbu_data_attr);
611 sysfs_create_bin_file(&rbu_device->dev.kobj, &rbu_image_type_attr);
612
613 rc = request_firmware_nowait(THIS_MODULE, FW_ACTION_NOHOTPLUG,
614 "dell_rbu", &rbu_device->dev,
615 &context, callbackfn_rbu);
616 if (rc)
617 printk(KERN_ERR "dell_rbu:%s:request_firmware_nowait"
618 " failed %d\n", __FUNCTION__, rc);
619
620 return rc;
621
622}
623
624static __exit void dcdrbu_exit(void)
625{
626 spin_lock(&rbu_data.lock);
627 packet_empty_list();
628 img_update_free();
629 spin_unlock(&rbu_data.lock);
630 platform_device_unregister(rbu_device);
631}
632
633module_exit(dcdrbu_exit);
634module_init(dcdrbu_init);
diff --git a/drivers/hwmon/Kconfig b/drivers/hwmon/Kconfig
index 140d5f851a5..138dc50270e 100644
--- a/drivers/hwmon/Kconfig
+++ b/drivers/hwmon/Kconfig
@@ -12,12 +12,20 @@ config HWMON
12 of a system. Most modern motherboards include such a device. It 12 of a system. Most modern motherboards include such a device. It
13 can include temperature sensors, voltage sensors, fan speed 13 can include temperature sensors, voltage sensors, fan speed
14 sensors and various additional features such as the ability to 14 sensors and various additional features such as the ability to
15 control the speed of the fans. 15 control the speed of the fans. If you want this support you
16 should say Y here and also to the specific driver(s) for your
17 sensors chip(s) below.
18
19 This support can also be built as a module. If so, the module
20 will be called hwmon.
21
22config HWMON_VID
23 tristate
24 default n
16 25
17config SENSORS_ADM1021 26config SENSORS_ADM1021
18 tristate "Analog Devices ADM1021 and compatibles" 27 tristate "Analog Devices ADM1021 and compatibles"
19 depends on HWMON && I2C 28 depends on HWMON && I2C
20 select I2C_SENSOR
21 help 29 help
22 If you say yes here you get support for Analog Devices ADM1021 30 If you say yes here you get support for Analog Devices ADM1021
23 and ADM1023 sensor chips and clones: Maxim MAX1617 and MAX1617A, 31 and ADM1023 sensor chips and clones: Maxim MAX1617 and MAX1617A,
@@ -30,7 +38,7 @@ config SENSORS_ADM1021
30config SENSORS_ADM1025 38config SENSORS_ADM1025
31 tristate "Analog Devices ADM1025 and compatibles" 39 tristate "Analog Devices ADM1025 and compatibles"
32 depends on HWMON && I2C && EXPERIMENTAL 40 depends on HWMON && I2C && EXPERIMENTAL
33 select I2C_SENSOR 41 select HWMON_VID
34 help 42 help
35 If you say yes here you get support for Analog Devices ADM1025 43 If you say yes here you get support for Analog Devices ADM1025
36 and Philips NE1619 sensor chips. 44 and Philips NE1619 sensor chips.
@@ -41,7 +49,7 @@ config SENSORS_ADM1025
41config SENSORS_ADM1026 49config SENSORS_ADM1026
42 tristate "Analog Devices ADM1026 and compatibles" 50 tristate "Analog Devices ADM1026 and compatibles"
43 depends on HWMON && I2C && EXPERIMENTAL 51 depends on HWMON && I2C && EXPERIMENTAL
44 select I2C_SENSOR 52 select HWMON_VID
45 help 53 help
46 If you say yes here you get support for Analog Devices ADM1026 54 If you say yes here you get support for Analog Devices ADM1026
47 sensor chip. 55 sensor chip.
@@ -52,7 +60,6 @@ config SENSORS_ADM1026
52config SENSORS_ADM1031 60config SENSORS_ADM1031
53 tristate "Analog Devices ADM1031 and compatibles" 61 tristate "Analog Devices ADM1031 and compatibles"
54 depends on HWMON && I2C && EXPERIMENTAL 62 depends on HWMON && I2C && EXPERIMENTAL
55 select I2C_SENSOR
56 help 63 help
57 If you say yes here you get support for Analog Devices ADM1031 64 If you say yes here you get support for Analog Devices ADM1031
58 and ADM1030 sensor chips. 65 and ADM1030 sensor chips.
@@ -63,7 +70,7 @@ config SENSORS_ADM1031
63config SENSORS_ADM9240 70config SENSORS_ADM9240
64 tristate "Analog Devices ADM9240 and compatibles" 71 tristate "Analog Devices ADM9240 and compatibles"
65 depends on HWMON && I2C && EXPERIMENTAL 72 depends on HWMON && I2C && EXPERIMENTAL
66 select I2C_SENSOR 73 select HWMON_VID
67 help 74 help
68 If you say yes here you get support for Analog Devices ADM9240, 75 If you say yes here you get support for Analog Devices ADM9240,
69 Dallas DS1780, National Semiconductor LM81 sensor chips. 76 Dallas DS1780, National Semiconductor LM81 sensor chips.
@@ -74,7 +81,7 @@ config SENSORS_ADM9240
74config SENSORS_ASB100 81config SENSORS_ASB100
75 tristate "Asus ASB100 Bach" 82 tristate "Asus ASB100 Bach"
76 depends on HWMON && I2C && EXPERIMENTAL 83 depends on HWMON && I2C && EXPERIMENTAL
77 select I2C_SENSOR 84 select HWMON_VID
78 help 85 help
79 If you say yes here you get support for the ASB100 Bach sensor 86 If you say yes here you get support for the ASB100 Bach sensor
80 chip found on some Asus mainboards. 87 chip found on some Asus mainboards.
@@ -85,7 +92,7 @@ config SENSORS_ASB100
85config SENSORS_ATXP1 92config SENSORS_ATXP1
86 tristate "Attansic ATXP1 VID controller" 93 tristate "Attansic ATXP1 VID controller"
87 depends on HWMON && I2C && EXPERIMENTAL 94 depends on HWMON && I2C && EXPERIMENTAL
88 select I2C_SENSOR 95 select HWMON_VID
89 help 96 help
90 If you say yes here you get support for the Attansic ATXP1 VID 97 If you say yes here you get support for the Attansic ATXP1 VID
91 controller. 98 controller.
@@ -99,7 +106,6 @@ config SENSORS_ATXP1
99config SENSORS_DS1621 106config SENSORS_DS1621
100 tristate "Dallas Semiconductor DS1621 and DS1625" 107 tristate "Dallas Semiconductor DS1621 and DS1625"
101 depends on HWMON && I2C && EXPERIMENTAL 108 depends on HWMON && I2C && EXPERIMENTAL
102 select I2C_SENSOR
103 help 109 help
104 If you say yes here you get support for Dallas Semiconductor 110 If you say yes here you get support for Dallas Semiconductor
105 DS1621 and DS1625 sensor chips. 111 DS1621 and DS1625 sensor chips.
@@ -110,7 +116,6 @@ config SENSORS_DS1621
110config SENSORS_FSCHER 116config SENSORS_FSCHER
111 tristate "FSC Hermes" 117 tristate "FSC Hermes"
112 depends on HWMON && I2C && EXPERIMENTAL 118 depends on HWMON && I2C && EXPERIMENTAL
113 select I2C_SENSOR
114 help 119 help
115 If you say yes here you get support for Fujitsu Siemens 120 If you say yes here you get support for Fujitsu Siemens
116 Computers Hermes sensor chips. 121 Computers Hermes sensor chips.
@@ -121,7 +126,6 @@ config SENSORS_FSCHER
121config SENSORS_FSCPOS 126config SENSORS_FSCPOS
122 tristate "FSC Poseidon" 127 tristate "FSC Poseidon"
123 depends on HWMON && I2C && EXPERIMENTAL 128 depends on HWMON && I2C && EXPERIMENTAL
124 select I2C_SENSOR
125 help 129 help
126 If you say yes here you get support for Fujitsu Siemens 130 If you say yes here you get support for Fujitsu Siemens
127 Computers Poseidon sensor chips. 131 Computers Poseidon sensor chips.
@@ -132,7 +136,6 @@ config SENSORS_FSCPOS
132config SENSORS_GL518SM 136config SENSORS_GL518SM
133 tristate "Genesys Logic GL518SM" 137 tristate "Genesys Logic GL518SM"
134 depends on HWMON && I2C 138 depends on HWMON && I2C
135 select I2C_SENSOR
136 help 139 help
137 If you say yes here you get support for Genesys Logic GL518SM 140 If you say yes here you get support for Genesys Logic GL518SM
138 sensor chips. 141 sensor chips.
@@ -143,7 +146,7 @@ config SENSORS_GL518SM
143config SENSORS_GL520SM 146config SENSORS_GL520SM
144 tristate "Genesys Logic GL520SM" 147 tristate "Genesys Logic GL520SM"
145 depends on HWMON && I2C && EXPERIMENTAL 148 depends on HWMON && I2C && EXPERIMENTAL
146 select I2C_SENSOR 149 select HWMON_VID
147 help 150 help
148 If you say yes here you get support for Genesys Logic GL520SM 151 If you say yes here you get support for Genesys Logic GL520SM
149 sensor chips. 152 sensor chips.
@@ -154,7 +157,8 @@ config SENSORS_GL520SM
154config SENSORS_IT87 157config SENSORS_IT87
155 tristate "ITE IT87xx and compatibles" 158 tristate "ITE IT87xx and compatibles"
156 depends on HWMON && I2C 159 depends on HWMON && I2C
157 select I2C_SENSOR 160 select I2C_ISA
161 select HWMON_VID
158 help 162 help
159 If you say yes here you get support for ITE IT87xx sensor chips 163 If you say yes here you get support for ITE IT87xx sensor chips
160 and clones: SiS960. 164 and clones: SiS960.
@@ -165,7 +169,6 @@ config SENSORS_IT87
165config SENSORS_LM63 169config SENSORS_LM63
166 tristate "National Semiconductor LM63" 170 tristate "National Semiconductor LM63"
167 depends on HWMON && I2C && EXPERIMENTAL 171 depends on HWMON && I2C && EXPERIMENTAL
168 select I2C_SENSOR
169 help 172 help
170 If you say yes here you get support for the National Semiconductor 173 If you say yes here you get support for the National Semiconductor
171 LM63 remote diode digital temperature sensor with integrated fan 174 LM63 remote diode digital temperature sensor with integrated fan
@@ -178,7 +181,6 @@ config SENSORS_LM63
178config SENSORS_LM75 181config SENSORS_LM75
179 tristate "National Semiconductor LM75 and compatibles" 182 tristate "National Semiconductor LM75 and compatibles"
180 depends on HWMON && I2C 183 depends on HWMON && I2C
181 select I2C_SENSOR
182 help 184 help
183 If you say yes here you get support for National Semiconductor LM75 185 If you say yes here you get support for National Semiconductor LM75
184 sensor chips and clones: Dallas Semiconductor DS75 and DS1775 (in 186 sensor chips and clones: Dallas Semiconductor DS75 and DS1775 (in
@@ -194,7 +196,6 @@ config SENSORS_LM75
194config SENSORS_LM77 196config SENSORS_LM77
195 tristate "National Semiconductor LM77" 197 tristate "National Semiconductor LM77"
196 depends on HWMON && I2C && EXPERIMENTAL 198 depends on HWMON && I2C && EXPERIMENTAL
197 select I2C_SENSOR
198 help 199 help
199 If you say yes here you get support for National Semiconductor LM77 200 If you say yes here you get support for National Semiconductor LM77
200 sensor chips. 201 sensor chips.
@@ -205,7 +206,8 @@ config SENSORS_LM77
205config SENSORS_LM78 206config SENSORS_LM78
206 tristate "National Semiconductor LM78 and compatibles" 207 tristate "National Semiconductor LM78 and compatibles"
207 depends on HWMON && I2C && EXPERIMENTAL 208 depends on HWMON && I2C && EXPERIMENTAL
208 select I2C_SENSOR 209 select I2C_ISA
210 select HWMON_VID
209 help 211 help
210 If you say yes here you get support for National Semiconductor LM78, 212 If you say yes here you get support for National Semiconductor LM78,
211 LM78-J and LM79. 213 LM78-J and LM79.
@@ -216,7 +218,6 @@ config SENSORS_LM78
216config SENSORS_LM80 218config SENSORS_LM80
217 tristate "National Semiconductor LM80" 219 tristate "National Semiconductor LM80"
218 depends on HWMON && I2C && EXPERIMENTAL 220 depends on HWMON && I2C && EXPERIMENTAL
219 select I2C_SENSOR
220 help 221 help
221 If you say yes here you get support for National Semiconductor 222 If you say yes here you get support for National Semiconductor
222 LM80 sensor chips. 223 LM80 sensor chips.
@@ -227,7 +228,6 @@ config SENSORS_LM80
227config SENSORS_LM83 228config SENSORS_LM83
228 tristate "National Semiconductor LM83" 229 tristate "National Semiconductor LM83"
229 depends on HWMON && I2C 230 depends on HWMON && I2C
230 select I2C_SENSOR
231 help 231 help
232 If you say yes here you get support for National Semiconductor 232 If you say yes here you get support for National Semiconductor
233 LM83 sensor chips. 233 LM83 sensor chips.
@@ -238,7 +238,7 @@ config SENSORS_LM83
238config SENSORS_LM85 238config SENSORS_LM85
239 tristate "National Semiconductor LM85 and compatibles" 239 tristate "National Semiconductor LM85 and compatibles"
240 depends on HWMON && I2C && EXPERIMENTAL 240 depends on HWMON && I2C && EXPERIMENTAL
241 select I2C_SENSOR 241 select HWMON_VID
242 help 242 help
243 If you say yes here you get support for National Semiconductor LM85 243 If you say yes here you get support for National Semiconductor LM85
244 sensor chips and clones: ADT7463, EMC6D100, EMC6D102 and ADM1027. 244 sensor chips and clones: ADT7463, EMC6D100, EMC6D102 and ADM1027.
@@ -249,7 +249,7 @@ config SENSORS_LM85
249config SENSORS_LM87 249config SENSORS_LM87
250 tristate "National Semiconductor LM87" 250 tristate "National Semiconductor LM87"
251 depends on HWMON && I2C && EXPERIMENTAL 251 depends on HWMON && I2C && EXPERIMENTAL
252 select I2C_SENSOR 252 select HWMON_VID
253 help 253 help
254 If you say yes here you get support for National Semiconductor LM87 254 If you say yes here you get support for National Semiconductor LM87
255 sensor chips. 255 sensor chips.
@@ -260,7 +260,6 @@ config SENSORS_LM87
260config SENSORS_LM90 260config SENSORS_LM90
261 tristate "National Semiconductor LM90 and compatibles" 261 tristate "National Semiconductor LM90 and compatibles"
262 depends on HWMON && I2C 262 depends on HWMON && I2C
263 select I2C_SENSOR
264 help 263 help
265 If you say yes here you get support for National Semiconductor LM90, 264 If you say yes here you get support for National Semiconductor LM90,
266 LM86, LM89 and LM99, Analog Devices ADM1032 and Maxim MAX6657 and 265 LM86, LM89 and LM99, Analog Devices ADM1032 and Maxim MAX6657 and
@@ -275,7 +274,6 @@ config SENSORS_LM90
275config SENSORS_LM92 274config SENSORS_LM92
276 tristate "National Semiconductor LM92 and compatibles" 275 tristate "National Semiconductor LM92 and compatibles"
277 depends on HWMON && I2C && EXPERIMENTAL 276 depends on HWMON && I2C && EXPERIMENTAL
278 select I2C_SENSOR
279 help 277 help
280 If you say yes here you get support for National Semiconductor LM92 278 If you say yes here you get support for National Semiconductor LM92
281 and Maxim MAX6635 sensor chips. 279 and Maxim MAX6635 sensor chips.
@@ -286,7 +284,6 @@ config SENSORS_LM92
286config SENSORS_MAX1619 284config SENSORS_MAX1619
287 tristate "Maxim MAX1619 sensor chip" 285 tristate "Maxim MAX1619 sensor chip"
288 depends on HWMON && I2C && EXPERIMENTAL 286 depends on HWMON && I2C && EXPERIMENTAL
289 select I2C_SENSOR
290 help 287 help
291 If you say yes here you get support for MAX1619 sensor chip. 288 If you say yes here you get support for MAX1619 sensor chip.
292 289
@@ -296,8 +293,8 @@ config SENSORS_MAX1619
296config SENSORS_PC87360 293config SENSORS_PC87360
297 tristate "National Semiconductor PC87360 family" 294 tristate "National Semiconductor PC87360 family"
298 depends on HWMON && I2C && EXPERIMENTAL 295 depends on HWMON && I2C && EXPERIMENTAL
299 select I2C_SENSOR
300 select I2C_ISA 296 select I2C_ISA
297 select HWMON_VID
301 help 298 help
302 If you say yes here you get access to the hardware monitoring 299 If you say yes here you get access to the hardware monitoring
303 functions of the National Semiconductor PC8736x Super-I/O chips. 300 functions of the National Semiconductor PC8736x Super-I/O chips.
@@ -311,7 +308,6 @@ config SENSORS_PC87360
311config SENSORS_SIS5595 308config SENSORS_SIS5595
312 tristate "Silicon Integrated Systems Corp. SiS5595" 309 tristate "Silicon Integrated Systems Corp. SiS5595"
313 depends on HWMON && I2C && PCI && EXPERIMENTAL 310 depends on HWMON && I2C && PCI && EXPERIMENTAL
314 select I2C_SENSOR
315 select I2C_ISA 311 select I2C_ISA
316 help 312 help
317 If you say yes here you get support for the integrated sensors in 313 If you say yes here you get support for the integrated sensors in
@@ -323,7 +319,6 @@ config SENSORS_SIS5595
323config SENSORS_SMSC47M1 319config SENSORS_SMSC47M1
324 tristate "SMSC LPC47M10x and compatibles" 320 tristate "SMSC LPC47M10x and compatibles"
325 depends on HWMON && I2C && EXPERIMENTAL 321 depends on HWMON && I2C && EXPERIMENTAL
326 select I2C_SENSOR
327 select I2C_ISA 322 select I2C_ISA
328 help 323 help
329 If you say yes here you get support for the integrated fan 324 If you say yes here you get support for the integrated fan
@@ -336,7 +331,6 @@ config SENSORS_SMSC47M1
336config SENSORS_SMSC47B397 331config SENSORS_SMSC47B397
337 tristate "SMSC LPC47B397-NC" 332 tristate "SMSC LPC47B397-NC"
338 depends on HWMON && I2C && EXPERIMENTAL 333 depends on HWMON && I2C && EXPERIMENTAL
339 select I2C_SENSOR
340 select I2C_ISA 334 select I2C_ISA
341 help 335 help
342 If you say yes here you get support for the SMSC LPC47B397-NC 336 If you say yes here you get support for the SMSC LPC47B397-NC
@@ -348,7 +342,6 @@ config SENSORS_SMSC47B397
348config SENSORS_VIA686A 342config SENSORS_VIA686A
349 tristate "VIA686A" 343 tristate "VIA686A"
350 depends on HWMON && I2C && PCI 344 depends on HWMON && I2C && PCI
351 select I2C_SENSOR
352 select I2C_ISA 345 select I2C_ISA
353 help 346 help
354 If you say yes here you get support for the integrated sensors in 347 If you say yes here you get support for the integrated sensors in
@@ -360,7 +353,8 @@ config SENSORS_VIA686A
360config SENSORS_W83781D 353config SENSORS_W83781D
361 tristate "Winbond W83781D, W83782D, W83783S, W83627HF, Asus AS99127F" 354 tristate "Winbond W83781D, W83782D, W83783S, W83627HF, Asus AS99127F"
362 depends on HWMON && I2C 355 depends on HWMON && I2C
363 select I2C_SENSOR 356 select I2C_ISA
357 select HWMON_VID
364 help 358 help
365 If you say yes here you get support for the Winbond W8378x series 359 If you say yes here you get support for the Winbond W8378x series
366 of sensor chips: the W83781D, W83782D, W83783S and W83627HF, 360 of sensor chips: the W83781D, W83782D, W83783S and W83627HF,
@@ -369,10 +363,18 @@ config SENSORS_W83781D
369 This driver can also be built as a module. If so, the module 363 This driver can also be built as a module. If so, the module
370 will be called w83781d. 364 will be called w83781d.
371 365
366config SENSORS_W83792D
367 tristate "Winbond W83792D"
368 depends on HWMON && I2C && EXPERIMENTAL
369 help
370 If you say yes here you get support for the Winbond W83792D chip.
371
372 This driver can also be built as a module. If so, the module
373 will be called w83792d.
374
372config SENSORS_W83L785TS 375config SENSORS_W83L785TS
373 tristate "Winbond W83L785TS-S" 376 tristate "Winbond W83L785TS-S"
374 depends on HWMON && I2C && EXPERIMENTAL 377 depends on HWMON && I2C && EXPERIMENTAL
375 select I2C_SENSOR
376 help 378 help
377 If you say yes here you get support for the Winbond W83L785TS-S 379 If you say yes here you get support for the Winbond W83L785TS-S
378 sensor chip, which is used on the Asus A7N8X, among other 380 sensor chip, which is used on the Asus A7N8X, among other
@@ -384,8 +386,8 @@ config SENSORS_W83L785TS
384config SENSORS_W83627HF 386config SENSORS_W83627HF
385 tristate "Winbond W83627HF, W83627THF, W83637HF, W83697HF" 387 tristate "Winbond W83627HF, W83627THF, W83637HF, W83697HF"
386 depends on HWMON && I2C && EXPERIMENTAL 388 depends on HWMON && I2C && EXPERIMENTAL
387 select I2C_SENSOR
388 select I2C_ISA 389 select I2C_ISA
390 select HWMON_VID
389 help 391 help
390 If you say yes here you get support for the Winbond W836X7 series 392 If you say yes here you get support for the Winbond W836X7 series
391 of sensor chips: the W83627HF, W83627THF, W83637HF, and the W83697HF 393 of sensor chips: the W83627HF, W83627THF, W83637HF, and the W83697HF
@@ -396,7 +398,6 @@ config SENSORS_W83627HF
396config SENSORS_W83627EHF 398config SENSORS_W83627EHF
397 tristate "Winbond W83627EHF" 399 tristate "Winbond W83627EHF"
398 depends on HWMON && I2C && EXPERIMENTAL 400 depends on HWMON && I2C && EXPERIMENTAL
399 select I2C_SENSOR
400 select I2C_ISA 401 select I2C_ISA
401 help 402 help
402 If you say yes here you get preliminary support for the hardware 403 If you say yes here you get preliminary support for the hardware
@@ -404,6 +405,9 @@ config SENSORS_W83627EHF
404 Only fan and temperature inputs are supported at the moment, while 405 Only fan and temperature inputs are supported at the moment, while
405 the chip does much more than that. 406 the chip does much more than that.
406 407
408 This driver also supports the W83627EHG, which is the lead-free
409 version of the W83627EHF.
410
407 This driver can also be built as a module. If so, the module 411 This driver can also be built as a module. If so, the module
408 will be called w83627ehf. 412 will be called w83627ehf.
409 413
diff --git a/drivers/hwmon/Makefile b/drivers/hwmon/Makefile
index 2781403a023..381f1bf04cc 100644
--- a/drivers/hwmon/Makefile
+++ b/drivers/hwmon/Makefile
@@ -2,9 +2,13 @@
2# Makefile for sensor chip drivers. 2# Makefile for sensor chip drivers.
3# 3#
4 4
5obj-$(CONFIG_HWMON) += hwmon.o
6obj-$(CONFIG_HWMON_VID) += hwmon-vid.o
7
5# asb100, then w83781d go first, as they can override other drivers' addresses. 8# asb100, then w83781d go first, as they can override other drivers' addresses.
6obj-$(CONFIG_SENSORS_ASB100) += asb100.o 9obj-$(CONFIG_SENSORS_ASB100) += asb100.o
7obj-$(CONFIG_SENSORS_W83627HF) += w83627hf.o 10obj-$(CONFIG_SENSORS_W83627HF) += w83627hf.o
11obj-$(CONFIG_SENSORS_W83792D) += w83792d.o
8obj-$(CONFIG_SENSORS_W83781D) += w83781d.o 12obj-$(CONFIG_SENSORS_W83781D) += w83781d.o
9 13
10obj-$(CONFIG_SENSORS_ADM1021) += adm1021.o 14obj-$(CONFIG_SENSORS_ADM1021) += adm1021.o
diff --git a/drivers/hwmon/adm1021.c b/drivers/hwmon/adm1021.c
index d2c774c32f4..e928cdb041c 100644
--- a/drivers/hwmon/adm1021.c
+++ b/drivers/hwmon/adm1021.c
@@ -24,7 +24,8 @@
24#include <linux/slab.h> 24#include <linux/slab.h>
25#include <linux/jiffies.h> 25#include <linux/jiffies.h>
26#include <linux/i2c.h> 26#include <linux/i2c.h>
27#include <linux/i2c-sensor.h> 27#include <linux/hwmon.h>
28#include <linux/err.h>
28 29
29 30
30/* Addresses to scan */ 31/* Addresses to scan */
@@ -32,10 +33,9 @@ static unsigned short normal_i2c[] = { 0x18, 0x19, 0x1a,
32 0x29, 0x2a, 0x2b, 33 0x29, 0x2a, 0x2b,
33 0x4c, 0x4d, 0x4e, 34 0x4c, 0x4d, 0x4e,
34 I2C_CLIENT_END }; 35 I2C_CLIENT_END };
35static unsigned int normal_isa[] = { I2C_CLIENT_ISA_END };
36 36
37/* Insmod parameters */ 37/* Insmod parameters */
38SENSORS_INSMOD_8(adm1021, adm1023, max1617, max1617a, thmc10, lm84, gl523sm, mc1066); 38I2C_CLIENT_INSMOD_8(adm1021, adm1023, max1617, max1617a, thmc10, lm84, gl523sm, mc1066);
39 39
40/* adm1021 constants specified below */ 40/* adm1021 constants specified below */
41 41
@@ -89,6 +89,7 @@ clearing it. Weird, ey? --Phil */
89/* Each client has this additional data */ 89/* Each client has this additional data */
90struct adm1021_data { 90struct adm1021_data {
91 struct i2c_client client; 91 struct i2c_client client;
92 struct class_device *class_dev;
92 enum chips type; 93 enum chips type;
93 94
94 struct semaphore update_lock; 95 struct semaphore update_lock;
@@ -185,7 +186,7 @@ static int adm1021_attach_adapter(struct i2c_adapter *adapter)
185{ 186{
186 if (!(adapter->class & I2C_CLASS_HWMON)) 187 if (!(adapter->class & I2C_CLASS_HWMON))
187 return 0; 188 return 0;
188 return i2c_detect(adapter, &addr_data, adm1021_detect); 189 return i2c_probe(adapter, &addr_data, adm1021_detect);
189} 190}
190 191
191static int adm1021_detect(struct i2c_adapter *adapter, int address, int kind) 192static int adm1021_detect(struct i2c_adapter *adapter, int address, int kind)
@@ -196,15 +197,6 @@ static int adm1021_detect(struct i2c_adapter *adapter, int address, int kind)
196 int err = 0; 197 int err = 0;
197 const char *type_name = ""; 198 const char *type_name = "";
198 199
199 /* Make sure we aren't probing the ISA bus!! This is just a safety check
200 at this moment; i2c_detect really won't call us. */
201#ifdef DEBUG
202 if (i2c_is_isa_adapter(adapter)) {
203 dev_dbg(&adapter->dev, "adm1021_detect called for an ISA bus adapter?!?\n");
204 return 0;
205 }
206#endif
207
208 if (!i2c_check_functionality(adapter, I2C_FUNC_SMBUS_BYTE_DATA)) 200 if (!i2c_check_functionality(adapter, I2C_FUNC_SMBUS_BYTE_DATA))
209 goto error0; 201 goto error0;
210 202
@@ -295,6 +287,12 @@ static int adm1021_detect(struct i2c_adapter *adapter, int address, int kind)
295 adm1021_init_client(new_client); 287 adm1021_init_client(new_client);
296 288
297 /* Register sysfs hooks */ 289 /* Register sysfs hooks */
290 data->class_dev = hwmon_device_register(&new_client->dev);
291 if (IS_ERR(data->class_dev)) {
292 err = PTR_ERR(data->class_dev);
293 goto error2;
294 }
295
298 device_create_file(&new_client->dev, &dev_attr_temp1_max); 296 device_create_file(&new_client->dev, &dev_attr_temp1_max);
299 device_create_file(&new_client->dev, &dev_attr_temp1_min); 297 device_create_file(&new_client->dev, &dev_attr_temp1_min);
300 device_create_file(&new_client->dev, &dev_attr_temp1_input); 298 device_create_file(&new_client->dev, &dev_attr_temp1_input);
@@ -305,6 +303,8 @@ static int adm1021_detect(struct i2c_adapter *adapter, int address, int kind)
305 303
306 return 0; 304 return 0;
307 305
306error2:
307 i2c_detach_client(new_client);
308error1: 308error1:
309 kfree(data); 309 kfree(data);
310error0: 310error0:
@@ -322,14 +322,15 @@ static void adm1021_init_client(struct i2c_client *client)
322 322
323static int adm1021_detach_client(struct i2c_client *client) 323static int adm1021_detach_client(struct i2c_client *client)
324{ 324{
325 struct adm1021_data *data = i2c_get_clientdata(client);
325 int err; 326 int err;
326 327
327 if ((err = i2c_detach_client(client))) { 328 hwmon_device_unregister(data->class_dev);
328 dev_err(&client->dev, "Client deregistration failed, client not detached.\n"); 329
330 if ((err = i2c_detach_client(client)))
329 return err; 331 return err;
330 }
331 332
332 kfree(i2c_get_clientdata(client)); 333 kfree(data);
333 return 0; 334 return 0;
334} 335}
335 336
diff --git a/drivers/hwmon/adm1025.c b/drivers/hwmon/adm1025.c
index e452d0daf90..526b7ff179e 100644
--- a/drivers/hwmon/adm1025.c
+++ b/drivers/hwmon/adm1025.c
@@ -50,8 +50,9 @@
50#include <linux/slab.h> 50#include <linux/slab.h>
51#include <linux/jiffies.h> 51#include <linux/jiffies.h>
52#include <linux/i2c.h> 52#include <linux/i2c.h>
53#include <linux/i2c-sensor.h> 53#include <linux/hwmon.h>
54#include <linux/i2c-vid.h> 54#include <linux/hwmon-vid.h>
55#include <linux/err.h>
55 56
56/* 57/*
57 * Addresses to scan 58 * Addresses to scan
@@ -60,13 +61,12 @@
60 */ 61 */
61 62
62static unsigned short normal_i2c[] = { 0x2c, 0x2d, 0x2e, I2C_CLIENT_END }; 63static unsigned short normal_i2c[] = { 0x2c, 0x2d, 0x2e, I2C_CLIENT_END };
63static unsigned int normal_isa[] = { I2C_CLIENT_ISA_END };
64 64
65/* 65/*
66 * Insmod parameters 66 * Insmod parameters
67 */ 67 */
68 68
69SENSORS_INSMOD_2(adm1025, ne1619); 69I2C_CLIENT_INSMOD_2(adm1025, ne1619);
70 70
71/* 71/*
72 * The ADM1025 registers 72 * The ADM1025 registers
@@ -132,6 +132,7 @@ static struct i2c_driver adm1025_driver = {
132 132
133struct adm1025_data { 133struct adm1025_data {
134 struct i2c_client client; 134 struct i2c_client client;
135 struct class_device *class_dev;
135 struct semaphore update_lock; 136 struct semaphore update_lock;
136 char valid; /* zero until following fields are valid */ 137 char valid; /* zero until following fields are valid */
137 unsigned long last_updated; /* in jiffies */ 138 unsigned long last_updated; /* in jiffies */
@@ -312,7 +313,7 @@ static int adm1025_attach_adapter(struct i2c_adapter *adapter)
312{ 313{
313 if (!(adapter->class & I2C_CLASS_HWMON)) 314 if (!(adapter->class & I2C_CLASS_HWMON))
314 return 0; 315 return 0;
315 return i2c_detect(adapter, &addr_data, adm1025_detect); 316 return i2c_probe(adapter, &addr_data, adm1025_detect);
316} 317}
317 318
318/* 319/*
@@ -416,6 +417,12 @@ static int adm1025_detect(struct i2c_adapter *adapter, int address, int kind)
416 adm1025_init_client(new_client); 417 adm1025_init_client(new_client);
417 418
418 /* Register sysfs hooks */ 419 /* Register sysfs hooks */
420 data->class_dev = hwmon_device_register(&new_client->dev);
421 if (IS_ERR(data->class_dev)) {
422 err = PTR_ERR(data->class_dev);
423 goto exit_detach;
424 }
425
419 device_create_file(&new_client->dev, &dev_attr_in0_input); 426 device_create_file(&new_client->dev, &dev_attr_in0_input);
420 device_create_file(&new_client->dev, &dev_attr_in1_input); 427 device_create_file(&new_client->dev, &dev_attr_in1_input);
421 device_create_file(&new_client->dev, &dev_attr_in2_input); 428 device_create_file(&new_client->dev, &dev_attr_in2_input);
@@ -452,6 +459,8 @@ static int adm1025_detect(struct i2c_adapter *adapter, int address, int kind)
452 459
453 return 0; 460 return 0;
454 461
462exit_detach:
463 i2c_detach_client(new_client);
455exit_free: 464exit_free:
456 kfree(data); 465 kfree(data);
457exit: 466exit:
@@ -464,7 +473,7 @@ static void adm1025_init_client(struct i2c_client *client)
464 struct adm1025_data *data = i2c_get_clientdata(client); 473 struct adm1025_data *data = i2c_get_clientdata(client);
465 int i; 474 int i;
466 475
467 data->vrm = i2c_which_vrm(); 476 data->vrm = vid_which_vrm();
468 477
469 /* 478 /*
470 * Set high limits 479 * Set high limits
@@ -502,15 +511,15 @@ static void adm1025_init_client(struct i2c_client *client)
502 511
503static int adm1025_detach_client(struct i2c_client *client) 512static int adm1025_detach_client(struct i2c_client *client)
504{ 513{
514 struct adm1025_data *data = i2c_get_clientdata(client);
505 int err; 515 int err;
506 516
507 if ((err = i2c_detach_client(client))) { 517 hwmon_device_unregister(data->class_dev);
508 dev_err(&client->dev, "Client deregistration failed, " 518
509 "client not detached.\n"); 519 if ((err = i2c_detach_client(client)))
510 return err; 520 return err;
511 }
512 521
513 kfree(i2c_get_clientdata(client)); 522 kfree(data);
514 return 0; 523 return 0;
515} 524}
516 525
diff --git a/drivers/hwmon/adm1026.c b/drivers/hwmon/adm1026.c
index c8a7f47911f..625158110fd 100644
--- a/drivers/hwmon/adm1026.c
+++ b/drivers/hwmon/adm1026.c
@@ -28,16 +28,16 @@
28#include <linux/slab.h> 28#include <linux/slab.h>
29#include <linux/jiffies.h> 29#include <linux/jiffies.h>
30#include <linux/i2c.h> 30#include <linux/i2c.h>
31#include <linux/i2c-sensor.h> 31#include <linux/hwmon.h>
32#include <linux/i2c-vid.h>
33#include <linux/hwmon-sysfs.h> 32#include <linux/hwmon-sysfs.h>
33#include <linux/hwmon-vid.h>
34#include <linux/err.h>
34 35
35/* Addresses to scan */ 36/* Addresses to scan */
36static unsigned short normal_i2c[] = { 0x2c, 0x2d, 0x2e, I2C_CLIENT_END }; 37static unsigned short normal_i2c[] = { 0x2c, 0x2d, 0x2e, I2C_CLIENT_END };
37static unsigned int normal_isa[] = { I2C_CLIENT_ISA_END };
38 38
39/* Insmod parameters */ 39/* Insmod parameters */
40SENSORS_INSMOD_1(adm1026); 40I2C_CLIENT_INSMOD_1(adm1026);
41 41
42static int gpio_input[17] = { -1, -1, -1, -1, -1, -1, -1, -1, -1, 42static int gpio_input[17] = { -1, -1, -1, -1, -1, -1, -1, -1, -1,
43 -1, -1, -1, -1, -1, -1, -1, -1 }; 43 -1, -1, -1, -1, -1, -1, -1, -1 };
@@ -259,6 +259,7 @@ struct pwm_data {
259 259
260struct adm1026_data { 260struct adm1026_data {
261 struct i2c_client client; 261 struct i2c_client client;
262 struct class_device *class_dev;
262 struct semaphore lock; 263 struct semaphore lock;
263 enum chips type; 264 enum chips type;
264 265
@@ -319,13 +320,15 @@ int adm1026_attach_adapter(struct i2c_adapter *adapter)
319 if (!(adapter->class & I2C_CLASS_HWMON)) { 320 if (!(adapter->class & I2C_CLASS_HWMON)) {
320 return 0; 321 return 0;
321 } 322 }
322 return i2c_detect(adapter, &addr_data, adm1026_detect); 323 return i2c_probe(adapter, &addr_data, adm1026_detect);
323} 324}
324 325
325int adm1026_detach_client(struct i2c_client *client) 326int adm1026_detach_client(struct i2c_client *client)
326{ 327{
328 struct adm1026_data *data = i2c_get_clientdata(client);
329 hwmon_device_unregister(data->class_dev);
327 i2c_detach_client(client); 330 i2c_detach_client(client);
328 kfree(i2c_get_clientdata(client)); 331 kfree(data);
329 return 0; 332 return 0;
330} 333}
331 334
@@ -1549,12 +1552,18 @@ int adm1026_detect(struct i2c_adapter *adapter, int address,
1549 goto exitfree; 1552 goto exitfree;
1550 1553
1551 /* Set the VRM version */ 1554 /* Set the VRM version */
1552 data->vrm = i2c_which_vrm(); 1555 data->vrm = vid_which_vrm();
1553 1556
1554 /* Initialize the ADM1026 chip */ 1557 /* Initialize the ADM1026 chip */
1555 adm1026_init_client(new_client); 1558 adm1026_init_client(new_client);
1556 1559
1557 /* Register sysfs hooks */ 1560 /* Register sysfs hooks */
1561 data->class_dev = hwmon_device_register(&new_client->dev);
1562 if (IS_ERR(data->class_dev)) {
1563 err = PTR_ERR(data->class_dev);
1564 goto exitdetach;
1565 }
1566
1558 device_create_file(&new_client->dev, &sensor_dev_attr_in0_input.dev_attr); 1567 device_create_file(&new_client->dev, &sensor_dev_attr_in0_input.dev_attr);
1559 device_create_file(&new_client->dev, &sensor_dev_attr_in0_max.dev_attr); 1568 device_create_file(&new_client->dev, &sensor_dev_attr_in0_max.dev_attr);
1560 device_create_file(&new_client->dev, &sensor_dev_attr_in0_min.dev_attr); 1569 device_create_file(&new_client->dev, &sensor_dev_attr_in0_min.dev_attr);
@@ -1690,6 +1699,8 @@ int adm1026_detect(struct i2c_adapter *adapter, int address,
1690 return 0; 1699 return 0;
1691 1700
1692 /* Error out and cleanup code */ 1701 /* Error out and cleanup code */
1702exitdetach:
1703 i2c_detach_client(new_client);
1693exitfree: 1704exitfree:
1694 kfree(data); 1705 kfree(data);
1695exit: 1706exit:
diff --git a/drivers/hwmon/adm1031.c b/drivers/hwmon/adm1031.c
index 93625095727..58338ed7c8a 100644
--- a/drivers/hwmon/adm1031.c
+++ b/drivers/hwmon/adm1031.c
@@ -26,7 +26,8 @@
26#include <linux/slab.h> 26#include <linux/slab.h>
27#include <linux/jiffies.h> 27#include <linux/jiffies.h>
28#include <linux/i2c.h> 28#include <linux/i2c.h>
29#include <linux/i2c-sensor.h> 29#include <linux/hwmon.h>
30#include <linux/err.h>
30 31
31/* Following macros takes channel parameter starting from 0 to 2 */ 32/* Following macros takes channel parameter starting from 0 to 2 */
32#define ADM1031_REG_FAN_SPEED(nr) (0x08 + (nr)) 33#define ADM1031_REG_FAN_SPEED(nr) (0x08 + (nr))
@@ -59,16 +60,16 @@
59 60
60/* Addresses to scan */ 61/* Addresses to scan */
61static unsigned short normal_i2c[] = { 0x2c, 0x2d, 0x2e, I2C_CLIENT_END }; 62static unsigned short normal_i2c[] = { 0x2c, 0x2d, 0x2e, I2C_CLIENT_END };
62static unsigned int normal_isa[] = { I2C_CLIENT_ISA_END };
63 63
64/* Insmod parameters */ 64/* Insmod parameters */
65SENSORS_INSMOD_2(adm1030, adm1031); 65I2C_CLIENT_INSMOD_2(adm1030, adm1031);
66 66
67typedef u8 auto_chan_table_t[8][2]; 67typedef u8 auto_chan_table_t[8][2];
68 68
69/* Each client has this additional data */ 69/* Each client has this additional data */
70struct adm1031_data { 70struct adm1031_data {
71 struct i2c_client client; 71 struct i2c_client client;
72 struct class_device *class_dev;
72 struct semaphore update_lock; 73 struct semaphore update_lock;
73 int chip_type; 74 int chip_type;
74 char valid; /* !=0 if following fields are valid */ 75 char valid; /* !=0 if following fields are valid */
@@ -725,10 +726,10 @@ static int adm1031_attach_adapter(struct i2c_adapter *adapter)
725{ 726{
726 if (!(adapter->class & I2C_CLASS_HWMON)) 727 if (!(adapter->class & I2C_CLASS_HWMON))
727 return 0; 728 return 0;
728 return i2c_detect(adapter, &addr_data, adm1031_detect); 729 return i2c_probe(adapter, &addr_data, adm1031_detect);
729} 730}
730 731
731/* This function is called by i2c_detect */ 732/* This function is called by i2c_probe */
732static int adm1031_detect(struct i2c_adapter *adapter, int address, int kind) 733static int adm1031_detect(struct i2c_adapter *adapter, int address, int kind)
733{ 734{
734 struct i2c_client *new_client; 735 struct i2c_client *new_client;
@@ -788,6 +789,12 @@ static int adm1031_detect(struct i2c_adapter *adapter, int address, int kind)
788 adm1031_init_client(new_client); 789 adm1031_init_client(new_client);
789 790
790 /* Register sysfs hooks */ 791 /* Register sysfs hooks */
792 data->class_dev = hwmon_device_register(&new_client->dev);
793 if (IS_ERR(data->class_dev)) {
794 err = PTR_ERR(data->class_dev);
795 goto exit_detach;
796 }
797
791 device_create_file(&new_client->dev, &dev_attr_fan1_input); 798 device_create_file(&new_client->dev, &dev_attr_fan1_input);
792 device_create_file(&new_client->dev, &dev_attr_fan1_div); 799 device_create_file(&new_client->dev, &dev_attr_fan1_div);
793 device_create_file(&new_client->dev, &dev_attr_fan1_min); 800 device_create_file(&new_client->dev, &dev_attr_fan1_min);
@@ -833,6 +840,8 @@ static int adm1031_detect(struct i2c_adapter *adapter, int address, int kind)
833 840
834 return 0; 841 return 0;
835 842
843exit_detach:
844 i2c_detach_client(new_client);
836exit_free: 845exit_free:
837 kfree(data); 846 kfree(data);
838exit: 847exit:
@@ -841,11 +850,14 @@ exit:
841 850
842static int adm1031_detach_client(struct i2c_client *client) 851static int adm1031_detach_client(struct i2c_client *client)
843{ 852{
853 struct adm1031_data *data = i2c_get_clientdata(client);
844 int ret; 854 int ret;
855
856 hwmon_device_unregister(data->class_dev);
845 if ((ret = i2c_detach_client(client)) != 0) { 857 if ((ret = i2c_detach_client(client)) != 0) {
846 return ret; 858 return ret;
847 } 859 }
848 kfree(i2c_get_clientdata(client)); 860 kfree(data);
849 return 0; 861 return 0;
850} 862}
851 863
diff --git a/drivers/hwmon/adm9240.c b/drivers/hwmon/adm9240.c
index ce2a6eb93f6..bc7faef162f 100644
--- a/drivers/hwmon/adm9240.c
+++ b/drivers/hwmon/adm9240.c
@@ -45,17 +45,16 @@
45#include <linux/module.h> 45#include <linux/module.h>
46#include <linux/slab.h> 46#include <linux/slab.h>
47#include <linux/i2c.h> 47#include <linux/i2c.h>
48#include <linux/i2c-sensor.h> 48#include <linux/hwmon.h>
49#include <linux/i2c-vid.h> 49#include <linux/hwmon-vid.h>
50#include <linux/err.h>
50 51
51/* Addresses to scan */ 52/* Addresses to scan */
52static unsigned short normal_i2c[] = { 0x2c, 0x2d, 0x2e, 0x2f, 53static unsigned short normal_i2c[] = { 0x2c, 0x2d, 0x2e, 0x2f,
53 I2C_CLIENT_END }; 54 I2C_CLIENT_END };
54 55
55static unsigned int normal_isa[] = { I2C_CLIENT_ISA_END };
56
57/* Insmod parameters */ 56/* Insmod parameters */
58SENSORS_INSMOD_3(adm9240, ds1780, lm81); 57I2C_CLIENT_INSMOD_3(adm9240, ds1780, lm81);
59 58
60/* ADM9240 registers */ 59/* ADM9240 registers */
61#define ADM9240_REG_MAN_ID 0x3e 60#define ADM9240_REG_MAN_ID 0x3e
@@ -150,6 +149,7 @@ static struct i2c_driver adm9240_driver = {
150struct adm9240_data { 149struct adm9240_data {
151 enum chips type; 150 enum chips type;
152 struct i2c_client client; 151 struct i2c_client client;
152 struct class_device *class_dev;
153 struct semaphore update_lock; 153 struct semaphore update_lock;
154 char valid; 154 char valid;
155 unsigned long last_updated_measure; 155 unsigned long last_updated_measure;
@@ -582,6 +582,12 @@ static int adm9240_detect(struct i2c_adapter *adapter, int address, int kind)
582 adm9240_init_client(new_client); 582 adm9240_init_client(new_client);
583 583
584 /* populate sysfs filesystem */ 584 /* populate sysfs filesystem */
585 data->class_dev = hwmon_device_register(&new_client->dev);
586 if (IS_ERR(data->class_dev)) {
587 err = PTR_ERR(data->class_dev);
588 goto exit_detach;
589 }
590
585 device_create_file(&new_client->dev, &dev_attr_in0_input); 591 device_create_file(&new_client->dev, &dev_attr_in0_input);
586 device_create_file(&new_client->dev, &dev_attr_in0_min); 592 device_create_file(&new_client->dev, &dev_attr_in0_min);
587 device_create_file(&new_client->dev, &dev_attr_in0_max); 593 device_create_file(&new_client->dev, &dev_attr_in0_max);
@@ -615,6 +621,9 @@ static int adm9240_detect(struct i2c_adapter *adapter, int address, int kind)
615 device_create_file(&new_client->dev, &dev_attr_cpu0_vid); 621 device_create_file(&new_client->dev, &dev_attr_cpu0_vid);
616 622
617 return 0; 623 return 0;
624
625exit_detach:
626 i2c_detach_client(new_client);
618exit_free: 627exit_free:
619 kfree(data); 628 kfree(data);
620exit: 629exit:
@@ -625,20 +634,20 @@ static int adm9240_attach_adapter(struct i2c_adapter *adapter)
625{ 634{
626 if (!(adapter->class & I2C_CLASS_HWMON)) 635 if (!(adapter->class & I2C_CLASS_HWMON))
627 return 0; 636 return 0;
628 return i2c_detect(adapter, &addr_data, adm9240_detect); 637 return i2c_probe(adapter, &addr_data, adm9240_detect);
629} 638}
630 639
631static int adm9240_detach_client(struct i2c_client *client) 640static int adm9240_detach_client(struct i2c_client *client)
632{ 641{
642 struct adm9240_data *data = i2c_get_clientdata(client);
633 int err; 643 int err;
634 644
635 if ((err = i2c_detach_client(client))) { 645 hwmon_device_unregister(data->class_dev);
636 dev_err(&client->dev, "Client deregistration failed, " 646
637 "client not detached.\n"); 647 if ((err = i2c_detach_client(client)))
638 return err; 648 return err;
639 }
640 649
641 kfree(i2c_get_clientdata(client)); 650 kfree(data);
642 return 0; 651 return 0;
643} 652}
644 653
@@ -648,7 +657,7 @@ static void adm9240_init_client(struct i2c_client *client)
648 u8 conf = adm9240_read_value(client, ADM9240_REG_CONFIG); 657 u8 conf = adm9240_read_value(client, ADM9240_REG_CONFIG);
649 u8 mode = adm9240_read_value(client, ADM9240_REG_TEMP_CONF) & 3; 658 u8 mode = adm9240_read_value(client, ADM9240_REG_TEMP_CONF) & 3;
650 659
651 data->vrm = i2c_which_vrm(); /* need this to report vid as mV */ 660 data->vrm = vid_which_vrm(); /* need this to report vid as mV */
652 661
653 dev_info(&client->dev, "Using VRM: %d.%d\n", data->vrm / 10, 662 dev_info(&client->dev, "Using VRM: %d.%d\n", data->vrm / 10,
654 data->vrm % 10); 663 data->vrm % 10);
diff --git a/drivers/hwmon/asb100.c b/drivers/hwmon/asb100.c
index 70d996d6fe0..8e34855a627 100644
--- a/drivers/hwmon/asb100.c
+++ b/drivers/hwmon/asb100.c
@@ -39,8 +39,9 @@
39#include <linux/module.h> 39#include <linux/module.h>
40#include <linux/slab.h> 40#include <linux/slab.h>
41#include <linux/i2c.h> 41#include <linux/i2c.h>
42#include <linux/i2c-sensor.h> 42#include <linux/hwmon.h>
43#include <linux/i2c-vid.h> 43#include <linux/hwmon-vid.h>
44#include <linux/err.h>
44#include <linux/init.h> 45#include <linux/init.h>
45#include <linux/jiffies.h> 46#include <linux/jiffies.h>
46#include "lm75.h" 47#include "lm75.h"
@@ -54,11 +55,8 @@
54/* I2C addresses to scan */ 55/* I2C addresses to scan */
55static unsigned short normal_i2c[] = { 0x2d, I2C_CLIENT_END }; 56static unsigned short normal_i2c[] = { 0x2d, I2C_CLIENT_END };
56 57
57/* ISA addresses to scan (none) */
58static unsigned int normal_isa[] = { I2C_CLIENT_ISA_END };
59
60/* Insmod parameters */ 58/* Insmod parameters */
61SENSORS_INSMOD_1(asb100); 59I2C_CLIENT_INSMOD_1(asb100);
62I2C_CLIENT_MODULE_PARM(force_subclients, "List of subclient addresses: " 60I2C_CLIENT_MODULE_PARM(force_subclients, "List of subclient addresses: "
63 "{bus, clientaddr, subclientaddr1, subclientaddr2}"); 61 "{bus, clientaddr, subclientaddr1, subclientaddr2}");
64 62
@@ -183,6 +181,7 @@ static u8 DIV_TO_REG(long val)
183 dynamically allocated, at the same time the client itself is allocated. */ 181 dynamically allocated, at the same time the client itself is allocated. */
184struct asb100_data { 182struct asb100_data {
185 struct i2c_client client; 183 struct i2c_client client;
184 struct class_device *class_dev;
186 struct semaphore lock; 185 struct semaphore lock;
187 enum chips type; 186 enum chips type;
188 187
@@ -621,7 +620,7 @@ static int asb100_attach_adapter(struct i2c_adapter *adapter)
621{ 620{
622 if (!(adapter->class & I2C_CLASS_HWMON)) 621 if (!(adapter->class & I2C_CLASS_HWMON))
623 return 0; 622 return 0;
624 return i2c_detect(adapter, &addr_data, asb100_detect); 623 return i2c_probe(adapter, &addr_data, asb100_detect);
625} 624}
626 625
627static int asb100_detect_subclients(struct i2c_adapter *adapter, int address, 626static int asb100_detect_subclients(struct i2c_adapter *adapter, int address,
@@ -714,14 +713,6 @@ static int asb100_detect(struct i2c_adapter *adapter, int address, int kind)
714 struct i2c_client *new_client; 713 struct i2c_client *new_client;
715 struct asb100_data *data; 714 struct asb100_data *data;
716 715
717 /* asb100 is SMBus only */
718 if (i2c_is_isa_adapter(adapter)) {
719 pr_debug("asb100.o: detect failed, "
720 "cannot attach to legacy adapter!\n");
721 err = -ENODEV;
722 goto ERROR0;
723 }
724
725 if (!i2c_check_functionality(adapter, I2C_FUNC_SMBUS_BYTE_DATA)) { 716 if (!i2c_check_functionality(adapter, I2C_FUNC_SMBUS_BYTE_DATA)) {
726 pr_debug("asb100.o: detect failed, " 717 pr_debug("asb100.o: detect failed, "
727 "smbus byte data not supported!\n"); 718 "smbus byte data not supported!\n");
@@ -821,6 +812,12 @@ static int asb100_detect(struct i2c_adapter *adapter, int address, int kind)
821 data->fan_min[2] = asb100_read_value(new_client, ASB100_REG_FAN_MIN(2)); 812 data->fan_min[2] = asb100_read_value(new_client, ASB100_REG_FAN_MIN(2));
822 813
823 /* Register sysfs hooks */ 814 /* Register sysfs hooks */
815 data->class_dev = hwmon_device_register(&new_client->dev);
816 if (IS_ERR(data->class_dev)) {
817 err = PTR_ERR(data->class_dev);
818 goto ERROR3;
819 }
820
824 device_create_file_in(new_client, 0); 821 device_create_file_in(new_client, 0);
825 device_create_file_in(new_client, 1); 822 device_create_file_in(new_client, 1);
826 device_create_file_in(new_client, 2); 823 device_create_file_in(new_client, 2);
@@ -847,6 +844,11 @@ static int asb100_detect(struct i2c_adapter *adapter, int address, int kind)
847 844
848 return 0; 845 return 0;
849 846
847ERROR3:
848 i2c_detach_client(data->lm75[1]);
849 i2c_detach_client(data->lm75[0]);
850 kfree(data->lm75[1]);
851 kfree(data->lm75[0]);
850ERROR2: 852ERROR2:
851 i2c_detach_client(new_client); 853 i2c_detach_client(new_client);
852ERROR1: 854ERROR1:
@@ -857,21 +859,23 @@ ERROR0:
857 859
858static int asb100_detach_client(struct i2c_client *client) 860static int asb100_detach_client(struct i2c_client *client)
859{ 861{
862 struct asb100_data *data = i2c_get_clientdata(client);
860 int err; 863 int err;
861 864
862 if ((err = i2c_detach_client(client))) { 865 /* main client */
863 dev_err(&client->dev, "client deregistration failed; " 866 if (data)
864 "client not detached.\n"); 867 hwmon_device_unregister(data->class_dev);
868
869 if ((err = i2c_detach_client(client)))
865 return err; 870 return err;
866 }
867 871
868 if (i2c_get_clientdata(client)==NULL) { 872 /* main client */
869 /* subclients */ 873 if (data)
874 kfree(data);
875
876 /* subclient */
877 else
870 kfree(client); 878 kfree(client);
871 } else {
872 /* main client */
873 kfree(i2c_get_clientdata(client));
874 }
875 879
876 return 0; 880 return 0;
877} 881}
@@ -969,7 +973,7 @@ static void asb100_init_client(struct i2c_client *client)
969 973
970 vid = asb100_read_value(client, ASB100_REG_VID_FANDIV) & 0x0f; 974 vid = asb100_read_value(client, ASB100_REG_VID_FANDIV) & 0x0f;
971 vid |= (asb100_read_value(client, ASB100_REG_CHIPID) & 0x01) << 4; 975 vid |= (asb100_read_value(client, ASB100_REG_CHIPID) & 0x01) << 4;
972 data->vrm = i2c_which_vrm(); 976 data->vrm = vid_which_vrm();
973 vid = vid_from_reg(vid, data->vrm); 977 vid = vid_from_reg(vid, data->vrm);
974 978
975 /* Start monitoring */ 979 /* Start monitoring */
diff --git a/drivers/hwmon/atxp1.c b/drivers/hwmon/atxp1.c
index fca3fc1cef7..deb4d34c953 100644
--- a/drivers/hwmon/atxp1.c
+++ b/drivers/hwmon/atxp1.c
@@ -23,8 +23,9 @@
23#include <linux/module.h> 23#include <linux/module.h>
24#include <linux/jiffies.h> 24#include <linux/jiffies.h>
25#include <linux/i2c.h> 25#include <linux/i2c.h>
26#include <linux/i2c-sensor.h> 26#include <linux/hwmon.h>
27#include <linux/i2c-vid.h> 27#include <linux/hwmon-vid.h>
28#include <linux/err.h>
28 29
29MODULE_LICENSE("GPL"); 30MODULE_LICENSE("GPL");
30MODULE_DESCRIPTION("System voltages control via Attansic ATXP1"); 31MODULE_DESCRIPTION("System voltages control via Attansic ATXP1");
@@ -40,9 +41,8 @@ MODULE_AUTHOR("Sebastian Witt <se.witt@gmx.net>");
40#define ATXP1_GPIO1MASK 0x0f 41#define ATXP1_GPIO1MASK 0x0f
41 42
42static unsigned short normal_i2c[] = { 0x37, 0x4e, I2C_CLIENT_END }; 43static unsigned short normal_i2c[] = { 0x37, 0x4e, I2C_CLIENT_END };
43static unsigned int normal_isa[] = { I2C_CLIENT_ISA_END };
44 44
45SENSORS_INSMOD_1(atxp1); 45I2C_CLIENT_INSMOD_1(atxp1);
46 46
47static int atxp1_attach_adapter(struct i2c_adapter * adapter); 47static int atxp1_attach_adapter(struct i2c_adapter * adapter);
48static int atxp1_detach_client(struct i2c_client * client); 48static int atxp1_detach_client(struct i2c_client * client);
@@ -59,6 +59,7 @@ static struct i2c_driver atxp1_driver = {
59 59
60struct atxp1_data { 60struct atxp1_data {
61 struct i2c_client client; 61 struct i2c_client client;
62 struct class_device *class_dev;
62 struct semaphore update_lock; 63 struct semaphore update_lock;
63 unsigned long last_updated; 64 unsigned long last_updated;
64 u8 valid; 65 u8 valid;
@@ -252,7 +253,7 @@ static DEVICE_ATTR(gpio2, S_IRUGO | S_IWUSR, atxp1_showgpio2, atxp1_storegpio2);
252 253
253static int atxp1_attach_adapter(struct i2c_adapter *adapter) 254static int atxp1_attach_adapter(struct i2c_adapter *adapter)
254{ 255{
255 return i2c_detect(adapter, &addr_data, &atxp1_detect); 256 return i2c_probe(adapter, &addr_data, &atxp1_detect);
256}; 257};
257 258
258static int atxp1_detect(struct i2c_adapter *adapter, int address, int kind) 259static int atxp1_detect(struct i2c_adapter *adapter, int address, int kind)
@@ -295,7 +296,7 @@ static int atxp1_detect(struct i2c_adapter *adapter, int address, int kind)
295 } 296 }
296 297
297 /* Get VRM */ 298 /* Get VRM */
298 data->vrm = i2c_which_vrm(); 299 data->vrm = vid_which_vrm();
299 300
300 if ((data->vrm != 90) && (data->vrm != 91)) { 301 if ((data->vrm != 90) && (data->vrm != 91)) {
301 dev_err(&new_client->dev, "Not supporting VRM %d.%d\n", 302 dev_err(&new_client->dev, "Not supporting VRM %d.%d\n",
@@ -317,6 +318,12 @@ static int atxp1_detect(struct i2c_adapter *adapter, int address, int kind)
317 goto exit_free; 318 goto exit_free;
318 } 319 }
319 320
321 data->class_dev = hwmon_device_register(&new_client->dev);
322 if (IS_ERR(data->class_dev)) {
323 err = PTR_ERR(data->class_dev);
324 goto exit_detach;
325 }
326
320 device_create_file(&new_client->dev, &dev_attr_gpio1); 327 device_create_file(&new_client->dev, &dev_attr_gpio1);
321 device_create_file(&new_client->dev, &dev_attr_gpio2); 328 device_create_file(&new_client->dev, &dev_attr_gpio2);
322 device_create_file(&new_client->dev, &dev_attr_cpu0_vid); 329 device_create_file(&new_client->dev, &dev_attr_cpu0_vid);
@@ -326,6 +333,8 @@ static int atxp1_detect(struct i2c_adapter *adapter, int address, int kind)
326 333
327 return 0; 334 return 0;
328 335
336exit_detach:
337 i2c_detach_client(new_client);
329exit_free: 338exit_free:
330 kfree(data); 339 kfree(data);
331exit: 340exit:
@@ -334,14 +343,17 @@ exit:
334 343
335static int atxp1_detach_client(struct i2c_client * client) 344static int atxp1_detach_client(struct i2c_client * client)
336{ 345{
346 struct atxp1_data * data = i2c_get_clientdata(client);
337 int err; 347 int err;
338 348
349 hwmon_device_unregister(data->class_dev);
350
339 err = i2c_detach_client(client); 351 err = i2c_detach_client(client);
340 352
341 if (err) 353 if (err)
342 dev_err(&client->dev, "Failed to detach client.\n"); 354 dev_err(&client->dev, "Failed to detach client.\n");
343 else 355 else
344 kfree(i2c_get_clientdata(client)); 356 kfree(data);
345 357
346 return err; 358 return err;
347}; 359};
diff --git a/drivers/hwmon/ds1621.c b/drivers/hwmon/ds1621.c
index 5360d58804f..b0199e063d0 100644
--- a/drivers/hwmon/ds1621.c
+++ b/drivers/hwmon/ds1621.c
@@ -26,16 +26,16 @@
26#include <linux/slab.h> 26#include <linux/slab.h>
27#include <linux/jiffies.h> 27#include <linux/jiffies.h>
28#include <linux/i2c.h> 28#include <linux/i2c.h>
29#include <linux/i2c-sensor.h> 29#include <linux/hwmon.h>
30#include <linux/err.h>
30#include "lm75.h" 31#include "lm75.h"
31 32
32/* Addresses to scan */ 33/* Addresses to scan */
33static unsigned short normal_i2c[] = { 0x48, 0x49, 0x4a, 0x4b, 0x4c, 34static unsigned short normal_i2c[] = { 0x48, 0x49, 0x4a, 0x4b, 0x4c,
34 0x4d, 0x4e, 0x4f, I2C_CLIENT_END }; 35 0x4d, 0x4e, 0x4f, I2C_CLIENT_END };
35static unsigned int normal_isa[] = { I2C_CLIENT_ISA_END };
36 36
37/* Insmod parameters */ 37/* Insmod parameters */
38SENSORS_INSMOD_1(ds1621); 38I2C_CLIENT_INSMOD_1(ds1621);
39static int polarity = -1; 39static int polarity = -1;
40module_param(polarity, int, 0); 40module_param(polarity, int, 0);
41MODULE_PARM_DESC(polarity, "Output's polarity: 0 = active high, 1 = active low"); 41MODULE_PARM_DESC(polarity, "Output's polarity: 0 = active high, 1 = active low");
@@ -71,6 +71,7 @@ MODULE_PARM_DESC(polarity, "Output's polarity: 0 = active high, 1 = active low")
71/* Each client has this additional data */ 71/* Each client has this additional data */
72struct ds1621_data { 72struct ds1621_data {
73 struct i2c_client client; 73 struct i2c_client client;
74 struct class_device *class_dev;
74 struct semaphore update_lock; 75 struct semaphore update_lock;
75 char valid; /* !=0 if following fields are valid */ 76 char valid; /* !=0 if following fields are valid */
76 unsigned long last_updated; /* In jiffies */ 77 unsigned long last_updated; /* In jiffies */
@@ -179,10 +180,10 @@ static DEVICE_ATTR(temp1_max, S_IWUSR | S_IRUGO, show_temp_max, set_temp_max);
179 180
180static int ds1621_attach_adapter(struct i2c_adapter *adapter) 181static int ds1621_attach_adapter(struct i2c_adapter *adapter)
181{ 182{
182 return i2c_detect(adapter, &addr_data, ds1621_detect); 183 return i2c_probe(adapter, &addr_data, ds1621_detect);
183} 184}
184 185
185/* This function is called by i2c_detect */ 186/* This function is called by i2c_probe */
186int ds1621_detect(struct i2c_adapter *adapter, int address, 187int ds1621_detect(struct i2c_adapter *adapter, int address,
187 int kind) 188 int kind)
188{ 189{
@@ -250,6 +251,12 @@ int ds1621_detect(struct i2c_adapter *adapter, int address,
250 ds1621_init_client(new_client); 251 ds1621_init_client(new_client);
251 252
252 /* Register sysfs hooks */ 253 /* Register sysfs hooks */
254 data->class_dev = hwmon_device_register(&new_client->dev);
255 if (IS_ERR(data->class_dev)) {
256 err = PTR_ERR(data->class_dev);
257 goto exit_detach;
258 }
259
253 device_create_file(&new_client->dev, &dev_attr_alarms); 260 device_create_file(&new_client->dev, &dev_attr_alarms);
254 device_create_file(&new_client->dev, &dev_attr_temp1_input); 261 device_create_file(&new_client->dev, &dev_attr_temp1_input);
255 device_create_file(&new_client->dev, &dev_attr_temp1_min); 262 device_create_file(&new_client->dev, &dev_attr_temp1_min);
@@ -259,6 +266,8 @@ int ds1621_detect(struct i2c_adapter *adapter, int address,
259 266
260/* OK, this is not exactly good programming practice, usually. But it is 267/* OK, this is not exactly good programming practice, usually. But it is
261 very code-efficient in this case. */ 268 very code-efficient in this case. */
269 exit_detach:
270 i2c_detach_client(new_client);
262 exit_free: 271 exit_free:
263 kfree(data); 272 kfree(data);
264 exit: 273 exit:
@@ -267,15 +276,15 @@ int ds1621_detect(struct i2c_adapter *adapter, int address,
267 276
268static int ds1621_detach_client(struct i2c_client *client) 277static int ds1621_detach_client(struct i2c_client *client)
269{ 278{
279 struct ds1621_data *data = i2c_get_clientdata(client);
270 int err; 280 int err;
271 281
272 if ((err = i2c_detach_client(client))) { 282 hwmon_device_unregister(data->class_dev);
273 dev_err(&client->dev, "Client deregistration failed, " 283
274 "client not detached.\n"); 284 if ((err = i2c_detach_client(client)))
275 return err; 285 return err;
276 }
277 286
278 kfree(i2c_get_clientdata(client)); 287 kfree(data);
279 288
280 return 0; 289 return 0;
281} 290}
diff --git a/drivers/hwmon/fscher.c b/drivers/hwmon/fscher.c
index da411741c2c..eef6061d786 100644
--- a/drivers/hwmon/fscher.c
+++ b/drivers/hwmon/fscher.c
@@ -31,20 +31,20 @@
31#include <linux/slab.h> 31#include <linux/slab.h>
32#include <linux/jiffies.h> 32#include <linux/jiffies.h>
33#include <linux/i2c.h> 33#include <linux/i2c.h>
34#include <linux/i2c-sensor.h> 34#include <linux/hwmon.h>
35#include <linux/err.h>
35 36
36/* 37/*
37 * Addresses to scan 38 * Addresses to scan
38 */ 39 */
39 40
40static unsigned short normal_i2c[] = { 0x73, I2C_CLIENT_END }; 41static unsigned short normal_i2c[] = { 0x73, I2C_CLIENT_END };
41static unsigned int normal_isa[] = { I2C_CLIENT_ISA_END };
42 42
43/* 43/*
44 * Insmod parameters 44 * Insmod parameters
45 */ 45 */
46 46
47SENSORS_INSMOD_1(fscher); 47I2C_CLIENT_INSMOD_1(fscher);
48 48
49/* 49/*
50 * The FSCHER registers 50 * The FSCHER registers
@@ -132,6 +132,7 @@ static struct i2c_driver fscher_driver = {
132 132
133struct fscher_data { 133struct fscher_data {
134 struct i2c_client client; 134 struct i2c_client client;
135 struct class_device *class_dev;
135 struct semaphore update_lock; 136 struct semaphore update_lock;
136 char valid; /* zero until following fields are valid */ 137 char valid; /* zero until following fields are valid */
137 unsigned long last_updated; /* in jiffies */ 138 unsigned long last_updated; /* in jiffies */
@@ -287,7 +288,7 @@ static int fscher_attach_adapter(struct i2c_adapter *adapter)
287{ 288{
288 if (!(adapter->class & I2C_CLASS_HWMON)) 289 if (!(adapter->class & I2C_CLASS_HWMON))
289 return 0; 290 return 0;
290 return i2c_detect(adapter, &addr_data, fscher_detect); 291 return i2c_probe(adapter, &addr_data, fscher_detect);
291} 292}
292 293
293static int fscher_detect(struct i2c_adapter *adapter, int address, int kind) 294static int fscher_detect(struct i2c_adapter *adapter, int address, int kind)
@@ -341,6 +342,12 @@ static int fscher_detect(struct i2c_adapter *adapter, int address, int kind)
341 fscher_init_client(new_client); 342 fscher_init_client(new_client);
342 343
343 /* Register sysfs hooks */ 344 /* Register sysfs hooks */
345 data->class_dev = hwmon_device_register(&new_client->dev);
346 if (IS_ERR(data->class_dev)) {
347 err = PTR_ERR(data->class_dev);
348 goto exit_detach;
349 }
350
344 device_create_file_revision(new_client); 351 device_create_file_revision(new_client);
345 device_create_file_alarms(new_client); 352 device_create_file_alarms(new_client);
346 device_create_file_control(new_client); 353 device_create_file_control(new_client);
@@ -360,6 +367,8 @@ static int fscher_detect(struct i2c_adapter *adapter, int address, int kind)
360 367
361 return 0; 368 return 0;
362 369
370exit_detach:
371 i2c_detach_client(new_client);
363exit_free: 372exit_free:
364 kfree(data); 373 kfree(data);
365exit: 374exit:
@@ -368,15 +377,15 @@ exit:
368 377
369static int fscher_detach_client(struct i2c_client *client) 378static int fscher_detach_client(struct i2c_client *client)
370{ 379{
380 struct fscher_data *data = i2c_get_clientdata(client);
371 int err; 381 int err;
372 382
373 if ((err = i2c_detach_client(client))) { 383 hwmon_device_unregister(data->class_dev);
374 dev_err(&client->dev, "Client deregistration failed, " 384
375 "client not detached.\n"); 385 if ((err = i2c_detach_client(client)))
376 return err; 386 return err;
377 }
378 387
379 kfree(i2c_get_clientdata(client)); 388 kfree(data);
380 return 0; 389 return 0;
381} 390}
382 391
diff --git a/drivers/hwmon/fscpos.c b/drivers/hwmon/fscpos.c
index 301ae98bd0a..5fc77a5fed0 100644
--- a/drivers/hwmon/fscpos.c
+++ b/drivers/hwmon/fscpos.c
@@ -34,19 +34,19 @@
34#include <linux/slab.h> 34#include <linux/slab.h>
35#include <linux/jiffies.h> 35#include <linux/jiffies.h>
36#include <linux/i2c.h> 36#include <linux/i2c.h>
37#include <linux/i2c-sensor.h>
38#include <linux/init.h> 37#include <linux/init.h>
38#include <linux/hwmon.h>
39#include <linux/err.h>
39 40
40/* 41/*
41 * Addresses to scan 42 * Addresses to scan
42 */ 43 */
43static unsigned short normal_i2c[] = { 0x73, I2C_CLIENT_END }; 44static unsigned short normal_i2c[] = { 0x73, I2C_CLIENT_END };
44static unsigned int normal_isa[] = { I2C_CLIENT_ISA_END };
45 45
46/* 46/*
47 * Insmod parameters 47 * Insmod parameters
48 */ 48 */
49SENSORS_INSMOD_1(fscpos); 49I2C_CLIENT_INSMOD_1(fscpos);
50 50
51/* 51/*
52 * The FSCPOS registers 52 * The FSCPOS registers
@@ -113,6 +113,7 @@ static struct i2c_driver fscpos_driver = {
113 */ 113 */
114struct fscpos_data { 114struct fscpos_data {
115 struct i2c_client client; 115 struct i2c_client client;
116 struct class_device *class_dev;
116 struct semaphore update_lock; 117 struct semaphore update_lock;
117 char valid; /* 0 until following fields are valid */ 118 char valid; /* 0 until following fields are valid */
118 unsigned long last_updated; /* In jiffies */ 119 unsigned long last_updated; /* In jiffies */
@@ -434,7 +435,7 @@ static int fscpos_attach_adapter(struct i2c_adapter *adapter)
434{ 435{
435 if (!(adapter->class & I2C_CLASS_HWMON)) 436 if (!(adapter->class & I2C_CLASS_HWMON))
436 return 0; 437 return 0;
437 return i2c_detect(adapter, &addr_data, fscpos_detect); 438 return i2c_probe(adapter, &addr_data, fscpos_detect);
438} 439}
439 440
440int fscpos_detect(struct i2c_adapter *adapter, int address, int kind) 441int fscpos_detect(struct i2c_adapter *adapter, int address, int kind)
@@ -496,6 +497,12 @@ int fscpos_detect(struct i2c_adapter *adapter, int address, int kind)
496 dev_info(&new_client->dev, "Found fscpos chip, rev %u\n", data->revision); 497 dev_info(&new_client->dev, "Found fscpos chip, rev %u\n", data->revision);
497 498
498 /* Register sysfs hooks */ 499 /* Register sysfs hooks */
500 data->class_dev = hwmon_device_register(&new_client->dev);
501 if (IS_ERR(data->class_dev)) {
502 err = PTR_ERR(data->class_dev);
503 goto exit_detach;
504 }
505
499 device_create_file(&new_client->dev, &dev_attr_event); 506 device_create_file(&new_client->dev, &dev_attr_event);
500 device_create_file(&new_client->dev, &dev_attr_in0_input); 507 device_create_file(&new_client->dev, &dev_attr_in0_input);
501 device_create_file(&new_client->dev, &dev_attr_in1_input); 508 device_create_file(&new_client->dev, &dev_attr_in1_input);
@@ -526,6 +533,8 @@ int fscpos_detect(struct i2c_adapter *adapter, int address, int kind)
526 533
527 return 0; 534 return 0;
528 535
536exit_detach:
537 i2c_detach_client(new_client);
529exit_free: 538exit_free:
530 kfree(data); 539 kfree(data);
531exit: 540exit:
@@ -534,14 +543,14 @@ exit:
534 543
535static int fscpos_detach_client(struct i2c_client *client) 544static int fscpos_detach_client(struct i2c_client *client)
536{ 545{
546 struct fscpos_data *data = i2c_get_clientdata(client);
537 int err; 547 int err;
538 548
539 if ((err = i2c_detach_client(client))) { 549 hwmon_device_unregister(data->class_dev);
540 dev_err(&client->dev, "Client deregistration failed, client" 550
541 " not detached.\n"); 551 if ((err = i2c_detach_client(client)))
542 return err; 552 return err;
543 } 553 kfree(data);
544 kfree(i2c_get_clientdata(client));
545 return 0; 554 return 0;
546} 555}
547 556
diff --git a/drivers/hwmon/gl518sm.c b/drivers/hwmon/gl518sm.c
index 6bedf729dcf..256b9323c84 100644
--- a/drivers/hwmon/gl518sm.c
+++ b/drivers/hwmon/gl518sm.c
@@ -41,14 +41,14 @@
41#include <linux/slab.h> 41#include <linux/slab.h>
42#include <linux/jiffies.h> 42#include <linux/jiffies.h>
43#include <linux/i2c.h> 43#include <linux/i2c.h>
44#include <linux/i2c-sensor.h> 44#include <linux/hwmon.h>
45#include <linux/err.h>
45 46
46/* Addresses to scan */ 47/* Addresses to scan */
47static unsigned short normal_i2c[] = { 0x2c, 0x2d, I2C_CLIENT_END }; 48static unsigned short normal_i2c[] = { 0x2c, 0x2d, I2C_CLIENT_END };
48static unsigned int normal_isa[] = { I2C_CLIENT_ISA_END };
49 49
50/* Insmod parameters */ 50/* Insmod parameters */
51SENSORS_INSMOD_2(gl518sm_r00, gl518sm_r80); 51I2C_CLIENT_INSMOD_2(gl518sm_r00, gl518sm_r80);
52 52
53/* Many GL518 constants specified below */ 53/* Many GL518 constants specified below */
54 54
@@ -117,6 +117,7 @@ static inline u8 FAN_TO_REG(long rpm, int div)
117/* Each client has this additional data */ 117/* Each client has this additional data */
118struct gl518_data { 118struct gl518_data {
119 struct i2c_client client; 119 struct i2c_client client;
120 struct class_device *class_dev;
120 enum chips type; 121 enum chips type;
121 122
122 struct semaphore update_lock; 123 struct semaphore update_lock;
@@ -346,7 +347,7 @@ static int gl518_attach_adapter(struct i2c_adapter *adapter)
346{ 347{
347 if (!(adapter->class & I2C_CLASS_HWMON)) 348 if (!(adapter->class & I2C_CLASS_HWMON))
348 return 0; 349 return 0;
349 return i2c_detect(adapter, &addr_data, gl518_detect); 350 return i2c_probe(adapter, &addr_data, gl518_detect);
350} 351}
351 352
352static int gl518_detect(struct i2c_adapter *adapter, int address, int kind) 353static int gl518_detect(struct i2c_adapter *adapter, int address, int kind)
@@ -419,6 +420,12 @@ static int gl518_detect(struct i2c_adapter *adapter, int address, int kind)
419 gl518_init_client((struct i2c_client *) new_client); 420 gl518_init_client((struct i2c_client *) new_client);
420 421
421 /* Register sysfs hooks */ 422 /* Register sysfs hooks */
423 data->class_dev = hwmon_device_register(&new_client->dev);
424 if (IS_ERR(data->class_dev)) {
425 err = PTR_ERR(data->class_dev);
426 goto exit_detach;
427 }
428
422 device_create_file(&new_client->dev, &dev_attr_in0_input); 429 device_create_file(&new_client->dev, &dev_attr_in0_input);
423 device_create_file(&new_client->dev, &dev_attr_in1_input); 430 device_create_file(&new_client->dev, &dev_attr_in1_input);
424 device_create_file(&new_client->dev, &dev_attr_in2_input); 431 device_create_file(&new_client->dev, &dev_attr_in2_input);
@@ -450,6 +457,8 @@ static int gl518_detect(struct i2c_adapter *adapter, int address, int kind)
450/* OK, this is not exactly good programming practice, usually. But it is 457/* OK, this is not exactly good programming practice, usually. But it is
451 very code-efficient in this case. */ 458 very code-efficient in this case. */
452 459
460exit_detach:
461 i2c_detach_client(new_client);
453exit_free: 462exit_free:
454 kfree(data); 463 kfree(data);
455exit: 464exit:
@@ -477,16 +486,15 @@ static void gl518_init_client(struct i2c_client *client)
477 486
478static int gl518_detach_client(struct i2c_client *client) 487static int gl518_detach_client(struct i2c_client *client)
479{ 488{
489 struct gl518_data *data = i2c_get_clientdata(client);
480 int err; 490 int err;
481 491
482 if ((err = i2c_detach_client(client))) { 492 hwmon_device_unregister(data->class_dev);
483 dev_err(&client->dev, "Client deregistration failed, "
484 "client not detached.\n");
485 return err;
486 }
487 493
488 kfree(i2c_get_clientdata(client)); 494 if ((err = i2c_detach_client(client)))
495 return err;
489 496
497 kfree(data);
490 return 0; 498 return 0;
491} 499}
492 500
diff --git a/drivers/hwmon/gl520sm.c b/drivers/hwmon/gl520sm.c
index 80ae8d30c2a..12fd757066f 100644
--- a/drivers/hwmon/gl520sm.c
+++ b/drivers/hwmon/gl520sm.c
@@ -26,8 +26,9 @@
26#include <linux/slab.h> 26#include <linux/slab.h>
27#include <linux/jiffies.h> 27#include <linux/jiffies.h>
28#include <linux/i2c.h> 28#include <linux/i2c.h>
29#include <linux/i2c-sensor.h> 29#include <linux/hwmon.h>
30#include <linux/i2c-vid.h> 30#include <linux/hwmon-vid.h>
31#include <linux/err.h>
31 32
32/* Type of the extra sensor */ 33/* Type of the extra sensor */
33static unsigned short extra_sensor_type; 34static unsigned short extra_sensor_type;
@@ -36,10 +37,9 @@ MODULE_PARM_DESC(extra_sensor_type, "Type of extra sensor (0=autodetect, 1=tempe
36 37
37/* Addresses to scan */ 38/* Addresses to scan */
38static unsigned short normal_i2c[] = { 0x2c, 0x2d, I2C_CLIENT_END }; 39static unsigned short normal_i2c[] = { 0x2c, 0x2d, I2C_CLIENT_END };
39static unsigned int normal_isa[] = { I2C_CLIENT_ISA_END };
40 40
41/* Insmod parameters */ 41/* Insmod parameters */
42SENSORS_INSMOD_1(gl520sm); 42I2C_CLIENT_INSMOD_1(gl520sm);
43 43
44/* Many GL520 constants specified below 44/* Many GL520 constants specified below
45One of the inputs can be configured as either temp or voltage. 45One of the inputs can be configured as either temp or voltage.
@@ -120,6 +120,7 @@ static struct i2c_driver gl520_driver = {
120/* Client data */ 120/* Client data */
121struct gl520_data { 121struct gl520_data {
122 struct i2c_client client; 122 struct i2c_client client;
123 struct class_device *class_dev;
123 struct semaphore update_lock; 124 struct semaphore update_lock;
124 char valid; /* zero until the following fields are valid */ 125 char valid; /* zero until the following fields are valid */
125 unsigned long last_updated; /* in jiffies */ 126 unsigned long last_updated; /* in jiffies */
@@ -518,7 +519,7 @@ static int gl520_attach_adapter(struct i2c_adapter *adapter)
518{ 519{
519 if (!(adapter->class & I2C_CLASS_HWMON)) 520 if (!(adapter->class & I2C_CLASS_HWMON))
520 return 0; 521 return 0;
521 return i2c_detect(adapter, &addr_data, gl520_detect); 522 return i2c_probe(adapter, &addr_data, gl520_detect);
522} 523}
523 524
524static int gl520_detect(struct i2c_adapter *adapter, int address, int kind) 525static int gl520_detect(struct i2c_adapter *adapter, int address, int kind)
@@ -571,6 +572,12 @@ static int gl520_detect(struct i2c_adapter *adapter, int address, int kind)
571 gl520_init_client(new_client); 572 gl520_init_client(new_client);
572 573
573 /* Register sysfs hooks */ 574 /* Register sysfs hooks */
575 data->class_dev = hwmon_device_register(&new_client->dev);
576 if (IS_ERR(data->class_dev)) {
577 err = PTR_ERR(data->class_dev);
578 goto exit_detach;
579 }
580
574 device_create_file_vid(new_client, 0); 581 device_create_file_vid(new_client, 0);
575 582
576 device_create_file_in(new_client, 0); 583 device_create_file_in(new_client, 0);
@@ -592,6 +599,8 @@ static int gl520_detect(struct i2c_adapter *adapter, int address, int kind)
592 599
593 return 0; 600 return 0;
594 601
602exit_detach:
603 i2c_detach_client(new_client);
595exit_free: 604exit_free:
596 kfree(data); 605 kfree(data);
597exit: 606exit:
@@ -608,7 +617,7 @@ static void gl520_init_client(struct i2c_client *client)
608 conf = oldconf = gl520_read_value(client, GL520_REG_CONF); 617 conf = oldconf = gl520_read_value(client, GL520_REG_CONF);
609 618
610 data->alarm_mask = 0xff; 619 data->alarm_mask = 0xff;
611 data->vrm = i2c_which_vrm(); 620 data->vrm = vid_which_vrm();
612 621
613 if (extra_sensor_type == 1) 622 if (extra_sensor_type == 1)
614 conf &= ~0x10; 623 conf &= ~0x10;
@@ -639,15 +648,15 @@ static void gl520_init_client(struct i2c_client *client)
639 648
640static int gl520_detach_client(struct i2c_client *client) 649static int gl520_detach_client(struct i2c_client *client)
641{ 650{
651 struct gl520_data *data = i2c_get_clientdata(client);
642 int err; 652 int err;
643 653
644 if ((err = i2c_detach_client(client))) { 654 hwmon_device_unregister(data->class_dev);
645 dev_err(&client->dev, "Client deregistration failed, " 655
646 "client not detached.\n"); 656 if ((err = i2c_detach_client(client)))
647 return err; 657 return err;
648 }
649 658
650 kfree(i2c_get_clientdata(client)); 659 kfree(data);
651 return 0; 660 return 0;
652} 661}
653 662
diff --git a/drivers/hwmon/hwmon-vid.c b/drivers/hwmon/hwmon-vid.c
new file mode 100644
index 00000000000..312769ad4da
--- /dev/null
+++ b/drivers/hwmon/hwmon-vid.c
@@ -0,0 +1,189 @@
1/*
2 hwmon-vid.c - VID/VRM/VRD voltage conversions
3
4 Copyright (c) 2004 Rudolf Marek <r.marek@sh.cvut.cz>
5
6 Partly imported from i2c-vid.h of the lm_sensors project
7 Copyright (c) 2002 Mark D. Studebaker <mdsxyz123@yahoo.com>
8 With assistance from Trent Piepho <xyzzy@speakeasy.org>
9
10 This program is free software; you can redistribute it and/or modify
11 it under the terms of the GNU General Public License as published by
12 the Free Software Foundation; either version 2 of the License, or
13 (at your option) any later version.
14
15 This program is distributed in the hope that it will be useful,
16 but WITHOUT ANY WARRANTY; without even the implied warranty of
17 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 GNU General Public License for more details.
19
20 You should have received a copy of the GNU General Public License
21 along with this program; if not, write to the Free Software
22 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
23*/
24
25#include <linux/config.h>
26#include <linux/module.h>
27#include <linux/kernel.h>
28#include <linux/hwmon-vid.h>
29
30/*
31 Common code for decoding VID pins.
32
33 References:
34
35 For VRM 8.4 to 9.1, "VRM x.y DC-DC Converter Design Guidelines",
36 available at http://developer.intel.com/.
37
38 For VRD 10.0 and up, "VRD x.y Design Guide",
39 available at http://developer.intel.com/.
40
41 AMD Opteron processors don't follow the Intel specifications.
42 I'm going to "make up" 2.4 as the spec number for the Opterons.
43 No good reason just a mnemonic for the 24x Opteron processor
44 series.
45
46 Opteron VID encoding is:
47 00000 = 1.550 V
48 00001 = 1.525 V
49 . . . .
50 11110 = 0.800 V
51 11111 = 0.000 V (off)
52*/
53
54/* vrm is the VRM/VRD document version multiplied by 10.
55 val is the 4-, 5- or 6-bit VID code.
56 Returned value is in mV to avoid floating point in the kernel. */
57int vid_from_reg(int val, int vrm)
58{
59 int vid;
60
61 switch(vrm) {
62
63 case 0:
64 return 0;
65
66 case 100: /* VRD 10.0 */
67 if((val & 0x1f) == 0x1f)
68 return 0;
69 if((val & 0x1f) <= 0x09 || val == 0x0a)
70 vid = 10875 - (val & 0x1f) * 250;
71 else
72 vid = 18625 - (val & 0x1f) * 250;
73 if(val & 0x20)
74 vid -= 125;
75 vid /= 10; /* only return 3 dec. places for now */
76 return vid;
77
78 case 24: /* Opteron processor */
79 return(val == 0x1f ? 0 : 1550 - val * 25);
80
81 case 91: /* VRM 9.1 */
82 case 90: /* VRM 9.0 */
83 return(val == 0x1f ? 0 :
84 1850 - val * 25);
85
86 case 85: /* VRM 8.5 */
87 return((val & 0x10 ? 25 : 0) +
88 ((val & 0x0f) > 0x04 ? 2050 : 1250) -
89 ((val & 0x0f) * 50));
90
91 case 84: /* VRM 8.4 */
92 val &= 0x0f;
93 /* fall through */
94 default: /* VRM 8.2 */
95 return(val == 0x1f ? 0 :
96 val & 0x10 ? 5100 - (val) * 100 :
97 2050 - (val) * 50);
98 }
99}
100
101
102/*
103 After this point is the code to automatically determine which
104 VRM/VRD specification should be used depending on the CPU.
105*/
106
107struct vrm_model {
108 u8 vendor;
109 u8 eff_family;
110 u8 eff_model;
111 int vrm_type;
112};
113
114#define ANY 0xFF
115
116#ifdef CONFIG_X86
117
118static struct vrm_model vrm_models[] = {
119 {X86_VENDOR_AMD, 0x6, ANY, 90}, /* Athlon Duron etc */
120 {X86_VENDOR_AMD, 0xF, ANY, 24}, /* Athlon 64, Opteron */
121 {X86_VENDOR_INTEL, 0x6, 0x9, 85}, /* 0.13um too */
122 {X86_VENDOR_INTEL, 0x6, 0xB, 85}, /* Tualatin */
123 {X86_VENDOR_INTEL, 0x6, ANY, 82}, /* any P6 */
124 {X86_VENDOR_INTEL, 0x7, ANY, 0}, /* Itanium */
125 {X86_VENDOR_INTEL, 0xF, 0x0, 90}, /* P4 */
126 {X86_VENDOR_INTEL, 0xF, 0x1, 90}, /* P4 Willamette */
127 {X86_VENDOR_INTEL, 0xF, 0x2, 90}, /* P4 Northwood */
128 {X86_VENDOR_INTEL, 0xF, 0x3, 100}, /* P4 Prescott */
129 {X86_VENDOR_INTEL, 0xF, 0x4, 100}, /* P4 Prescott */
130 {X86_VENDOR_INTEL, 0x10,ANY, 0}, /* Itanium 2 */
131 {X86_VENDOR_UNKNOWN, ANY, ANY, 0} /* stop here */
132};
133
134static int find_vrm(u8 eff_family, u8 eff_model, u8 vendor)
135{
136 int i = 0;
137
138 while (vrm_models[i].vendor!=X86_VENDOR_UNKNOWN) {
139 if (vrm_models[i].vendor==vendor)
140 if ((vrm_models[i].eff_family==eff_family)
141 && ((vrm_models[i].eff_model==eff_model) ||
142 (vrm_models[i].eff_model==ANY)))
143 return vrm_models[i].vrm_type;
144 i++;
145 }
146
147 return 0;
148}
149
150int vid_which_vrm(void)
151{
152 struct cpuinfo_x86 *c = cpu_data;
153 u32 eax;
154 u8 eff_family, eff_model;
155 int vrm_ret;
156
157 if (c->x86 < 6) /* Any CPU with family lower than 6 */
158 return 0; /* doesn't have VID and/or CPUID */
159
160 eax = cpuid_eax(1);
161 eff_family = ((eax & 0x00000F00)>>8);
162 eff_model = ((eax & 0x000000F0)>>4);
163 if (eff_family == 0xF) { /* use extended model & family */
164 eff_family += ((eax & 0x00F00000)>>20);
165 eff_model += ((eax & 0x000F0000)>>16)<<4;
166 }
167 vrm_ret = find_vrm(eff_family,eff_model,c->x86_vendor);
168 if (vrm_ret == 0)
169 printk(KERN_INFO "hwmon-vid: Unknown VRM version of your "
170 "x86 CPU\n");
171 return vrm_ret;
172}
173
174/* and now something completely different for the non-x86 world */
175#else
176int vid_which_vrm(void)
177{
178 printk(KERN_INFO "hwmon-vid: Unknown VRM version of your CPU\n");
179 return 0;
180}
181#endif
182
183EXPORT_SYMBOL(vid_from_reg);
184EXPORT_SYMBOL(vid_which_vrm);
185
186MODULE_AUTHOR("Rudolf Marek <r.marek@sh.cvut.cz>");
187
188MODULE_DESCRIPTION("hwmon-vid driver");
189MODULE_LICENSE("GPL");
diff --git a/drivers/hwmon/hwmon.c b/drivers/hwmon/hwmon.c
new file mode 100644
index 00000000000..9b41c9bd805
--- /dev/null
+++ b/drivers/hwmon/hwmon.c
@@ -0,0 +1,98 @@
1/*
2 hwmon.c - part of lm_sensors, Linux kernel modules for hardware monitoring
3
4 This file defines the sysfs class "hwmon", for use by sensors drivers.
5
6 Copyright (C) 2005 Mark M. Hoffman <mhoffman@lightlink.com>
7
8 This program is free software; you can redistribute it and/or modify
9 it under the terms of the GNU General Public License as published by
10 the Free Software Foundation; version 2 of the License.
11*/
12
13#include <linux/module.h>
14#include <linux/device.h>
15#include <linux/err.h>
16#include <linux/kdev_t.h>
17#include <linux/idr.h>
18#include <linux/hwmon.h>
19
20#define HWMON_ID_PREFIX "hwmon"
21#define HWMON_ID_FORMAT HWMON_ID_PREFIX "%d"
22
23static struct class *hwmon_class;
24
25static DEFINE_IDR(hwmon_idr);
26
27/**
28 * hwmon_device_register - register w/ hwmon sysfs class
29 * @dev: the device to register
30 *
31 * hwmon_device_unregister() must be called when the class device is no
32 * longer needed.
33 *
34 * Returns the pointer to the new struct class device.
35 */
36struct class_device *hwmon_device_register(struct device *dev)
37{
38 struct class_device *cdev;
39 int id;
40
41 if (idr_pre_get(&hwmon_idr, GFP_KERNEL) == 0)
42 return ERR_PTR(-ENOMEM);
43
44 if (idr_get_new(&hwmon_idr, NULL, &id) < 0)
45 return ERR_PTR(-ENOMEM);
46
47 id = id & MAX_ID_MASK;
48 cdev = class_device_create(hwmon_class, MKDEV(0,0), dev,
49 HWMON_ID_FORMAT, id);
50
51 if (IS_ERR(cdev))
52 idr_remove(&hwmon_idr, id);
53
54 return cdev;
55}
56
57/**
58 * hwmon_device_unregister - removes the previously registered class device
59 *
60 * @cdev: the class device to destroy
61 */
62void hwmon_device_unregister(struct class_device *cdev)
63{
64 int id;
65
66 if (sscanf(cdev->class_id, HWMON_ID_FORMAT, &id) == 1) {
67 class_device_unregister(cdev);
68 idr_remove(&hwmon_idr, id);
69 } else
70 dev_dbg(cdev->dev,
71 "hwmon_device_unregister() failed: bad class ID!\n");
72}
73
74static int __init hwmon_init(void)
75{
76 hwmon_class = class_create(THIS_MODULE, "hwmon");
77 if (IS_ERR(hwmon_class)) {
78 printk(KERN_ERR "hwmon.c: couldn't create sysfs class\n");
79 return PTR_ERR(hwmon_class);
80 }
81 return 0;
82}
83
84static void __exit hwmon_exit(void)
85{
86 class_destroy(hwmon_class);
87}
88
89module_init(hwmon_init);
90module_exit(hwmon_exit);
91
92EXPORT_SYMBOL_GPL(hwmon_device_register);
93EXPORT_SYMBOL_GPL(hwmon_device_unregister);
94
95MODULE_AUTHOR("Mark M. Hoffman <mhoffman@lightlink.com>");
96MODULE_DESCRIPTION("hardware monitoring sysfs/class support");
97MODULE_LICENSE("GPL");
98
diff --git a/drivers/hwmon/it87.c b/drivers/hwmon/it87.c
index db20c9e4739..53cc2b6d638 100644
--- a/drivers/hwmon/it87.c
+++ b/drivers/hwmon/it87.c
@@ -36,19 +36,21 @@
36#include <linux/slab.h> 36#include <linux/slab.h>
37#include <linux/jiffies.h> 37#include <linux/jiffies.h>
38#include <linux/i2c.h> 38#include <linux/i2c.h>
39#include <linux/i2c-sensor.h> 39#include <linux/i2c-isa.h>
40#include <linux/i2c-vid.h> 40#include <linux/hwmon.h>
41#include <linux/hwmon-sysfs.h> 41#include <linux/hwmon-sysfs.h>
42#include <linux/hwmon-vid.h>
43#include <linux/err.h>
42#include <asm/io.h> 44#include <asm/io.h>
43 45
44 46
45/* Addresses to scan */ 47/* Addresses to scan */
46static unsigned short normal_i2c[] = { 0x28, 0x29, 0x2a, 0x2b, 0x2c, 0x2d, 48static unsigned short normal_i2c[] = { 0x28, 0x29, 0x2a, 0x2b, 0x2c, 0x2d,
47 0x2e, 0x2f, I2C_CLIENT_END }; 49 0x2e, 0x2f, I2C_CLIENT_END };
48static unsigned int normal_isa[] = { 0x0290, I2C_CLIENT_ISA_END }; 50static unsigned short isa_address = 0x290;
49 51
50/* Insmod parameters */ 52/* Insmod parameters */
51SENSORS_INSMOD_2(it87, it8712); 53I2C_CLIENT_INSMOD_2(it87, it8712);
52 54
53#define REG 0x2e /* The register to read/write */ 55#define REG 0x2e /* The register to read/write */
54#define DEV 0x07 /* Register: Logical device select */ 56#define DEV 0x07 /* Register: Logical device select */
@@ -192,6 +194,7 @@ static int DIV_TO_REG(int val)
192 allocated. */ 194 allocated. */
193struct it87_data { 195struct it87_data {
194 struct i2c_client client; 196 struct i2c_client client;
197 struct class_device *class_dev;
195 struct semaphore lock; 198 struct semaphore lock;
196 enum chips type; 199 enum chips type;
197 200
@@ -218,7 +221,7 @@ struct it87_data {
218 221
219 222
220static int it87_attach_adapter(struct i2c_adapter *adapter); 223static int it87_attach_adapter(struct i2c_adapter *adapter);
221static int it87_find(int *address); 224static int it87_isa_attach_adapter(struct i2c_adapter *adapter);
222static int it87_detect(struct i2c_adapter *adapter, int address, int kind); 225static int it87_detect(struct i2c_adapter *adapter, int address, int kind);
223static int it87_detach_client(struct i2c_client *client); 226static int it87_detach_client(struct i2c_client *client);
224 227
@@ -239,6 +242,14 @@ static struct i2c_driver it87_driver = {
239 .detach_client = it87_detach_client, 242 .detach_client = it87_detach_client,
240}; 243};
241 244
245static struct i2c_driver it87_isa_driver = {
246 .owner = THIS_MODULE,
247 .name = "it87-isa",
248 .attach_adapter = it87_isa_attach_adapter,
249 .detach_client = it87_detach_client,
250};
251
252
242static ssize_t show_in(struct device *dev, struct device_attribute *attr, 253static ssize_t show_in(struct device *dev, struct device_attribute *attr,
243 char *buf) 254 char *buf)
244{ 255{
@@ -686,11 +697,16 @@ static int it87_attach_adapter(struct i2c_adapter *adapter)
686{ 697{
687 if (!(adapter->class & I2C_CLASS_HWMON)) 698 if (!(adapter->class & I2C_CLASS_HWMON))
688 return 0; 699 return 0;
689 return i2c_detect(adapter, &addr_data, it87_detect); 700 return i2c_probe(adapter, &addr_data, it87_detect);
690} 701}
691 702
692/* SuperIO detection - will change normal_isa[0] if a chip is found */ 703static int it87_isa_attach_adapter(struct i2c_adapter *adapter)
693static int it87_find(int *address) 704{
705 return it87_detect(adapter, isa_address, -1);
706}
707
708/* SuperIO detection - will change isa_address if a chip is found */
709static int __init it87_find(int *address)
694{ 710{
695 int err = -ENODEV; 711 int err = -ENODEV;
696 712
@@ -721,7 +737,7 @@ exit:
721 return err; 737 return err;
722} 738}
723 739
724/* This function is called by i2c_detect */ 740/* This function is called by i2c_probe */
725int it87_detect(struct i2c_adapter *adapter, int address, int kind) 741int it87_detect(struct i2c_adapter *adapter, int address, int kind)
726{ 742{
727 int i; 743 int i;
@@ -738,7 +754,7 @@ int it87_detect(struct i2c_adapter *adapter, int address, int kind)
738 754
739 /* Reserve the ISA region */ 755 /* Reserve the ISA region */
740 if (is_isa) 756 if (is_isa)
741 if (!request_region(address, IT87_EXTENT, it87_driver.name)) 757 if (!request_region(address, IT87_EXTENT, it87_isa_driver.name))
742 goto ERROR0; 758 goto ERROR0;
743 759
744 /* Probe whether there is anything available on this address. Already 760 /* Probe whether there is anything available on this address. Already
@@ -784,7 +800,7 @@ int it87_detect(struct i2c_adapter *adapter, int address, int kind)
784 i2c_set_clientdata(new_client, data); 800 i2c_set_clientdata(new_client, data);
785 new_client->addr = address; 801 new_client->addr = address;
786 new_client->adapter = adapter; 802 new_client->adapter = adapter;
787 new_client->driver = &it87_driver; 803 new_client->driver = is_isa ? &it87_isa_driver : &it87_driver;
788 new_client->flags = 0; 804 new_client->flags = 0;
789 805
790 /* Now, we do the remaining detection. */ 806 /* Now, we do the remaining detection. */
@@ -840,6 +856,12 @@ int it87_detect(struct i2c_adapter *adapter, int address, int kind)
840 it87_init_client(new_client, data); 856 it87_init_client(new_client, data);
841 857
842 /* Register sysfs hooks */ 858 /* Register sysfs hooks */
859 data->class_dev = hwmon_device_register(&new_client->dev);
860 if (IS_ERR(data->class_dev)) {
861 err = PTR_ERR(data->class_dev);
862 goto ERROR3;
863 }
864
843 device_create_file(&new_client->dev, &sensor_dev_attr_in0_input.dev_attr); 865 device_create_file(&new_client->dev, &sensor_dev_attr_in0_input.dev_attr);
844 device_create_file(&new_client->dev, &sensor_dev_attr_in1_input.dev_attr); 866 device_create_file(&new_client->dev, &sensor_dev_attr_in1_input.dev_attr);
845 device_create_file(&new_client->dev, &sensor_dev_attr_in2_input.dev_attr); 867 device_create_file(&new_client->dev, &sensor_dev_attr_in2_input.dev_attr);
@@ -897,13 +919,15 @@ int it87_detect(struct i2c_adapter *adapter, int address, int kind)
897 } 919 }
898 920
899 if (data->type == it8712) { 921 if (data->type == it8712) {
900 data->vrm = i2c_which_vrm(); 922 data->vrm = vid_which_vrm();
901 device_create_file_vrm(new_client); 923 device_create_file_vrm(new_client);
902 device_create_file_vid(new_client); 924 device_create_file_vid(new_client);
903 } 925 }
904 926
905 return 0; 927 return 0;
906 928
929ERROR3:
930 i2c_detach_client(new_client);
907ERROR2: 931ERROR2:
908 kfree(data); 932 kfree(data);
909ERROR1: 933ERROR1:
@@ -915,17 +939,17 @@ ERROR0:
915 939
916static int it87_detach_client(struct i2c_client *client) 940static int it87_detach_client(struct i2c_client *client)
917{ 941{
942 struct it87_data *data = i2c_get_clientdata(client);
918 int err; 943 int err;
919 944
920 if ((err = i2c_detach_client(client))) { 945 hwmon_device_unregister(data->class_dev);
921 dev_err(&client->dev, 946
922 "Client deregistration failed, client not detached.\n"); 947 if ((err = i2c_detach_client(client)))
923 return err; 948 return err;
924 }
925 949
926 if(i2c_is_isa_client(client)) 950 if(i2c_is_isa_client(client))
927 release_region(client->addr, IT87_EXTENT); 951 release_region(client->addr, IT87_EXTENT);
928 kfree(i2c_get_clientdata(client)); 952 kfree(data);
929 953
930 return 0; 954 return 0;
931} 955}
@@ -1158,16 +1182,28 @@ static struct it87_data *it87_update_device(struct device *dev)
1158 1182
1159static int __init sm_it87_init(void) 1183static int __init sm_it87_init(void)
1160{ 1184{
1161 int addr; 1185 int addr, res;
1162 1186
1163 if (!it87_find(&addr)) { 1187 if (!it87_find(&addr)) {
1164 normal_isa[0] = addr; 1188 isa_address = addr;
1189 }
1190
1191 res = i2c_add_driver(&it87_driver);
1192 if (res)
1193 return res;
1194
1195 res = i2c_isa_add_driver(&it87_isa_driver);
1196 if (res) {
1197 i2c_del_driver(&it87_driver);
1198 return res;
1165 } 1199 }
1166 return i2c_add_driver(&it87_driver); 1200
1201 return 0;
1167} 1202}
1168 1203
1169static void __exit sm_it87_exit(void) 1204static void __exit sm_it87_exit(void)
1170{ 1205{
1206 i2c_isa_del_driver(&it87_isa_driver);
1171 i2c_del_driver(&it87_driver); 1207 i2c_del_driver(&it87_driver);
1172} 1208}
1173 1209
diff --git a/drivers/hwmon/lm63.c b/drivers/hwmon/lm63.c
index 7c6f9ea5a25..be5c7095ecb 100644
--- a/drivers/hwmon/lm63.c
+++ b/drivers/hwmon/lm63.c
@@ -42,8 +42,9 @@
42#include <linux/slab.h> 42#include <linux/slab.h>
43#include <linux/jiffies.h> 43#include <linux/jiffies.h>
44#include <linux/i2c.h> 44#include <linux/i2c.h>
45#include <linux/i2c-sensor.h>
46#include <linux/hwmon-sysfs.h> 45#include <linux/hwmon-sysfs.h>
46#include <linux/hwmon.h>
47#include <linux/err.h>
47 48
48/* 49/*
49 * Addresses to scan 50 * Addresses to scan
@@ -51,13 +52,12 @@
51 */ 52 */
52 53
53static unsigned short normal_i2c[] = { 0x4c, I2C_CLIENT_END }; 54static unsigned short normal_i2c[] = { 0x4c, I2C_CLIENT_END };
54static unsigned int normal_isa[] = { I2C_CLIENT_ISA_END };
55 55
56/* 56/*
57 * Insmod parameters 57 * Insmod parameters
58 */ 58 */
59 59
60SENSORS_INSMOD_1(lm63); 60I2C_CLIENT_INSMOD_1(lm63);
61 61
62/* 62/*
63 * The LM63 registers 63 * The LM63 registers
@@ -152,6 +152,7 @@ static struct i2c_driver lm63_driver = {
152 152
153struct lm63_data { 153struct lm63_data {
154 struct i2c_client client; 154 struct i2c_client client;
155 struct class_device *class_dev;
155 struct semaphore update_lock; 156 struct semaphore update_lock;
156 char valid; /* zero until following fields are valid */ 157 char valid; /* zero until following fields are valid */
157 unsigned long last_updated; /* in jiffies */ 158 unsigned long last_updated; /* in jiffies */
@@ -358,7 +359,7 @@ static int lm63_attach_adapter(struct i2c_adapter *adapter)
358{ 359{
359 if (!(adapter->class & I2C_CLASS_HWMON)) 360 if (!(adapter->class & I2C_CLASS_HWMON))
360 return 0; 361 return 0;
361 return i2c_detect(adapter, &addr_data, lm63_detect); 362 return i2c_probe(adapter, &addr_data, lm63_detect);
362} 363}
363 364
364/* 365/*
@@ -437,6 +438,12 @@ static int lm63_detect(struct i2c_adapter *adapter, int address, int kind)
437 lm63_init_client(new_client); 438 lm63_init_client(new_client);
438 439
439 /* Register sysfs hooks */ 440 /* Register sysfs hooks */
441 data->class_dev = hwmon_device_register(&new_client->dev);
442 if (IS_ERR(data->class_dev)) {
443 err = PTR_ERR(data->class_dev);
444 goto exit_detach;
445 }
446
440 if (data->config & 0x04) { /* tachometer enabled */ 447 if (data->config & 0x04) { /* tachometer enabled */
441 device_create_file(&new_client->dev, 448 device_create_file(&new_client->dev,
442 &sensor_dev_attr_fan1_input.dev_attr); 449 &sensor_dev_attr_fan1_input.dev_attr);
@@ -462,6 +469,8 @@ static int lm63_detect(struct i2c_adapter *adapter, int address, int kind)
462 469
463 return 0; 470 return 0;
464 471
472exit_detach:
473 i2c_detach_client(new_client);
465exit_free: 474exit_free:
466 kfree(data); 475 kfree(data);
467exit: 476exit:
@@ -505,15 +514,15 @@ static void lm63_init_client(struct i2c_client *client)
505 514
506static int lm63_detach_client(struct i2c_client *client) 515static int lm63_detach_client(struct i2c_client *client)
507{ 516{
517 struct lm63_data *data = i2c_get_clientdata(client);
508 int err; 518 int err;
509 519
510 if ((err = i2c_detach_client(client))) { 520 hwmon_device_unregister(data->class_dev);
511 dev_err(&client->dev, "Client deregistration failed, " 521
512 "client not detached\n"); 522 if ((err = i2c_detach_client(client)))
513 return err; 523 return err;
514 }
515 524
516 kfree(i2c_get_clientdata(client)); 525 kfree(data);
517 return 0; 526 return 0;
518} 527}
519 528
diff --git a/drivers/hwmon/lm75.c b/drivers/hwmon/lm75.c
index 5be164ed278..9a3ebdf583f 100644
--- a/drivers/hwmon/lm75.c
+++ b/drivers/hwmon/lm75.c
@@ -23,17 +23,17 @@
23#include <linux/slab.h> 23#include <linux/slab.h>
24#include <linux/jiffies.h> 24#include <linux/jiffies.h>
25#include <linux/i2c.h> 25#include <linux/i2c.h>
26#include <linux/i2c-sensor.h> 26#include <linux/hwmon.h>
27#include <linux/err.h>
27#include "lm75.h" 28#include "lm75.h"
28 29
29 30
30/* Addresses to scan */ 31/* Addresses to scan */
31static unsigned short normal_i2c[] = { 0x48, 0x49, 0x4a, 0x4b, 0x4c, 32static unsigned short normal_i2c[] = { 0x48, 0x49, 0x4a, 0x4b, 0x4c,
32 0x4d, 0x4e, 0x4f, I2C_CLIENT_END }; 33 0x4d, 0x4e, 0x4f, I2C_CLIENT_END };
33static unsigned int normal_isa[] = { I2C_CLIENT_ISA_END };
34 34
35/* Insmod parameters */ 35/* Insmod parameters */
36SENSORS_INSMOD_1(lm75); 36I2C_CLIENT_INSMOD_1(lm75);
37 37
38/* Many LM75 constants specified below */ 38/* Many LM75 constants specified below */
39 39
@@ -46,6 +46,7 @@ SENSORS_INSMOD_1(lm75);
46/* Each client has this additional data */ 46/* Each client has this additional data */
47struct lm75_data { 47struct lm75_data {
48 struct i2c_client client; 48 struct i2c_client client;
49 struct class_device *class_dev;
49 struct semaphore update_lock; 50 struct semaphore update_lock;
50 char valid; /* !=0 if following fields are valid */ 51 char valid; /* !=0 if following fields are valid */
51 unsigned long last_updated; /* In jiffies */ 52 unsigned long last_updated; /* In jiffies */
@@ -107,10 +108,10 @@ static int lm75_attach_adapter(struct i2c_adapter *adapter)
107{ 108{
108 if (!(adapter->class & I2C_CLASS_HWMON)) 109 if (!(adapter->class & I2C_CLASS_HWMON))
109 return 0; 110 return 0;
110 return i2c_detect(adapter, &addr_data, lm75_detect); 111 return i2c_probe(adapter, &addr_data, lm75_detect);
111} 112}
112 113
113/* This function is called by i2c_detect */ 114/* This function is called by i2c_probe */
114static int lm75_detect(struct i2c_adapter *adapter, int address, int kind) 115static int lm75_detect(struct i2c_adapter *adapter, int address, int kind)
115{ 116{
116 int i; 117 int i;
@@ -119,16 +120,6 @@ static int lm75_detect(struct i2c_adapter *adapter, int address, int kind)
119 int err = 0; 120 int err = 0;
120 const char *name = ""; 121 const char *name = "";
121 122
122 /* Make sure we aren't probing the ISA bus!! This is just a safety check
123 at this moment; i2c_detect really won't call us. */
124#ifdef DEBUG
125 if (i2c_is_isa_adapter(adapter)) {
126 dev_dbg(&adapter->dev,
127 "lm75_detect called for an ISA bus adapter?!?\n");
128 goto exit;
129 }
130#endif
131
132 if (!i2c_check_functionality(adapter, I2C_FUNC_SMBUS_BYTE_DATA | 123 if (!i2c_check_functionality(adapter, I2C_FUNC_SMBUS_BYTE_DATA |
133 I2C_FUNC_SMBUS_WORD_DATA)) 124 I2C_FUNC_SMBUS_WORD_DATA))
134 goto exit; 125 goto exit;
@@ -208,12 +199,20 @@ static int lm75_detect(struct i2c_adapter *adapter, int address, int kind)
208 lm75_init_client(new_client); 199 lm75_init_client(new_client);
209 200
210 /* Register sysfs hooks */ 201 /* Register sysfs hooks */
202 data->class_dev = hwmon_device_register(&new_client->dev);
203 if (IS_ERR(data->class_dev)) {
204 err = PTR_ERR(data->class_dev);
205 goto exit_detach;
206 }
207
211 device_create_file(&new_client->dev, &dev_attr_temp1_max); 208 device_create_file(&new_client->dev, &dev_attr_temp1_max);
212 device_create_file(&new_client->dev, &dev_attr_temp1_max_hyst); 209 device_create_file(&new_client->dev, &dev_attr_temp1_max_hyst);
213 device_create_file(&new_client->dev, &dev_attr_temp1_input); 210 device_create_file(&new_client->dev, &dev_attr_temp1_input);
214 211
215 return 0; 212 return 0;
216 213
214exit_detach:
215 i2c_detach_client(new_client);
217exit_free: 216exit_free:
218 kfree(data); 217 kfree(data);
219exit: 218exit:
@@ -222,8 +221,10 @@ exit:
222 221
223static int lm75_detach_client(struct i2c_client *client) 222static int lm75_detach_client(struct i2c_client *client)
224{ 223{
224 struct lm75_data *data = i2c_get_clientdata(client);
225 hwmon_device_unregister(data->class_dev);
225 i2c_detach_client(client); 226 i2c_detach_client(client);
226 kfree(i2c_get_clientdata(client)); 227 kfree(data);
227 return 0; 228 return 0;
228} 229}
229 230
@@ -251,8 +252,12 @@ static int lm75_write_value(struct i2c_client *client, u8 reg, u16 value)
251 252
252static void lm75_init_client(struct i2c_client *client) 253static void lm75_init_client(struct i2c_client *client)
253{ 254{
254 /* Initialize the LM75 chip */ 255 int reg;
255 lm75_write_value(client, LM75_REG_CONF, 0); 256
257 /* Enable if in shutdown mode */
258 reg = lm75_read_value(client, LM75_REG_CONF);
259 if (reg >= 0 && (reg & 0x01))
260 lm75_write_value(client, LM75_REG_CONF, reg & 0xfe);
256} 261}
257 262
258static struct lm75_data *lm75_update_device(struct device *dev) 263static struct lm75_data *lm75_update_device(struct device *dev)
diff --git a/drivers/hwmon/lm75.h b/drivers/hwmon/lm75.h
index 63e3f2fb4c2..af7dc650ee1 100644
--- a/drivers/hwmon/lm75.h
+++ b/drivers/hwmon/lm75.h
@@ -25,7 +25,7 @@
25 which contains this code, we don't worry about the wasted space. 25 which contains this code, we don't worry about the wasted space.
26*/ 26*/
27 27
28#include <linux/i2c-sensor.h> 28#include <linux/hwmon.h>
29 29
30/* straight from the datasheet */ 30/* straight from the datasheet */
31#define LM75_TEMP_MIN (-55000) 31#define LM75_TEMP_MIN (-55000)
diff --git a/drivers/hwmon/lm77.c b/drivers/hwmon/lm77.c
index b98f4495299..866eab96a6f 100644
--- a/drivers/hwmon/lm77.c
+++ b/drivers/hwmon/lm77.c
@@ -30,15 +30,14 @@
30#include <linux/slab.h> 30#include <linux/slab.h>
31#include <linux/jiffies.h> 31#include <linux/jiffies.h>
32#include <linux/i2c.h> 32#include <linux/i2c.h>
33#include <linux/i2c-sensor.h> 33#include <linux/hwmon.h>
34 34#include <linux/err.h>
35 35
36/* Addresses to scan */ 36/* Addresses to scan */
37static unsigned short normal_i2c[] = { 0x48, 0x49, 0x4a, 0x4b, I2C_CLIENT_END }; 37static unsigned short normal_i2c[] = { 0x48, 0x49, 0x4a, 0x4b, I2C_CLIENT_END };
38static unsigned int normal_isa[] = { I2C_CLIENT_ISA_END };
39 38
40/* Insmod parameters */ 39/* Insmod parameters */
41SENSORS_INSMOD_1(lm77); 40I2C_CLIENT_INSMOD_1(lm77);
42 41
43/* The LM77 registers */ 42/* The LM77 registers */
44#define LM77_REG_TEMP 0x00 43#define LM77_REG_TEMP 0x00
@@ -51,6 +50,7 @@ SENSORS_INSMOD_1(lm77);
51/* Each client has this additional data */ 50/* Each client has this additional data */
52struct lm77_data { 51struct lm77_data {
53 struct i2c_client client; 52 struct i2c_client client;
53 struct class_device *class_dev;
54 struct semaphore update_lock; 54 struct semaphore update_lock;
55 char valid; 55 char valid;
56 unsigned long last_updated; /* In jiffies */ 56 unsigned long last_updated; /* In jiffies */
@@ -208,10 +208,10 @@ static int lm77_attach_adapter(struct i2c_adapter *adapter)
208{ 208{
209 if (!(adapter->class & I2C_CLASS_HWMON)) 209 if (!(adapter->class & I2C_CLASS_HWMON))
210 return 0; 210 return 0;
211 return i2c_detect(adapter, &addr_data, lm77_detect); 211 return i2c_probe(adapter, &addr_data, lm77_detect);
212} 212}
213 213
214/* This function is called by i2c_detect */ 214/* This function is called by i2c_probe */
215static int lm77_detect(struct i2c_adapter *adapter, int address, int kind) 215static int lm77_detect(struct i2c_adapter *adapter, int address, int kind)
216{ 216{
217 struct i2c_client *new_client; 217 struct i2c_client *new_client;
@@ -317,6 +317,12 @@ static int lm77_detect(struct i2c_adapter *adapter, int address, int kind)
317 lm77_init_client(new_client); 317 lm77_init_client(new_client);
318 318
319 /* Register sysfs hooks */ 319 /* Register sysfs hooks */
320 data->class_dev = hwmon_device_register(&new_client->dev);
321 if (IS_ERR(data->class_dev)) {
322 err = PTR_ERR(data->class_dev);
323 goto exit_detach;
324 }
325
320 device_create_file(&new_client->dev, &dev_attr_temp1_input); 326 device_create_file(&new_client->dev, &dev_attr_temp1_input);
321 device_create_file(&new_client->dev, &dev_attr_temp1_crit); 327 device_create_file(&new_client->dev, &dev_attr_temp1_crit);
322 device_create_file(&new_client->dev, &dev_attr_temp1_min); 328 device_create_file(&new_client->dev, &dev_attr_temp1_min);
@@ -327,6 +333,8 @@ static int lm77_detect(struct i2c_adapter *adapter, int address, int kind)
327 device_create_file(&new_client->dev, &dev_attr_alarms); 333 device_create_file(&new_client->dev, &dev_attr_alarms);
328 return 0; 334 return 0;
329 335
336exit_detach:
337 i2c_detach_client(new_client);
330exit_free: 338exit_free:
331 kfree(data); 339 kfree(data);
332exit: 340exit:
@@ -335,8 +343,10 @@ exit:
335 343
336static int lm77_detach_client(struct i2c_client *client) 344static int lm77_detach_client(struct i2c_client *client)
337{ 345{
346 struct lm77_data *data = i2c_get_clientdata(client);
347 hwmon_device_unregister(data->class_dev);
338 i2c_detach_client(client); 348 i2c_detach_client(client);
339 kfree(i2c_get_clientdata(client)); 349 kfree(data);
340 return 0; 350 return 0;
341} 351}
342 352
diff --git a/drivers/hwmon/lm78.c b/drivers/hwmon/lm78.c
index 29241469dcb..f6730dc3573 100644
--- a/drivers/hwmon/lm78.c
+++ b/drivers/hwmon/lm78.c
@@ -23,7 +23,10 @@
23#include <linux/slab.h> 23#include <linux/slab.h>
24#include <linux/jiffies.h> 24#include <linux/jiffies.h>
25#include <linux/i2c.h> 25#include <linux/i2c.h>
26#include <linux/i2c-sensor.h> 26#include <linux/i2c-isa.h>
27#include <linux/hwmon.h>
28#include <linux/hwmon-vid.h>
29#include <linux/err.h>
27#include <asm/io.h> 30#include <asm/io.h>
28 31
29/* Addresses to scan */ 32/* Addresses to scan */
@@ -31,10 +34,10 @@ static unsigned short normal_i2c[] = { 0x20, 0x21, 0x22, 0x23, 0x24,
31 0x25, 0x26, 0x27, 0x28, 0x29, 34 0x25, 0x26, 0x27, 0x28, 0x29,
32 0x2a, 0x2b, 0x2c, 0x2d, 0x2e, 35 0x2a, 0x2b, 0x2c, 0x2d, 0x2e,
33 0x2f, I2C_CLIENT_END }; 36 0x2f, I2C_CLIENT_END };
34static unsigned int normal_isa[] = { 0x0290, I2C_CLIENT_ISA_END }; 37static unsigned short isa_address = 0x290;
35 38
36/* Insmod parameters */ 39/* Insmod parameters */
37SENSORS_INSMOD_3(lm78, lm78j, lm79); 40I2C_CLIENT_INSMOD_2(lm78, lm79);
38 41
39/* Many LM78 constants specified below */ 42/* Many LM78 constants specified below */
40 43
@@ -104,13 +107,6 @@ static inline int TEMP_FROM_REG(s8 val)
104 return val * 1000; 107 return val * 1000;
105} 108}
106 109
107/* VID: mV
108 REG: (see doc/vid) */
109static inline int VID_FROM_REG(u8 val)
110{
111 return val==0x1f ? 0 : val>=0x10 ? 5100-val*100 : 2050-val*50;
112}
113
114#define DIV_FROM_REG(val) (1 << (val)) 110#define DIV_FROM_REG(val) (1 << (val))
115 111
116/* There are some complications in a module like this. First off, LM78 chips 112/* There are some complications in a module like this. First off, LM78 chips
@@ -134,6 +130,7 @@ static inline int VID_FROM_REG(u8 val)
134 allocated. */ 130 allocated. */
135struct lm78_data { 131struct lm78_data {
136 struct i2c_client client; 132 struct i2c_client client;
133 struct class_device *class_dev;
137 struct semaphore lock; 134 struct semaphore lock;
138 enum chips type; 135 enum chips type;
139 136
@@ -156,6 +153,7 @@ struct lm78_data {
156 153
157 154
158static int lm78_attach_adapter(struct i2c_adapter *adapter); 155static int lm78_attach_adapter(struct i2c_adapter *adapter);
156static int lm78_isa_attach_adapter(struct i2c_adapter *adapter);
159static int lm78_detect(struct i2c_adapter *adapter, int address, int kind); 157static int lm78_detect(struct i2c_adapter *adapter, int address, int kind);
160static int lm78_detach_client(struct i2c_client *client); 158static int lm78_detach_client(struct i2c_client *client);
161 159
@@ -174,6 +172,14 @@ static struct i2c_driver lm78_driver = {
174 .detach_client = lm78_detach_client, 172 .detach_client = lm78_detach_client,
175}; 173};
176 174
175static struct i2c_driver lm78_isa_driver = {
176 .owner = THIS_MODULE,
177 .name = "lm78-isa",
178 .attach_adapter = lm78_isa_attach_adapter,
179 .detach_client = lm78_detach_client,
180};
181
182
177/* 7 Voltages */ 183/* 7 Voltages */
178static ssize_t show_in(struct device *dev, char *buf, int nr) 184static ssize_t show_in(struct device *dev, char *buf, int nr)
179{ 185{
@@ -445,7 +451,7 @@ static DEVICE_ATTR(fan3_div, S_IRUGO, show_fan_3_div, NULL);
445static ssize_t show_vid(struct device *dev, struct device_attribute *attr, char *buf) 451static ssize_t show_vid(struct device *dev, struct device_attribute *attr, char *buf)
446{ 452{
447 struct lm78_data *data = lm78_update_device(dev); 453 struct lm78_data *data = lm78_update_device(dev);
448 return sprintf(buf, "%d\n", VID_FROM_REG(data->vid)); 454 return sprintf(buf, "%d\n", vid_from_reg(82, data->vid));
449} 455}
450static DEVICE_ATTR(cpu0_vid, S_IRUGO, show_vid, NULL); 456static DEVICE_ATTR(cpu0_vid, S_IRUGO, show_vid, NULL);
451 457
@@ -465,10 +471,15 @@ static int lm78_attach_adapter(struct i2c_adapter *adapter)
465{ 471{
466 if (!(adapter->class & I2C_CLASS_HWMON)) 472 if (!(adapter->class & I2C_CLASS_HWMON))
467 return 0; 473 return 0;
468 return i2c_detect(adapter, &addr_data, lm78_detect); 474 return i2c_probe(adapter, &addr_data, lm78_detect);
475}
476
477static int lm78_isa_attach_adapter(struct i2c_adapter *adapter)
478{
479 return lm78_detect(adapter, isa_address, -1);
469} 480}
470 481
471/* This function is called by i2c_detect */ 482/* This function is called by i2c_probe */
472int lm78_detect(struct i2c_adapter *adapter, int address, int kind) 483int lm78_detect(struct i2c_adapter *adapter, int address, int kind)
473{ 484{
474 int i, err; 485 int i, err;
@@ -485,7 +496,8 @@ int lm78_detect(struct i2c_adapter *adapter, int address, int kind)
485 496
486 /* Reserve the ISA region */ 497 /* Reserve the ISA region */
487 if (is_isa) 498 if (is_isa)
488 if (!request_region(address, LM78_EXTENT, lm78_driver.name)) { 499 if (!request_region(address, LM78_EXTENT,
500 lm78_isa_driver.name)) {
489 err = -EBUSY; 501 err = -EBUSY;
490 goto ERROR0; 502 goto ERROR0;
491 } 503 }
@@ -540,7 +552,7 @@ int lm78_detect(struct i2c_adapter *adapter, int address, int kind)
540 i2c_set_clientdata(new_client, data); 552 i2c_set_clientdata(new_client, data);
541 new_client->addr = address; 553 new_client->addr = address;
542 new_client->adapter = adapter; 554 new_client->adapter = adapter;
543 new_client->driver = &lm78_driver; 555 new_client->driver = is_isa ? &lm78_isa_driver : &lm78_driver;
544 new_client->flags = 0; 556 new_client->flags = 0;
545 557
546 /* Now, we do the remaining detection. */ 558 /* Now, we do the remaining detection. */
@@ -559,10 +571,9 @@ int lm78_detect(struct i2c_adapter *adapter, int address, int kind)
559 /* Determine the chip type. */ 571 /* Determine the chip type. */
560 if (kind <= 0) { 572 if (kind <= 0) {
561 i = lm78_read_value(new_client, LM78_REG_CHIPID); 573 i = lm78_read_value(new_client, LM78_REG_CHIPID);
562 if (i == 0x00 || i == 0x20) 574 if (i == 0x00 || i == 0x20 /* LM78 */
575 || i == 0x40) /* LM78-J */
563 kind = lm78; 576 kind = lm78;
564 else if (i == 0x40)
565 kind = lm78j;
566 else if ((i & 0xfe) == 0xc0) 577 else if ((i & 0xfe) == 0xc0)
567 kind = lm79; 578 kind = lm79;
568 else { 579 else {
@@ -578,8 +589,6 @@ int lm78_detect(struct i2c_adapter *adapter, int address, int kind)
578 589
579 if (kind == lm78) { 590 if (kind == lm78) {
580 client_name = "lm78"; 591 client_name = "lm78";
581 } else if (kind == lm78j) {
582 client_name = "lm78-j";
583 } else if (kind == lm79) { 592 } else if (kind == lm79) {
584 client_name = "lm79"; 593 client_name = "lm79";
585 } 594 }
@@ -605,6 +614,12 @@ int lm78_detect(struct i2c_adapter *adapter, int address, int kind)
605 } 614 }
606 615
607 /* Register sysfs hooks */ 616 /* Register sysfs hooks */
617 data->class_dev = hwmon_device_register(&new_client->dev);
618 if (IS_ERR(data->class_dev)) {
619 err = PTR_ERR(data->class_dev);
620 goto ERROR3;
621 }
622
608 device_create_file(&new_client->dev, &dev_attr_in0_input); 623 device_create_file(&new_client->dev, &dev_attr_in0_input);
609 device_create_file(&new_client->dev, &dev_attr_in0_min); 624 device_create_file(&new_client->dev, &dev_attr_in0_min);
610 device_create_file(&new_client->dev, &dev_attr_in0_max); 625 device_create_file(&new_client->dev, &dev_attr_in0_max);
@@ -643,6 +658,8 @@ int lm78_detect(struct i2c_adapter *adapter, int address, int kind)
643 658
644 return 0; 659 return 0;
645 660
661ERROR3:
662 i2c_detach_client(new_client);
646ERROR2: 663ERROR2:
647 kfree(data); 664 kfree(data);
648ERROR1: 665ERROR1:
@@ -654,18 +671,18 @@ ERROR0:
654 671
655static int lm78_detach_client(struct i2c_client *client) 672static int lm78_detach_client(struct i2c_client *client)
656{ 673{
674 struct lm78_data *data = i2c_get_clientdata(client);
657 int err; 675 int err;
658 676
659 if ((err = i2c_detach_client(client))) { 677 hwmon_device_unregister(data->class_dev);
660 dev_err(&client->dev, 678
661 "Client deregistration failed, client not detached.\n"); 679 if ((err = i2c_detach_client(client)))
662 return err; 680 return err;
663 }
664 681
665 if(i2c_is_isa_client(client)) 682 if(i2c_is_isa_client(client))
666 release_region(client->addr, LM78_EXTENT); 683 release_region(client->addr, LM78_EXTENT);
667 684
668 kfree(i2c_get_clientdata(client)); 685 kfree(data);
669 686
670 return 0; 687 return 0;
671} 688}
@@ -777,18 +794,31 @@ static struct lm78_data *lm78_update_device(struct device *dev)
777 794
778static int __init sm_lm78_init(void) 795static int __init sm_lm78_init(void)
779{ 796{
780 return i2c_add_driver(&lm78_driver); 797 int res;
798
799 res = i2c_add_driver(&lm78_driver);
800 if (res)
801 return res;
802
803 res = i2c_isa_add_driver(&lm78_isa_driver);
804 if (res) {
805 i2c_del_driver(&lm78_driver);
806 return res;
807 }
808
809 return 0;
781} 810}
782 811
783static void __exit sm_lm78_exit(void) 812static void __exit sm_lm78_exit(void)
784{ 813{
814 i2c_isa_del_driver(&lm78_isa_driver);
785 i2c_del_driver(&lm78_driver); 815 i2c_del_driver(&lm78_driver);
786} 816}
787 817
788 818
789 819
790MODULE_AUTHOR("Frodo Looijaard <frodol@dds.nl>"); 820MODULE_AUTHOR("Frodo Looijaard <frodol@dds.nl>");
791MODULE_DESCRIPTION("LM78, LM78-J and LM79 driver"); 821MODULE_DESCRIPTION("LM78/LM79 driver");
792MODULE_LICENSE("GPL"); 822MODULE_LICENSE("GPL");
793 823
794module_init(sm_lm78_init); 824module_init(sm_lm78_init);
diff --git a/drivers/hwmon/lm80.c b/drivers/hwmon/lm80.c
index 8100595feb4..83af8b3a0ca 100644
--- a/drivers/hwmon/lm80.c
+++ b/drivers/hwmon/lm80.c
@@ -26,15 +26,15 @@
26#include <linux/slab.h> 26#include <linux/slab.h>
27#include <linux/jiffies.h> 27#include <linux/jiffies.h>
28#include <linux/i2c.h> 28#include <linux/i2c.h>
29#include <linux/i2c-sensor.h> 29#include <linux/hwmon.h>
30#include <linux/err.h>
30 31
31/* Addresses to scan */ 32/* Addresses to scan */
32static unsigned short normal_i2c[] = { 0x28, 0x29, 0x2a, 0x2b, 0x2c, 33static unsigned short normal_i2c[] = { 0x28, 0x29, 0x2a, 0x2b, 0x2c,
33 0x2d, 0x2e, 0x2f, I2C_CLIENT_END }; 34 0x2d, 0x2e, 0x2f, I2C_CLIENT_END };
34static unsigned int normal_isa[] = { I2C_CLIENT_ISA_END };
35 35
36/* Insmod parameters */ 36/* Insmod parameters */
37SENSORS_INSMOD_1(lm80); 37I2C_CLIENT_INSMOD_1(lm80);
38 38
39/* Many LM80 constants specified below */ 39/* Many LM80 constants specified below */
40 40
@@ -107,6 +107,7 @@ static inline long TEMP_FROM_REG(u16 temp)
107 107
108struct lm80_data { 108struct lm80_data {
109 struct i2c_client client; 109 struct i2c_client client;
110 struct class_device *class_dev;
110 struct semaphore update_lock; 111 struct semaphore update_lock;
111 char valid; /* !=0 if following fields are valid */ 112 char valid; /* !=0 if following fields are valid */
112 unsigned long last_updated; /* In jiffies */ 113 unsigned long last_updated; /* In jiffies */
@@ -389,7 +390,7 @@ static int lm80_attach_adapter(struct i2c_adapter *adapter)
389{ 390{
390 if (!(adapter->class & I2C_CLASS_HWMON)) 391 if (!(adapter->class & I2C_CLASS_HWMON))
391 return 0; 392 return 0;
392 return i2c_detect(adapter, &addr_data, lm80_detect); 393 return i2c_probe(adapter, &addr_data, lm80_detect);
393} 394}
394 395
395int lm80_detect(struct i2c_adapter *adapter, int address, int kind) 396int lm80_detect(struct i2c_adapter *adapter, int address, int kind)
@@ -451,6 +452,12 @@ int lm80_detect(struct i2c_adapter *adapter, int address, int kind)
451 data->fan_min[1] = lm80_read_value(new_client, LM80_REG_FAN_MIN(2)); 452 data->fan_min[1] = lm80_read_value(new_client, LM80_REG_FAN_MIN(2));
452 453
453 /* Register sysfs hooks */ 454 /* Register sysfs hooks */
455 data->class_dev = hwmon_device_register(&new_client->dev);
456 if (IS_ERR(data->class_dev)) {
457 err = PTR_ERR(data->class_dev);
458 goto error_detach;
459 }
460
454 device_create_file(&new_client->dev, &dev_attr_in0_min); 461 device_create_file(&new_client->dev, &dev_attr_in0_min);
455 device_create_file(&new_client->dev, &dev_attr_in1_min); 462 device_create_file(&new_client->dev, &dev_attr_in1_min);
456 device_create_file(&new_client->dev, &dev_attr_in2_min); 463 device_create_file(&new_client->dev, &dev_attr_in2_min);
@@ -487,6 +494,8 @@ int lm80_detect(struct i2c_adapter *adapter, int address, int kind)
487 494
488 return 0; 495 return 0;
489 496
497error_detach:
498 i2c_detach_client(new_client);
490error_free: 499error_free:
491 kfree(data); 500 kfree(data);
492exit: 501exit:
@@ -495,15 +504,15 @@ exit:
495 504
496static int lm80_detach_client(struct i2c_client *client) 505static int lm80_detach_client(struct i2c_client *client)
497{ 506{
507 struct lm80_data *data = i2c_get_clientdata(client);
498 int err; 508 int err;
499 509
500 if ((err = i2c_detach_client(client))) { 510 hwmon_device_unregister(data->class_dev);
501 dev_err(&client->dev, "Client deregistration failed, " 511
502 "client not detached.\n"); 512 if ((err = i2c_detach_client(client)))
503 return err; 513 return err;
504 }
505 514
506 kfree(i2c_get_clientdata(client)); 515 kfree(data);
507 return 0; 516 return 0;
508} 517}
509 518
diff --git a/drivers/hwmon/lm83.c b/drivers/hwmon/lm83.c
index a49008b444c..d74b2c20c71 100644
--- a/drivers/hwmon/lm83.c
+++ b/drivers/hwmon/lm83.c
@@ -32,8 +32,9 @@
32#include <linux/slab.h> 32#include <linux/slab.h>
33#include <linux/jiffies.h> 33#include <linux/jiffies.h>
34#include <linux/i2c.h> 34#include <linux/i2c.h>
35#include <linux/i2c-sensor.h>
36#include <linux/hwmon-sysfs.h> 35#include <linux/hwmon-sysfs.h>
36#include <linux/hwmon.h>
37#include <linux/err.h>
37 38
38/* 39/*
39 * Addresses to scan 40 * Addresses to scan
@@ -45,13 +46,12 @@ static unsigned short normal_i2c[] = { 0x18, 0x19, 0x1a,
45 0x29, 0x2a, 0x2b, 46 0x29, 0x2a, 0x2b,
46 0x4c, 0x4d, 0x4e, 47 0x4c, 0x4d, 0x4e,
47 I2C_CLIENT_END }; 48 I2C_CLIENT_END };
48static unsigned int normal_isa[] = { I2C_CLIENT_ISA_END };
49 49
50/* 50/*
51 * Insmod parameters 51 * Insmod parameters
52 */ 52 */
53 53
54SENSORS_INSMOD_1(lm83); 54I2C_CLIENT_INSMOD_1(lm83);
55 55
56/* 56/*
57 * The LM83 registers 57 * The LM83 registers
@@ -138,6 +138,7 @@ static struct i2c_driver lm83_driver = {
138 138
139struct lm83_data { 139struct lm83_data {
140 struct i2c_client client; 140 struct i2c_client client;
141 struct class_device *class_dev;
141 struct semaphore update_lock; 142 struct semaphore update_lock;
142 char valid; /* zero until following fields are valid */ 143 char valid; /* zero until following fields are valid */
143 unsigned long last_updated; /* in jiffies */ 144 unsigned long last_updated; /* in jiffies */
@@ -212,7 +213,7 @@ static int lm83_attach_adapter(struct i2c_adapter *adapter)
212{ 213{
213 if (!(adapter->class & I2C_CLASS_HWMON)) 214 if (!(adapter->class & I2C_CLASS_HWMON))
214 return 0; 215 return 0;
215 return i2c_detect(adapter, &addr_data, lm83_detect); 216 return i2c_probe(adapter, &addr_data, lm83_detect);
216} 217}
217 218
218/* 219/*
@@ -312,6 +313,12 @@ static int lm83_detect(struct i2c_adapter *adapter, int address, int kind)
312 */ 313 */
313 314
314 /* Register sysfs hooks */ 315 /* Register sysfs hooks */
316 data->class_dev = hwmon_device_register(&new_client->dev);
317 if (IS_ERR(data->class_dev)) {
318 err = PTR_ERR(data->class_dev);
319 goto exit_detach;
320 }
321
315 device_create_file(&new_client->dev, 322 device_create_file(&new_client->dev,
316 &sensor_dev_attr_temp1_input.dev_attr); 323 &sensor_dev_attr_temp1_input.dev_attr);
317 device_create_file(&new_client->dev, 324 device_create_file(&new_client->dev,
@@ -340,6 +347,8 @@ static int lm83_detect(struct i2c_adapter *adapter, int address, int kind)
340 347
341 return 0; 348 return 0;
342 349
350exit_detach:
351 i2c_detach_client(new_client);
343exit_free: 352exit_free:
344 kfree(data); 353 kfree(data);
345exit: 354exit:
@@ -348,15 +357,15 @@ exit:
348 357
349static int lm83_detach_client(struct i2c_client *client) 358static int lm83_detach_client(struct i2c_client *client)
350{ 359{
360 struct lm83_data *data = i2c_get_clientdata(client);
351 int err; 361 int err;
352 362
353 if ((err = i2c_detach_client(client))) { 363 hwmon_device_unregister(data->class_dev);
354 dev_err(&client->dev, 364
355 "Client deregistration failed, client not detached.\n"); 365 if ((err = i2c_detach_client(client)))
356 return err; 366 return err;
357 }
358 367
359 kfree(i2c_get_clientdata(client)); 368 kfree(data);
360 return 0; 369 return 0;
361} 370}
362 371
diff --git a/drivers/hwmon/lm85.c b/drivers/hwmon/lm85.c
index b4d7fd41826..ab214df9624 100644
--- a/drivers/hwmon/lm85.c
+++ b/drivers/hwmon/lm85.c
@@ -28,15 +28,15 @@
28#include <linux/slab.h> 28#include <linux/slab.h>
29#include <linux/jiffies.h> 29#include <linux/jiffies.h>
30#include <linux/i2c.h> 30#include <linux/i2c.h>
31#include <linux/i2c-sensor.h> 31#include <linux/hwmon.h>
32#include <linux/i2c-vid.h> 32#include <linux/hwmon-vid.h>
33#include <linux/err.h>
33 34
34/* Addresses to scan */ 35/* Addresses to scan */
35static unsigned short normal_i2c[] = { 0x2c, 0x2d, 0x2e, I2C_CLIENT_END }; 36static unsigned short normal_i2c[] = { 0x2c, 0x2d, 0x2e, I2C_CLIENT_END };
36static unsigned int normal_isa[] = { I2C_CLIENT_ISA_END };
37 37
38/* Insmod parameters */ 38/* Insmod parameters */
39SENSORS_INSMOD_6(lm85b, lm85c, adm1027, adt7463, emc6d100, emc6d102); 39I2C_CLIENT_INSMOD_6(lm85b, lm85c, adm1027, adt7463, emc6d100, emc6d102);
40 40
41/* The LM85 registers */ 41/* The LM85 registers */
42 42
@@ -281,15 +281,6 @@ static int ZONE_TO_REG( int zone )
281#define PPR_TO_REG(val,fan) (SENSORS_LIMIT((val)-1,0,3)<<(fan *2)) 281#define PPR_TO_REG(val,fan) (SENSORS_LIMIT((val)-1,0,3)<<(fan *2))
282#define PPR_FROM_REG(val,fan) ((((val)>>(fan * 2))&0x03)+1) 282#define PPR_FROM_REG(val,fan) ((((val)>>(fan * 2))&0x03)+1)
283 283
284/* i2c-vid.h defines vid_from_reg() */
285#define VID_FROM_REG(val,vrm) (vid_from_reg((val),(vrm)))
286
287/* Unlike some other drivers we DO NOT set initial limits. Use
288 * the config file to set limits. Some users have reported
289 * motherboards shutting down when we set limits in a previous
290 * version of the driver.
291 */
292
293/* Chip sampling rates 284/* Chip sampling rates
294 * 285 *
295 * Some sensors are not updated more frequently than once per second 286 * Some sensors are not updated more frequently than once per second
@@ -339,6 +330,7 @@ struct lm85_autofan {
339 330
340struct lm85_data { 331struct lm85_data {
341 struct i2c_client client; 332 struct i2c_client client;
333 struct class_device *class_dev;
342 struct semaphore lock; 334 struct semaphore lock;
343 enum chips type; 335 enum chips type;
344 336
@@ -1019,7 +1011,7 @@ int lm85_attach_adapter(struct i2c_adapter *adapter)
1019{ 1011{
1020 if (!(adapter->class & I2C_CLASS_HWMON)) 1012 if (!(adapter->class & I2C_CLASS_HWMON))
1021 return 0; 1013 return 0;
1022 return i2c_detect(adapter, &addr_data, lm85_detect); 1014 return i2c_probe(adapter, &addr_data, lm85_detect);
1023} 1015}
1024 1016
1025int lm85_detect(struct i2c_adapter *adapter, int address, 1017int lm85_detect(struct i2c_adapter *adapter, int address,
@@ -1031,11 +1023,6 @@ int lm85_detect(struct i2c_adapter *adapter, int address,
1031 int err = 0; 1023 int err = 0;
1032 const char *type_name = ""; 1024 const char *type_name = "";
1033 1025
1034 if (i2c_is_isa_adapter(adapter)) {
1035 /* This chip has no ISA interface */
1036 goto ERROR0 ;
1037 };
1038
1039 if (!i2c_check_functionality(adapter, 1026 if (!i2c_check_functionality(adapter,
1040 I2C_FUNC_SMBUS_BYTE_DATA)) { 1027 I2C_FUNC_SMBUS_BYTE_DATA)) {
1041 /* We need to be able to do byte I/O */ 1028 /* We need to be able to do byte I/O */
@@ -1160,12 +1147,18 @@ int lm85_detect(struct i2c_adapter *adapter, int address,
1160 goto ERROR1; 1147 goto ERROR1;
1161 1148
1162 /* Set the VRM version */ 1149 /* Set the VRM version */
1163 data->vrm = i2c_which_vrm(); 1150 data->vrm = vid_which_vrm();
1164 1151
1165 /* Initialize the LM85 chip */ 1152 /* Initialize the LM85 chip */
1166 lm85_init_client(new_client); 1153 lm85_init_client(new_client);
1167 1154
1168 /* Register sysfs hooks */ 1155 /* Register sysfs hooks */
1156 data->class_dev = hwmon_device_register(&new_client->dev);
1157 if (IS_ERR(data->class_dev)) {
1158 err = PTR_ERR(data->class_dev);
1159 goto ERROR2;
1160 }
1161
1169 device_create_file(&new_client->dev, &dev_attr_fan1_input); 1162 device_create_file(&new_client->dev, &dev_attr_fan1_input);
1170 device_create_file(&new_client->dev, &dev_attr_fan2_input); 1163 device_create_file(&new_client->dev, &dev_attr_fan2_input);
1171 device_create_file(&new_client->dev, &dev_attr_fan3_input); 1164 device_create_file(&new_client->dev, &dev_attr_fan3_input);
@@ -1235,6 +1228,8 @@ int lm85_detect(struct i2c_adapter *adapter, int address,
1235 return 0; 1228 return 0;
1236 1229
1237 /* Error out and cleanup code */ 1230 /* Error out and cleanup code */
1231 ERROR2:
1232 i2c_detach_client(new_client);
1238 ERROR1: 1233 ERROR1:
1239 kfree(data); 1234 kfree(data);
1240 ERROR0: 1235 ERROR0:
@@ -1243,8 +1238,10 @@ int lm85_detect(struct i2c_adapter *adapter, int address,
1243 1238
1244int lm85_detach_client(struct i2c_client *client) 1239int lm85_detach_client(struct i2c_client *client)
1245{ 1240{
1241 struct lm85_data *data = i2c_get_clientdata(client);
1242 hwmon_device_unregister(data->class_dev);
1246 i2c_detach_client(client); 1243 i2c_detach_client(client);
1247 kfree(i2c_get_clientdata(client)); 1244 kfree(data);
1248 return 0; 1245 return 0;
1249} 1246}
1250 1247
diff --git a/drivers/hwmon/lm87.c b/drivers/hwmon/lm87.c
index 1921ed1af18..dca996de4c3 100644
--- a/drivers/hwmon/lm87.c
+++ b/drivers/hwmon/lm87.c
@@ -57,8 +57,9 @@
57#include <linux/slab.h> 57#include <linux/slab.h>
58#include <linux/jiffies.h> 58#include <linux/jiffies.h>
59#include <linux/i2c.h> 59#include <linux/i2c.h>
60#include <linux/i2c-sensor.h> 60#include <linux/hwmon.h>
61#include <linux/i2c-vid.h> 61#include <linux/hwmon-vid.h>
62#include <linux/err.h>
62 63
63/* 64/*
64 * Addresses to scan 65 * Addresses to scan
@@ -66,13 +67,12 @@
66 */ 67 */
67 68
68static unsigned short normal_i2c[] = { 0x2c, 0x2d, 0x2e, I2C_CLIENT_END }; 69static unsigned short normal_i2c[] = { 0x2c, 0x2d, 0x2e, I2C_CLIENT_END };
69static unsigned int normal_isa[] = { I2C_CLIENT_ISA_END };
70 70
71/* 71/*
72 * Insmod parameters 72 * Insmod parameters
73 */ 73 */
74 74
75SENSORS_INSMOD_1(lm87); 75I2C_CLIENT_INSMOD_1(lm87);
76 76
77/* 77/*
78 * The LM87 registers 78 * The LM87 registers
@@ -175,6 +175,7 @@ static struct i2c_driver lm87_driver = {
175 175
176struct lm87_data { 176struct lm87_data {
177 struct i2c_client client; 177 struct i2c_client client;
178 struct class_device *class_dev;
178 struct semaphore update_lock; 179 struct semaphore update_lock;
179 char valid; /* zero until following fields are valid */ 180 char valid; /* zero until following fields are valid */
180 unsigned long last_updated; /* In jiffies */ 181 unsigned long last_updated; /* In jiffies */
@@ -537,7 +538,7 @@ static int lm87_attach_adapter(struct i2c_adapter *adapter)
537{ 538{
538 if (!(adapter->class & I2C_CLASS_HWMON)) 539 if (!(adapter->class & I2C_CLASS_HWMON))
539 return 0; 540 return 0;
540 return i2c_detect(adapter, &addr_data, lm87_detect); 541 return i2c_probe(adapter, &addr_data, lm87_detect);
541} 542}
542 543
543/* 544/*
@@ -608,6 +609,12 @@ static int lm87_detect(struct i2c_adapter *adapter, int address, int kind)
608 data->in_scale[7] = 1875; 609 data->in_scale[7] = 1875;
609 610
610 /* Register sysfs hooks */ 611 /* Register sysfs hooks */
612 data->class_dev = hwmon_device_register(&new_client->dev);
613 if (IS_ERR(data->class_dev)) {
614 err = PTR_ERR(data->class_dev);
615 goto exit_detach;
616 }
617
611 device_create_file(&new_client->dev, &dev_attr_in1_input); 618 device_create_file(&new_client->dev, &dev_attr_in1_input);
612 device_create_file(&new_client->dev, &dev_attr_in1_min); 619 device_create_file(&new_client->dev, &dev_attr_in1_min);
613 device_create_file(&new_client->dev, &dev_attr_in1_max); 620 device_create_file(&new_client->dev, &dev_attr_in1_max);
@@ -673,6 +680,8 @@ static int lm87_detect(struct i2c_adapter *adapter, int address, int kind)
673 680
674 return 0; 681 return 0;
675 682
683exit_detach:
684 i2c_detach_client(new_client);
676exit_free: 685exit_free:
677 kfree(data); 686 kfree(data);
678exit: 687exit:
@@ -685,7 +694,7 @@ static void lm87_init_client(struct i2c_client *client)
685 u8 config; 694 u8 config;
686 695
687 data->channel = lm87_read_value(client, LM87_REG_CHANNEL_MODE); 696 data->channel = lm87_read_value(client, LM87_REG_CHANNEL_MODE);
688 data->vrm = i2c_which_vrm(); 697 data->vrm = vid_which_vrm();
689 698
690 config = lm87_read_value(client, LM87_REG_CONFIG); 699 config = lm87_read_value(client, LM87_REG_CONFIG);
691 if (!(config & 0x01)) { 700 if (!(config & 0x01)) {
@@ -719,15 +728,15 @@ static void lm87_init_client(struct i2c_client *client)
719 728
720static int lm87_detach_client(struct i2c_client *client) 729static int lm87_detach_client(struct i2c_client *client)
721{ 730{
731 struct lm87_data *data = i2c_get_clientdata(client);
722 int err; 732 int err;
723 733
724 if ((err = i2c_detach_client(client))) { 734 hwmon_device_unregister(data->class_dev);
725 dev_err(&client->dev, "Client deregistration failed, " 735
726 "client not detached.\n"); 736 if ((err = i2c_detach_client(client)))
727 return err; 737 return err;
728 }
729 738
730 kfree(i2c_get_clientdata(client)); 739 kfree(data);
731 return 0; 740 return 0;
732} 741}
733 742
diff --git a/drivers/hwmon/lm90.c b/drivers/hwmon/lm90.c
index a67dcadf7cb..14de05fcd43 100644
--- a/drivers/hwmon/lm90.c
+++ b/drivers/hwmon/lm90.c
@@ -75,8 +75,9 @@
75#include <linux/slab.h> 75#include <linux/slab.h>
76#include <linux/jiffies.h> 76#include <linux/jiffies.h>
77#include <linux/i2c.h> 77#include <linux/i2c.h>
78#include <linux/i2c-sensor.h>
79#include <linux/hwmon-sysfs.h> 78#include <linux/hwmon-sysfs.h>
79#include <linux/hwmon.h>
80#include <linux/err.h>
80 81
81/* 82/*
82 * Addresses to scan 83 * Addresses to scan
@@ -89,13 +90,12 @@
89 */ 90 */
90 91
91static unsigned short normal_i2c[] = { 0x4c, 0x4d, I2C_CLIENT_END }; 92static unsigned short normal_i2c[] = { 0x4c, 0x4d, I2C_CLIENT_END };
92static unsigned int normal_isa[] = { I2C_CLIENT_ISA_END };
93 93
94/* 94/*
95 * Insmod parameters 95 * Insmod parameters
96 */ 96 */
97 97
98SENSORS_INSMOD_6(lm90, adm1032, lm99, lm86, max6657, adt7461); 98I2C_CLIENT_INSMOD_6(lm90, adm1032, lm99, lm86, max6657, adt7461);
99 99
100/* 100/*
101 * The LM90 registers 101 * The LM90 registers
@@ -200,6 +200,7 @@ static struct i2c_driver lm90_driver = {
200 200
201struct lm90_data { 201struct lm90_data {
202 struct i2c_client client; 202 struct i2c_client client;
203 struct class_device *class_dev;
203 struct semaphore update_lock; 204 struct semaphore update_lock;
204 char valid; /* zero until following fields are valid */ 205 char valid; /* zero until following fields are valid */
205 unsigned long last_updated; /* in jiffies */ 206 unsigned long last_updated; /* in jiffies */
@@ -352,7 +353,7 @@ static int lm90_attach_adapter(struct i2c_adapter *adapter)
352{ 353{
353 if (!(adapter->class & I2C_CLASS_HWMON)) 354 if (!(adapter->class & I2C_CLASS_HWMON))
354 return 0; 355 return 0;
355 return i2c_detect(adapter, &addr_data, lm90_detect); 356 return i2c_probe(adapter, &addr_data, lm90_detect);
356} 357}
357 358
358/* 359/*
@@ -500,6 +501,12 @@ static int lm90_detect(struct i2c_adapter *adapter, int address, int kind)
500 lm90_init_client(new_client); 501 lm90_init_client(new_client);
501 502
502 /* Register sysfs hooks */ 503 /* Register sysfs hooks */
504 data->class_dev = hwmon_device_register(&new_client->dev);
505 if (IS_ERR(data->class_dev)) {
506 err = PTR_ERR(data->class_dev);
507 goto exit_detach;
508 }
509
503 device_create_file(&new_client->dev, 510 device_create_file(&new_client->dev,
504 &sensor_dev_attr_temp1_input.dev_attr); 511 &sensor_dev_attr_temp1_input.dev_attr);
505 device_create_file(&new_client->dev, 512 device_create_file(&new_client->dev,
@@ -524,6 +531,8 @@ static int lm90_detect(struct i2c_adapter *adapter, int address, int kind)
524 531
525 return 0; 532 return 0;
526 533
534exit_detach:
535 i2c_detach_client(new_client);
527exit_free: 536exit_free:
528 kfree(data); 537 kfree(data);
529exit: 538exit:
@@ -547,15 +556,15 @@ static void lm90_init_client(struct i2c_client *client)
547 556
548static int lm90_detach_client(struct i2c_client *client) 557static int lm90_detach_client(struct i2c_client *client)
549{ 558{
559 struct lm90_data *data = i2c_get_clientdata(client);
550 int err; 560 int err;
551 561
552 if ((err = i2c_detach_client(client))) { 562 hwmon_device_unregister(data->class_dev);
553 dev_err(&client->dev, "Client deregistration failed, " 563
554 "client not detached.\n"); 564 if ((err = i2c_detach_client(client)))
555 return err; 565 return err;
556 }
557 566
558 kfree(i2c_get_clientdata(client)); 567 kfree(data);
559 return 0; 568 return 0;
560} 569}
561 570
diff --git a/drivers/hwmon/lm92.c b/drivers/hwmon/lm92.c
index 215c8e40ffd..647b7c7cd57 100644
--- a/drivers/hwmon/lm92.c
+++ b/drivers/hwmon/lm92.c
@@ -44,17 +44,16 @@
44#include <linux/init.h> 44#include <linux/init.h>
45#include <linux/slab.h> 45#include <linux/slab.h>
46#include <linux/i2c.h> 46#include <linux/i2c.h>
47#include <linux/i2c-sensor.h> 47#include <linux/hwmon.h>
48 48#include <linux/err.h>
49 49
50/* The LM92 and MAX6635 have 2 two-state pins for address selection, 50/* The LM92 and MAX6635 have 2 two-state pins for address selection,
51 resulting in 4 possible addresses. */ 51 resulting in 4 possible addresses. */
52static unsigned short normal_i2c[] = { 0x48, 0x49, 0x4a, 0x4b, 52static unsigned short normal_i2c[] = { 0x48, 0x49, 0x4a, 0x4b,
53 I2C_CLIENT_END }; 53 I2C_CLIENT_END };
54static unsigned int normal_isa[] = { I2C_CLIENT_ISA_END };
55 54
56/* Insmod parameters */ 55/* Insmod parameters */
57SENSORS_INSMOD_1(lm92); 56I2C_CLIENT_INSMOD_1(lm92);
58 57
59/* The LM92 registers */ 58/* The LM92 registers */
60#define LM92_REG_CONFIG 0x01 /* 8-bit, RW */ 59#define LM92_REG_CONFIG 0x01 /* 8-bit, RW */
@@ -96,6 +95,7 @@ static struct i2c_driver lm92_driver;
96/* Client data (each client gets its own) */ 95/* Client data (each client gets its own) */
97struct lm92_data { 96struct lm92_data {
98 struct i2c_client client; 97 struct i2c_client client;
98 struct class_device *class_dev;
99 struct semaphore update_lock; 99 struct semaphore update_lock;
100 char valid; /* zero until following fields are valid */ 100 char valid; /* zero until following fields are valid */
101 unsigned long last_updated; /* in jiffies */ 101 unsigned long last_updated; /* in jiffies */
@@ -359,6 +359,12 @@ static int lm92_detect(struct i2c_adapter *adapter, int address, int kind)
359 lm92_init_client(new_client); 359 lm92_init_client(new_client);
360 360
361 /* Register sysfs hooks */ 361 /* Register sysfs hooks */
362 data->class_dev = hwmon_device_register(&new_client->dev);
363 if (IS_ERR(data->class_dev)) {
364 err = PTR_ERR(data->class_dev);
365 goto exit_detach;
366 }
367
362 device_create_file(&new_client->dev, &dev_attr_temp1_input); 368 device_create_file(&new_client->dev, &dev_attr_temp1_input);
363 device_create_file(&new_client->dev, &dev_attr_temp1_crit); 369 device_create_file(&new_client->dev, &dev_attr_temp1_crit);
364 device_create_file(&new_client->dev, &dev_attr_temp1_crit_hyst); 370 device_create_file(&new_client->dev, &dev_attr_temp1_crit_hyst);
@@ -370,6 +376,8 @@ static int lm92_detect(struct i2c_adapter *adapter, int address, int kind)
370 376
371 return 0; 377 return 0;
372 378
379exit_detach:
380 i2c_detach_client(new_client);
373exit_free: 381exit_free:
374 kfree(data); 382 kfree(data);
375exit: 383exit:
@@ -380,20 +388,20 @@ static int lm92_attach_adapter(struct i2c_adapter *adapter)
380{ 388{
381 if (!(adapter->class & I2C_CLASS_HWMON)) 389 if (!(adapter->class & I2C_CLASS_HWMON))
382 return 0; 390 return 0;
383 return i2c_detect(adapter, &addr_data, lm92_detect); 391 return i2c_probe(adapter, &addr_data, lm92_detect);
384} 392}
385 393
386static int lm92_detach_client(struct i2c_client *client) 394static int lm92_detach_client(struct i2c_client *client)
387{ 395{
396 struct lm92_data *data = i2c_get_clientdata(client);
388 int err; 397 int err;
389 398
390 if ((err = i2c_detach_client(client))) { 399 hwmon_device_unregister(data->class_dev);
391 dev_err(&client->dev, "Client deregistration failed, " 400
392 "client not detached.\n"); 401 if ((err = i2c_detach_client(client)))
393 return err; 402 return err;
394 }
395 403
396 kfree(i2c_get_clientdata(client)); 404 kfree(data);
397 return 0; 405 return 0;
398} 406}
399 407
diff --git a/drivers/hwmon/max1619.c b/drivers/hwmon/max1619.c
index 3c159f1d49e..16bf71f3a04 100644
--- a/drivers/hwmon/max1619.c
+++ b/drivers/hwmon/max1619.c
@@ -31,20 +31,19 @@
31#include <linux/slab.h> 31#include <linux/slab.h>
32#include <linux/jiffies.h> 32#include <linux/jiffies.h>
33#include <linux/i2c.h> 33#include <linux/i2c.h>
34#include <linux/i2c-sensor.h> 34#include <linux/hwmon.h>
35 35#include <linux/err.h>
36 36
37static unsigned short normal_i2c[] = { 0x18, 0x19, 0x1a, 37static unsigned short normal_i2c[] = { 0x18, 0x19, 0x1a,
38 0x29, 0x2a, 0x2b, 38 0x29, 0x2a, 0x2b,
39 0x4c, 0x4d, 0x4e, 39 0x4c, 0x4d, 0x4e,
40 I2C_CLIENT_END }; 40 I2C_CLIENT_END };
41static unsigned int normal_isa[] = { I2C_CLIENT_ISA_END };
42 41
43/* 42/*
44 * Insmod parameters 43 * Insmod parameters
45 */ 44 */
46 45
47SENSORS_INSMOD_1(max1619); 46I2C_CLIENT_INSMOD_1(max1619);
48 47
49/* 48/*
50 * The MAX1619 registers 49 * The MAX1619 registers
@@ -104,6 +103,7 @@ static struct i2c_driver max1619_driver = {
104 103
105struct max1619_data { 104struct max1619_data {
106 struct i2c_client client; 105 struct i2c_client client;
106 struct class_device *class_dev;
107 struct semaphore update_lock; 107 struct semaphore update_lock;
108 char valid; /* zero until following fields are valid */ 108 char valid; /* zero until following fields are valid */
109 unsigned long last_updated; /* in jiffies */ 109 unsigned long last_updated; /* in jiffies */
@@ -179,7 +179,7 @@ static int max1619_attach_adapter(struct i2c_adapter *adapter)
179{ 179{
180 if (!(adapter->class & I2C_CLASS_HWMON)) 180 if (!(adapter->class & I2C_CLASS_HWMON))
181 return 0; 181 return 0;
182 return i2c_detect(adapter, &addr_data, max1619_detect); 182 return i2c_probe(adapter, &addr_data, max1619_detect);
183} 183}
184 184
185/* 185/*
@@ -275,6 +275,12 @@ static int max1619_detect(struct i2c_adapter *adapter, int address, int kind)
275 max1619_init_client(new_client); 275 max1619_init_client(new_client);
276 276
277 /* Register sysfs hooks */ 277 /* Register sysfs hooks */
278 data->class_dev = hwmon_device_register(&new_client->dev);
279 if (IS_ERR(data->class_dev)) {
280 err = PTR_ERR(data->class_dev);
281 goto exit_detach;
282 }
283
278 device_create_file(&new_client->dev, &dev_attr_temp1_input); 284 device_create_file(&new_client->dev, &dev_attr_temp1_input);
279 device_create_file(&new_client->dev, &dev_attr_temp2_input); 285 device_create_file(&new_client->dev, &dev_attr_temp2_input);
280 device_create_file(&new_client->dev, &dev_attr_temp2_min); 286 device_create_file(&new_client->dev, &dev_attr_temp2_min);
@@ -285,6 +291,8 @@ static int max1619_detect(struct i2c_adapter *adapter, int address, int kind)
285 291
286 return 0; 292 return 0;
287 293
294exit_detach:
295 i2c_detach_client(new_client);
288exit_free: 296exit_free:
289 kfree(data); 297 kfree(data);
290exit: 298exit:
@@ -308,15 +316,15 @@ static void max1619_init_client(struct i2c_client *client)
308 316
309static int max1619_detach_client(struct i2c_client *client) 317static int max1619_detach_client(struct i2c_client *client)
310{ 318{
319 struct max1619_data *data = i2c_get_clientdata(client);
311 int err; 320 int err;
312 321
313 if ((err = i2c_detach_client(client))) { 322 hwmon_device_unregister(data->class_dev);
314 dev_err(&client->dev, "Client deregistration failed, " 323
315 "client not detached.\n"); 324 if ((err = i2c_detach_client(client)))
316 return err; 325 return err;
317 }
318 326
319 kfree(i2c_get_clientdata(client)); 327 kfree(data);
320 return 0; 328 return 0;
321} 329}
322 330
diff --git a/drivers/hwmon/pc87360.c b/drivers/hwmon/pc87360.c
index fa4032d53b7..cf2a35799c7 100644
--- a/drivers/hwmon/pc87360.c
+++ b/drivers/hwmon/pc87360.c
@@ -38,23 +38,19 @@
38#include <linux/slab.h> 38#include <linux/slab.h>
39#include <linux/jiffies.h> 39#include <linux/jiffies.h>
40#include <linux/i2c.h> 40#include <linux/i2c.h>
41#include <linux/i2c-sensor.h> 41#include <linux/i2c-isa.h>
42#include <linux/i2c-vid.h> 42#include <linux/hwmon.h>
43#include <linux/hwmon-sysfs.h>
44#include <linux/hwmon-vid.h>
45#include <linux/err.h>
43#include <asm/io.h> 46#include <asm/io.h>
44 47
45static unsigned short normal_i2c[] = { I2C_CLIENT_END };
46static unsigned int normal_isa[] = { 0, I2C_CLIENT_ISA_END };
47static struct i2c_force_data forces[] = {{ NULL }};
48static u8 devid; 48static u8 devid;
49static unsigned int extra_isa[3]; 49static unsigned short address;
50static unsigned short extra_isa[3];
50static u8 confreg[4]; 51static u8 confreg[4];
51 52
52enum chips { any_chip, pc87360, pc87363, pc87364, pc87365, pc87366 }; 53enum chips { any_chip, pc87360, pc87363, pc87364, pc87365, pc87366 };
53static struct i2c_address_data addr_data = {
54 .normal_i2c = normal_i2c,
55 .normal_isa = normal_isa,
56 .forces = forces,
57};
58 54
59static int init = 1; 55static int init = 1;
60module_param(init, int, 0); 56module_param(init, int, 0);
@@ -186,6 +182,7 @@ static inline u8 PWM_TO_REG(int val, int inv)
186 182
187struct pc87360_data { 183struct pc87360_data {
188 struct i2c_client client; 184 struct i2c_client client;
185 struct class_device *class_dev;
189 struct semaphore lock; 186 struct semaphore lock;
190 struct semaphore update_lock; 187 struct semaphore update_lock;
191 char valid; /* !=0 if following fields are valid */ 188 char valid; /* !=0 if following fields are valid */
@@ -224,8 +221,7 @@ struct pc87360_data {
224 * Functions declaration 221 * Functions declaration
225 */ 222 */
226 223
227static int pc87360_attach_adapter(struct i2c_adapter *adapter); 224static int pc87360_detect(struct i2c_adapter *adapter);
228static int pc87360_detect(struct i2c_adapter *adapter, int address, int kind);
229static int pc87360_detach_client(struct i2c_client *client); 225static int pc87360_detach_client(struct i2c_client *client);
230 226
231static int pc87360_read_value(struct pc87360_data *data, u8 ldi, u8 bank, 227static int pc87360_read_value(struct pc87360_data *data, u8 ldi, u8 bank,
@@ -242,8 +238,7 @@ static struct pc87360_data *pc87360_update_device(struct device *dev);
242static struct i2c_driver pc87360_driver = { 238static struct i2c_driver pc87360_driver = {
243 .owner = THIS_MODULE, 239 .owner = THIS_MODULE,
244 .name = "pc87360", 240 .name = "pc87360",
245 .flags = I2C_DF_NOTIFY, 241 .attach_adapter = pc87360_detect,
246 .attach_adapter = pc87360_attach_adapter,
247 .detach_client = pc87360_detach_client, 242 .detach_client = pc87360_detach_client,
248}; 243};
249 244
@@ -251,168 +246,178 @@ static struct i2c_driver pc87360_driver = {
251 * Sysfs stuff 246 * Sysfs stuff
252 */ 247 */
253 248
254static ssize_t set_fan_min(struct device *dev, const char *buf, 249static ssize_t show_fan_input(struct device *dev, struct device_attribute *devattr, char *buf)
255 size_t count, int nr) 250{
251 struct sensor_device_attribute *attr = to_sensor_dev_attr(devattr);
252 struct pc87360_data *data = pc87360_update_device(dev);
253 return sprintf(buf, "%u\n", FAN_FROM_REG(data->fan[attr->index],
254 FAN_DIV_FROM_REG(data->fan_status[attr->index])));
255}
256static ssize_t show_fan_min(struct device *dev, struct device_attribute *devattr, char *buf)
257{
258 struct sensor_device_attribute *attr = to_sensor_dev_attr(devattr);
259 struct pc87360_data *data = pc87360_update_device(dev);
260 return sprintf(buf, "%u\n", FAN_FROM_REG(data->fan_min[attr->index],
261 FAN_DIV_FROM_REG(data->fan_status[attr->index])));
262}
263static ssize_t show_fan_div(struct device *dev, struct device_attribute *devattr, char *buf)
264{
265 struct sensor_device_attribute *attr = to_sensor_dev_attr(devattr);
266 struct pc87360_data *data = pc87360_update_device(dev);
267 return sprintf(buf, "%u\n",
268 FAN_DIV_FROM_REG(data->fan_status[attr->index]));
269}
270static ssize_t show_fan_status(struct device *dev, struct device_attribute *devattr, char *buf)
256{ 271{
272 struct sensor_device_attribute *attr = to_sensor_dev_attr(devattr);
273 struct pc87360_data *data = pc87360_update_device(dev);
274 return sprintf(buf, "%u\n",
275 FAN_STATUS_FROM_REG(data->fan_status[attr->index]));
276}
277static ssize_t set_fan_min(struct device *dev, struct device_attribute *devattr, const char *buf,
278 size_t count)
279{
280 struct sensor_device_attribute *attr = to_sensor_dev_attr(devattr);
257 struct i2c_client *client = to_i2c_client(dev); 281 struct i2c_client *client = to_i2c_client(dev);
258 struct pc87360_data *data = i2c_get_clientdata(client); 282 struct pc87360_data *data = i2c_get_clientdata(client);
259 long fan_min = simple_strtol(buf, NULL, 10); 283 long fan_min = simple_strtol(buf, NULL, 10);
260 284
261 down(&data->update_lock); 285 down(&data->update_lock);
262 fan_min = FAN_TO_REG(fan_min, FAN_DIV_FROM_REG(data->fan_status[nr])); 286 fan_min = FAN_TO_REG(fan_min, FAN_DIV_FROM_REG(data->fan_status[attr->index]));
263 287
264 /* If it wouldn't fit, change clock divisor */ 288 /* If it wouldn't fit, change clock divisor */
265 while (fan_min > 255 289 while (fan_min > 255
266 && (data->fan_status[nr] & 0x60) != 0x60) { 290 && (data->fan_status[attr->index] & 0x60) != 0x60) {
267 fan_min >>= 1; 291 fan_min >>= 1;
268 data->fan[nr] >>= 1; 292 data->fan[attr->index] >>= 1;
269 data->fan_status[nr] += 0x20; 293 data->fan_status[attr->index] += 0x20;
270 } 294 }
271 data->fan_min[nr] = fan_min > 255 ? 255 : fan_min; 295 data->fan_min[attr->index] = fan_min > 255 ? 255 : fan_min;
272 pc87360_write_value(data, LD_FAN, NO_BANK, PC87360_REG_FAN_MIN(nr), 296 pc87360_write_value(data, LD_FAN, NO_BANK, PC87360_REG_FAN_MIN(attr->index),
273 data->fan_min[nr]); 297 data->fan_min[attr->index]);
274 298
275 /* Write new divider, preserve alarm bits */ 299 /* Write new divider, preserve alarm bits */
276 pc87360_write_value(data, LD_FAN, NO_BANK, PC87360_REG_FAN_STATUS(nr), 300 pc87360_write_value(data, LD_FAN, NO_BANK, PC87360_REG_FAN_STATUS(attr->index),
277 data->fan_status[nr] & 0xF9); 301 data->fan_status[attr->index] & 0xF9);
278 up(&data->update_lock); 302 up(&data->update_lock);
279 303
280 return count; 304 return count;
281} 305}
282 306
283#define show_and_set_fan(offset) \ 307#define show_and_set_fan(offset) \
284static ssize_t show_fan##offset##_input(struct device *dev, struct device_attribute *attr, char *buf) \ 308static SENSOR_DEVICE_ATTR(fan##offset##_input, S_IRUGO, \
285{ \ 309 show_fan_input, NULL, offset-1); \
286 struct pc87360_data *data = pc87360_update_device(dev); \ 310static SENSOR_DEVICE_ATTR(fan##offset##_min, S_IWUSR | S_IRUGO, \
287 return sprintf(buf, "%u\n", FAN_FROM_REG(data->fan[offset-1], \ 311 show_fan_min, set_fan_min, offset-1); \
288 FAN_DIV_FROM_REG(data->fan_status[offset-1]))); \ 312static SENSOR_DEVICE_ATTR(fan##offset##_div, S_IRUGO, \
289} \ 313 show_fan_div, NULL, offset-1); \
290static ssize_t show_fan##offset##_min(struct device *dev, struct device_attribute *attr, char *buf) \ 314static SENSOR_DEVICE_ATTR(fan##offset##_status, S_IRUGO, \
291{ \ 315 show_fan_status, NULL, offset-1);
292 struct pc87360_data *data = pc87360_update_device(dev); \
293 return sprintf(buf, "%u\n", FAN_FROM_REG(data->fan_min[offset-1], \
294 FAN_DIV_FROM_REG(data->fan_status[offset-1]))); \
295} \
296static ssize_t show_fan##offset##_div(struct device *dev, struct device_attribute *attr, char *buf) \
297{ \
298 struct pc87360_data *data = pc87360_update_device(dev); \
299 return sprintf(buf, "%u\n", \
300 FAN_DIV_FROM_REG(data->fan_status[offset-1])); \
301} \
302static ssize_t show_fan##offset##_status(struct device *dev, struct device_attribute *attr, char *buf) \
303{ \
304 struct pc87360_data *data = pc87360_update_device(dev); \
305 return sprintf(buf, "%u\n", \
306 FAN_STATUS_FROM_REG(data->fan_status[offset-1])); \
307} \
308static ssize_t set_fan##offset##_min(struct device *dev, struct device_attribute *attr, const char *buf, \
309 size_t count) \
310{ \
311 return set_fan_min(dev, buf, count, offset-1); \
312} \
313static DEVICE_ATTR(fan##offset##_input, S_IRUGO, \
314 show_fan##offset##_input, NULL); \
315static DEVICE_ATTR(fan##offset##_min, S_IWUSR | S_IRUGO, \
316 show_fan##offset##_min, set_fan##offset##_min); \
317static DEVICE_ATTR(fan##offset##_div, S_IRUGO, \
318 show_fan##offset##_div, NULL); \
319static DEVICE_ATTR(fan##offset##_status, S_IRUGO, \
320 show_fan##offset##_status, NULL);
321show_and_set_fan(1) 316show_and_set_fan(1)
322show_and_set_fan(2) 317show_and_set_fan(2)
323show_and_set_fan(3) 318show_and_set_fan(3)
324 319
320static ssize_t show_pwm(struct device *dev, struct device_attribute *devattr, char *buf)
321{
322 struct sensor_device_attribute *attr = to_sensor_dev_attr(devattr);
323 struct pc87360_data *data = pc87360_update_device(dev);
324 return sprintf(buf, "%u\n",
325 PWM_FROM_REG(data->pwm[attr->index],
326 FAN_CONFIG_INVERT(data->fan_conf,
327 attr->index)));
328}
329static ssize_t set_pwm(struct device *dev, struct device_attribute *devattr, const char *buf,
330 size_t count)
331{
332 struct sensor_device_attribute *attr = to_sensor_dev_attr(devattr);
333 struct i2c_client *client = to_i2c_client(dev);
334 struct pc87360_data *data = i2c_get_clientdata(client);
335 long val = simple_strtol(buf, NULL, 10);
336
337 down(&data->update_lock);
338 data->pwm[attr->index] = PWM_TO_REG(val,
339 FAN_CONFIG_INVERT(data->fan_conf, attr->index));
340 pc87360_write_value(data, LD_FAN, NO_BANK, PC87360_REG_PWM(attr->index),
341 data->pwm[attr->index]);
342 up(&data->update_lock);
343 return count;
344}
345
325#define show_and_set_pwm(offset) \ 346#define show_and_set_pwm(offset) \
326static ssize_t show_pwm##offset(struct device *dev, struct device_attribute *attr, char *buf) \ 347static SENSOR_DEVICE_ATTR(pwm##offset, S_IWUSR | S_IRUGO, \
327{ \ 348 show_pwm, set_pwm, offset-1);
328 struct pc87360_data *data = pc87360_update_device(dev); \
329 return sprintf(buf, "%u\n", \
330 PWM_FROM_REG(data->pwm[offset-1], \
331 FAN_CONFIG_INVERT(data->fan_conf, \
332 offset-1))); \
333} \
334static ssize_t set_pwm##offset(struct device *dev, struct device_attribute *attr, const char *buf, \
335 size_t count) \
336{ \
337 struct i2c_client *client = to_i2c_client(dev); \
338 struct pc87360_data *data = i2c_get_clientdata(client); \
339 long val = simple_strtol(buf, NULL, 10); \
340 \
341 down(&data->update_lock); \
342 data->pwm[offset-1] = PWM_TO_REG(val, \
343 FAN_CONFIG_INVERT(data->fan_conf, offset-1)); \
344 pc87360_write_value(data, LD_FAN, NO_BANK, PC87360_REG_PWM(offset-1), \
345 data->pwm[offset-1]); \
346 up(&data->update_lock); \
347 return count; \
348} \
349static DEVICE_ATTR(pwm##offset, S_IWUSR | S_IRUGO, \
350 show_pwm##offset, set_pwm##offset);
351show_and_set_pwm(1) 349show_and_set_pwm(1)
352show_and_set_pwm(2) 350show_and_set_pwm(2)
353show_and_set_pwm(3) 351show_and_set_pwm(3)
354 352
353static ssize_t show_in_input(struct device *dev, struct device_attribute *devattr, char *buf)
354{
355 struct sensor_device_attribute *attr = to_sensor_dev_attr(devattr);
356 struct pc87360_data *data = pc87360_update_device(dev);
357 return sprintf(buf, "%u\n", IN_FROM_REG(data->in[attr->index],
358 data->in_vref));
359}
360static ssize_t show_in_min(struct device *dev, struct device_attribute *devattr, char *buf)
361{
362 struct sensor_device_attribute *attr = to_sensor_dev_attr(devattr);
363 struct pc87360_data *data = pc87360_update_device(dev);
364 return sprintf(buf, "%u\n", IN_FROM_REG(data->in_min[attr->index],
365 data->in_vref));
366}
367static ssize_t show_in_max(struct device *dev, struct device_attribute *devattr, char *buf)
368{
369 struct sensor_device_attribute *attr = to_sensor_dev_attr(devattr);
370 struct pc87360_data *data = pc87360_update_device(dev);
371 return sprintf(buf, "%u\n", IN_FROM_REG(data->in_max[attr->index],
372 data->in_vref));
373}
374static ssize_t show_in_status(struct device *dev, struct device_attribute *devattr, char *buf)
375{
376 struct sensor_device_attribute *attr = to_sensor_dev_attr(devattr);
377 struct pc87360_data *data = pc87360_update_device(dev);
378 return sprintf(buf, "%u\n", data->in_status[attr->index]);
379}
380static ssize_t set_in_min(struct device *dev, struct device_attribute *devattr, const char *buf,
381 size_t count)
382{
383 struct sensor_device_attribute *attr = to_sensor_dev_attr(devattr);
384 struct i2c_client *client = to_i2c_client(dev);
385 struct pc87360_data *data = i2c_get_clientdata(client);
386 long val = simple_strtol(buf, NULL, 10);
387
388 down(&data->update_lock);
389 data->in_min[attr->index] = IN_TO_REG(val, data->in_vref);
390 pc87360_write_value(data, LD_IN, attr->index, PC87365_REG_IN_MIN,
391 data->in_min[attr->index]);
392 up(&data->update_lock);
393 return count;
394}
395static ssize_t set_in_max(struct device *dev, struct device_attribute *devattr, const char *buf,
396 size_t count)
397{
398 struct sensor_device_attribute *attr = to_sensor_dev_attr(devattr);
399 struct i2c_client *client = to_i2c_client(dev);
400 struct pc87360_data *data = i2c_get_clientdata(client);
401 long val = simple_strtol(buf, NULL, 10);
402
403 down(&data->update_lock);
404 data->in_max[attr->index] = IN_TO_REG(val,
405 data->in_vref);
406 pc87360_write_value(data, LD_IN, attr->index, PC87365_REG_IN_MAX,
407 data->in_max[attr->index]);
408 up(&data->update_lock);
409 return count;
410}
411
355#define show_and_set_in(offset) \ 412#define show_and_set_in(offset) \
356static ssize_t show_in##offset##_input(struct device *dev, struct device_attribute *attr, char *buf) \ 413static SENSOR_DEVICE_ATTR(in##offset##_input, S_IRUGO, \
357{ \ 414 show_in_input, NULL, offset); \
358 struct pc87360_data *data = pc87360_update_device(dev); \ 415static SENSOR_DEVICE_ATTR(in##offset##_min, S_IWUSR | S_IRUGO, \
359 return sprintf(buf, "%u\n", IN_FROM_REG(data->in[offset], \ 416 show_in_min, set_in_min, offset); \
360 data->in_vref)); \ 417static SENSOR_DEVICE_ATTR(in##offset##_max, S_IWUSR | S_IRUGO, \
361} \ 418 show_in_max, set_in_max, offset); \
362static ssize_t show_in##offset##_min(struct device *dev, struct device_attribute *attr, char *buf) \ 419static SENSOR_DEVICE_ATTR(in##offset##_status, S_IRUGO, \
363{ \ 420 show_in_status, NULL, offset);
364 struct pc87360_data *data = pc87360_update_device(dev); \
365 return sprintf(buf, "%u\n", IN_FROM_REG(data->in_min[offset], \
366 data->in_vref)); \
367} \
368static ssize_t show_in##offset##_max(struct device *dev, struct device_attribute *attr, char *buf) \
369{ \
370 struct pc87360_data *data = pc87360_update_device(dev); \
371 return sprintf(buf, "%u\n", IN_FROM_REG(data->in_max[offset], \
372 data->in_vref)); \
373} \
374static ssize_t show_in##offset##_status(struct device *dev, struct device_attribute *attr, char *buf) \
375{ \
376 struct pc87360_data *data = pc87360_update_device(dev); \
377 return sprintf(buf, "%u\n", data->in_status[offset]); \
378} \
379static ssize_t set_in##offset##_min(struct device *dev, struct device_attribute *attr, const char *buf, \
380 size_t count) \
381{ \
382 struct i2c_client *client = to_i2c_client(dev); \
383 struct pc87360_data *data = i2c_get_clientdata(client); \
384 long val = simple_strtol(buf, NULL, 10); \
385 \
386 down(&data->update_lock); \
387 data->in_min[offset] = IN_TO_REG(val, data->in_vref); \
388 pc87360_write_value(data, LD_IN, offset, PC87365_REG_IN_MIN, \
389 data->in_min[offset]); \
390 up(&data->update_lock); \
391 return count; \
392} \
393static ssize_t set_in##offset##_max(struct device *dev, struct device_attribute *attr, const char *buf, \
394 size_t count) \
395{ \
396 struct i2c_client *client = to_i2c_client(dev); \
397 struct pc87360_data *data = i2c_get_clientdata(client); \
398 long val = simple_strtol(buf, NULL, 10); \
399 \
400 down(&data->update_lock); \
401 data->in_max[offset] = IN_TO_REG(val, \
402 data->in_vref); \
403 pc87360_write_value(data, LD_IN, offset, PC87365_REG_IN_MAX, \
404 data->in_max[offset]); \
405 up(&data->update_lock); \
406 return count; \
407} \
408static DEVICE_ATTR(in##offset##_input, S_IRUGO, \
409 show_in##offset##_input, NULL); \
410static DEVICE_ATTR(in##offset##_min, S_IWUSR | S_IRUGO, \
411 show_in##offset##_min, set_in##offset##_min); \
412static DEVICE_ATTR(in##offset##_max, S_IWUSR | S_IRUGO, \
413 show_in##offset##_max, set_in##offset##_max); \
414static DEVICE_ATTR(in##offset##_status, S_IRUGO, \
415 show_in##offset##_status, NULL);
416show_and_set_in(0) 421show_and_set_in(0)
417show_and_set_in(1) 422show_and_set_in(1)
418show_and_set_in(2) 423show_and_set_in(2)
@@ -425,88 +430,97 @@ show_and_set_in(8)
425show_and_set_in(9) 430show_and_set_in(9)
426show_and_set_in(10) 431show_and_set_in(10)
427 432
433static ssize_t show_therm_input(struct device *dev, struct device_attribute *devattr, char *buf)
434{
435 struct sensor_device_attribute *attr = to_sensor_dev_attr(devattr);
436 struct pc87360_data *data = pc87360_update_device(dev);
437 return sprintf(buf, "%u\n", IN_FROM_REG(data->in[attr->index],
438 data->in_vref));
439}
440static ssize_t show_therm_min(struct device *dev, struct device_attribute *devattr, char *buf)
441{
442 struct sensor_device_attribute *attr = to_sensor_dev_attr(devattr);
443 struct pc87360_data *data = pc87360_update_device(dev);
444 return sprintf(buf, "%u\n", IN_FROM_REG(data->in_min[attr->index],
445 data->in_vref));
446}
447static ssize_t show_therm_max(struct device *dev, struct device_attribute *devattr, char *buf)
448{
449 struct sensor_device_attribute *attr = to_sensor_dev_attr(devattr);
450 struct pc87360_data *data = pc87360_update_device(dev);
451 return sprintf(buf, "%u\n", IN_FROM_REG(data->in_max[attr->index],
452 data->in_vref));
453}
454static ssize_t show_therm_crit(struct device *dev, struct device_attribute *devattr, char *buf)
455{
456 struct sensor_device_attribute *attr = to_sensor_dev_attr(devattr);
457 struct pc87360_data *data = pc87360_update_device(dev);
458 return sprintf(buf, "%u\n", IN_FROM_REG(data->in_crit[attr->index-11],
459 data->in_vref));
460}
461static ssize_t show_therm_status(struct device *dev, struct device_attribute *devattr, char *buf)
462{
463 struct sensor_device_attribute *attr = to_sensor_dev_attr(devattr);
464 struct pc87360_data *data = pc87360_update_device(dev);
465 return sprintf(buf, "%u\n", data->in_status[attr->index]);
466}
467static ssize_t set_therm_min(struct device *dev, struct device_attribute *devattr, const char *buf,
468 size_t count)
469{
470 struct sensor_device_attribute *attr = to_sensor_dev_attr(devattr);
471 struct i2c_client *client = to_i2c_client(dev);
472 struct pc87360_data *data = i2c_get_clientdata(client);
473 long val = simple_strtol(buf, NULL, 10);
474
475 down(&data->update_lock);
476 data->in_min[attr->index] = IN_TO_REG(val, data->in_vref);
477 pc87360_write_value(data, LD_IN, attr->index, PC87365_REG_TEMP_MIN,
478 data->in_min[attr->index]);
479 up(&data->update_lock);
480 return count;
481}
482static ssize_t set_therm_max(struct device *dev, struct device_attribute *devattr, const char *buf,
483 size_t count)
484{
485 struct sensor_device_attribute *attr = to_sensor_dev_attr(devattr);
486 struct i2c_client *client = to_i2c_client(dev);
487 struct pc87360_data *data = i2c_get_clientdata(client);
488 long val = simple_strtol(buf, NULL, 10);
489
490 down(&data->update_lock);
491 data->in_max[attr->index] = IN_TO_REG(val, data->in_vref);
492 pc87360_write_value(data, LD_IN, attr->index, PC87365_REG_TEMP_MAX,
493 data->in_max[attr->index]);
494 up(&data->update_lock);
495 return count;
496}
497static ssize_t set_therm_crit(struct device *dev, struct device_attribute *devattr, const char *buf,
498 size_t count)
499{
500 struct sensor_device_attribute *attr = to_sensor_dev_attr(devattr);
501 struct i2c_client *client = to_i2c_client(dev);
502 struct pc87360_data *data = i2c_get_clientdata(client);
503 long val = simple_strtol(buf, NULL, 10);
504
505 down(&data->update_lock);
506 data->in_crit[attr->index-11] = IN_TO_REG(val, data->in_vref);
507 pc87360_write_value(data, LD_IN, attr->index, PC87365_REG_TEMP_CRIT,
508 data->in_crit[attr->index-11]);
509 up(&data->update_lock);
510 return count;
511}
512
428#define show_and_set_therm(offset) \ 513#define show_and_set_therm(offset) \
429static ssize_t show_temp##offset##_input(struct device *dev, struct device_attribute *attr, char *buf) \ 514static SENSOR_DEVICE_ATTR(temp##offset##_input, S_IRUGO, \
430{ \ 515 show_therm_input, NULL, 11+offset-4); \
431 struct pc87360_data *data = pc87360_update_device(dev); \ 516static SENSOR_DEVICE_ATTR(temp##offset##_min, S_IWUSR | S_IRUGO, \
432 return sprintf(buf, "%u\n", IN_FROM_REG(data->in[offset+7], \ 517 show_therm_min, set_therm_min, 11+offset-4); \
433 data->in_vref)); \ 518static SENSOR_DEVICE_ATTR(temp##offset##_max, S_IWUSR | S_IRUGO, \
434} \ 519 show_therm_max, set_therm_max, 11+offset-4); \
435static ssize_t show_temp##offset##_min(struct device *dev, struct device_attribute *attr, char *buf) \ 520static SENSOR_DEVICE_ATTR(temp##offset##_crit, S_IWUSR | S_IRUGO, \
436{ \ 521 show_therm_crit, set_therm_crit, 11+offset-4); \
437 struct pc87360_data *data = pc87360_update_device(dev); \ 522static SENSOR_DEVICE_ATTR(temp##offset##_status, S_IRUGO, \
438 return sprintf(buf, "%u\n", IN_FROM_REG(data->in_min[offset+7], \ 523 show_therm_status, NULL, 11+offset-4);
439 data->in_vref)); \
440} \
441static ssize_t show_temp##offset##_max(struct device *dev, struct device_attribute *attr, char *buf) \
442{ \
443 struct pc87360_data *data = pc87360_update_device(dev); \
444 return sprintf(buf, "%u\n", IN_FROM_REG(data->in_max[offset+7], \
445 data->in_vref)); \
446} \
447static ssize_t show_temp##offset##_crit(struct device *dev, struct device_attribute *attr, char *buf) \
448{ \
449 struct pc87360_data *data = pc87360_update_device(dev); \
450 return sprintf(buf, "%u\n", IN_FROM_REG(data->in_crit[offset-4], \
451 data->in_vref)); \
452} \
453static ssize_t show_temp##offset##_status(struct device *dev, struct device_attribute *attr, char *buf) \
454{ \
455 struct pc87360_data *data = pc87360_update_device(dev); \
456 return sprintf(buf, "%u\n", data->in_status[offset+7]); \
457} \
458static ssize_t set_temp##offset##_min(struct device *dev, struct device_attribute *attr, const char *buf, \
459 size_t count) \
460{ \
461 struct i2c_client *client = to_i2c_client(dev); \
462 struct pc87360_data *data = i2c_get_clientdata(client); \
463 long val = simple_strtol(buf, NULL, 10); \
464 \
465 down(&data->update_lock); \
466 data->in_min[offset+7] = IN_TO_REG(val, data->in_vref); \
467 pc87360_write_value(data, LD_IN, offset+7, PC87365_REG_TEMP_MIN, \
468 data->in_min[offset+7]); \
469 up(&data->update_lock); \
470 return count; \
471} \
472static ssize_t set_temp##offset##_max(struct device *dev, struct device_attribute *attr, const char *buf, \
473 size_t count) \
474{ \
475 struct i2c_client *client = to_i2c_client(dev); \
476 struct pc87360_data *data = i2c_get_clientdata(client); \
477 long val = simple_strtol(buf, NULL, 10); \
478 \
479 down(&data->update_lock); \
480 data->in_max[offset+7] = IN_TO_REG(val, data->in_vref); \
481 pc87360_write_value(data, LD_IN, offset+7, PC87365_REG_TEMP_MAX, \
482 data->in_max[offset+7]); \
483 up(&data->update_lock); \
484 return count; \
485} \
486static ssize_t set_temp##offset##_crit(struct device *dev, struct device_attribute *attr, const char *buf, \
487 size_t count) \
488{ \
489 struct i2c_client *client = to_i2c_client(dev); \
490 struct pc87360_data *data = i2c_get_clientdata(client); \
491 long val = simple_strtol(buf, NULL, 10); \
492 \
493 down(&data->update_lock); \
494 data->in_crit[offset-4] = IN_TO_REG(val, data->in_vref); \
495 pc87360_write_value(data, LD_IN, offset+7, PC87365_REG_TEMP_CRIT, \
496 data->in_crit[offset-4]); \
497 up(&data->update_lock); \
498 return count; \
499} \
500static DEVICE_ATTR(temp##offset##_input, S_IRUGO, \
501 show_temp##offset##_input, NULL); \
502static DEVICE_ATTR(temp##offset##_min, S_IWUSR | S_IRUGO, \
503 show_temp##offset##_min, set_temp##offset##_min); \
504static DEVICE_ATTR(temp##offset##_max, S_IWUSR | S_IRUGO, \
505 show_temp##offset##_max, set_temp##offset##_max); \
506static DEVICE_ATTR(temp##offset##_crit, S_IWUSR | S_IRUGO, \
507 show_temp##offset##_crit, set_temp##offset##_crit); \
508static DEVICE_ATTR(temp##offset##_status, S_IRUGO, \
509 show_temp##offset##_status, NULL);
510show_and_set_therm(4) 524show_and_set_therm(4)
511show_and_set_therm(5) 525show_and_set_therm(5)
512show_and_set_therm(6) 526show_and_set_therm(6)
@@ -539,84 +553,93 @@ static ssize_t show_in_alarms(struct device *dev, struct device_attribute *attr,
539} 553}
540static DEVICE_ATTR(alarms_in, S_IRUGO, show_in_alarms, NULL); 554static DEVICE_ATTR(alarms_in, S_IRUGO, show_in_alarms, NULL);
541 555
556static ssize_t show_temp_input(struct device *dev, struct device_attribute *devattr, char *buf)
557{
558 struct sensor_device_attribute *attr = to_sensor_dev_attr(devattr);
559 struct pc87360_data *data = pc87360_update_device(dev);
560 return sprintf(buf, "%d\n", TEMP_FROM_REG(data->temp[attr->index]));
561}
562static ssize_t show_temp_min(struct device *dev, struct device_attribute *devattr, char *buf)
563{
564 struct sensor_device_attribute *attr = to_sensor_dev_attr(devattr);
565 struct pc87360_data *data = pc87360_update_device(dev);
566 return sprintf(buf, "%d\n", TEMP_FROM_REG(data->temp_min[attr->index]));
567}
568static ssize_t show_temp_max(struct device *dev, struct device_attribute *devattr, char *buf)
569{
570 struct sensor_device_attribute *attr = to_sensor_dev_attr(devattr);
571 struct pc87360_data *data = pc87360_update_device(dev);
572 return sprintf(buf, "%d\n", TEMP_FROM_REG(data->temp_max[attr->index]));
573}
574static ssize_t show_temp_crit(struct device *dev, struct device_attribute *devattr, char *buf)
575{
576 struct sensor_device_attribute *attr = to_sensor_dev_attr(devattr);
577 struct pc87360_data *data = pc87360_update_device(dev);
578 return sprintf(buf, "%d\n", TEMP_FROM_REG(data->temp_crit[attr->index]));
579}
580static ssize_t show_temp_status(struct device *dev, struct device_attribute *devattr, char *buf)
581{
582 struct sensor_device_attribute *attr = to_sensor_dev_attr(devattr);
583 struct pc87360_data *data = pc87360_update_device(dev);
584 return sprintf(buf, "%d\n", data->temp_status[attr->index]);
585}
586static ssize_t set_temp_min(struct device *dev, struct device_attribute *devattr, const char *buf,
587 size_t count)
588{
589 struct sensor_device_attribute *attr = to_sensor_dev_attr(devattr);
590 struct i2c_client *client = to_i2c_client(dev);
591 struct pc87360_data *data = i2c_get_clientdata(client);
592 long val = simple_strtol(buf, NULL, 10);
593
594 down(&data->update_lock);
595 data->temp_min[attr->index] = TEMP_TO_REG(val);
596 pc87360_write_value(data, LD_TEMP, attr->index, PC87365_REG_TEMP_MIN,
597 data->temp_min[attr->index]);
598 up(&data->update_lock);
599 return count;
600}
601static ssize_t set_temp_max(struct device *dev, struct device_attribute *devattr, const char *buf,
602 size_t count)
603{
604 struct sensor_device_attribute *attr = to_sensor_dev_attr(devattr);
605 struct i2c_client *client = to_i2c_client(dev);
606 struct pc87360_data *data = i2c_get_clientdata(client);
607 long val = simple_strtol(buf, NULL, 10);
608
609 down(&data->update_lock);
610 data->temp_max[attr->index] = TEMP_TO_REG(val);
611 pc87360_write_value(data, LD_TEMP, attr->index, PC87365_REG_TEMP_MAX,
612 data->temp_max[attr->index]);
613 up(&data->update_lock);
614 return count;
615}
616static ssize_t set_temp_crit(struct device *dev, struct device_attribute *devattr, const char *buf,
617 size_t count)
618{
619 struct sensor_device_attribute *attr = to_sensor_dev_attr(devattr);
620 struct i2c_client *client = to_i2c_client(dev);
621 struct pc87360_data *data = i2c_get_clientdata(client);
622 long val = simple_strtol(buf, NULL, 10);
623
624 down(&data->update_lock);
625 data->temp_crit[attr->index] = TEMP_TO_REG(val);
626 pc87360_write_value(data, LD_TEMP, attr->index, PC87365_REG_TEMP_CRIT,
627 data->temp_crit[attr->index]);
628 up(&data->update_lock);
629 return count;
630}
631
542#define show_and_set_temp(offset) \ 632#define show_and_set_temp(offset) \
543static ssize_t show_temp##offset##_input(struct device *dev, struct device_attribute *attr, char *buf) \ 633static SENSOR_DEVICE_ATTR(temp##offset##_input, S_IRUGO, \
544{ \ 634 show_temp_input, NULL, offset-1); \
545 struct pc87360_data *data = pc87360_update_device(dev); \ 635static SENSOR_DEVICE_ATTR(temp##offset##_min, S_IWUSR | S_IRUGO, \
546 return sprintf(buf, "%d\n", TEMP_FROM_REG(data->temp[offset-1])); \ 636 show_temp_min, set_temp_min, offset-1); \
547} \ 637static SENSOR_DEVICE_ATTR(temp##offset##_max, S_IWUSR | S_IRUGO, \
548static ssize_t show_temp##offset##_min(struct device *dev, struct device_attribute *attr, char *buf) \ 638 show_temp_max, set_temp_max, offset-1); \
549{ \ 639static SENSOR_DEVICE_ATTR(temp##offset##_crit, S_IWUSR | S_IRUGO, \
550 struct pc87360_data *data = pc87360_update_device(dev); \ 640 show_temp_crit, set_temp_crit, offset-1); \
551 return sprintf(buf, "%d\n", TEMP_FROM_REG(data->temp_min[offset-1])); \ 641static SENSOR_DEVICE_ATTR(temp##offset##_status, S_IRUGO, \
552} \ 642 show_temp_status, NULL, offset-1);
553static ssize_t show_temp##offset##_max(struct device *dev, struct device_attribute *attr, char *buf) \
554{ \
555 struct pc87360_data *data = pc87360_update_device(dev); \
556 return sprintf(buf, "%d\n", TEMP_FROM_REG(data->temp_max[offset-1])); \
557}\
558static ssize_t show_temp##offset##_crit(struct device *dev, struct device_attribute *attr, char *buf) \
559{ \
560 struct pc87360_data *data = pc87360_update_device(dev); \
561 return sprintf(buf, "%d\n", TEMP_FROM_REG(data->temp_crit[offset-1])); \
562}\
563static ssize_t show_temp##offset##_status(struct device *dev, struct device_attribute *attr, char *buf) \
564{ \
565 struct pc87360_data *data = pc87360_update_device(dev); \
566 return sprintf(buf, "%d\n", data->temp_status[offset-1]); \
567}\
568static ssize_t set_temp##offset##_min(struct device *dev, struct device_attribute *attr, const char *buf, \
569 size_t count) \
570{ \
571 struct i2c_client *client = to_i2c_client(dev); \
572 struct pc87360_data *data = i2c_get_clientdata(client); \
573 long val = simple_strtol(buf, NULL, 10); \
574 \
575 down(&data->update_lock); \
576 data->temp_min[offset-1] = TEMP_TO_REG(val); \
577 pc87360_write_value(data, LD_TEMP, offset-1, PC87365_REG_TEMP_MIN, \
578 data->temp_min[offset-1]); \
579 up(&data->update_lock); \
580 return count; \
581} \
582static ssize_t set_temp##offset##_max(struct device *dev, struct device_attribute *attr, const char *buf, \
583 size_t count) \
584{ \
585 struct i2c_client *client = to_i2c_client(dev); \
586 struct pc87360_data *data = i2c_get_clientdata(client); \
587 long val = simple_strtol(buf, NULL, 10); \
588 \
589 down(&data->update_lock); \
590 data->temp_max[offset-1] = TEMP_TO_REG(val); \
591 pc87360_write_value(data, LD_TEMP, offset-1, PC87365_REG_TEMP_MAX, \
592 data->temp_max[offset-1]); \
593 up(&data->update_lock); \
594 return count; \
595} \
596static ssize_t set_temp##offset##_crit(struct device *dev, struct device_attribute *attr, const char *buf, \
597 size_t count) \
598{ \
599 struct i2c_client *client = to_i2c_client(dev); \
600 struct pc87360_data *data = i2c_get_clientdata(client); \
601 long val = simple_strtol(buf, NULL, 10); \
602 \
603 down(&data->update_lock); \
604 data->temp_crit[offset-1] = TEMP_TO_REG(val); \
605 pc87360_write_value(data, LD_TEMP, offset-1, PC87365_REG_TEMP_CRIT, \
606 data->temp_crit[offset-1]); \
607 up(&data->update_lock); \
608 return count; \
609} \
610static DEVICE_ATTR(temp##offset##_input, S_IRUGO, \
611 show_temp##offset##_input, NULL); \
612static DEVICE_ATTR(temp##offset##_min, S_IWUSR | S_IRUGO, \
613 show_temp##offset##_min, set_temp##offset##_min); \
614static DEVICE_ATTR(temp##offset##_max, S_IWUSR | S_IRUGO, \
615 show_temp##offset##_max, set_temp##offset##_max); \
616static DEVICE_ATTR(temp##offset##_crit, S_IWUSR | S_IRUGO, \
617 show_temp##offset##_crit, set_temp##offset##_crit); \
618static DEVICE_ATTR(temp##offset##_status, S_IRUGO, \
619 show_temp##offset##_status, NULL);
620show_and_set_temp(1) 643show_and_set_temp(1)
621show_and_set_temp(2) 644show_and_set_temp(2)
622show_and_set_temp(3) 645show_and_set_temp(3)
@@ -632,12 +655,7 @@ static DEVICE_ATTR(alarms_temp, S_IRUGO, show_temp_alarms, NULL);
632 * Device detection, registration and update 655 * Device detection, registration and update
633 */ 656 */
634 657
635static int pc87360_attach_adapter(struct i2c_adapter *adapter) 658static int __init pc87360_find(int sioaddr, u8 *devid, unsigned short *addresses)
636{
637 return i2c_detect(adapter, &addr_data, pc87360_detect);
638}
639
640static int pc87360_find(int sioaddr, u8 *devid, int *address)
641{ 659{
642 u16 val; 660 u16 val;
643 int i; 661 int i;
@@ -683,7 +701,7 @@ static int pc87360_find(int sioaddr, u8 *devid, int *address)
683 continue; 701 continue;
684 } 702 }
685 703
686 address[i] = val; 704 addresses[i] = val;
687 705
688 if (i==0) { /* Fans */ 706 if (i==0) { /* Fans */
689 confreg[0] = superio_inb(sioaddr, 0xF0); 707 confreg[0] = superio_inb(sioaddr, 0xF0);
@@ -727,9 +745,7 @@ static int pc87360_find(int sioaddr, u8 *devid, int *address)
727 return 0; 745 return 0;
728} 746}
729 747
730/* We don't really care about the address. 748static int pc87360_detect(struct i2c_adapter *adapter)
731 Read from extra_isa instead. */
732int pc87360_detect(struct i2c_adapter *adapter, int address, int kind)
733{ 749{
734 int i; 750 int i;
735 struct i2c_client *new_client; 751 struct i2c_client *new_client;
@@ -738,9 +754,6 @@ int pc87360_detect(struct i2c_adapter *adapter, int address, int kind)
738 const char *name = "pc87360"; 754 const char *name = "pc87360";
739 int use_thermistors = 0; 755 int use_thermistors = 0;
740 756
741 if (!i2c_is_isa_adapter(adapter))
742 return -ENODEV;
743
744 if (!(data = kmalloc(sizeof(struct pc87360_data), GFP_KERNEL))) 757 if (!(data = kmalloc(sizeof(struct pc87360_data), GFP_KERNEL)))
745 return -ENOMEM; 758 return -ENOMEM;
746 memset(data, 0x00, sizeof(struct pc87360_data)); 759 memset(data, 0x00, sizeof(struct pc87360_data));
@@ -838,51 +851,57 @@ int pc87360_detect(struct i2c_adapter *adapter, int address, int kind)
838 } 851 }
839 852
840 /* Register sysfs hooks */ 853 /* Register sysfs hooks */
854 data->class_dev = hwmon_device_register(&new_client->dev);
855 if (IS_ERR(data->class_dev)) {
856 err = PTR_ERR(data->class_dev);
857 goto ERROR3;
858 }
859
841 if (data->innr) { 860 if (data->innr) {
842 device_create_file(&new_client->dev, &dev_attr_in0_input); 861 device_create_file(&new_client->dev, &sensor_dev_attr_in0_input.dev_attr);
843 device_create_file(&new_client->dev, &dev_attr_in1_input); 862 device_create_file(&new_client->dev, &sensor_dev_attr_in1_input.dev_attr);
844 device_create_file(&new_client->dev, &dev_attr_in2_input); 863 device_create_file(&new_client->dev, &sensor_dev_attr_in2_input.dev_attr);
845 device_create_file(&new_client->dev, &dev_attr_in3_input); 864 device_create_file(&new_client->dev, &sensor_dev_attr_in3_input.dev_attr);
846 device_create_file(&new_client->dev, &dev_attr_in4_input); 865 device_create_file(&new_client->dev, &sensor_dev_attr_in4_input.dev_attr);
847 device_create_file(&new_client->dev, &dev_attr_in5_input); 866 device_create_file(&new_client->dev, &sensor_dev_attr_in5_input.dev_attr);
848 device_create_file(&new_client->dev, &dev_attr_in6_input); 867 device_create_file(&new_client->dev, &sensor_dev_attr_in6_input.dev_attr);
849 device_create_file(&new_client->dev, &dev_attr_in7_input); 868 device_create_file(&new_client->dev, &sensor_dev_attr_in7_input.dev_attr);
850 device_create_file(&new_client->dev, &dev_attr_in8_input); 869 device_create_file(&new_client->dev, &sensor_dev_attr_in8_input.dev_attr);
851 device_create_file(&new_client->dev, &dev_attr_in9_input); 870 device_create_file(&new_client->dev, &sensor_dev_attr_in9_input.dev_attr);
852 device_create_file(&new_client->dev, &dev_attr_in10_input); 871 device_create_file(&new_client->dev, &sensor_dev_attr_in10_input.dev_attr);
853 device_create_file(&new_client->dev, &dev_attr_in0_min); 872 device_create_file(&new_client->dev, &sensor_dev_attr_in0_min.dev_attr);
854 device_create_file(&new_client->dev, &dev_attr_in1_min); 873 device_create_file(&new_client->dev, &sensor_dev_attr_in1_min.dev_attr);
855 device_create_file(&new_client->dev, &dev_attr_in2_min); 874 device_create_file(&new_client->dev, &sensor_dev_attr_in2_min.dev_attr);
856 device_create_file(&new_client->dev, &dev_attr_in3_min); 875 device_create_file(&new_client->dev, &sensor_dev_attr_in3_min.dev_attr);
857 device_create_file(&new_client->dev, &dev_attr_in4_min); 876 device_create_file(&new_client->dev, &sensor_dev_attr_in4_min.dev_attr);
858 device_create_file(&new_client->dev, &dev_attr_in5_min); 877 device_create_file(&new_client->dev, &sensor_dev_attr_in5_min.dev_attr);
859 device_create_file(&new_client->dev, &dev_attr_in6_min); 878 device_create_file(&new_client->dev, &sensor_dev_attr_in6_min.dev_attr);
860 device_create_file(&new_client->dev, &dev_attr_in7_min); 879 device_create_file(&new_client->dev, &sensor_dev_attr_in7_min.dev_attr);
861 device_create_file(&new_client->dev, &dev_attr_in8_min); 880 device_create_file(&new_client->dev, &sensor_dev_attr_in8_min.dev_attr);
862 device_create_file(&new_client->dev, &dev_attr_in9_min); 881 device_create_file(&new_client->dev, &sensor_dev_attr_in9_min.dev_attr);
863 device_create_file(&new_client->dev, &dev_attr_in10_min); 882 device_create_file(&new_client->dev, &sensor_dev_attr_in10_min.dev_attr);
864 device_create_file(&new_client->dev, &dev_attr_in0_max); 883 device_create_file(&new_client->dev, &sensor_dev_attr_in0_max.dev_attr);
865 device_create_file(&new_client->dev, &dev_attr_in1_max); 884 device_create_file(&new_client->dev, &sensor_dev_attr_in1_max.dev_attr);
866 device_create_file(&new_client->dev, &dev_attr_in2_max); 885 device_create_file(&new_client->dev, &sensor_dev_attr_in2_max.dev_attr);
867 device_create_file(&new_client->dev, &dev_attr_in3_max); 886 device_create_file(&new_client->dev, &sensor_dev_attr_in3_max.dev_attr);
868 device_create_file(&new_client->dev, &dev_attr_in4_max); 887 device_create_file(&new_client->dev, &sensor_dev_attr_in4_max.dev_attr);
869 device_create_file(&new_client->dev, &dev_attr_in5_max); 888 device_create_file(&new_client->dev, &sensor_dev_attr_in5_max.dev_attr);
870 device_create_file(&new_client->dev, &dev_attr_in6_max); 889 device_create_file(&new_client->dev, &sensor_dev_attr_in6_max.dev_attr);
871 device_create_file(&new_client->dev, &dev_attr_in7_max); 890 device_create_file(&new_client->dev, &sensor_dev_attr_in7_max.dev_attr);
872 device_create_file(&new_client->dev, &dev_attr_in8_max); 891 device_create_file(&new_client->dev, &sensor_dev_attr_in8_max.dev_attr);
873 device_create_file(&new_client->dev, &dev_attr_in9_max); 892 device_create_file(&new_client->dev, &sensor_dev_attr_in9_max.dev_attr);
874 device_create_file(&new_client->dev, &dev_attr_in10_max); 893 device_create_file(&new_client->dev, &sensor_dev_attr_in10_max.dev_attr);
875 device_create_file(&new_client->dev, &dev_attr_in0_status); 894 device_create_file(&new_client->dev, &sensor_dev_attr_in0_status.dev_attr);
876 device_create_file(&new_client->dev, &dev_attr_in1_status); 895 device_create_file(&new_client->dev, &sensor_dev_attr_in1_status.dev_attr);
877 device_create_file(&new_client->dev, &dev_attr_in2_status); 896 device_create_file(&new_client->dev, &sensor_dev_attr_in2_status.dev_attr);
878 device_create_file(&new_client->dev, &dev_attr_in3_status); 897 device_create_file(&new_client->dev, &sensor_dev_attr_in3_status.dev_attr);
879 device_create_file(&new_client->dev, &dev_attr_in4_status); 898 device_create_file(&new_client->dev, &sensor_dev_attr_in4_status.dev_attr);
880 device_create_file(&new_client->dev, &dev_attr_in5_status); 899 device_create_file(&new_client->dev, &sensor_dev_attr_in5_status.dev_attr);
881 device_create_file(&new_client->dev, &dev_attr_in6_status); 900 device_create_file(&new_client->dev, &sensor_dev_attr_in6_status.dev_attr);
882 device_create_file(&new_client->dev, &dev_attr_in7_status); 901 device_create_file(&new_client->dev, &sensor_dev_attr_in7_status.dev_attr);
883 device_create_file(&new_client->dev, &dev_attr_in8_status); 902 device_create_file(&new_client->dev, &sensor_dev_attr_in8_status.dev_attr);
884 device_create_file(&new_client->dev, &dev_attr_in9_status); 903 device_create_file(&new_client->dev, &sensor_dev_attr_in9_status.dev_attr);
885 device_create_file(&new_client->dev, &dev_attr_in10_status); 904 device_create_file(&new_client->dev, &sensor_dev_attr_in10_status.dev_attr);
886 905
887 device_create_file(&new_client->dev, &dev_attr_cpu0_vid); 906 device_create_file(&new_client->dev, &dev_attr_cpu0_vid);
888 device_create_file(&new_client->dev, &dev_attr_vrm); 907 device_create_file(&new_client->dev, &dev_attr_vrm);
@@ -890,90 +909,92 @@ int pc87360_detect(struct i2c_adapter *adapter, int address, int kind)
890 } 909 }
891 910
892 if (data->tempnr) { 911 if (data->tempnr) {
893 device_create_file(&new_client->dev, &dev_attr_temp1_input); 912 device_create_file(&new_client->dev, &sensor_dev_attr_temp1_input.dev_attr);
894 device_create_file(&new_client->dev, &dev_attr_temp2_input); 913 device_create_file(&new_client->dev, &sensor_dev_attr_temp2_input.dev_attr);
895 device_create_file(&new_client->dev, &dev_attr_temp1_min); 914 device_create_file(&new_client->dev, &sensor_dev_attr_temp1_min.dev_attr);
896 device_create_file(&new_client->dev, &dev_attr_temp2_min); 915 device_create_file(&new_client->dev, &sensor_dev_attr_temp2_min.dev_attr);
897 device_create_file(&new_client->dev, &dev_attr_temp1_max); 916 device_create_file(&new_client->dev, &sensor_dev_attr_temp1_max.dev_attr);
898 device_create_file(&new_client->dev, &dev_attr_temp2_max); 917 device_create_file(&new_client->dev, &sensor_dev_attr_temp2_max.dev_attr);
899 device_create_file(&new_client->dev, &dev_attr_temp1_crit); 918 device_create_file(&new_client->dev, &sensor_dev_attr_temp1_crit.dev_attr);
900 device_create_file(&new_client->dev, &dev_attr_temp2_crit); 919 device_create_file(&new_client->dev, &sensor_dev_attr_temp2_crit.dev_attr);
901 device_create_file(&new_client->dev, &dev_attr_temp1_status); 920 device_create_file(&new_client->dev, &sensor_dev_attr_temp1_status.dev_attr);
902 device_create_file(&new_client->dev, &dev_attr_temp2_status); 921 device_create_file(&new_client->dev, &sensor_dev_attr_temp2_status.dev_attr);
903 922
904 device_create_file(&new_client->dev, &dev_attr_alarms_temp); 923 device_create_file(&new_client->dev, &dev_attr_alarms_temp);
905 } 924 }
906 if (data->tempnr == 3) { 925 if (data->tempnr == 3) {
907 device_create_file(&new_client->dev, &dev_attr_temp3_input); 926 device_create_file(&new_client->dev, &sensor_dev_attr_temp3_input.dev_attr);
908 device_create_file(&new_client->dev, &dev_attr_temp3_min); 927 device_create_file(&new_client->dev, &sensor_dev_attr_temp3_min.dev_attr);
909 device_create_file(&new_client->dev, &dev_attr_temp3_max); 928 device_create_file(&new_client->dev, &sensor_dev_attr_temp3_max.dev_attr);
910 device_create_file(&new_client->dev, &dev_attr_temp3_crit); 929 device_create_file(&new_client->dev, &sensor_dev_attr_temp3_crit.dev_attr);
911 device_create_file(&new_client->dev, &dev_attr_temp3_status); 930 device_create_file(&new_client->dev, &sensor_dev_attr_temp3_status.dev_attr);
912 } 931 }
913 if (data->innr == 14) { 932 if (data->innr == 14) {
914 device_create_file(&new_client->dev, &dev_attr_temp4_input); 933 device_create_file(&new_client->dev, &sensor_dev_attr_temp4_input.dev_attr);
915 device_create_file(&new_client->dev, &dev_attr_temp5_input); 934 device_create_file(&new_client->dev, &sensor_dev_attr_temp5_input.dev_attr);
916 device_create_file(&new_client->dev, &dev_attr_temp6_input); 935 device_create_file(&new_client->dev, &sensor_dev_attr_temp6_input.dev_attr);
917 device_create_file(&new_client->dev, &dev_attr_temp4_min); 936 device_create_file(&new_client->dev, &sensor_dev_attr_temp4_min.dev_attr);
918 device_create_file(&new_client->dev, &dev_attr_temp5_min); 937 device_create_file(&new_client->dev, &sensor_dev_attr_temp5_min.dev_attr);
919 device_create_file(&new_client->dev, &dev_attr_temp6_min); 938 device_create_file(&new_client->dev, &sensor_dev_attr_temp6_min.dev_attr);
920 device_create_file(&new_client->dev, &dev_attr_temp4_max); 939 device_create_file(&new_client->dev, &sensor_dev_attr_temp4_max.dev_attr);
921 device_create_file(&new_client->dev, &dev_attr_temp5_max); 940 device_create_file(&new_client->dev, &sensor_dev_attr_temp5_max.dev_attr);
922 device_create_file(&new_client->dev, &dev_attr_temp6_max); 941 device_create_file(&new_client->dev, &sensor_dev_attr_temp6_max.dev_attr);
923 device_create_file(&new_client->dev, &dev_attr_temp4_crit); 942 device_create_file(&new_client->dev, &sensor_dev_attr_temp4_crit.dev_attr);
924 device_create_file(&new_client->dev, &dev_attr_temp5_crit); 943 device_create_file(&new_client->dev, &sensor_dev_attr_temp5_crit.dev_attr);
925 device_create_file(&new_client->dev, &dev_attr_temp6_crit); 944 device_create_file(&new_client->dev, &sensor_dev_attr_temp6_crit.dev_attr);
926 device_create_file(&new_client->dev, &dev_attr_temp4_status); 945 device_create_file(&new_client->dev, &sensor_dev_attr_temp4_status.dev_attr);
927 device_create_file(&new_client->dev, &dev_attr_temp5_status); 946 device_create_file(&new_client->dev, &sensor_dev_attr_temp5_status.dev_attr);
928 device_create_file(&new_client->dev, &dev_attr_temp6_status); 947 device_create_file(&new_client->dev, &sensor_dev_attr_temp6_status.dev_attr);
929 } 948 }
930 949
931 if (data->fannr) { 950 if (data->fannr) {
932 if (FAN_CONFIG_MONITOR(data->fan_conf, 0)) { 951 if (FAN_CONFIG_MONITOR(data->fan_conf, 0)) {
933 device_create_file(&new_client->dev, 952 device_create_file(&new_client->dev,
934 &dev_attr_fan1_input); 953 &sensor_dev_attr_fan1_input.dev_attr);
935 device_create_file(&new_client->dev, 954 device_create_file(&new_client->dev,
936 &dev_attr_fan1_min); 955 &sensor_dev_attr_fan1_min.dev_attr);
937 device_create_file(&new_client->dev, 956 device_create_file(&new_client->dev,
938 &dev_attr_fan1_div); 957 &sensor_dev_attr_fan1_div.dev_attr);
939 device_create_file(&new_client->dev, 958 device_create_file(&new_client->dev,
940 &dev_attr_fan1_status); 959 &sensor_dev_attr_fan1_status.dev_attr);
941 } 960 }
942 961
943 if (FAN_CONFIG_MONITOR(data->fan_conf, 1)) { 962 if (FAN_CONFIG_MONITOR(data->fan_conf, 1)) {
944 device_create_file(&new_client->dev, 963 device_create_file(&new_client->dev,
945 &dev_attr_fan2_input); 964 &sensor_dev_attr_fan2_input.dev_attr);
946 device_create_file(&new_client->dev, 965 device_create_file(&new_client->dev,
947 &dev_attr_fan2_min); 966 &sensor_dev_attr_fan2_min.dev_attr);
948 device_create_file(&new_client->dev, 967 device_create_file(&new_client->dev,
949 &dev_attr_fan2_div); 968 &sensor_dev_attr_fan2_div.dev_attr);
950 device_create_file(&new_client->dev, 969 device_create_file(&new_client->dev,
951 &dev_attr_fan2_status); 970 &sensor_dev_attr_fan2_status.dev_attr);
952 } 971 }
953 972
954 if (FAN_CONFIG_CONTROL(data->fan_conf, 0)) 973 if (FAN_CONFIG_CONTROL(data->fan_conf, 0))
955 device_create_file(&new_client->dev, &dev_attr_pwm1); 974 device_create_file(&new_client->dev, &sensor_dev_attr_pwm1.dev_attr);
956 if (FAN_CONFIG_CONTROL(data->fan_conf, 1)) 975 if (FAN_CONFIG_CONTROL(data->fan_conf, 1))
957 device_create_file(&new_client->dev, &dev_attr_pwm2); 976 device_create_file(&new_client->dev, &sensor_dev_attr_pwm2.dev_attr);
958 } 977 }
959 if (data->fannr == 3) { 978 if (data->fannr == 3) {
960 if (FAN_CONFIG_MONITOR(data->fan_conf, 2)) { 979 if (FAN_CONFIG_MONITOR(data->fan_conf, 2)) {
961 device_create_file(&new_client->dev, 980 device_create_file(&new_client->dev,
962 &dev_attr_fan3_input); 981 &sensor_dev_attr_fan3_input.dev_attr);
963 device_create_file(&new_client->dev, 982 device_create_file(&new_client->dev,
964 &dev_attr_fan3_min); 983 &sensor_dev_attr_fan3_min.dev_attr);
965 device_create_file(&new_client->dev, 984 device_create_file(&new_client->dev,
966 &dev_attr_fan3_div); 985 &sensor_dev_attr_fan3_div.dev_attr);
967 device_create_file(&new_client->dev, 986 device_create_file(&new_client->dev,
968 &dev_attr_fan3_status); 987 &sensor_dev_attr_fan3_status.dev_attr);
969 } 988 }
970 989
971 if (FAN_CONFIG_CONTROL(data->fan_conf, 2)) 990 if (FAN_CONFIG_CONTROL(data->fan_conf, 2))
972 device_create_file(&new_client->dev, &dev_attr_pwm3); 991 device_create_file(&new_client->dev, &sensor_dev_attr_pwm3.dev_attr);
973 } 992 }
974 993
975 return 0; 994 return 0;
976 995
996ERROR3:
997 i2c_detach_client(new_client);
977ERROR2: 998ERROR2:
978 for (i = 0; i < 3; i++) { 999 for (i = 0; i < 3; i++) {
979 if (data->address[i]) { 1000 if (data->address[i]) {
@@ -990,11 +1011,10 @@ static int pc87360_detach_client(struct i2c_client *client)
990 struct pc87360_data *data = i2c_get_clientdata(client); 1011 struct pc87360_data *data = i2c_get_clientdata(client);
991 int i; 1012 int i;
992 1013
993 if ((i = i2c_detach_client(client))) { 1014 hwmon_device_unregister(data->class_dev);
994 dev_err(&client->dev, "Client deregistration failed, " 1015
995 "client not detached.\n"); 1016 if ((i = i2c_detach_client(client)))
996 return i; 1017 return i;
997 }
998 1018
999 for (i = 0; i < 3; i++) { 1019 for (i = 0; i < 3; i++) {
1000 if (data->address[i]) { 1020 if (data->address[i]) {
@@ -1320,23 +1340,23 @@ static int __init pc87360_init(void)
1320 /* Arbitrarily pick one of the addresses */ 1340 /* Arbitrarily pick one of the addresses */
1321 for (i = 0; i < 3; i++) { 1341 for (i = 0; i < 3; i++) {
1322 if (extra_isa[i] != 0x0000) { 1342 if (extra_isa[i] != 0x0000) {
1323 normal_isa[0] = extra_isa[i]; 1343 address = extra_isa[i];
1324 break; 1344 break;
1325 } 1345 }
1326 } 1346 }
1327 1347
1328 if (normal_isa[0] == 0x0000) { 1348 if (address == 0x0000) {
1329 printk(KERN_WARNING "pc87360: No active logical device, " 1349 printk(KERN_WARNING "pc87360: No active logical device, "
1330 "module not inserted.\n"); 1350 "module not inserted.\n");
1331 return -ENODEV; 1351 return -ENODEV;
1332 } 1352 }
1333 1353
1334 return i2c_add_driver(&pc87360_driver); 1354 return i2c_isa_add_driver(&pc87360_driver);
1335} 1355}
1336 1356
1337static void __exit pc87360_exit(void) 1357static void __exit pc87360_exit(void)
1338{ 1358{
1339 i2c_del_driver(&pc87360_driver); 1359 i2c_isa_del_driver(&pc87360_driver);
1340} 1360}
1341 1361
1342 1362
diff --git a/drivers/hwmon/sis5595.c b/drivers/hwmon/sis5595.c
index 6bbfc8fb4f1..8610bce0824 100644
--- a/drivers/hwmon/sis5595.c
+++ b/drivers/hwmon/sis5595.c
@@ -55,7 +55,9 @@
55#include <linux/ioport.h> 55#include <linux/ioport.h>
56#include <linux/pci.h> 56#include <linux/pci.h>
57#include <linux/i2c.h> 57#include <linux/i2c.h>
58#include <linux/i2c-sensor.h> 58#include <linux/i2c-isa.h>
59#include <linux/hwmon.h>
60#include <linux/err.h>
59#include <linux/init.h> 61#include <linux/init.h>
60#include <linux/jiffies.h> 62#include <linux/jiffies.h>
61#include <asm/io.h> 63#include <asm/io.h>
@@ -68,14 +70,10 @@ module_param(force_addr, ushort, 0);
68MODULE_PARM_DESC(force_addr, 70MODULE_PARM_DESC(force_addr,
69 "Initialize the base address of the sensors"); 71 "Initialize the base address of the sensors");
70 72
71/* Addresses to scan. 73/* Device address
72 Note that we can't determine the ISA address until we have initialized 74 Note that we can't determine the ISA address until we have initialized
73 our module */ 75 our module */
74static unsigned short normal_i2c[] = { I2C_CLIENT_END }; 76static unsigned short address;
75static unsigned int normal_isa[] = { 0x0000, I2C_CLIENT_ISA_END };
76
77/* Insmod parameters */
78SENSORS_INSMOD_1(sis5595);
79 77
80/* Many SIS5595 constants specified below */ 78/* Many SIS5595 constants specified below */
81 79
@@ -168,6 +166,7 @@ static inline u8 DIV_TO_REG(int val)
168 allocated. */ 166 allocated. */
169struct sis5595_data { 167struct sis5595_data {
170 struct i2c_client client; 168 struct i2c_client client;
169 struct class_device *class_dev;
171 struct semaphore lock; 170 struct semaphore lock;
172 171
173 struct semaphore update_lock; 172 struct semaphore update_lock;
@@ -190,8 +189,7 @@ struct sis5595_data {
190 189
191static struct pci_dev *s_bridge; /* pointer to the (only) sis5595 */ 190static struct pci_dev *s_bridge; /* pointer to the (only) sis5595 */
192 191
193static int sis5595_attach_adapter(struct i2c_adapter *adapter); 192static int sis5595_detect(struct i2c_adapter *adapter);
194static int sis5595_detect(struct i2c_adapter *adapter, int address, int kind);
195static int sis5595_detach_client(struct i2c_client *client); 193static int sis5595_detach_client(struct i2c_client *client);
196 194
197static int sis5595_read_value(struct i2c_client *client, u8 register); 195static int sis5595_read_value(struct i2c_client *client, u8 register);
@@ -202,9 +200,7 @@ static void sis5595_init_client(struct i2c_client *client);
202static struct i2c_driver sis5595_driver = { 200static struct i2c_driver sis5595_driver = {
203 .owner = THIS_MODULE, 201 .owner = THIS_MODULE,
204 .name = "sis5595", 202 .name = "sis5595",
205 .id = I2C_DRIVERID_SIS5595, 203 .attach_adapter = sis5595_detect,
206 .flags = I2C_DF_NOTIFY,
207 .attach_adapter = sis5595_attach_adapter,
208 .detach_client = sis5595_detach_client, 204 .detach_client = sis5595_detach_client,
209}; 205};
210 206
@@ -476,14 +472,7 @@ static ssize_t show_alarms(struct device *dev, struct device_attribute *attr, ch
476static DEVICE_ATTR(alarms, S_IRUGO, show_alarms, NULL); 472static DEVICE_ATTR(alarms, S_IRUGO, show_alarms, NULL);
477 473
478/* This is called when the module is loaded */ 474/* This is called when the module is loaded */
479static int sis5595_attach_adapter(struct i2c_adapter *adapter) 475static int sis5595_detect(struct i2c_adapter *adapter)
480{
481 if (!(adapter->class & I2C_CLASS_HWMON))
482 return 0;
483 return i2c_detect(adapter, &addr_data, sis5595_detect);
484}
485
486int sis5595_detect(struct i2c_adapter *adapter, int address, int kind)
487{ 476{
488 int err = 0; 477 int err = 0;
489 int i; 478 int i;
@@ -492,10 +481,6 @@ int sis5595_detect(struct i2c_adapter *adapter, int address, int kind)
492 char val; 481 char val;
493 u16 a; 482 u16 a;
494 483
495 /* Make sure we are probing the ISA bus!! */
496 if (!i2c_is_isa_adapter(adapter))
497 goto exit;
498
499 if (force_addr) 484 if (force_addr)
500 address = force_addr & ~(SIS5595_EXTENT - 1); 485 address = force_addr & ~(SIS5595_EXTENT - 1);
501 /* Reserve the ISA region */ 486 /* Reserve the ISA region */
@@ -578,6 +563,12 @@ int sis5595_detect(struct i2c_adapter *adapter, int address, int kind)
578 } 563 }
579 564
580 /* Register sysfs hooks */ 565 /* Register sysfs hooks */
566 data->class_dev = hwmon_device_register(&new_client->dev);
567 if (IS_ERR(data->class_dev)) {
568 err = PTR_ERR(data->class_dev);
569 goto exit_detach;
570 }
571
581 device_create_file(&new_client->dev, &dev_attr_in0_input); 572 device_create_file(&new_client->dev, &dev_attr_in0_input);
582 device_create_file(&new_client->dev, &dev_attr_in0_min); 573 device_create_file(&new_client->dev, &dev_attr_in0_min);
583 device_create_file(&new_client->dev, &dev_attr_in0_max); 574 device_create_file(&new_client->dev, &dev_attr_in0_max);
@@ -608,7 +599,9 @@ int sis5595_detect(struct i2c_adapter *adapter, int address, int kind)
608 device_create_file(&new_client->dev, &dev_attr_temp1_max_hyst); 599 device_create_file(&new_client->dev, &dev_attr_temp1_max_hyst);
609 } 600 }
610 return 0; 601 return 0;
611 602
603exit_detach:
604 i2c_detach_client(new_client);
612exit_free: 605exit_free:
613 kfree(data); 606 kfree(data);
614exit_release: 607exit_release:
@@ -619,18 +612,17 @@ exit:
619 612
620static int sis5595_detach_client(struct i2c_client *client) 613static int sis5595_detach_client(struct i2c_client *client)
621{ 614{
615 struct sis5595_data *data = i2c_get_clientdata(client);
622 int err; 616 int err;
623 617
624 if ((err = i2c_detach_client(client))) { 618 hwmon_device_unregister(data->class_dev);
625 dev_err(&client->dev, 619
626 "Client deregistration failed, client not detached.\n"); 620 if ((err = i2c_detach_client(client)))
627 return err; 621 return err;
628 }
629 622
630 if (i2c_is_isa_client(client)) 623 release_region(client->addr, SIS5595_EXTENT);
631 release_region(client->addr, SIS5595_EXTENT);
632 624
633 kfree(i2c_get_clientdata(client)); 625 kfree(data);
634 626
635 return 0; 627 return 0;
636} 628}
@@ -745,7 +737,6 @@ static int __devinit sis5595_pci_probe(struct pci_dev *dev,
745{ 737{
746 u16 val; 738 u16 val;
747 int *i; 739 int *i;
748 int addr = 0;
749 740
750 for (i = blacklist; *i != 0; i++) { 741 for (i = blacklist; *i != 0; i++) {
751 struct pci_dev *dev; 742 struct pci_dev *dev;
@@ -761,22 +752,19 @@ static int __devinit sis5595_pci_probe(struct pci_dev *dev,
761 pci_read_config_word(dev, SIS5595_BASE_REG, &val)) 752 pci_read_config_word(dev, SIS5595_BASE_REG, &val))
762 return -ENODEV; 753 return -ENODEV;
763 754
764 addr = val & ~(SIS5595_EXTENT - 1); 755 address = val & ~(SIS5595_EXTENT - 1);
765 if (addr == 0 && force_addr == 0) { 756 if (address == 0 && force_addr == 0) {
766 dev_err(&dev->dev, "Base address not set - upgrade BIOS or use force_addr=0xaddr\n"); 757 dev_err(&dev->dev, "Base address not set - upgrade BIOS or use force_addr=0xaddr\n");
767 return -ENODEV; 758 return -ENODEV;
768 } 759 }
769 if (force_addr)
770 addr = force_addr; /* so detect will get called */
771 760
772 if (!addr) { 761 if (!address) {
773 dev_err(&dev->dev,"No SiS 5595 sensors found.\n"); 762 dev_err(&dev->dev,"No SiS 5595 sensors found.\n");
774 return -ENODEV; 763 return -ENODEV;
775 } 764 }
776 normal_isa[0] = addr;
777 765
778 s_bridge = pci_dev_get(dev); 766 s_bridge = pci_dev_get(dev);
779 if (i2c_add_driver(&sis5595_driver)) { 767 if (i2c_isa_add_driver(&sis5595_driver)) {
780 pci_dev_put(s_bridge); 768 pci_dev_put(s_bridge);
781 s_bridge = NULL; 769 s_bridge = NULL;
782 } 770 }
@@ -803,7 +791,7 @@ static void __exit sm_sis5595_exit(void)
803{ 791{
804 pci_unregister_driver(&sis5595_pci_driver); 792 pci_unregister_driver(&sis5595_pci_driver);
805 if (s_bridge != NULL) { 793 if (s_bridge != NULL) {
806 i2c_del_driver(&sis5595_driver); 794 i2c_isa_del_driver(&sis5595_driver);
807 pci_dev_put(s_bridge); 795 pci_dev_put(s_bridge);
808 s_bridge = NULL; 796 s_bridge = NULL;
809 } 797 }
diff --git a/drivers/hwmon/smsc47b397.c b/drivers/hwmon/smsc47b397.c
index fdeeb3ab6f2..7fe71576dea 100644
--- a/drivers/hwmon/smsc47b397.c
+++ b/drivers/hwmon/smsc47b397.c
@@ -31,23 +31,14 @@
31#include <linux/ioport.h> 31#include <linux/ioport.h>
32#include <linux/jiffies.h> 32#include <linux/jiffies.h>
33#include <linux/i2c.h> 33#include <linux/i2c.h>
34#include <linux/i2c-sensor.h> 34#include <linux/i2c-isa.h>
35#include <linux/hwmon.h>
36#include <linux/err.h>
35#include <linux/init.h> 37#include <linux/init.h>
36#include <asm/io.h> 38#include <asm/io.h>
37 39
38static unsigned short normal_i2c[] = { I2C_CLIENT_END };
39/* Address is autodetected, there is no default value */ 40/* Address is autodetected, there is no default value */
40static unsigned int normal_isa[] = { 0x0000, I2C_CLIENT_ISA_END }; 41static unsigned short address;
41static struct i2c_force_data forces[] = {{NULL}};
42
43enum chips { any_chip, smsc47b397 };
44static struct i2c_address_data addr_data = {
45 .normal_i2c = normal_i2c,
46 .normal_isa = normal_isa,
47 .probe = normal_i2c, /* cheat */
48 .ignore = normal_i2c, /* cheat */
49 .forces = forces,
50};
51 42
52/* Super-I/0 registers and commands */ 43/* Super-I/0 registers and commands */
53 44
@@ -100,6 +91,7 @@ static u8 smsc47b397_reg_temp[] = {0x25, 0x26, 0x27, 0x80};
100 91
101struct smsc47b397_data { 92struct smsc47b397_data {
102 struct i2c_client client; 93 struct i2c_client client;
94 struct class_device *class_dev;
103 struct semaphore lock; 95 struct semaphore lock;
104 96
105 struct semaphore update_lock; 97 struct semaphore update_lock;
@@ -215,52 +207,40 @@ sysfs_fan(4);
215#define device_create_file_fan(client, num) \ 207#define device_create_file_fan(client, num) \
216 device_create_file(&client->dev, &dev_attr_fan##num##_input) 208 device_create_file(&client->dev, &dev_attr_fan##num##_input)
217 209
218static int smsc47b397_detect(struct i2c_adapter *adapter, int addr, int kind);
219
220static int smsc47b397_attach_adapter(struct i2c_adapter *adapter)
221{
222 if (!(adapter->class & I2C_CLASS_HWMON))
223 return 0;
224 return i2c_detect(adapter, &addr_data, smsc47b397_detect);
225}
226
227static int smsc47b397_detach_client(struct i2c_client *client) 210static int smsc47b397_detach_client(struct i2c_client *client)
228{ 211{
212 struct smsc47b397_data *data = i2c_get_clientdata(client);
229 int err; 213 int err;
230 214
231 if ((err = i2c_detach_client(client))) { 215 hwmon_device_unregister(data->class_dev);
232 dev_err(&client->dev, "Client deregistration failed, " 216
233 "client not detached.\n"); 217 if ((err = i2c_detach_client(client)))
234 return err; 218 return err;
235 }
236 219
237 release_region(client->addr, SMSC_EXTENT); 220 release_region(client->addr, SMSC_EXTENT);
238 kfree(i2c_get_clientdata(client)); 221 kfree(data);
239 222
240 return 0; 223 return 0;
241} 224}
242 225
226static int smsc47b397_detect(struct i2c_adapter *adapter);
227
243static struct i2c_driver smsc47b397_driver = { 228static struct i2c_driver smsc47b397_driver = {
244 .owner = THIS_MODULE, 229 .owner = THIS_MODULE,
245 .name = "smsc47b397", 230 .name = "smsc47b397",
246 .id = I2C_DRIVERID_SMSC47B397, 231 .attach_adapter = smsc47b397_detect,
247 .flags = I2C_DF_NOTIFY,
248 .attach_adapter = smsc47b397_attach_adapter,
249 .detach_client = smsc47b397_detach_client, 232 .detach_client = smsc47b397_detach_client,
250}; 233};
251 234
252static int smsc47b397_detect(struct i2c_adapter *adapter, int addr, int kind) 235static int smsc47b397_detect(struct i2c_adapter *adapter)
253{ 236{
254 struct i2c_client *new_client; 237 struct i2c_client *new_client;
255 struct smsc47b397_data *data; 238 struct smsc47b397_data *data;
256 int err = 0; 239 int err = 0;
257 240
258 if (!i2c_is_isa_adapter(adapter)) { 241 if (!request_region(address, SMSC_EXTENT, smsc47b397_driver.name)) {
259 return 0; 242 dev_err(&adapter->dev, "Region 0x%x already in use!\n",
260 } 243 address);
261
262 if (!request_region(addr, SMSC_EXTENT, smsc47b397_driver.name)) {
263 dev_err(&adapter->dev, "Region 0x%x already in use!\n", addr);
264 return -EBUSY; 244 return -EBUSY;
265 } 245 }
266 246
@@ -272,7 +252,7 @@ static int smsc47b397_detect(struct i2c_adapter *adapter, int addr, int kind)
272 252
273 new_client = &data->client; 253 new_client = &data->client;
274 i2c_set_clientdata(new_client, data); 254 i2c_set_clientdata(new_client, data);
275 new_client->addr = addr; 255 new_client->addr = address;
276 init_MUTEX(&data->lock); 256 init_MUTEX(&data->lock);
277 new_client->adapter = adapter; 257 new_client->adapter = adapter;
278 new_client->driver = &smsc47b397_driver; 258 new_client->driver = &smsc47b397_driver;
@@ -285,6 +265,12 @@ static int smsc47b397_detect(struct i2c_adapter *adapter, int addr, int kind)
285 if ((err = i2c_attach_client(new_client))) 265 if ((err = i2c_attach_client(new_client)))
286 goto error_free; 266 goto error_free;
287 267
268 data->class_dev = hwmon_device_register(&new_client->dev);
269 if (IS_ERR(data->class_dev)) {
270 err = PTR_ERR(data->class_dev);
271 goto error_detach;
272 }
273
288 device_create_file_temp(new_client, 1); 274 device_create_file_temp(new_client, 1);
289 device_create_file_temp(new_client, 2); 275 device_create_file_temp(new_client, 2);
290 device_create_file_temp(new_client, 3); 276 device_create_file_temp(new_client, 3);
@@ -297,14 +283,16 @@ static int smsc47b397_detect(struct i2c_adapter *adapter, int addr, int kind)
297 283
298 return 0; 284 return 0;
299 285
286error_detach:
287 i2c_detach_client(new_client);
300error_free: 288error_free:
301 kfree(data); 289 kfree(data);
302error_release: 290error_release:
303 release_region(addr, SMSC_EXTENT); 291 release_region(address, SMSC_EXTENT);
304 return err; 292 return err;
305} 293}
306 294
307static int __init smsc47b397_find(unsigned int *addr) 295static int __init smsc47b397_find(unsigned short *addr)
308{ 296{
309 u8 id, rev; 297 u8 id, rev;
310 298
@@ -333,15 +321,15 @@ static int __init smsc47b397_init(void)
333{ 321{
334 int ret; 322 int ret;
335 323
336 if ((ret = smsc47b397_find(normal_isa))) 324 if ((ret = smsc47b397_find(&address)))
337 return ret; 325 return ret;
338 326
339 return i2c_add_driver(&smsc47b397_driver); 327 return i2c_isa_add_driver(&smsc47b397_driver);
340} 328}
341 329
342static void __exit smsc47b397_exit(void) 330static void __exit smsc47b397_exit(void)
343{ 331{
344 i2c_del_driver(&smsc47b397_driver); 332 i2c_isa_del_driver(&smsc47b397_driver);
345} 333}
346 334
347MODULE_AUTHOR("Mark M. Hoffman <mhoffman@lightlink.com>"); 335MODULE_AUTHOR("Mark M. Hoffman <mhoffman@lightlink.com>");
diff --git a/drivers/hwmon/smsc47m1.c b/drivers/hwmon/smsc47m1.c
index 7166ad0b2fd..7e699a8ede2 100644
--- a/drivers/hwmon/smsc47m1.c
+++ b/drivers/hwmon/smsc47m1.c
@@ -30,21 +30,14 @@
30#include <linux/ioport.h> 30#include <linux/ioport.h>
31#include <linux/jiffies.h> 31#include <linux/jiffies.h>
32#include <linux/i2c.h> 32#include <linux/i2c.h>
33#include <linux/i2c-sensor.h> 33#include <linux/i2c-isa.h>
34#include <linux/hwmon.h>
35#include <linux/err.h>
34#include <linux/init.h> 36#include <linux/init.h>
35#include <asm/io.h> 37#include <asm/io.h>
36 38
37static unsigned short normal_i2c[] = { I2C_CLIENT_END };
38/* Address is autodetected, there is no default value */ 39/* Address is autodetected, there is no default value */
39static unsigned int normal_isa[] = { 0x0000, I2C_CLIENT_ISA_END }; 40static unsigned short address;
40static struct i2c_force_data forces[] = {{NULL}};
41
42enum chips { any_chip, smsc47m1 };
43static struct i2c_address_data addr_data = {
44 .normal_i2c = normal_i2c,
45 .normal_isa = normal_isa,
46 .forces = forces,
47};
48 41
49/* Super-I/0 registers and commands */ 42/* Super-I/0 registers and commands */
50 43
@@ -108,6 +101,7 @@ superio_exit(void)
108 101
109struct smsc47m1_data { 102struct smsc47m1_data {
110 struct i2c_client client; 103 struct i2c_client client;
104 struct class_device *class_dev;
111 struct semaphore lock; 105 struct semaphore lock;
112 106
113 struct semaphore update_lock; 107 struct semaphore update_lock;
@@ -121,9 +115,7 @@ struct smsc47m1_data {
121}; 115};
122 116
123 117
124static int smsc47m1_attach_adapter(struct i2c_adapter *adapter); 118static int smsc47m1_detect(struct i2c_adapter *adapter);
125static int smsc47m1_find(int *address);
126static int smsc47m1_detect(struct i2c_adapter *adapter, int address, int kind);
127static int smsc47m1_detach_client(struct i2c_client *client); 119static int smsc47m1_detach_client(struct i2c_client *client);
128 120
129static int smsc47m1_read_value(struct i2c_client *client, u8 reg); 121static int smsc47m1_read_value(struct i2c_client *client, u8 reg);
@@ -136,9 +128,7 @@ static struct smsc47m1_data *smsc47m1_update_device(struct device *dev,
136static struct i2c_driver smsc47m1_driver = { 128static struct i2c_driver smsc47m1_driver = {
137 .owner = THIS_MODULE, 129 .owner = THIS_MODULE,
138 .name = "smsc47m1", 130 .name = "smsc47m1",
139 .id = I2C_DRIVERID_SMSC47M1, 131 .attach_adapter = smsc47m1_detect,
140 .flags = I2C_DF_NOTIFY,
141 .attach_adapter = smsc47m1_attach_adapter,
142 .detach_client = smsc47m1_detach_client, 132 .detach_client = smsc47m1_detach_client,
143}; 133};
144 134
@@ -354,14 +344,7 @@ fan_present(2);
354 344
355static DEVICE_ATTR(alarms, S_IRUGO, get_alarms, NULL); 345static DEVICE_ATTR(alarms, S_IRUGO, get_alarms, NULL);
356 346
357static int smsc47m1_attach_adapter(struct i2c_adapter *adapter) 347static int __init smsc47m1_find(unsigned short *addr)
358{
359 if (!(adapter->class & I2C_CLASS_HWMON))
360 return 0;
361 return i2c_detect(adapter, &addr_data, smsc47m1_detect);
362}
363
364static int smsc47m1_find(int *address)
365{ 348{
366 u8 val; 349 u8 val;
367 350
@@ -388,10 +371,10 @@ static int smsc47m1_find(int *address)
388 } 371 }
389 372
390 superio_select(); 373 superio_select();
391 *address = (superio_inb(SUPERIO_REG_BASE) << 8) 374 *addr = (superio_inb(SUPERIO_REG_BASE) << 8)
392 | superio_inb(SUPERIO_REG_BASE + 1); 375 | superio_inb(SUPERIO_REG_BASE + 1);
393 val = superio_inb(SUPERIO_REG_ACT); 376 val = superio_inb(SUPERIO_REG_ACT);
394 if (*address == 0 || (val & 0x01) == 0) { 377 if (*addr == 0 || (val & 0x01) == 0) {
395 printk(KERN_INFO "smsc47m1: Device is disabled, will not use\n"); 378 printk(KERN_INFO "smsc47m1: Device is disabled, will not use\n");
396 superio_exit(); 379 superio_exit();
397 return -ENODEV; 380 return -ENODEV;
@@ -401,17 +384,13 @@ static int smsc47m1_find(int *address)
401 return 0; 384 return 0;
402} 385}
403 386
404static int smsc47m1_detect(struct i2c_adapter *adapter, int address, int kind) 387static int smsc47m1_detect(struct i2c_adapter *adapter)
405{ 388{
406 struct i2c_client *new_client; 389 struct i2c_client *new_client;
407 struct smsc47m1_data *data; 390 struct smsc47m1_data *data;
408 int err = 0; 391 int err = 0;
409 int fan1, fan2, pwm1, pwm2; 392 int fan1, fan2, pwm1, pwm2;
410 393
411 if (!i2c_is_isa_adapter(adapter)) {
412 return 0;
413 }
414
415 if (!request_region(address, SMSC_EXTENT, smsc47m1_driver.name)) { 394 if (!request_region(address, SMSC_EXTENT, smsc47m1_driver.name)) {
416 dev_err(&adapter->dev, "Region 0x%x already in use!\n", address); 395 dev_err(&adapter->dev, "Region 0x%x already in use!\n", address);
417 return -EBUSY; 396 return -EBUSY;
@@ -461,6 +440,13 @@ static int smsc47m1_detect(struct i2c_adapter *adapter, int address, int kind)
461 function. */ 440 function. */
462 smsc47m1_update_device(&new_client->dev, 1); 441 smsc47m1_update_device(&new_client->dev, 1);
463 442
443 /* Register sysfs hooks */
444 data->class_dev = hwmon_device_register(&new_client->dev);
445 if (IS_ERR(data->class_dev)) {
446 err = PTR_ERR(data->class_dev);
447 goto error_detach;
448 }
449
464 if (fan1) { 450 if (fan1) {
465 device_create_file(&new_client->dev, &dev_attr_fan1_input); 451 device_create_file(&new_client->dev, &dev_attr_fan1_input);
466 device_create_file(&new_client->dev, &dev_attr_fan1_min); 452 device_create_file(&new_client->dev, &dev_attr_fan1_min);
@@ -494,6 +480,8 @@ static int smsc47m1_detect(struct i2c_adapter *adapter, int address, int kind)
494 480
495 return 0; 481 return 0;
496 482
483error_detach:
484 i2c_detach_client(new_client);
497error_free: 485error_free:
498 kfree(data); 486 kfree(data);
499error_release: 487error_release:
@@ -503,16 +491,16 @@ error_release:
503 491
504static int smsc47m1_detach_client(struct i2c_client *client) 492static int smsc47m1_detach_client(struct i2c_client *client)
505{ 493{
494 struct smsc47m1_data *data = i2c_get_clientdata(client);
506 int err; 495 int err;
507 496
508 if ((err = i2c_detach_client(client))) { 497 hwmon_device_unregister(data->class_dev);
509 dev_err(&client->dev, "Client deregistration failed, " 498
510 "client not detached.\n"); 499 if ((err = i2c_detach_client(client)))
511 return err; 500 return err;
512 }
513 501
514 release_region(client->addr, SMSC_EXTENT); 502 release_region(client->addr, SMSC_EXTENT);
515 kfree(i2c_get_clientdata(client)); 503 kfree(data);
516 504
517 return 0; 505 return 0;
518} 506}
@@ -573,16 +561,16 @@ static struct smsc47m1_data *smsc47m1_update_device(struct device *dev,
573 561
574static int __init sm_smsc47m1_init(void) 562static int __init sm_smsc47m1_init(void)
575{ 563{
576 if (smsc47m1_find(normal_isa)) { 564 if (smsc47m1_find(&address)) {
577 return -ENODEV; 565 return -ENODEV;
578 } 566 }
579 567
580 return i2c_add_driver(&smsc47m1_driver); 568 return i2c_isa_add_driver(&smsc47m1_driver);
581} 569}
582 570
583static void __exit sm_smsc47m1_exit(void) 571static void __exit sm_smsc47m1_exit(void)
584{ 572{
585 i2c_del_driver(&smsc47m1_driver); 573 i2c_isa_del_driver(&smsc47m1_driver);
586} 574}
587 575
588MODULE_AUTHOR("Mark D. Studebaker <mdsxyz123@yahoo.com>"); 576MODULE_AUTHOR("Mark D. Studebaker <mdsxyz123@yahoo.com>");
diff --git a/drivers/hwmon/via686a.c b/drivers/hwmon/via686a.c
index 164d4794839..eb84997627c 100644
--- a/drivers/hwmon/via686a.c
+++ b/drivers/hwmon/via686a.c
@@ -35,7 +35,9 @@
35#include <linux/pci.h> 35#include <linux/pci.h>
36#include <linux/jiffies.h> 36#include <linux/jiffies.h>
37#include <linux/i2c.h> 37#include <linux/i2c.h>
38#include <linux/i2c-sensor.h> 38#include <linux/i2c-isa.h>
39#include <linux/hwmon.h>
40#include <linux/err.h>
39#include <linux/init.h> 41#include <linux/init.h>
40#include <asm/io.h> 42#include <asm/io.h>
41 43
@@ -47,14 +49,10 @@ module_param(force_addr, ushort, 0);
47MODULE_PARM_DESC(force_addr, 49MODULE_PARM_DESC(force_addr,
48 "Initialize the base address of the sensors"); 50 "Initialize the base address of the sensors");
49 51
50/* Addresses to scan. 52/* Device address
51 Note that we can't determine the ISA address until we have initialized 53 Note that we can't determine the ISA address until we have initialized
52 our module */ 54 our module */
53static unsigned short normal_i2c[] = { I2C_CLIENT_END }; 55static unsigned short address;
54static unsigned int normal_isa[] = { 0x0000, I2C_CLIENT_ISA_END };
55
56/* Insmod parameters */
57SENSORS_INSMOD_1(via686a);
58 56
59/* 57/*
60 The Via 686a southbridge has a LM78-like chip integrated on the same IC. 58 The Via 686a southbridge has a LM78-like chip integrated on the same IC.
@@ -297,6 +295,7 @@ static inline long TEMP_FROM_REG10(u16 val)
297 via686a client is allocated. */ 295 via686a client is allocated. */
298struct via686a_data { 296struct via686a_data {
299 struct i2c_client client; 297 struct i2c_client client;
298 struct class_device *class_dev;
300 struct semaphore update_lock; 299 struct semaphore update_lock;
301 char valid; /* !=0 if following fields are valid */ 300 char valid; /* !=0 if following fields are valid */
302 unsigned long last_updated; /* In jiffies */ 301 unsigned long last_updated; /* In jiffies */
@@ -315,8 +314,7 @@ struct via686a_data {
315 314
316static struct pci_dev *s_bridge; /* pointer to the (only) via686a */ 315static struct pci_dev *s_bridge; /* pointer to the (only) via686a */
317 316
318static int via686a_attach_adapter(struct i2c_adapter *adapter); 317static int via686a_detect(struct i2c_adapter *adapter);
319static int via686a_detect(struct i2c_adapter *adapter, int address, int kind);
320static int via686a_detach_client(struct i2c_client *client); 318static int via686a_detach_client(struct i2c_client *client);
321 319
322static inline int via686a_read_value(struct i2c_client *client, u8 reg) 320static inline int via686a_read_value(struct i2c_client *client, u8 reg)
@@ -576,22 +574,13 @@ static DEVICE_ATTR(alarms, S_IRUGO, show_alarms, NULL);
576static struct i2c_driver via686a_driver = { 574static struct i2c_driver via686a_driver = {
577 .owner = THIS_MODULE, 575 .owner = THIS_MODULE,
578 .name = "via686a", 576 .name = "via686a",
579 .id = I2C_DRIVERID_VIA686A, 577 .attach_adapter = via686a_detect,
580 .flags = I2C_DF_NOTIFY,
581 .attach_adapter = via686a_attach_adapter,
582 .detach_client = via686a_detach_client, 578 .detach_client = via686a_detach_client,
583}; 579};
584 580
585 581
586/* This is called when the module is loaded */ 582/* This is called when the module is loaded */
587static int via686a_attach_adapter(struct i2c_adapter *adapter) 583static int via686a_detect(struct i2c_adapter *adapter)
588{
589 if (!(adapter->class & I2C_CLASS_HWMON))
590 return 0;
591 return i2c_detect(adapter, &addr_data, via686a_detect);
592}
593
594static int via686a_detect(struct i2c_adapter *adapter, int address, int kind)
595{ 584{
596 struct i2c_client *new_client; 585 struct i2c_client *new_client;
597 struct via686a_data *data; 586 struct via686a_data *data;
@@ -599,13 +588,6 @@ static int via686a_detect(struct i2c_adapter *adapter, int address, int kind)
599 const char client_name[] = "via686a"; 588 const char client_name[] = "via686a";
600 u16 val; 589 u16 val;
601 590
602 /* Make sure we are probing the ISA bus!! */
603 if (!i2c_is_isa_adapter(adapter)) {
604 dev_err(&adapter->dev,
605 "via686a_detect called for an I2C bus adapter?!?\n");
606 return 0;
607 }
608
609 /* 8231 requires multiple of 256, we enforce that on 686 as well */ 591 /* 8231 requires multiple of 256, we enforce that on 686 as well */
610 if (force_addr) 592 if (force_addr)
611 address = force_addr & 0xFF00; 593 address = force_addr & 0xFF00;
@@ -637,7 +619,7 @@ static int via686a_detect(struct i2c_adapter *adapter, int address, int kind)
637 619
638 if (!(data = kmalloc(sizeof(struct via686a_data), GFP_KERNEL))) { 620 if (!(data = kmalloc(sizeof(struct via686a_data), GFP_KERNEL))) {
639 err = -ENOMEM; 621 err = -ENOMEM;
640 goto ERROR0; 622 goto exit_release;
641 } 623 }
642 memset(data, 0, sizeof(struct via686a_data)); 624 memset(data, 0, sizeof(struct via686a_data));
643 625
@@ -655,12 +637,18 @@ static int via686a_detect(struct i2c_adapter *adapter, int address, int kind)
655 init_MUTEX(&data->update_lock); 637 init_MUTEX(&data->update_lock);
656 /* Tell the I2C layer a new client has arrived */ 638 /* Tell the I2C layer a new client has arrived */
657 if ((err = i2c_attach_client(new_client))) 639 if ((err = i2c_attach_client(new_client)))
658 goto ERROR3; 640 goto exit_free;
659 641
660 /* Initialize the VIA686A chip */ 642 /* Initialize the VIA686A chip */
661 via686a_init_client(new_client); 643 via686a_init_client(new_client);
662 644
663 /* Register sysfs hooks */ 645 /* Register sysfs hooks */
646 data->class_dev = hwmon_device_register(&new_client->dev);
647 if (IS_ERR(data->class_dev)) {
648 err = PTR_ERR(data->class_dev);
649 goto exit_detach;
650 }
651
664 device_create_file(&new_client->dev, &dev_attr_in0_input); 652 device_create_file(&new_client->dev, &dev_attr_in0_input);
665 device_create_file(&new_client->dev, &dev_attr_in1_input); 653 device_create_file(&new_client->dev, &dev_attr_in1_input);
666 device_create_file(&new_client->dev, &dev_attr_in2_input); 654 device_create_file(&new_client->dev, &dev_attr_in2_input);
@@ -695,25 +683,27 @@ static int via686a_detect(struct i2c_adapter *adapter, int address, int kind)
695 683
696 return 0; 684 return 0;
697 685
698ERROR3: 686exit_detach:
687 i2c_detach_client(new_client);
688exit_free:
699 kfree(data); 689 kfree(data);
700ERROR0: 690exit_release:
701 release_region(address, VIA686A_EXTENT); 691 release_region(address, VIA686A_EXTENT);
702 return err; 692 return err;
703} 693}
704 694
705static int via686a_detach_client(struct i2c_client *client) 695static int via686a_detach_client(struct i2c_client *client)
706{ 696{
697 struct via686a_data *data = i2c_get_clientdata(client);
707 int err; 698 int err;
708 699
709 if ((err = i2c_detach_client(client))) { 700 hwmon_device_unregister(data->class_dev);
710 dev_err(&client->dev, 701
711 "Client deregistration failed, client not detached.\n"); 702 if ((err = i2c_detach_client(client)))
712 return err; 703 return err;
713 }
714 704
715 release_region(client->addr, VIA686A_EXTENT); 705 release_region(client->addr, VIA686A_EXTENT);
716 kfree(i2c_get_clientdata(client)); 706 kfree(data);
717 707
718 return 0; 708 return 0;
719} 709}
@@ -810,29 +800,25 @@ static int __devinit via686a_pci_probe(struct pci_dev *dev,
810 const struct pci_device_id *id) 800 const struct pci_device_id *id)
811{ 801{
812 u16 val; 802 u16 val;
813 int addr = 0;
814 803
815 if (PCIBIOS_SUCCESSFUL != 804 if (PCIBIOS_SUCCESSFUL !=
816 pci_read_config_word(dev, VIA686A_BASE_REG, &val)) 805 pci_read_config_word(dev, VIA686A_BASE_REG, &val))
817 return -ENODEV; 806 return -ENODEV;
818 807
819 addr = val & ~(VIA686A_EXTENT - 1); 808 address = val & ~(VIA686A_EXTENT - 1);
820 if (addr == 0 && force_addr == 0) { 809 if (address == 0 && force_addr == 0) {
821 dev_err(&dev->dev, "base address not set - upgrade BIOS " 810 dev_err(&dev->dev, "base address not set - upgrade BIOS "
822 "or use force_addr=0xaddr\n"); 811 "or use force_addr=0xaddr\n");
823 return -ENODEV; 812 return -ENODEV;
824 } 813 }
825 if (force_addr)
826 addr = force_addr; /* so detect will get called */
827 814
828 if (!addr) { 815 if (!address) {
829 dev_err(&dev->dev, "No Via 686A sensors found.\n"); 816 dev_err(&dev->dev, "No Via 686A sensors found.\n");
830 return -ENODEV; 817 return -ENODEV;
831 } 818 }
832 normal_isa[0] = addr;
833 819
834 s_bridge = pci_dev_get(dev); 820 s_bridge = pci_dev_get(dev);
835 if (i2c_add_driver(&via686a_driver)) { 821 if (i2c_isa_add_driver(&via686a_driver)) {
836 pci_dev_put(s_bridge); 822 pci_dev_put(s_bridge);
837 s_bridge = NULL; 823 s_bridge = NULL;
838 } 824 }
@@ -859,7 +845,7 @@ static void __exit sm_via686a_exit(void)
859{ 845{
860 pci_unregister_driver(&via686a_pci_driver); 846 pci_unregister_driver(&via686a_pci_driver);
861 if (s_bridge != NULL) { 847 if (s_bridge != NULL) {
862 i2c_del_driver(&via686a_driver); 848 i2c_isa_del_driver(&via686a_driver);
863 pci_dev_put(s_bridge); 849 pci_dev_put(s_bridge);
864 s_bridge = NULL; 850 s_bridge = NULL;
865 } 851 }
diff --git a/drivers/hwmon/w83627ehf.c b/drivers/hwmon/w83627ehf.c
index 8a40b6976e1..b60efe8f8b2 100644
--- a/drivers/hwmon/w83627ehf.c
+++ b/drivers/hwmon/w83627ehf.c
@@ -9,6 +9,9 @@
9 Thanks to Leon Moonen, Steve Cliffe and Grant Coady for their help 9 Thanks to Leon Moonen, Steve Cliffe and Grant Coady for their help
10 in testing and debugging this driver. 10 in testing and debugging this driver.
11 11
12 This driver also supports the W83627EHG, which is the lead-free
13 version of the W83627EHF.
14
12 This program is free software; you can redistribute it and/or modify 15 This program is free software; you can redistribute it and/or modify
13 it under the terms of the GNU General Public License as published by 16 it under the terms of the GNU General Public License as published by
14 the Free Software Foundation; either version 2 of the License, or 17 the Free Software Foundation; either version 2 of the License, or
@@ -37,17 +40,14 @@
37#include <linux/init.h> 40#include <linux/init.h>
38#include <linux/slab.h> 41#include <linux/slab.h>
39#include <linux/i2c.h> 42#include <linux/i2c.h>
40#include <linux/i2c-sensor.h> 43#include <linux/i2c-isa.h>
44#include <linux/hwmon.h>
45#include <linux/err.h>
41#include <asm/io.h> 46#include <asm/io.h>
42#include "lm75.h" 47#include "lm75.h"
43 48
44/* Addresses to scan 49/* The actual ISA address is read from Super-I/O configuration space */
45 The actual ISA address is read from Super-I/O configuration space */ 50static unsigned short address;
46static unsigned short normal_i2c[] = { I2C_CLIENT_END };
47static unsigned int normal_isa[] = { 0, I2C_CLIENT_ISA_END };
48
49/* Insmod parameters */
50SENSORS_INSMOD_1(w83627ehf);
51 51
52/* 52/*
53 * Super-I/O constants and functions 53 * Super-I/O constants and functions
@@ -174,6 +174,7 @@ temp1_to_reg(int temp)
174 174
175struct w83627ehf_data { 175struct w83627ehf_data {
176 struct i2c_client client; 176 struct i2c_client client;
177 struct class_device *class_dev;
177 struct semaphore lock; 178 struct semaphore lock;
178 179
179 struct semaphore update_lock; 180 struct semaphore update_lock;
@@ -666,15 +667,12 @@ static void w83627ehf_init_client(struct i2c_client *client)
666 } 667 }
667} 668}
668 669
669static int w83627ehf_detect(struct i2c_adapter *adapter, int address, int kind) 670static int w83627ehf_detect(struct i2c_adapter *adapter)
670{ 671{
671 struct i2c_client *client; 672 struct i2c_client *client;
672 struct w83627ehf_data *data; 673 struct w83627ehf_data *data;
673 int i, err = 0; 674 int i, err = 0;
674 675
675 if (!i2c_is_isa_adapter(adapter))
676 return 0;
677
678 if (!request_region(address, REGION_LENGTH, w83627ehf_driver.name)) { 676 if (!request_region(address, REGION_LENGTH, w83627ehf_driver.name)) {
679 err = -EBUSY; 677 err = -EBUSY;
680 goto exit; 678 goto exit;
@@ -720,6 +718,12 @@ static int w83627ehf_detect(struct i2c_adapter *adapter, int address, int kind)
720 data->has_fan |= (1 << 4); 718 data->has_fan |= (1 << 4);
721 719
722 /* Register sysfs hooks */ 720 /* Register sysfs hooks */
721 data->class_dev = hwmon_device_register(&client->dev);
722 if (IS_ERR(data->class_dev)) {
723 err = PTR_ERR(data->class_dev);
724 goto exit_detach;
725 }
726
723 device_create_file(&client->dev, &dev_attr_fan1_input); 727 device_create_file(&client->dev, &dev_attr_fan1_input);
724 device_create_file(&client->dev, &dev_attr_fan1_min); 728 device_create_file(&client->dev, &dev_attr_fan1_min);
725 device_create_file(&client->dev, &dev_attr_fan1_div); 729 device_create_file(&client->dev, &dev_attr_fan1_div);
@@ -753,6 +757,8 @@ static int w83627ehf_detect(struct i2c_adapter *adapter, int address, int kind)
753 757
754 return 0; 758 return 0;
755 759
760exit_detach:
761 i2c_detach_client(client);
756exit_free: 762exit_free:
757 kfree(data); 763 kfree(data);
758exit_release: 764exit_release:
@@ -761,24 +767,17 @@ exit:
761 return err; 767 return err;
762} 768}
763 769
764static int w83627ehf_attach_adapter(struct i2c_adapter *adapter)
765{
766 if (!(adapter->class & I2C_CLASS_HWMON))
767 return 0;
768 return i2c_detect(adapter, &addr_data, w83627ehf_detect);
769}
770
771static int w83627ehf_detach_client(struct i2c_client *client) 770static int w83627ehf_detach_client(struct i2c_client *client)
772{ 771{
772 struct w83627ehf_data *data = i2c_get_clientdata(client);
773 int err; 773 int err;
774 774
775 if ((err = i2c_detach_client(client))) { 775 hwmon_device_unregister(data->class_dev);
776 dev_err(&client->dev, "Client deregistration failed, " 776
777 "client not detached.\n"); 777 if ((err = i2c_detach_client(client)))
778 return err; 778 return err;
779 }
780 release_region(client->addr, REGION_LENGTH); 779 release_region(client->addr, REGION_LENGTH);
781 kfree(i2c_get_clientdata(client)); 780 kfree(data);
782 781
783 return 0; 782 return 0;
784} 783}
@@ -786,12 +785,11 @@ static int w83627ehf_detach_client(struct i2c_client *client)
786static struct i2c_driver w83627ehf_driver = { 785static struct i2c_driver w83627ehf_driver = {
787 .owner = THIS_MODULE, 786 .owner = THIS_MODULE,
788 .name = "w83627ehf", 787 .name = "w83627ehf",
789 .flags = I2C_DF_NOTIFY, 788 .attach_adapter = w83627ehf_detect,
790 .attach_adapter = w83627ehf_attach_adapter,
791 .detach_client = w83627ehf_detach_client, 789 .detach_client = w83627ehf_detach_client,
792}; 790};
793 791
794static int __init w83627ehf_find(int sioaddr, int *address) 792static int __init w83627ehf_find(int sioaddr, unsigned short *addr)
795{ 793{
796 u16 val; 794 u16 val;
797 795
@@ -809,8 +807,8 @@ static int __init w83627ehf_find(int sioaddr, int *address)
809 superio_select(W83627EHF_LD_HWM); 807 superio_select(W83627EHF_LD_HWM);
810 val = (superio_inb(SIO_REG_ADDR) << 8) 808 val = (superio_inb(SIO_REG_ADDR) << 8)
811 | superio_inb(SIO_REG_ADDR + 1); 809 | superio_inb(SIO_REG_ADDR + 1);
812 *address = val & ~(REGION_LENGTH - 1); 810 *addr = val & ~(REGION_LENGTH - 1);
813 if (*address == 0) { 811 if (*addr == 0) {
814 superio_exit(); 812 superio_exit();
815 return -ENODEV; 813 return -ENODEV;
816 } 814 }
@@ -826,16 +824,16 @@ static int __init w83627ehf_find(int sioaddr, int *address)
826 824
827static int __init sensors_w83627ehf_init(void) 825static int __init sensors_w83627ehf_init(void)
828{ 826{
829 if (w83627ehf_find(0x2e, &normal_isa[0]) 827 if (w83627ehf_find(0x2e, &address)
830 && w83627ehf_find(0x4e, &normal_isa[0])) 828 && w83627ehf_find(0x4e, &address))
831 return -ENODEV; 829 return -ENODEV;
832 830
833 return i2c_add_driver(&w83627ehf_driver); 831 return i2c_isa_add_driver(&w83627ehf_driver);
834} 832}
835 833
836static void __exit sensors_w83627ehf_exit(void) 834static void __exit sensors_w83627ehf_exit(void)
837{ 835{
838 i2c_del_driver(&w83627ehf_driver); 836 i2c_isa_del_driver(&w83627ehf_driver);
839} 837}
840 838
841MODULE_AUTHOR("Jean Delvare <khali@linux-fr.org>"); 839MODULE_AUTHOR("Jean Delvare <khali@linux-fr.org>");
diff --git a/drivers/hwmon/w83627hf.c b/drivers/hwmon/w83627hf.c
index bd87a42e068..02bd5c0239a 100644
--- a/drivers/hwmon/w83627hf.c
+++ b/drivers/hwmon/w83627hf.c
@@ -42,8 +42,10 @@
42#include <linux/slab.h> 42#include <linux/slab.h>
43#include <linux/jiffies.h> 43#include <linux/jiffies.h>
44#include <linux/i2c.h> 44#include <linux/i2c.h>
45#include <linux/i2c-sensor.h> 45#include <linux/i2c-isa.h>
46#include <linux/i2c-vid.h> 46#include <linux/hwmon.h>
47#include <linux/hwmon-vid.h>
48#include <linux/err.h>
47#include <asm/io.h> 49#include <asm/io.h>
48#include "lm75.h" 50#include "lm75.h"
49 51
@@ -56,12 +58,11 @@ module_param(force_i2c, byte, 0);
56MODULE_PARM_DESC(force_i2c, 58MODULE_PARM_DESC(force_i2c,
57 "Initialize the i2c address of the sensors"); 59 "Initialize the i2c address of the sensors");
58 60
59/* Addresses to scan */ 61/* The actual ISA address is read from Super-I/O configuration space */
60static unsigned short normal_i2c[] = { I2C_CLIENT_END }; 62static unsigned short address;
61static unsigned int normal_isa[] = { 0, I2C_CLIENT_ISA_END };
62 63
63/* Insmod parameters */ 64/* Insmod parameters */
64SENSORS_INSMOD_4(w83627hf, w83627thf, w83697hf, w83637hf); 65enum chips { any_chip, w83627hf, w83627thf, w83697hf, w83637hf };
65 66
66static int init = 1; 67static int init = 1;
67module_param(init, bool, 0); 68module_param(init, bool, 0);
@@ -277,6 +278,7 @@ static inline u8 DIV_TO_REG(long val)
277 dynamically allocated, at the same time when a new client is allocated. */ 278 dynamically allocated, at the same time when a new client is allocated. */
278struct w83627hf_data { 279struct w83627hf_data {
279 struct i2c_client client; 280 struct i2c_client client;
281 struct class_device *class_dev;
280 struct semaphore lock; 282 struct semaphore lock;
281 enum chips type; 283 enum chips type;
282 284
@@ -314,9 +316,7 @@ struct w83627hf_data {
314}; 316};
315 317
316 318
317static int w83627hf_attach_adapter(struct i2c_adapter *adapter); 319static int w83627hf_detect(struct i2c_adapter *adapter);
318static int w83627hf_detect(struct i2c_adapter *adapter, int address,
319 int kind);
320static int w83627hf_detach_client(struct i2c_client *client); 320static int w83627hf_detach_client(struct i2c_client *client);
321 321
322static int w83627hf_read_value(struct i2c_client *client, u16 register); 322static int w83627hf_read_value(struct i2c_client *client, u16 register);
@@ -328,9 +328,7 @@ static void w83627hf_init_client(struct i2c_client *client);
328static struct i2c_driver w83627hf_driver = { 328static struct i2c_driver w83627hf_driver = {
329 .owner = THIS_MODULE, 329 .owner = THIS_MODULE,
330 .name = "w83627hf", 330 .name = "w83627hf",
331 .id = I2C_DRIVERID_W83627HF, 331 .attach_adapter = w83627hf_detect,
332 .flags = I2C_DF_NOTIFY,
333 .attach_adapter = w83627hf_attach_adapter,
334 .detach_client = w83627hf_detach_client, 332 .detach_client = w83627hf_detach_client,
335}; 333};
336 334
@@ -959,16 +957,7 @@ device_create_file(&client->dev, &dev_attr_temp##offset##_type); \
959} while (0) 957} while (0)
960 958
961 959
962/* This function is called when: 960static int __init w83627hf_find(int sioaddr, unsigned short *addr)
963 * w83627hf_driver is inserted (when this module is loaded), for each
964 available adapter
965 * when a new adapter is inserted (and w83627hf_driver is still present) */
966static int w83627hf_attach_adapter(struct i2c_adapter *adapter)
967{
968 return i2c_detect(adapter, &addr_data, w83627hf_detect);
969}
970
971static int w83627hf_find(int sioaddr, int *address)
972{ 961{
973 u16 val; 962 u16 val;
974 963
@@ -988,32 +977,24 @@ static int w83627hf_find(int sioaddr, int *address)
988 superio_select(W83627HF_LD_HWM); 977 superio_select(W83627HF_LD_HWM);
989 val = (superio_inb(WINB_BASE_REG) << 8) | 978 val = (superio_inb(WINB_BASE_REG) << 8) |
990 superio_inb(WINB_BASE_REG + 1); 979 superio_inb(WINB_BASE_REG + 1);
991 *address = val & ~(WINB_EXTENT - 1); 980 *addr = val & ~(WINB_EXTENT - 1);
992 if (*address == 0 && force_addr == 0) { 981 if (*addr == 0 && force_addr == 0) {
993 superio_exit(); 982 superio_exit();
994 return -ENODEV; 983 return -ENODEV;
995 } 984 }
996 if (force_addr)
997 *address = force_addr; /* so detect will get called */
998 985
999 superio_exit(); 986 superio_exit();
1000 return 0; 987 return 0;
1001} 988}
1002 989
1003int w83627hf_detect(struct i2c_adapter *adapter, int address, 990static int w83627hf_detect(struct i2c_adapter *adapter)
1004 int kind)
1005{ 991{
1006 int val; 992 int val, kind;
1007 struct i2c_client *new_client; 993 struct i2c_client *new_client;
1008 struct w83627hf_data *data; 994 struct w83627hf_data *data;
1009 int err = 0; 995 int err = 0;
1010 const char *client_name = ""; 996 const char *client_name = "";
1011 997
1012 if (!i2c_is_isa_adapter(adapter)) {
1013 err = -ENODEV;
1014 goto ERROR0;
1015 }
1016
1017 if(force_addr) 998 if(force_addr)
1018 address = force_addr & ~(WINB_EXTENT - 1); 999 address = force_addr & ~(WINB_EXTENT - 1);
1019 1000
@@ -1102,6 +1083,12 @@ int w83627hf_detect(struct i2c_adapter *adapter, int address,
1102 data->fan_min[2] = w83627hf_read_value(new_client, W83781D_REG_FAN_MIN(3)); 1083 data->fan_min[2] = w83627hf_read_value(new_client, W83781D_REG_FAN_MIN(3));
1103 1084
1104 /* Register sysfs hooks */ 1085 /* Register sysfs hooks */
1086 data->class_dev = hwmon_device_register(&new_client->dev);
1087 if (IS_ERR(data->class_dev)) {
1088 err = PTR_ERR(data->class_dev);
1089 goto ERROR3;
1090 }
1091
1105 device_create_file_in(new_client, 0); 1092 device_create_file_in(new_client, 0);
1106 if (kind != w83697hf) 1093 if (kind != w83697hf)
1107 device_create_file_in(new_client, 1); 1094 device_create_file_in(new_client, 1);
@@ -1152,6 +1139,8 @@ int w83627hf_detect(struct i2c_adapter *adapter, int address,
1152 1139
1153 return 0; 1140 return 0;
1154 1141
1142 ERROR3:
1143 i2c_detach_client(new_client);
1155 ERROR2: 1144 ERROR2:
1156 kfree(data); 1145 kfree(data);
1157 ERROR1: 1146 ERROR1:
@@ -1162,16 +1151,16 @@ int w83627hf_detect(struct i2c_adapter *adapter, int address,
1162 1151
1163static int w83627hf_detach_client(struct i2c_client *client) 1152static int w83627hf_detach_client(struct i2c_client *client)
1164{ 1153{
1154 struct w83627hf_data *data = i2c_get_clientdata(client);
1165 int err; 1155 int err;
1166 1156
1167 if ((err = i2c_detach_client(client))) { 1157 hwmon_device_unregister(data->class_dev);
1168 dev_err(&client->dev, 1158
1169 "Client deregistration failed, client not detached.\n"); 1159 if ((err = i2c_detach_client(client)))
1170 return err; 1160 return err;
1171 }
1172 1161
1173 release_region(client->addr, WINB_EXTENT); 1162 release_region(client->addr, WINB_EXTENT);
1174 kfree(i2c_get_clientdata(client)); 1163 kfree(data);
1175 1164
1176 return 0; 1165 return 0;
1177} 1166}
@@ -1327,7 +1316,7 @@ static void w83627hf_init_client(struct i2c_client *client)
1327 data->vrm = (data->vrm_ovt & 0x01) ? 90 : 82; 1316 data->vrm = (data->vrm_ovt & 0x01) ? 90 : 82;
1328 } else { 1317 } else {
1329 /* Convert VID to voltage based on default VRM */ 1318 /* Convert VID to voltage based on default VRM */
1330 data->vrm = i2c_which_vrm(); 1319 data->vrm = vid_which_vrm();
1331 } 1320 }
1332 1321
1333 tmp = w83627hf_read_value(client, W83781D_REG_SCFG1); 1322 tmp = w83627hf_read_value(client, W83781D_REG_SCFG1);
@@ -1485,20 +1474,17 @@ static struct w83627hf_data *w83627hf_update_device(struct device *dev)
1485 1474
1486static int __init sensors_w83627hf_init(void) 1475static int __init sensors_w83627hf_init(void)
1487{ 1476{
1488 int addr; 1477 if (w83627hf_find(0x2e, &address)
1489 1478 && w83627hf_find(0x4e, &address)) {
1490 if (w83627hf_find(0x2e, &addr)
1491 && w83627hf_find(0x4e, &addr)) {
1492 return -ENODEV; 1479 return -ENODEV;
1493 } 1480 }
1494 normal_isa[0] = addr;
1495 1481
1496 return i2c_add_driver(&w83627hf_driver); 1482 return i2c_isa_add_driver(&w83627hf_driver);
1497} 1483}
1498 1484
1499static void __exit sensors_w83627hf_exit(void) 1485static void __exit sensors_w83627hf_exit(void)
1500{ 1486{
1501 i2c_del_driver(&w83627hf_driver); 1487 i2c_isa_del_driver(&w83627hf_driver);
1502} 1488}
1503 1489
1504MODULE_AUTHOR("Frodo Looijaard <frodol@dds.nl>, " 1490MODULE_AUTHOR("Frodo Looijaard <frodol@dds.nl>, "
diff --git a/drivers/hwmon/w83781d.c b/drivers/hwmon/w83781d.c
index 0bb131ce09e..4c43337ca78 100644
--- a/drivers/hwmon/w83781d.c
+++ b/drivers/hwmon/w83781d.c
@@ -38,8 +38,10 @@
38#include <linux/slab.h> 38#include <linux/slab.h>
39#include <linux/jiffies.h> 39#include <linux/jiffies.h>
40#include <linux/i2c.h> 40#include <linux/i2c.h>
41#include <linux/i2c-sensor.h> 41#include <linux/i2c-isa.h>
42#include <linux/i2c-vid.h> 42#include <linux/hwmon.h>
43#include <linux/hwmon-vid.h>
44#include <linux/err.h>
43#include <asm/io.h> 45#include <asm/io.h>
44#include "lm75.h" 46#include "lm75.h"
45 47
@@ -47,10 +49,10 @@
47static unsigned short normal_i2c[] = { 0x20, 0x21, 0x22, 0x23, 0x24, 0x25, 49static unsigned short normal_i2c[] = { 0x20, 0x21, 0x22, 0x23, 0x24, 0x25,
48 0x26, 0x27, 0x28, 0x29, 0x2a, 0x2b, 50 0x26, 0x27, 0x28, 0x29, 0x2a, 0x2b,
49 0x2c, 0x2d, 0x2e, 0x2f, I2C_CLIENT_END }; 51 0x2c, 0x2d, 0x2e, 0x2f, I2C_CLIENT_END };
50static unsigned int normal_isa[] = { 0x0290, I2C_CLIENT_ISA_END }; 52static unsigned short isa_address = 0x290;
51 53
52/* Insmod parameters */ 54/* Insmod parameters */
53SENSORS_INSMOD_5(w83781d, w83782d, w83783s, w83627hf, as99127f); 55I2C_CLIENT_INSMOD_5(w83781d, w83782d, w83783s, w83627hf, as99127f);
54I2C_CLIENT_MODULE_PARM(force_subclients, "List of subclient addresses: " 56I2C_CLIENT_MODULE_PARM(force_subclients, "List of subclient addresses: "
55 "{bus, clientaddr, subclientaddr1, subclientaddr2}"); 57 "{bus, clientaddr, subclientaddr1, subclientaddr2}");
56 58
@@ -218,6 +220,7 @@ DIV_TO_REG(long val, enum chips type)
218 allocated. */ 220 allocated. */
219struct w83781d_data { 221struct w83781d_data {
220 struct i2c_client client; 222 struct i2c_client client;
223 struct class_device *class_dev;
221 struct semaphore lock; 224 struct semaphore lock;
222 enum chips type; 225 enum chips type;
223 226
@@ -255,6 +258,7 @@ struct w83781d_data {
255}; 258};
256 259
257static int w83781d_attach_adapter(struct i2c_adapter *adapter); 260static int w83781d_attach_adapter(struct i2c_adapter *adapter);
261static int w83781d_isa_attach_adapter(struct i2c_adapter *adapter);
258static int w83781d_detect(struct i2c_adapter *adapter, int address, int kind); 262static int w83781d_detect(struct i2c_adapter *adapter, int address, int kind);
259static int w83781d_detach_client(struct i2c_client *client); 263static int w83781d_detach_client(struct i2c_client *client);
260 264
@@ -273,6 +277,14 @@ static struct i2c_driver w83781d_driver = {
273 .detach_client = w83781d_detach_client, 277 .detach_client = w83781d_detach_client,
274}; 278};
275 279
280static struct i2c_driver w83781d_isa_driver = {
281 .owner = THIS_MODULE,
282 .name = "w83781d-isa",
283 .attach_adapter = w83781d_isa_attach_adapter,
284 .detach_client = w83781d_detach_client,
285};
286
287
276/* following are the sysfs callback functions */ 288/* following are the sysfs callback functions */
277#define show_in_reg(reg) \ 289#define show_in_reg(reg) \
278static ssize_t show_##reg (struct device *dev, char *buf, int nr) \ 290static ssize_t show_##reg (struct device *dev, char *buf, int nr) \
@@ -856,7 +868,13 @@ w83781d_attach_adapter(struct i2c_adapter *adapter)
856{ 868{
857 if (!(adapter->class & I2C_CLASS_HWMON)) 869 if (!(adapter->class & I2C_CLASS_HWMON))
858 return 0; 870 return 0;
859 return i2c_detect(adapter, &addr_data, w83781d_detect); 871 return i2c_probe(adapter, &addr_data, w83781d_detect);
872}
873
874static int
875w83781d_isa_attach_adapter(struct i2c_adapter *adapter)
876{
877 return w83781d_detect(adapter, isa_address, -1);
860} 878}
861 879
862/* Assumes that adapter is of I2C, not ISA variety. 880/* Assumes that adapter is of I2C, not ISA variety.
@@ -961,10 +979,10 @@ w83781d_detect_subclients(struct i2c_adapter *adapter, int address, int kind,
961ERROR_SC_3: 979ERROR_SC_3:
962 i2c_detach_client(data->lm75[0]); 980 i2c_detach_client(data->lm75[0]);
963ERROR_SC_2: 981ERROR_SC_2:
964 if (NULL != data->lm75[1]) 982 if (data->lm75[1])
965 kfree(data->lm75[1]); 983 kfree(data->lm75[1]);
966ERROR_SC_1: 984ERROR_SC_1:
967 if (NULL != data->lm75[0]) 985 if (data->lm75[0])
968 kfree(data->lm75[0]); 986 kfree(data->lm75[0]);
969ERROR_SC_0: 987ERROR_SC_0:
970 return err; 988 return err;
@@ -999,7 +1017,7 @@ w83781d_detect(struct i2c_adapter *adapter, int address, int kind)
999 1017
1000 if (is_isa) 1018 if (is_isa)
1001 if (!request_region(address, W83781D_EXTENT, 1019 if (!request_region(address, W83781D_EXTENT,
1002 w83781d_driver.name)) { 1020 w83781d_isa_driver.name)) {
1003 dev_dbg(&adapter->dev, "Request of region " 1021 dev_dbg(&adapter->dev, "Request of region "
1004 "0x%x-0x%x for w83781d failed\n", address, 1022 "0x%x-0x%x for w83781d failed\n", address,
1005 address + W83781D_EXTENT - 1); 1023 address + W83781D_EXTENT - 1);
@@ -1057,7 +1075,7 @@ w83781d_detect(struct i2c_adapter *adapter, int address, int kind)
1057 new_client->addr = address; 1075 new_client->addr = address;
1058 init_MUTEX(&data->lock); 1076 init_MUTEX(&data->lock);
1059 new_client->adapter = adapter; 1077 new_client->adapter = adapter;
1060 new_client->driver = &w83781d_driver; 1078 new_client->driver = is_isa ? &w83781d_isa_driver : &w83781d_driver;
1061 new_client->flags = 0; 1079 new_client->flags = 0;
1062 1080
1063 /* Now, we do the remaining detection. */ 1081 /* Now, we do the remaining detection. */
@@ -1189,6 +1207,12 @@ w83781d_detect(struct i2c_adapter *adapter, int address, int kind)
1189 data->pwmenable[i] = 1; 1207 data->pwmenable[i] = 1;
1190 1208
1191 /* Register sysfs hooks */ 1209 /* Register sysfs hooks */
1210 data->class_dev = hwmon_device_register(&new_client->dev);
1211 if (IS_ERR(data->class_dev)) {
1212 err = PTR_ERR(data->class_dev);
1213 goto ERROR4;
1214 }
1215
1192 device_create_file_in(new_client, 0); 1216 device_create_file_in(new_client, 0);
1193 if (kind != w83783s) 1217 if (kind != w83783s)
1194 device_create_file_in(new_client, 1); 1218 device_create_file_in(new_client, 1);
@@ -1241,6 +1265,15 @@ w83781d_detect(struct i2c_adapter *adapter, int address, int kind)
1241 1265
1242 return 0; 1266 return 0;
1243 1267
1268ERROR4:
1269 if (data->lm75[1]) {
1270 i2c_detach_client(data->lm75[1]);
1271 kfree(data->lm75[1]);
1272 }
1273 if (data->lm75[0]) {
1274 i2c_detach_client(data->lm75[0]);
1275 kfree(data->lm75[0]);
1276 }
1244ERROR3: 1277ERROR3:
1245 i2c_detach_client(new_client); 1278 i2c_detach_client(new_client);
1246ERROR2: 1279ERROR2:
@@ -1255,24 +1288,26 @@ ERROR0:
1255static int 1288static int
1256w83781d_detach_client(struct i2c_client *client) 1289w83781d_detach_client(struct i2c_client *client)
1257{ 1290{
1291 struct w83781d_data *data = i2c_get_clientdata(client);
1258 int err; 1292 int err;
1259 1293
1294 /* main client */
1295 if (data)
1296 hwmon_device_unregister(data->class_dev);
1297
1260 if (i2c_is_isa_client(client)) 1298 if (i2c_is_isa_client(client))
1261 release_region(client->addr, W83781D_EXTENT); 1299 release_region(client->addr, W83781D_EXTENT);
1262 1300
1263 if ((err = i2c_detach_client(client))) { 1301 if ((err = i2c_detach_client(client)))
1264 dev_err(&client->dev,
1265 "Client deregistration failed, client not detached.\n");
1266 return err; 1302 return err;
1267 }
1268 1303
1269 if (i2c_get_clientdata(client)==NULL) { 1304 /* main client */
1270 /* subclients */ 1305 if (data)
1306 kfree(data);
1307
1308 /* subclient */
1309 else
1271 kfree(client); 1310 kfree(client);
1272 } else {
1273 /* main client */
1274 kfree(i2c_get_clientdata(client));
1275 }
1276 1311
1277 return 0; 1312 return 0;
1278} 1313}
@@ -1443,7 +1478,7 @@ w83781d_init_client(struct i2c_client *client)
1443 w83781d_write_value(client, W83781D_REG_BEEP_INTS2, 0); 1478 w83781d_write_value(client, W83781D_REG_BEEP_INTS2, 0);
1444 } 1479 }
1445 1480
1446 data->vrm = i2c_which_vrm(); 1481 data->vrm = vid_which_vrm();
1447 1482
1448 if ((type != w83781d) && (type != as99127f)) { 1483 if ((type != w83781d) && (type != as99127f)) {
1449 tmp = w83781d_read_value(client, W83781D_REG_SCFG1); 1484 tmp = w83781d_read_value(client, W83781D_REG_SCFG1);
@@ -1613,12 +1648,25 @@ static struct w83781d_data *w83781d_update_device(struct device *dev)
1613static int __init 1648static int __init
1614sensors_w83781d_init(void) 1649sensors_w83781d_init(void)
1615{ 1650{
1616 return i2c_add_driver(&w83781d_driver); 1651 int res;
1652
1653 res = i2c_add_driver(&w83781d_driver);
1654 if (res)
1655 return res;
1656
1657 res = i2c_isa_add_driver(&w83781d_isa_driver);
1658 if (res) {
1659 i2c_del_driver(&w83781d_driver);
1660 return res;
1661 }
1662
1663 return 0;
1617} 1664}
1618 1665
1619static void __exit 1666static void __exit
1620sensors_w83781d_exit(void) 1667sensors_w83781d_exit(void)
1621{ 1668{
1669 i2c_isa_del_driver(&w83781d_isa_driver);
1622 i2c_del_driver(&w83781d_driver); 1670 i2c_del_driver(&w83781d_driver);
1623} 1671}
1624 1672
diff --git a/drivers/hwmon/w83792d.c b/drivers/hwmon/w83792d.c
new file mode 100644
index 00000000000..ba0c28015f6
--- /dev/null
+++ b/drivers/hwmon/w83792d.c
@@ -0,0 +1,1649 @@
1/*
2 w83792d.c - Part of lm_sensors, Linux kernel modules for hardware
3 monitoring
4 Copyright (C) 2004, 2005 Winbond Electronics Corp.
5 Chunhao Huang <DZShen@Winbond.com.tw>,
6 Rudolf Marek <r.marek@sh.cvut.cz>
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 Note:
23 1. This driver is only for 2.6 kernel, 2.4 kernel need a different driver.
24 2. This driver is only for Winbond W83792D C version device, there
25 are also some motherboards with B version W83792D device. The
26 calculation method to in6-in7(measured value, limits) is a little
27 different between C and B version. C or B version can be identified
28 by CR[0x49h].
29*/
30
31/*
32 Supports following chips:
33
34 Chip #vin #fanin #pwm #temp wchipid vendid i2c ISA
35 w83792d 9 7 7 3 0x7a 0x5ca3 yes no
36*/
37
38#include <linux/config.h>
39#include <linux/module.h>
40#include <linux/init.h>
41#include <linux/slab.h>
42#include <linux/i2c.h>
43#include <linux/hwmon.h>
44#include <linux/hwmon-sysfs.h>
45#include <linux/err.h>
46
47/* Addresses to scan */
48static unsigned short normal_i2c[] = { 0x2c, 0x2d, 0x2e, 0x2f, I2C_CLIENT_END };
49
50/* Insmod parameters */
51I2C_CLIENT_INSMOD_1(w83792d);
52I2C_CLIENT_MODULE_PARM(force_subclients, "List of subclient addresses: "
53 "{bus, clientaddr, subclientaddr1, subclientaddr2}");
54
55static int init;
56module_param(init, bool, 0);
57MODULE_PARM_DESC(init, "Set to one to force chip initialization");
58
59/* The W83792D registers */
60static const u8 W83792D_REG_IN[9] = {
61 0x20, /* Vcore A in DataSheet */
62 0x21, /* Vcore B in DataSheet */
63 0x22, /* VIN0 in DataSheet */
64 0x23, /* VIN1 in DataSheet */
65 0x24, /* VIN2 in DataSheet */
66 0x25, /* VIN3 in DataSheet */
67 0x26, /* 5VCC in DataSheet */
68 0xB0, /* 5VSB in DataSheet */
69 0xB1 /* VBAT in DataSheet */
70};
71#define W83792D_REG_LOW_BITS1 0x3E /* Low Bits I in DataSheet */
72#define W83792D_REG_LOW_BITS2 0x3F /* Low Bits II in DataSheet */
73static const u8 W83792D_REG_IN_MAX[9] = {
74 0x2B, /* Vcore A High Limit in DataSheet */
75 0x2D, /* Vcore B High Limit in DataSheet */
76 0x2F, /* VIN0 High Limit in DataSheet */
77 0x31, /* VIN1 High Limit in DataSheet */
78 0x33, /* VIN2 High Limit in DataSheet */
79 0x35, /* VIN3 High Limit in DataSheet */
80 0x37, /* 5VCC High Limit in DataSheet */
81 0xB4, /* 5VSB High Limit in DataSheet */
82 0xB6 /* VBAT High Limit in DataSheet */
83};
84static const u8 W83792D_REG_IN_MIN[9] = {
85 0x2C, /* Vcore A Low Limit in DataSheet */
86 0x2E, /* Vcore B Low Limit in DataSheet */
87 0x30, /* VIN0 Low Limit in DataSheet */
88 0x32, /* VIN1 Low Limit in DataSheet */
89 0x34, /* VIN2 Low Limit in DataSheet */
90 0x36, /* VIN3 Low Limit in DataSheet */
91 0x38, /* 5VCC Low Limit in DataSheet */
92 0xB5, /* 5VSB Low Limit in DataSheet */
93 0xB7 /* VBAT Low Limit in DataSheet */
94};
95static const u8 W83792D_REG_FAN[7] = {
96 0x28, /* FAN 1 Count in DataSheet */
97 0x29, /* FAN 2 Count in DataSheet */
98 0x2A, /* FAN 3 Count in DataSheet */
99 0xB8, /* FAN 4 Count in DataSheet */
100 0xB9, /* FAN 5 Count in DataSheet */
101 0xBA, /* FAN 6 Count in DataSheet */
102 0xBE /* FAN 7 Count in DataSheet */
103};
104static const u8 W83792D_REG_FAN_MIN[7] = {
105 0x3B, /* FAN 1 Count Low Limit in DataSheet */
106 0x3C, /* FAN 2 Count Low Limit in DataSheet */
107 0x3D, /* FAN 3 Count Low Limit in DataSheet */
108 0xBB, /* FAN 4 Count Low Limit in DataSheet */
109 0xBC, /* FAN 5 Count Low Limit in DataSheet */
110 0xBD, /* FAN 6 Count Low Limit in DataSheet */
111 0xBF /* FAN 7 Count Low Limit in DataSheet */
112};
113#define W83792D_REG_FAN_CFG 0x84 /* FAN Configuration in DataSheet */
114static const u8 W83792D_REG_FAN_DIV[4] = {
115 0x47, /* contains FAN2 and FAN1 Divisor */
116 0x5B, /* contains FAN4 and FAN3 Divisor */
117 0x5C, /* contains FAN6 and FAN5 Divisor */
118 0x9E /* contains FAN7 Divisor. */
119};
120static const u8 W83792D_REG_PWM[7] = {
121 0x81, /* FAN 1 Duty Cycle, be used to control */
122 0x83, /* FAN 2 Duty Cycle, be used to control */
123 0x94, /* FAN 3 Duty Cycle, be used to control */
124 0xA3, /* FAN 4 Duty Cycle, be used to control */
125 0xA4, /* FAN 5 Duty Cycle, be used to control */
126 0xA5, /* FAN 6 Duty Cycle, be used to control */
127 0xA6 /* FAN 7 Duty Cycle, be used to control */
128};
129#define W83792D_REG_BANK 0x4E
130#define W83792D_REG_TEMP2_CONFIG 0xC2
131#define W83792D_REG_TEMP3_CONFIG 0xCA
132
133static const u8 W83792D_REG_TEMP1[3] = {
134 0x27, /* TEMP 1 in DataSheet */
135 0x39, /* TEMP 1 Over in DataSheet */
136 0x3A, /* TEMP 1 Hyst in DataSheet */
137};
138
139static const u8 W83792D_REG_TEMP_ADD[2][6] = {
140 { 0xC0, /* TEMP 2 in DataSheet */
141 0xC1, /* TEMP 2(0.5 deg) in DataSheet */
142 0xC5, /* TEMP 2 Over High part in DataSheet */
143 0xC6, /* TEMP 2 Over Low part in DataSheet */
144 0xC3, /* TEMP 2 Thyst High part in DataSheet */
145 0xC4 }, /* TEMP 2 Thyst Low part in DataSheet */
146 { 0xC8, /* TEMP 3 in DataSheet */
147 0xC9, /* TEMP 3(0.5 deg) in DataSheet */
148 0xCD, /* TEMP 3 Over High part in DataSheet */
149 0xCE, /* TEMP 3 Over Low part in DataSheet */
150 0xCB, /* TEMP 3 Thyst High part in DataSheet */
151 0xCC } /* TEMP 3 Thyst Low part in DataSheet */
152};
153
154static const u8 W83792D_REG_THERMAL[3] = {
155 0x85, /* SmartFanI: Fan1 target value */
156 0x86, /* SmartFanI: Fan2 target value */
157 0x96 /* SmartFanI: Fan3 target value */
158};
159
160static const u8 W83792D_REG_TOLERANCE[3] = {
161 0x87, /* (bit3-0)SmartFan Fan1 tolerance */
162 0x87, /* (bit7-4)SmartFan Fan2 tolerance */
163 0x97 /* (bit3-0)SmartFan Fan3 tolerance */
164};
165
166static const u8 W83792D_REG_POINTS[3][4] = {
167 { 0x85, /* SmartFanII: Fan1 temp point 1 */
168 0xE3, /* SmartFanII: Fan1 temp point 2 */
169 0xE4, /* SmartFanII: Fan1 temp point 3 */
170 0xE5 }, /* SmartFanII: Fan1 temp point 4 */
171 { 0x86, /* SmartFanII: Fan2 temp point 1 */
172 0xE6, /* SmartFanII: Fan2 temp point 2 */
173 0xE7, /* SmartFanII: Fan2 temp point 3 */
174 0xE8 }, /* SmartFanII: Fan2 temp point 4 */
175 { 0x96, /* SmartFanII: Fan3 temp point 1 */
176 0xE9, /* SmartFanII: Fan3 temp point 2 */
177 0xEA, /* SmartFanII: Fan3 temp point 3 */
178 0xEB } /* SmartFanII: Fan3 temp point 4 */
179};
180
181static const u8 W83792D_REG_LEVELS[3][4] = {
182 { 0x88, /* (bit3-0) SmartFanII: Fan1 Non-Stop */
183 0x88, /* (bit7-4) SmartFanII: Fan1 Level 1 */
184 0xE0, /* (bit7-4) SmartFanII: Fan1 Level 2 */
185 0xE0 }, /* (bit3-0) SmartFanII: Fan1 Level 3 */
186 { 0x89, /* (bit3-0) SmartFanII: Fan2 Non-Stop */
187 0x89, /* (bit7-4) SmartFanII: Fan2 Level 1 */
188 0xE1, /* (bit7-4) SmartFanII: Fan2 Level 2 */
189 0xE1 }, /* (bit3-0) SmartFanII: Fan2 Level 3 */
190 { 0x98, /* (bit3-0) SmartFanII: Fan3 Non-Stop */
191 0x98, /* (bit7-4) SmartFanII: Fan3 Level 1 */
192 0xE2, /* (bit7-4) SmartFanII: Fan3 Level 2 */
193 0xE2 } /* (bit3-0) SmartFanII: Fan3 Level 3 */
194};
195
196#define W83792D_REG_CONFIG 0x40
197#define W83792D_REG_VID_FANDIV 0x47
198#define W83792D_REG_CHIPID 0x49
199#define W83792D_REG_WCHIPID 0x58
200#define W83792D_REG_CHIPMAN 0x4F
201#define W83792D_REG_PIN 0x4B
202#define W83792D_REG_I2C_SUBADDR 0x4A
203
204#define W83792D_REG_ALARM1 0xA9 /* realtime status register1 */
205#define W83792D_REG_ALARM2 0xAA /* realtime status register2 */
206#define W83792D_REG_ALARM3 0xAB /* realtime status register3 */
207#define W83792D_REG_CHASSIS 0x42 /* Bit 5: Case Open status bit */
208#define W83792D_REG_CHASSIS_CLR 0x44 /* Bit 7: Case Open CLR_CHS/Reset bit */
209
210/* control in0/in1 's limit modifiability */
211#define W83792D_REG_VID_IN_B 0x17
212
213#define W83792D_REG_VBAT 0x5D
214#define W83792D_REG_I2C_ADDR 0x48
215
216/* Conversions. Rounding and limit checking is only done on the TO_REG
217 variants. Note that you should be a bit careful with which arguments
218 these macros are called: arguments may be evaluated more than once.
219 Fixing this is just not worth it. */
220#define IN_FROM_REG(nr,val) (((nr)<=1)?(val*2): \
221 ((((nr)==6)||((nr)==7))?(val*6):(val*4)))
222#define IN_TO_REG(nr,val) (((nr)<=1)?(val/2): \
223 ((((nr)==6)||((nr)==7))?(val/6):(val/4)))
224
225static inline u8
226FAN_TO_REG(long rpm, int div)
227{
228 if (rpm == 0)
229 return 255;
230 rpm = SENSORS_LIMIT(rpm, 1, 1000000);
231 return SENSORS_LIMIT((1350000 + rpm * div / 2) / (rpm * div), 1, 254);
232}
233
234#define FAN_FROM_REG(val,div) ((val) == 0 ? -1 : \
235 ((val) == 255 ? 0 : \
236 1350000 / ((val) * (div))))
237
238/* for temp1 */
239#define TEMP1_TO_REG(val) (SENSORS_LIMIT(((val) < 0 ? (val)+0x100*1000 \
240 : (val)) / 1000, 0, 0xff))
241#define TEMP1_FROM_REG(val) (((val) & 0x80 ? (val)-0x100 : (val)) * 1000)
242/* for temp2 and temp3, because they need addtional resolution */
243#define TEMP_ADD_FROM_REG(val1, val2) \
244 ((((val1) & 0x80 ? (val1)-0x100 \
245 : (val1)) * 1000) + ((val2 & 0x80) ? 500 : 0))
246#define TEMP_ADD_TO_REG_HIGH(val) \
247 (SENSORS_LIMIT(((val) < 0 ? (val)+0x100*1000 \
248 : (val)) / 1000, 0, 0xff))
249#define TEMP_ADD_TO_REG_LOW(val) ((val%1000) ? 0x80 : 0x00)
250
251#define PWM_FROM_REG(val) (val)
252#define PWM_TO_REG(val) (SENSORS_LIMIT((val),0,255))
253#define DIV_FROM_REG(val) (1 << (val))
254
255static inline u8
256DIV_TO_REG(long val)
257{
258 int i;
259 val = SENSORS_LIMIT(val, 1, 128) >> 1;
260 for (i = 0; i < 6; i++) {
261 if (val == 0)
262 break;
263 val >>= 1;
264 }
265 return ((u8) i);
266}
267
268struct w83792d_data {
269 struct i2c_client client;
270 struct class_device *class_dev;
271 struct semaphore lock;
272 enum chips type;
273
274 struct semaphore update_lock;
275 char valid; /* !=0 if following fields are valid */
276 unsigned long last_updated; /* In jiffies */
277
278 /* array of 2 pointers to subclients */
279 struct i2c_client *lm75[2];
280
281 u8 in[9]; /* Register value */
282 u8 in_max[9]; /* Register value */
283 u8 in_min[9]; /* Register value */
284 u8 low_bits[2]; /* Additional resolution to voltage in0-6 */
285 u8 fan[7]; /* Register value */
286 u8 fan_min[7]; /* Register value */
287 u8 temp1[3]; /* current, over, thyst */
288 u8 temp_add[2][6]; /* Register value */
289 u8 fan_div[7]; /* Register encoding, shifted right */
290 u8 pwm[7]; /* We only consider the first 3 set of pwm,
291 although 792 chip has 7 set of pwm. */
292 u8 pwmenable[3];
293 u8 pwm_mode[7]; /* indicates PWM or DC mode: 1->PWM; 0->DC */
294 u32 alarms; /* realtime status register encoding,combined */
295 u8 chassis; /* Chassis status */
296 u8 chassis_clear; /* CLR_CHS, clear chassis intrusion detection */
297 u8 thermal_cruise[3]; /* Smart FanI: Fan1,2,3 target value */
298 u8 tolerance[3]; /* Fan1,2,3 tolerance(Smart Fan I/II) */
299 u8 sf2_points[3][4]; /* Smart FanII: Fan1,2,3 temperature points */
300 u8 sf2_levels[3][4]; /* Smart FanII: Fan1,2,3 duty cycle levels */
301};
302
303static int w83792d_attach_adapter(struct i2c_adapter *adapter);
304static int w83792d_detect(struct i2c_adapter *adapter, int address, int kind);
305static int w83792d_detach_client(struct i2c_client *client);
306
307static int w83792d_read_value(struct i2c_client *client, u8 register);
308static int w83792d_write_value(struct i2c_client *client, u8 register,
309 u8 value);
310static struct w83792d_data *w83792d_update_device(struct device *dev);
311
312#ifdef DEBUG
313static void w83792d_print_debug(struct w83792d_data *data, struct device *dev);
314#endif
315
316static void w83792d_init_client(struct i2c_client *client);
317
318static struct i2c_driver w83792d_driver = {
319 .owner = THIS_MODULE,
320 .name = "w83792d",
321 .flags = I2C_DF_NOTIFY,
322 .attach_adapter = w83792d_attach_adapter,
323 .detach_client = w83792d_detach_client,
324};
325
326static long in_count_from_reg(int nr, struct w83792d_data *data)
327{
328 u16 vol_count = data->in[nr];
329 u16 low_bits = 0;
330 vol_count = (vol_count << 2);
331 switch (nr)
332 {
333 case 0: /* vin0 */
334 low_bits = (data->low_bits[0]) & 0x03;
335 break;
336 case 1: /* vin1 */
337 low_bits = ((data->low_bits[0]) & 0x0c) >> 2;
338 break;
339 case 2: /* vin2 */
340 low_bits = ((data->low_bits[0]) & 0x30) >> 4;
341 break;
342 case 3: /* vin3 */
343 low_bits = ((data->low_bits[0]) & 0xc0) >> 6;
344 break;
345 case 4: /* vin4 */
346 low_bits = (data->low_bits[1]) & 0x03;
347 break;
348 case 5: /* vin5 */
349 low_bits = ((data->low_bits[1]) & 0x0c) >> 2;
350 break;
351 case 6: /* vin6 */
352 low_bits = ((data->low_bits[1]) & 0x30) >> 4;
353 default:
354 break;
355 }
356 vol_count = vol_count | low_bits;
357 return vol_count;
358}
359
360/* following are the sysfs callback functions */
361static ssize_t show_in(struct device *dev, struct device_attribute *attr,
362 char *buf)
363{
364 struct sensor_device_attribute *sensor_attr = to_sensor_dev_attr(attr);
365 int nr = sensor_attr->index;
366 struct w83792d_data *data = w83792d_update_device(dev);
367 return sprintf(buf,"%ld\n", IN_FROM_REG(nr,(in_count_from_reg(nr, data))));
368}
369
370#define show_in_reg(reg) \
371static ssize_t show_##reg(struct device *dev, struct device_attribute *attr, \
372 char *buf) \
373{ \
374 struct sensor_device_attribute *sensor_attr = to_sensor_dev_attr(attr); \
375 int nr = sensor_attr->index; \
376 struct w83792d_data *data = w83792d_update_device(dev); \
377 return sprintf(buf,"%ld\n", (long)(IN_FROM_REG(nr, (data->reg[nr])*4))); \
378}
379
380show_in_reg(in_min);
381show_in_reg(in_max);
382
383#define store_in_reg(REG, reg) \
384static ssize_t store_in_##reg (struct device *dev, \
385 struct device_attribute *attr, \
386 const char *buf, size_t count) \
387{ \
388 struct sensor_device_attribute *sensor_attr = to_sensor_dev_attr(attr); \
389 int nr = sensor_attr->index; \
390 struct i2c_client *client = to_i2c_client(dev); \
391 struct w83792d_data *data = i2c_get_clientdata(client); \
392 u32 val; \
393 \
394 val = simple_strtoul(buf, NULL, 10); \
395 data->in_##reg[nr] = SENSORS_LIMIT(IN_TO_REG(nr, val)/4, 0, 255); \
396 w83792d_write_value(client, W83792D_REG_IN_##REG[nr], data->in_##reg[nr]); \
397 \
398 return count; \
399}
400store_in_reg(MIN, min);
401store_in_reg(MAX, max);
402
403#define sysfs_in_reg(offset) \
404static SENSOR_DEVICE_ATTR(in##offset##_input, S_IRUGO, show_in, \
405 NULL, offset); \
406static SENSOR_DEVICE_ATTR(in##offset##_min, S_IRUGO | S_IWUSR, \
407 show_in_min, store_in_min, offset); \
408static SENSOR_DEVICE_ATTR(in##offset##_max, S_IRUGO | S_IWUSR, \
409 show_in_max, store_in_max, offset);
410
411sysfs_in_reg(0);
412sysfs_in_reg(1);
413sysfs_in_reg(2);
414sysfs_in_reg(3);
415sysfs_in_reg(4);
416sysfs_in_reg(5);
417sysfs_in_reg(6);
418sysfs_in_reg(7);
419sysfs_in_reg(8);
420
421#define device_create_file_in(client, offset) \
422do { \
423device_create_file(&client->dev, &sensor_dev_attr_in##offset##_input.dev_attr); \
424device_create_file(&client->dev, &sensor_dev_attr_in##offset##_max.dev_attr); \
425device_create_file(&client->dev, &sensor_dev_attr_in##offset##_min.dev_attr); \
426} while (0)
427
428#define show_fan_reg(reg) \
429static ssize_t show_##reg (struct device *dev, struct device_attribute *attr, \
430 char *buf) \
431{ \
432 struct sensor_device_attribute *sensor_attr = to_sensor_dev_attr(attr); \
433 int nr = sensor_attr->index - 1; \
434 struct w83792d_data *data = w83792d_update_device(dev); \
435 return sprintf(buf,"%d\n", \
436 FAN_FROM_REG(data->reg[nr], DIV_FROM_REG(data->fan_div[nr]))); \
437}
438
439show_fan_reg(fan);
440show_fan_reg(fan_min);
441
442static ssize_t
443store_fan_min(struct device *dev, struct device_attribute *attr,
444 const char *buf, size_t count)
445{
446 struct sensor_device_attribute *sensor_attr = to_sensor_dev_attr(attr);
447 int nr = sensor_attr->index - 1;
448 struct i2c_client *client = to_i2c_client(dev);
449 struct w83792d_data *data = i2c_get_clientdata(client);
450 u32 val;
451
452 val = simple_strtoul(buf, NULL, 10);
453 data->fan_min[nr] = FAN_TO_REG(val, DIV_FROM_REG(data->fan_div[nr]));
454 w83792d_write_value(client, W83792D_REG_FAN_MIN[nr],
455 data->fan_min[nr]);
456
457 return count;
458}
459
460static ssize_t
461show_fan_div(struct device *dev, struct device_attribute *attr,
462 char *buf)
463{
464 struct sensor_device_attribute *sensor_attr = to_sensor_dev_attr(attr);
465 int nr = sensor_attr->index;
466 struct w83792d_data *data = w83792d_update_device(dev);
467 return sprintf(buf, "%u\n", DIV_FROM_REG(data->fan_div[nr - 1]));
468}
469
470/* Note: we save and restore the fan minimum here, because its value is
471 determined in part by the fan divisor. This follows the principle of
472 least suprise; the user doesn't expect the fan minimum to change just
473 because the divisor changed. */
474static ssize_t
475store_fan_div(struct device *dev, struct device_attribute *attr,
476 const char *buf, size_t count)
477{
478 struct sensor_device_attribute *sensor_attr = to_sensor_dev_attr(attr);
479 int nr = sensor_attr->index - 1;
480 struct i2c_client *client = to_i2c_client(dev);
481 struct w83792d_data *data = i2c_get_clientdata(client);
482 unsigned long min;
483 /*u8 reg;*/
484 u8 fan_div_reg = 0;
485 u8 tmp_fan_div;
486
487 /* Save fan_min */
488 min = FAN_FROM_REG(data->fan_min[nr],
489 DIV_FROM_REG(data->fan_div[nr]));
490
491 data->fan_div[nr] = DIV_TO_REG(simple_strtoul(buf, NULL, 10));
492
493 fan_div_reg = w83792d_read_value(client, W83792D_REG_FAN_DIV[nr >> 1]);
494 fan_div_reg &= (nr & 0x01) ? 0x8f : 0xf8;
495 tmp_fan_div = (nr & 0x01) ? (((data->fan_div[nr]) << 4) & 0x70)
496 : ((data->fan_div[nr]) & 0x07);
497 w83792d_write_value(client, W83792D_REG_FAN_DIV[nr >> 1],
498 fan_div_reg | tmp_fan_div);
499
500 /* Restore fan_min */
501 data->fan_min[nr] = FAN_TO_REG(min, DIV_FROM_REG(data->fan_div[nr]));
502 w83792d_write_value(client, W83792D_REG_FAN_MIN[nr], data->fan_min[nr]);
503
504 return count;
505}
506
507#define sysfs_fan(offset) \
508static SENSOR_DEVICE_ATTR(fan##offset##_input, S_IRUGO, show_fan, NULL, \
509 offset); \
510static SENSOR_DEVICE_ATTR(fan##offset##_div, S_IRUGO | S_IWUSR, \
511 show_fan_div, store_fan_div, offset); \
512static SENSOR_DEVICE_ATTR(fan##offset##_min, S_IRUGO | S_IWUSR, \
513 show_fan_min, store_fan_min, offset);
514
515sysfs_fan(1);
516sysfs_fan(2);
517sysfs_fan(3);
518sysfs_fan(4);
519sysfs_fan(5);
520sysfs_fan(6);
521sysfs_fan(7);
522
523#define device_create_file_fan(client, offset) \
524do { \
525device_create_file(&client->dev, &sensor_dev_attr_fan##offset##_input.dev_attr); \
526device_create_file(&client->dev, &sensor_dev_attr_fan##offset##_div.dev_attr); \
527device_create_file(&client->dev, &sensor_dev_attr_fan##offset##_min.dev_attr); \
528} while (0)
529
530
531/* read/write the temperature1, includes measured value and limits */
532
533static ssize_t show_temp1(struct device *dev, struct device_attribute *attr,
534 char *buf)
535{
536 struct sensor_device_attribute *sensor_attr = to_sensor_dev_attr(attr);
537 int nr = sensor_attr->index;
538 struct w83792d_data *data = w83792d_update_device(dev);
539 return sprintf(buf, "%d\n", TEMP1_FROM_REG(data->temp1[nr]));
540}
541
542static ssize_t store_temp1(struct device *dev, struct device_attribute *attr,
543 const char *buf, size_t count)
544{
545 struct sensor_device_attribute *sensor_attr = to_sensor_dev_attr(attr);
546 int nr = sensor_attr->index;
547 struct i2c_client *client = to_i2c_client(dev);
548 struct w83792d_data *data = i2c_get_clientdata(client);
549 s32 val;
550
551 val = simple_strtol(buf, NULL, 10);
552
553 data->temp1[nr] = TEMP1_TO_REG(val);
554 w83792d_write_value(client, W83792D_REG_TEMP1[nr],
555 data->temp1[nr]);
556
557 return count;
558}
559
560
561static SENSOR_DEVICE_ATTR(temp1_input, S_IRUGO, show_temp1, NULL, 0);
562static SENSOR_DEVICE_ATTR(temp1_max, S_IRUGO | S_IWUSR, show_temp1,
563 store_temp1, 1);
564static SENSOR_DEVICE_ATTR(temp1_max_hyst, S_IRUGO | S_IWUSR, show_temp1,
565 store_temp1, 2);
566
567#define device_create_file_temp1(client) \
568do { \
569device_create_file(&client->dev, &sensor_dev_attr_temp1_input.dev_attr); \
570device_create_file(&client->dev, &sensor_dev_attr_temp1_max.dev_attr); \
571device_create_file(&client->dev, &sensor_dev_attr_temp1_max_hyst.dev_attr); \
572} while (0)
573
574
575/* read/write the temperature2-3, includes measured value and limits */
576
577static ssize_t show_temp23(struct device *dev, struct device_attribute *attr,
578 char *buf)
579{
580 struct sensor_device_attribute_2 *sensor_attr = to_sensor_dev_attr_2(attr);
581 int nr = sensor_attr->nr;
582 int index = sensor_attr->index;
583 struct w83792d_data *data = w83792d_update_device(dev);
584 return sprintf(buf,"%ld\n",
585 (long)TEMP_ADD_FROM_REG(data->temp_add[nr][index],
586 data->temp_add[nr][index+1]));
587}
588
589static ssize_t store_temp23(struct device *dev, struct device_attribute *attr,
590 const char *buf, size_t count)
591{
592 struct sensor_device_attribute_2 *sensor_attr = to_sensor_dev_attr_2(attr);
593 int nr = sensor_attr->nr;
594 int index = sensor_attr->index;
595 struct i2c_client *client = to_i2c_client(dev);
596 struct w83792d_data *data = i2c_get_clientdata(client);
597 s32 val;
598
599 val = simple_strtol(buf, NULL, 10);
600
601 data->temp_add[nr][index] = TEMP_ADD_TO_REG_HIGH(val);
602 data->temp_add[nr][index+1] = TEMP_ADD_TO_REG_LOW(val);
603 w83792d_write_value(client, W83792D_REG_TEMP_ADD[nr][index],
604 data->temp_add[nr][index]);
605 w83792d_write_value(client, W83792D_REG_TEMP_ADD[nr][index+1],
606 data->temp_add[nr][index+1]);
607
608 return count;
609}
610
611#define sysfs_temp23(name,idx) \
612static SENSOR_DEVICE_ATTR_2(name##_input, S_IRUGO, show_temp23, NULL, \
613 idx, 0); \
614static SENSOR_DEVICE_ATTR_2(name##_max, S_IRUGO | S_IWUSR, \
615 show_temp23, store_temp23, idx, 2); \
616static SENSOR_DEVICE_ATTR_2(name##_max_hyst, S_IRUGO | S_IWUSR, \
617 show_temp23, store_temp23, idx, 4);
618
619sysfs_temp23(temp2,0)
620sysfs_temp23(temp3,1)
621
622#define device_create_file_temp_add(client, offset) \
623do { \
624device_create_file(&client->dev, &sensor_dev_attr_temp##offset##_input.dev_attr); \
625device_create_file(&client->dev, &sensor_dev_attr_temp##offset##_max.dev_attr); \
626device_create_file(&client->dev, \
627&sensor_dev_attr_temp##offset##_max_hyst.dev_attr); \
628} while (0)
629
630
631/* get reatime status of all sensors items: voltage, temp, fan */
632static ssize_t
633show_alarms_reg(struct device *dev, struct device_attribute *attr, char *buf)
634{
635 struct w83792d_data *data = w83792d_update_device(dev);
636 return sprintf(buf, "%d\n", data->alarms);
637}
638
639static
640DEVICE_ATTR(alarms, S_IRUGO, show_alarms_reg, NULL);
641#define device_create_file_alarms(client) \
642device_create_file(&client->dev, &dev_attr_alarms);
643
644
645
646static ssize_t
647show_pwm(struct device *dev, struct device_attribute *attr,
648 char *buf)
649{
650 struct sensor_device_attribute *sensor_attr = to_sensor_dev_attr(attr);
651 int nr = sensor_attr->index;
652 struct w83792d_data *data = w83792d_update_device(dev);
653 return sprintf(buf, "%ld\n", (long) PWM_FROM_REG(data->pwm[nr-1]));
654}
655
656static ssize_t
657show_pwmenable(struct device *dev, struct device_attribute *attr,
658 char *buf)
659{
660 struct sensor_device_attribute *sensor_attr = to_sensor_dev_attr(attr);
661 int nr = sensor_attr->index - 1;
662 struct w83792d_data *data = w83792d_update_device(dev);
663 long pwm_enable_tmp = 1;
664
665 switch (data->pwmenable[nr]) {
666 case 0:
667 pwm_enable_tmp = 1; /* manual mode */
668 break;
669 case 1:
670 pwm_enable_tmp = 3; /*thermal cruise/Smart Fan I */
671 break;
672 case 2:
673 pwm_enable_tmp = 2; /* Smart Fan II */
674 break;
675 }
676
677 return sprintf(buf, "%ld\n", pwm_enable_tmp);
678}
679
680static ssize_t
681store_pwm(struct device *dev, struct device_attribute *attr,
682 const char *buf, size_t count)
683{
684 struct sensor_device_attribute *sensor_attr = to_sensor_dev_attr(attr);
685 int nr = sensor_attr->index - 1;
686 struct i2c_client *client = to_i2c_client(dev);
687 struct w83792d_data *data = i2c_get_clientdata(client);
688 u32 val;
689
690 val = simple_strtoul(buf, NULL, 10);
691 data->pwm[nr] = PWM_TO_REG(val);
692 w83792d_write_value(client, W83792D_REG_PWM[nr], data->pwm[nr]);
693
694 return count;
695}
696
697static ssize_t
698store_pwmenable(struct device *dev, struct device_attribute *attr,
699 const char *buf, size_t count)
700{
701 struct sensor_device_attribute *sensor_attr = to_sensor_dev_attr(attr);
702 int nr = sensor_attr->index - 1;
703 struct i2c_client *client = to_i2c_client(dev);
704 struct w83792d_data *data = i2c_get_clientdata(client);
705 u32 val;
706 u8 fan_cfg_tmp, cfg1_tmp, cfg2_tmp, cfg3_tmp, cfg4_tmp;
707
708 val = simple_strtoul(buf, NULL, 10);
709 switch (val) {
710 case 1:
711 data->pwmenable[nr] = 0; /* manual mode */
712 break;
713 case 2:
714 data->pwmenable[nr] = 2; /* Smart Fan II */
715 break;
716 case 3:
717 data->pwmenable[nr] = 1; /* thermal cruise/Smart Fan I */
718 break;
719 default:
720 return -EINVAL;
721 }
722 cfg1_tmp = data->pwmenable[0];
723 cfg2_tmp = (data->pwmenable[1]) << 2;
724 cfg3_tmp = (data->pwmenable[2]) << 4;
725 cfg4_tmp = w83792d_read_value(client,W83792D_REG_FAN_CFG) & 0xc0;
726 fan_cfg_tmp = ((cfg4_tmp | cfg3_tmp) | cfg2_tmp) | cfg1_tmp;
727 w83792d_write_value(client, W83792D_REG_FAN_CFG, fan_cfg_tmp);
728
729 return count;
730}
731
732#define sysfs_pwm(offset) \
733static SENSOR_DEVICE_ATTR(pwm##offset, S_IRUGO | S_IWUSR, \
734 show_pwm, store_pwm, offset); \
735static SENSOR_DEVICE_ATTR(pwm##offset##_enable, S_IRUGO | S_IWUSR, \
736 show_pwmenable, store_pwmenable, offset); \
737
738sysfs_pwm(1);
739sysfs_pwm(2);
740sysfs_pwm(3);
741
742
743#define device_create_file_pwm(client, offset) \
744do { \
745device_create_file(&client->dev, &sensor_dev_attr_pwm##offset.dev_attr); \
746} while (0)
747
748#define device_create_file_pwmenable(client, offset) \
749do { \
750device_create_file(&client->dev, &sensor_dev_attr_pwm##offset##_enable.dev_attr); \
751} while (0)
752
753
754static ssize_t
755show_pwm_mode(struct device *dev, struct device_attribute *attr,
756 char *buf)
757{
758 struct sensor_device_attribute *sensor_attr = to_sensor_dev_attr(attr);
759 int nr = sensor_attr->index;
760 struct w83792d_data *data = w83792d_update_device(dev);
761 return sprintf(buf, "%d\n", data->pwm_mode[nr-1]);
762}
763
764static ssize_t
765store_pwm_mode(struct device *dev, struct device_attribute *attr,
766 const char *buf, size_t count)
767{
768 struct sensor_device_attribute *sensor_attr = to_sensor_dev_attr(attr);
769 int nr = sensor_attr->index - 1;
770 struct i2c_client *client = to_i2c_client(dev);
771 struct w83792d_data *data = i2c_get_clientdata(client);
772 u32 val;
773 u8 pwm_mode_mask = 0;
774
775 val = simple_strtoul(buf, NULL, 10);
776 data->pwm_mode[nr] = SENSORS_LIMIT(val, 0, 1);
777 pwm_mode_mask = w83792d_read_value(client,
778 W83792D_REG_PWM[nr]) & 0x7f;
779 w83792d_write_value(client, W83792D_REG_PWM[nr],
780 ((data->pwm_mode[nr]) << 7) | pwm_mode_mask);
781
782 return count;
783}
784
785#define sysfs_pwm_mode(offset) \
786static SENSOR_DEVICE_ATTR(pwm##offset##_mode, S_IRUGO | S_IWUSR, \
787 show_pwm_mode, store_pwm_mode, offset);
788
789sysfs_pwm_mode(1);
790sysfs_pwm_mode(2);
791sysfs_pwm_mode(3);
792
793#define device_create_file_pwm_mode(client, offset) \
794do { \
795device_create_file(&client->dev, &sensor_dev_attr_pwm##offset##_mode.dev_attr); \
796} while (0)
797
798
799static ssize_t
800show_regs_chassis(struct device *dev, struct device_attribute *attr,
801 char *buf)
802{
803 struct w83792d_data *data = w83792d_update_device(dev);
804 return sprintf(buf, "%d\n", data->chassis);
805}
806
807static DEVICE_ATTR(chassis, S_IRUGO, show_regs_chassis, NULL);
808
809#define device_create_file_chassis(client) \
810do { \
811device_create_file(&client->dev, &dev_attr_chassis); \
812} while (0)
813
814
815static ssize_t
816show_chassis_clear(struct device *dev, struct device_attribute *attr, char *buf)
817{
818 struct w83792d_data *data = w83792d_update_device(dev);
819 return sprintf(buf, "%d\n", data->chassis_clear);
820}
821
822static ssize_t
823store_chassis_clear(struct device *dev, struct device_attribute *attr,
824 const char *buf, size_t count)
825{
826 struct i2c_client *client = to_i2c_client(dev);
827 struct w83792d_data *data = i2c_get_clientdata(client);
828 u32 val;
829 u8 temp1 = 0, temp2 = 0;
830
831 val = simple_strtoul(buf, NULL, 10);
832
833 data->chassis_clear = SENSORS_LIMIT(val, 0 ,1);
834 temp1 = ((data->chassis_clear) << 7) & 0x80;
835 temp2 = w83792d_read_value(client,
836 W83792D_REG_CHASSIS_CLR) & 0x7f;
837 w83792d_write_value(client, W83792D_REG_CHASSIS_CLR, temp1 | temp2);
838
839 return count;
840}
841
842static DEVICE_ATTR(chassis_clear, S_IRUGO | S_IWUSR,
843 show_chassis_clear, store_chassis_clear);
844
845#define device_create_file_chassis_clear(client) \
846do { \
847device_create_file(&client->dev, &dev_attr_chassis_clear); \
848} while (0)
849
850
851
852/* For Smart Fan I / Thermal Cruise */
853static ssize_t
854show_thermal_cruise(struct device *dev, struct device_attribute *attr,
855 char *buf)
856{
857 struct sensor_device_attribute *sensor_attr = to_sensor_dev_attr(attr);
858 int nr = sensor_attr->index;
859 struct w83792d_data *data = w83792d_update_device(dev);
860 return sprintf(buf, "%ld\n", (long)data->thermal_cruise[nr-1]);
861}
862
863static ssize_t
864store_thermal_cruise(struct device *dev, struct device_attribute *attr,
865 const char *buf, size_t count)
866{
867 struct sensor_device_attribute *sensor_attr = to_sensor_dev_attr(attr);
868 int nr = sensor_attr->index - 1;
869 struct i2c_client *client = to_i2c_client(dev);
870 struct w83792d_data *data = i2c_get_clientdata(client);
871 u32 val;
872 u8 target_tmp=0, target_mask=0;
873
874 val = simple_strtoul(buf, NULL, 10);
875 target_tmp = val;
876 target_tmp = target_tmp & 0x7f;
877 target_mask = w83792d_read_value(client, W83792D_REG_THERMAL[nr]) & 0x80;
878 data->thermal_cruise[nr] = SENSORS_LIMIT(target_tmp, 0, 255);
879 w83792d_write_value(client, W83792D_REG_THERMAL[nr],
880 (data->thermal_cruise[nr]) | target_mask);
881
882 return count;
883}
884
885#define sysfs_thermal_cruise(offset) \
886static SENSOR_DEVICE_ATTR(thermal_cruise##offset, S_IRUGO | S_IWUSR, \
887 show_thermal_cruise, store_thermal_cruise, offset);
888
889sysfs_thermal_cruise(1);
890sysfs_thermal_cruise(2);
891sysfs_thermal_cruise(3);
892
893#define device_create_file_thermal_cruise(client, offset) \
894do { \
895device_create_file(&client->dev, \
896&sensor_dev_attr_thermal_cruise##offset.dev_attr); \
897} while (0)
898
899
900/* For Smart Fan I/Thermal Cruise and Smart Fan II */
901static ssize_t
902show_tolerance(struct device *dev, struct device_attribute *attr,
903 char *buf)
904{
905 struct sensor_device_attribute *sensor_attr = to_sensor_dev_attr(attr);
906 int nr = sensor_attr->index;
907 struct w83792d_data *data = w83792d_update_device(dev);
908 return sprintf(buf, "%ld\n", (long)data->tolerance[nr-1]);
909}
910
911static ssize_t
912store_tolerance(struct device *dev, struct device_attribute *attr,
913 const char *buf, size_t count)
914{
915 struct sensor_device_attribute *sensor_attr = to_sensor_dev_attr(attr);
916 int nr = sensor_attr->index - 1;
917 struct i2c_client *client = to_i2c_client(dev);
918 struct w83792d_data *data = i2c_get_clientdata(client);
919 u32 val;
920 u8 tol_tmp, tol_mask;
921
922 val = simple_strtoul(buf, NULL, 10);
923 tol_mask = w83792d_read_value(client,
924 W83792D_REG_TOLERANCE[nr]) & ((nr == 1) ? 0x0f : 0xf0);
925 tol_tmp = SENSORS_LIMIT(val, 0, 15);
926 tol_tmp &= 0x0f;
927 data->tolerance[nr] = tol_tmp;
928 if (nr == 1) {
929 tol_tmp <<= 4;
930 }
931 w83792d_write_value(client, W83792D_REG_TOLERANCE[nr],
932 tol_mask | tol_tmp);
933
934 return count;
935}
936
937#define sysfs_tolerance(offset) \
938static SENSOR_DEVICE_ATTR(tolerance##offset, S_IRUGO | S_IWUSR, \
939 show_tolerance, store_tolerance, offset);
940
941sysfs_tolerance(1);
942sysfs_tolerance(2);
943sysfs_tolerance(3);
944
945#define device_create_file_tolerance(client, offset) \
946do { \
947device_create_file(&client->dev, &sensor_dev_attr_tolerance##offset.dev_attr); \
948} while (0)
949
950
951/* For Smart Fan II */
952static ssize_t
953show_sf2_point(struct device *dev, struct device_attribute *attr,
954 char *buf)
955{
956 struct sensor_device_attribute_2 *sensor_attr = to_sensor_dev_attr_2(attr);
957 int nr = sensor_attr->nr;
958 int index = sensor_attr->index;
959 struct w83792d_data *data = w83792d_update_device(dev);
960 return sprintf(buf, "%ld\n", (long)data->sf2_points[index-1][nr-1]);
961}
962
963static ssize_t
964store_sf2_point(struct device *dev, struct device_attribute *attr,
965 const char *buf, size_t count)
966{
967 struct sensor_device_attribute_2 *sensor_attr = to_sensor_dev_attr_2(attr);
968 int nr = sensor_attr->nr - 1;
969 int index = sensor_attr->index - 1;
970 struct i2c_client *client = to_i2c_client(dev);
971 struct w83792d_data *data = i2c_get_clientdata(client);
972 u32 val;
973 u8 mask_tmp = 0;
974
975 val = simple_strtoul(buf, NULL, 10);
976 data->sf2_points[index][nr] = SENSORS_LIMIT(val, 0, 127);
977 mask_tmp = w83792d_read_value(client,
978 W83792D_REG_POINTS[index][nr]) & 0x80;
979 w83792d_write_value(client, W83792D_REG_POINTS[index][nr],
980 mask_tmp|data->sf2_points[index][nr]);
981
982 return count;
983}
984
985#define sysfs_sf2_point(offset, index) \
986static SENSOR_DEVICE_ATTR_2(sf2_point##offset##_fan##index, S_IRUGO | S_IWUSR, \
987 show_sf2_point, store_sf2_point, offset, index);
988
989sysfs_sf2_point(1, 1); /* Fan1 */
990sysfs_sf2_point(2, 1); /* Fan1 */
991sysfs_sf2_point(3, 1); /* Fan1 */
992sysfs_sf2_point(4, 1); /* Fan1 */
993sysfs_sf2_point(1, 2); /* Fan2 */
994sysfs_sf2_point(2, 2); /* Fan2 */
995sysfs_sf2_point(3, 2); /* Fan2 */
996sysfs_sf2_point(4, 2); /* Fan2 */
997sysfs_sf2_point(1, 3); /* Fan3 */
998sysfs_sf2_point(2, 3); /* Fan3 */
999sysfs_sf2_point(3, 3); /* Fan3 */
1000sysfs_sf2_point(4, 3); /* Fan3 */
1001
1002#define device_create_file_sf2_point(client, offset, index) \
1003do { \
1004device_create_file(&client->dev, \
1005&sensor_dev_attr_sf2_point##offset##_fan##index.dev_attr); \
1006} while (0)
1007
1008
1009static ssize_t
1010show_sf2_level(struct device *dev, struct device_attribute *attr,
1011 char *buf)
1012{
1013 struct sensor_device_attribute_2 *sensor_attr = to_sensor_dev_attr_2(attr);
1014 int nr = sensor_attr->nr;
1015 int index = sensor_attr->index;
1016 struct w83792d_data *data = w83792d_update_device(dev);
1017 return sprintf(buf, "%d\n",
1018 (((data->sf2_levels[index-1][nr]) * 100) / 15));
1019}
1020
1021static ssize_t
1022store_sf2_level(struct device *dev, struct device_attribute *attr,
1023 const char *buf, size_t count)
1024{
1025 struct sensor_device_attribute_2 *sensor_attr = to_sensor_dev_attr_2(attr);
1026 int nr = sensor_attr->nr;
1027 int index = sensor_attr->index - 1;
1028 struct i2c_client *client = to_i2c_client(dev);
1029 struct w83792d_data *data = i2c_get_clientdata(client);
1030 u32 val;
1031 u8 mask_tmp=0, level_tmp=0;
1032
1033 val = simple_strtoul(buf, NULL, 10);
1034 data->sf2_levels[index][nr] = SENSORS_LIMIT((val * 15) / 100, 0, 15);
1035 mask_tmp = w83792d_read_value(client, W83792D_REG_LEVELS[index][nr])
1036 & ((nr==3) ? 0xf0 : 0x0f);
1037 if (nr==3) {
1038 level_tmp = data->sf2_levels[index][nr];
1039 } else {
1040 level_tmp = data->sf2_levels[index][nr] << 4;
1041 }
1042 w83792d_write_value(client, W83792D_REG_LEVELS[index][nr], level_tmp | mask_tmp);
1043
1044 return count;
1045}
1046
1047#define sysfs_sf2_level(offset, index) \
1048static SENSOR_DEVICE_ATTR_2(sf2_level##offset##_fan##index, S_IRUGO | S_IWUSR, \
1049 show_sf2_level, store_sf2_level, offset, index);
1050
1051sysfs_sf2_level(1, 1); /* Fan1 */
1052sysfs_sf2_level(2, 1); /* Fan1 */
1053sysfs_sf2_level(3, 1); /* Fan1 */
1054sysfs_sf2_level(1, 2); /* Fan2 */
1055sysfs_sf2_level(2, 2); /* Fan2 */
1056sysfs_sf2_level(3, 2); /* Fan2 */
1057sysfs_sf2_level(1, 3); /* Fan3 */
1058sysfs_sf2_level(2, 3); /* Fan3 */
1059sysfs_sf2_level(3, 3); /* Fan3 */
1060
1061#define device_create_file_sf2_level(client, offset, index) \
1062do { \
1063device_create_file(&client->dev, \
1064&sensor_dev_attr_sf2_level##offset##_fan##index.dev_attr); \
1065} while (0)
1066
1067
1068/* This function is called when:
1069 * w83792d_driver is inserted (when this module is loaded), for each
1070 available adapter
1071 * when a new adapter is inserted (and w83792d_driver is still present) */
1072static int
1073w83792d_attach_adapter(struct i2c_adapter *adapter)
1074{
1075 if (!(adapter->class & I2C_CLASS_HWMON))
1076 return 0;
1077 return i2c_probe(adapter, &addr_data, w83792d_detect);
1078}
1079
1080
1081static int
1082w83792d_create_subclient(struct i2c_adapter *adapter,
1083 struct i2c_client *new_client, int addr,
1084 struct i2c_client **sub_cli)
1085{
1086 int err;
1087 struct i2c_client *sub_client;
1088
1089 (*sub_cli) = sub_client = kmalloc(sizeof(struct i2c_client), GFP_KERNEL);
1090 if (!(sub_client)) {
1091 return -ENOMEM;
1092 }
1093 memset(sub_client, 0x00, sizeof(struct i2c_client));
1094 sub_client->addr = 0x48 + addr;
1095 i2c_set_clientdata(sub_client, NULL);
1096 sub_client->adapter = adapter;
1097 sub_client->driver = &w83792d_driver;
1098 sub_client->flags = 0;
1099 strlcpy(sub_client->name, "w83792d subclient", I2C_NAME_SIZE);
1100 if ((err = i2c_attach_client(sub_client))) {
1101 dev_err(&new_client->dev, "subclient registration "
1102 "at address 0x%x failed\n", sub_client->addr);
1103 kfree(sub_client);
1104 return err;
1105 }
1106 return 0;
1107}
1108
1109
1110static int
1111w83792d_detect_subclients(struct i2c_adapter *adapter, int address, int kind,
1112 struct i2c_client *new_client)
1113{
1114 int i, id, err;
1115 u8 val;
1116 struct w83792d_data *data = i2c_get_clientdata(new_client);
1117
1118 id = i2c_adapter_id(adapter);
1119 if (force_subclients[0] == id && force_subclients[1] == address) {
1120 for (i = 2; i <= 3; i++) {
1121 if (force_subclients[i] < 0x48 ||
1122 force_subclients[i] > 0x4f) {
1123 dev_err(&new_client->dev, "invalid subclient "
1124 "address %d; must be 0x48-0x4f\n",
1125 force_subclients[i]);
1126 err = -ENODEV;
1127 goto ERROR_SC_0;
1128 }
1129 }
1130 w83792d_write_value(new_client, W83792D_REG_I2C_SUBADDR,
1131 (force_subclients[2] & 0x07) |
1132 ((force_subclients[3] & 0x07) << 4));
1133 }
1134
1135 val = w83792d_read_value(new_client, W83792D_REG_I2C_SUBADDR);
1136 if (!(val & 0x08)) {
1137 err = w83792d_create_subclient(adapter, new_client, val & 0x7,
1138 &data->lm75[0]);
1139 if (err < 0)
1140 goto ERROR_SC_0;
1141 }
1142 if (!(val & 0x80)) {
1143 if ((data->lm75[0] != NULL) &&
1144 ((val & 0x7) == ((val >> 4) & 0x7))) {
1145 dev_err(&new_client->dev, "duplicate addresses 0x%x, "
1146 "use force_subclient\n", data->lm75[0]->addr);
1147 err = -ENODEV;
1148 goto ERROR_SC_1;
1149 }
1150 err = w83792d_create_subclient(adapter, new_client,
1151 (val >> 4) & 0x7, &data->lm75[1]);
1152 if (err < 0)
1153 goto ERROR_SC_1;
1154 }
1155
1156 return 0;
1157
1158/* Undo inits in case of errors */
1159
1160ERROR_SC_1:
1161 if (data->lm75[0] != NULL) {
1162 i2c_detach_client(data->lm75[0]);
1163 kfree(data->lm75[0]);
1164 }
1165ERROR_SC_0:
1166 return err;
1167}
1168
1169
1170static int
1171w83792d_detect(struct i2c_adapter *adapter, int address, int kind)
1172{
1173 int i = 0, val1 = 0, val2;
1174 struct i2c_client *new_client;
1175 struct w83792d_data *data;
1176 int err = 0;
1177 const char *client_name = "";
1178
1179 if (!i2c_check_functionality(adapter, I2C_FUNC_SMBUS_BYTE_DATA)) {
1180 goto ERROR0;
1181 }
1182
1183 /* OK. For now, we presume we have a valid client. We now create the
1184 client structure, even though we cannot fill it completely yet.
1185 But it allows us to access w83792d_{read,write}_value. */
1186
1187 if (!(data = kmalloc(sizeof(struct w83792d_data), GFP_KERNEL))) {
1188 err = -ENOMEM;
1189 goto ERROR0;
1190 }
1191 memset(data, 0, sizeof(struct w83792d_data));
1192
1193 new_client = &data->client;
1194 i2c_set_clientdata(new_client, data);
1195 new_client->addr = address;
1196 init_MUTEX(&data->lock);
1197 new_client->adapter = adapter;
1198 new_client->driver = &w83792d_driver;
1199 new_client->flags = 0;
1200
1201 /* Now, we do the remaining detection. */
1202
1203 /* The w83792d may be stuck in some other bank than bank 0. This may
1204 make reading other information impossible. Specify a force=... or
1205 force_*=... parameter, and the Winbond will be reset to the right
1206 bank. */
1207 if (kind < 0) {
1208 if (w83792d_read_value(new_client, W83792D_REG_CONFIG) & 0x80) {
1209 dev_warn(&new_client->dev, "Detection failed at step "
1210 "3\n");
1211 goto ERROR1;
1212 }
1213 val1 = w83792d_read_value(new_client, W83792D_REG_BANK);
1214 val2 = w83792d_read_value(new_client, W83792D_REG_CHIPMAN);
1215 /* Check for Winbond ID if in bank 0 */
1216 if (!(val1 & 0x07)) { /* is Bank0 */
1217 if (((!(val1 & 0x80)) && (val2 != 0xa3)) ||
1218 ((val1 & 0x80) && (val2 != 0x5c))) {
1219 goto ERROR1;
1220 }
1221 }
1222 /* If Winbond chip, address of chip and W83792D_REG_I2C_ADDR
1223 should match */
1224 if (w83792d_read_value(new_client,
1225 W83792D_REG_I2C_ADDR) != address) {
1226 dev_warn(&new_client->dev, "Detection failed "
1227 "at step 5\n");
1228 goto ERROR1;
1229 }
1230 }
1231
1232 /* We have either had a force parameter, or we have already detected the
1233 Winbond. Put it now into bank 0 and Vendor ID High Byte */
1234 w83792d_write_value(new_client,
1235 W83792D_REG_BANK,
1236 (w83792d_read_value(new_client,
1237 W83792D_REG_BANK) & 0x78) | 0x80);
1238
1239 /* Determine the chip type. */
1240 if (kind <= 0) {
1241 /* get vendor ID */
1242 val2 = w83792d_read_value(new_client, W83792D_REG_CHIPMAN);
1243 if (val2 != 0x5c) { /* the vendor is NOT Winbond */
1244 goto ERROR1;
1245 }
1246 val1 = w83792d_read_value(new_client, W83792D_REG_WCHIPID);
1247 if (val1 == 0x7a && address >= 0x2c) {
1248 kind = w83792d;
1249 } else {
1250 if (kind == 0)
1251 dev_warn(&new_client->dev,
1252 "w83792d: Ignoring 'force' parameter for"
1253 " unknown chip at adapter %d, address"
1254 " 0x%02x\n", i2c_adapter_id(adapter),
1255 address);
1256 goto ERROR1;
1257 }
1258 }
1259
1260 if (kind == w83792d) {
1261 client_name = "w83792d";
1262 } else {
1263 dev_err(&new_client->dev, "w83792d: Internal error: unknown"
1264 " kind (%d)?!?", kind);
1265 goto ERROR1;
1266 }
1267
1268 /* Fill in the remaining client fields and put into the global list */
1269 strlcpy(new_client->name, client_name, I2C_NAME_SIZE);
1270 data->type = kind;
1271
1272 data->valid = 0;
1273 init_MUTEX(&data->update_lock);
1274
1275 /* Tell the I2C layer a new client has arrived */
1276 if ((err = i2c_attach_client(new_client)))
1277 goto ERROR1;
1278
1279 if ((err = w83792d_detect_subclients(adapter, address,
1280 kind, new_client)))
1281 goto ERROR2;
1282
1283 /* Initialize the chip */
1284 w83792d_init_client(new_client);
1285
1286 /* A few vars need to be filled upon startup */
1287 for (i = 1; i <= 7; i++) {
1288 data->fan_min[i - 1] = w83792d_read_value(new_client,
1289 W83792D_REG_FAN_MIN[i]);
1290 }
1291
1292 /* Register sysfs hooks */
1293 data->class_dev = hwmon_device_register(&new_client->dev);
1294 if (IS_ERR(data->class_dev)) {
1295 err = PTR_ERR(data->class_dev);
1296 goto ERROR3;
1297 }
1298 device_create_file_in(new_client, 0);
1299 device_create_file_in(new_client, 1);
1300 device_create_file_in(new_client, 2);
1301 device_create_file_in(new_client, 3);
1302 device_create_file_in(new_client, 4);
1303 device_create_file_in(new_client, 5);
1304 device_create_file_in(new_client, 6);
1305 device_create_file_in(new_client, 7);
1306 device_create_file_in(new_client, 8);
1307
1308 device_create_file_fan(new_client, 1);
1309 device_create_file_fan(new_client, 2);
1310 device_create_file_fan(new_client, 3);
1311 device_create_file_fan(new_client, 4);
1312 device_create_file_fan(new_client, 5);
1313 device_create_file_fan(new_client, 6);
1314 device_create_file_fan(new_client, 7);
1315
1316 device_create_file_temp1(new_client); /* Temp1 */
1317 device_create_file_temp_add(new_client, 2); /* Temp2 */
1318 device_create_file_temp_add(new_client, 3); /* Temp3 */
1319
1320 device_create_file_alarms(new_client);
1321
1322 device_create_file_pwm(new_client, 1);
1323 device_create_file_pwm(new_client, 2);
1324 device_create_file_pwm(new_client, 3);
1325
1326 device_create_file_pwmenable(new_client, 1);
1327 device_create_file_pwmenable(new_client, 2);
1328 device_create_file_pwmenable(new_client, 3);
1329
1330 device_create_file_pwm_mode(new_client, 1);
1331 device_create_file_pwm_mode(new_client, 2);
1332 device_create_file_pwm_mode(new_client, 3);
1333
1334 device_create_file_chassis(new_client);
1335 device_create_file_chassis_clear(new_client);
1336
1337 device_create_file_thermal_cruise(new_client, 1);
1338 device_create_file_thermal_cruise(new_client, 2);
1339 device_create_file_thermal_cruise(new_client, 3);
1340
1341 device_create_file_tolerance(new_client, 1);
1342 device_create_file_tolerance(new_client, 2);
1343 device_create_file_tolerance(new_client, 3);
1344
1345 device_create_file_sf2_point(new_client, 1, 1); /* Fan1 */
1346 device_create_file_sf2_point(new_client, 2, 1); /* Fan1 */
1347 device_create_file_sf2_point(new_client, 3, 1); /* Fan1 */
1348 device_create_file_sf2_point(new_client, 4, 1); /* Fan1 */
1349 device_create_file_sf2_point(new_client, 1, 2); /* Fan2 */
1350 device_create_file_sf2_point(new_client, 2, 2); /* Fan2 */
1351 device_create_file_sf2_point(new_client, 3, 2); /* Fan2 */
1352 device_create_file_sf2_point(new_client, 4, 2); /* Fan2 */
1353 device_create_file_sf2_point(new_client, 1, 3); /* Fan3 */
1354 device_create_file_sf2_point(new_client, 2, 3); /* Fan3 */
1355 device_create_file_sf2_point(new_client, 3, 3); /* Fan3 */
1356 device_create_file_sf2_point(new_client, 4, 3); /* Fan3 */
1357
1358 device_create_file_sf2_level(new_client, 1, 1); /* Fan1 */
1359 device_create_file_sf2_level(new_client, 2, 1); /* Fan1 */
1360 device_create_file_sf2_level(new_client, 3, 1); /* Fan1 */
1361 device_create_file_sf2_level(new_client, 1, 2); /* Fan2 */
1362 device_create_file_sf2_level(new_client, 2, 2); /* Fan2 */
1363 device_create_file_sf2_level(new_client, 3, 2); /* Fan2 */
1364 device_create_file_sf2_level(new_client, 1, 3); /* Fan3 */
1365 device_create_file_sf2_level(new_client, 2, 3); /* Fan3 */
1366 device_create_file_sf2_level(new_client, 3, 3); /* Fan3 */
1367
1368 return 0;
1369
1370ERROR3:
1371 if (data->lm75[0] != NULL) {
1372 i2c_detach_client(data->lm75[0]);
1373 kfree(data->lm75[0]);
1374 }
1375 if (data->lm75[1] != NULL) {
1376 i2c_detach_client(data->lm75[1]);
1377 kfree(data->lm75[1]);
1378 }
1379ERROR2:
1380 i2c_detach_client(new_client);
1381ERROR1:
1382 kfree(data);
1383ERROR0:
1384 return err;
1385}
1386
1387static int
1388w83792d_detach_client(struct i2c_client *client)
1389{
1390 struct w83792d_data *data = i2c_get_clientdata(client);
1391 int err;
1392
1393 /* main client */
1394 if (data)
1395 hwmon_device_unregister(data->class_dev);
1396
1397 if ((err = i2c_detach_client(client)))
1398 return err;
1399
1400 /* main client */
1401 if (data)
1402 kfree(data);
1403 /* subclient */
1404 else
1405 kfree(client);
1406
1407 return 0;
1408}
1409
1410/* The SMBus locks itself, usually, but nothing may access the Winbond between
1411 bank switches. ISA access must always be locked explicitly!
1412 We ignore the W83792D BUSY flag at this moment - it could lead to deadlocks,
1413 would slow down the W83792D access and should not be necessary.
1414 There are some ugly typecasts here, but the good news is - they should
1415 nowhere else be necessary! */
1416static int
1417w83792d_read_value(struct i2c_client *client, u8 reg)
1418{
1419 int res=0;
1420 res = i2c_smbus_read_byte_data(client, reg);
1421
1422 return res;
1423}
1424
1425static int
1426w83792d_write_value(struct i2c_client *client, u8 reg, u8 value)
1427{
1428 i2c_smbus_write_byte_data(client, reg, value);
1429 return 0;
1430}
1431
1432/* Called when we have found a new W83792D. It should set limits, etc. */
1433static void
1434w83792d_init_client(struct i2c_client *client)
1435{
1436 u8 temp2_cfg, temp3_cfg, vid_in_b;
1437
1438 if (init) {
1439 w83792d_write_value(client, W83792D_REG_CONFIG, 0x80);
1440 }
1441 /* Clear the bit6 of W83792D_REG_VID_IN_B(set it into 0):
1442 W83792D_REG_VID_IN_B bit6 = 0: the high/low limit of
1443 vin0/vin1 can be modified by user;
1444 W83792D_REG_VID_IN_B bit6 = 1: the high/low limit of
1445 vin0/vin1 auto-updated, can NOT be modified by user. */
1446 vid_in_b = w83792d_read_value(client, W83792D_REG_VID_IN_B);
1447 w83792d_write_value(client, W83792D_REG_VID_IN_B,
1448 vid_in_b & 0xbf);
1449
1450 temp2_cfg = w83792d_read_value(client, W83792D_REG_TEMP2_CONFIG);
1451 temp3_cfg = w83792d_read_value(client, W83792D_REG_TEMP3_CONFIG);
1452 w83792d_write_value(client, W83792D_REG_TEMP2_CONFIG,
1453 temp2_cfg & 0xe6);
1454 w83792d_write_value(client, W83792D_REG_TEMP3_CONFIG,
1455 temp3_cfg & 0xe6);
1456
1457 /* Start monitoring */
1458 w83792d_write_value(client, W83792D_REG_CONFIG,
1459 (w83792d_read_value(client,
1460 W83792D_REG_CONFIG) & 0xf7)
1461 | 0x01);
1462}
1463
1464static struct w83792d_data *w83792d_update_device(struct device *dev)
1465{
1466 struct i2c_client *client = to_i2c_client(dev);
1467 struct w83792d_data *data = i2c_get_clientdata(client);
1468 int i, j;
1469 u8 reg_array_tmp[4], pwm_array_tmp[7], reg_tmp;
1470
1471 down(&data->update_lock);
1472
1473 if (time_after
1474 (jiffies - data->last_updated, (unsigned long) (HZ * 3))
1475 || time_before(jiffies, data->last_updated) || !data->valid) {
1476 dev_dbg(dev, "Starting device update\n");
1477
1478 /* Update the voltages measured value and limits */
1479 for (i = 0; i < 9; i++) {
1480 data->in[i] = w83792d_read_value(client,
1481 W83792D_REG_IN[i]);
1482 data->in_max[i] = w83792d_read_value(client,
1483 W83792D_REG_IN_MAX[i]);
1484 data->in_min[i] = w83792d_read_value(client,
1485 W83792D_REG_IN_MIN[i]);
1486 }
1487 data->low_bits[0] = w83792d_read_value(client,
1488 W83792D_REG_LOW_BITS1);
1489 data->low_bits[1] = w83792d_read_value(client,
1490 W83792D_REG_LOW_BITS2);
1491 for (i = 0; i < 7; i++) {
1492 /* Update the Fan measured value and limits */
1493 data->fan[i] = w83792d_read_value(client,
1494 W83792D_REG_FAN[i]);
1495 data->fan_min[i] = w83792d_read_value(client,
1496 W83792D_REG_FAN_MIN[i]);
1497 /* Update the PWM/DC Value and PWM/DC flag */
1498 pwm_array_tmp[i] = w83792d_read_value(client,
1499 W83792D_REG_PWM[i]);
1500 data->pwm[i] = pwm_array_tmp[i] & 0x0f;
1501 data->pwm_mode[i] = (pwm_array_tmp[i] >> 7) & 0x01;
1502 }
1503
1504 reg_tmp = w83792d_read_value(client, W83792D_REG_FAN_CFG);
1505 data->pwmenable[0] = reg_tmp & 0x03;
1506 data->pwmenable[1] = (reg_tmp>>2) & 0x03;
1507 data->pwmenable[2] = (reg_tmp>>4) & 0x03;
1508
1509 for (i = 0; i < 3; i++) {
1510 data->temp1[i] = w83792d_read_value(client,
1511 W83792D_REG_TEMP1[i]);
1512 }
1513 for (i = 0; i < 2; i++) {
1514 for (j = 0; j < 6; j++) {
1515 data->temp_add[i][j] = w83792d_read_value(
1516 client,W83792D_REG_TEMP_ADD[i][j]);
1517 }
1518 }
1519
1520 /* Update the Fan Divisor */
1521 for (i = 0; i < 4; i++) {
1522 reg_array_tmp[i] = w83792d_read_value(client,
1523 W83792D_REG_FAN_DIV[i]);
1524 }
1525 data->fan_div[0] = reg_array_tmp[0] & 0x07;
1526 data->fan_div[1] = (reg_array_tmp[0] >> 4) & 0x07;
1527 data->fan_div[2] = reg_array_tmp[1] & 0x07;
1528 data->fan_div[3] = (reg_array_tmp[1] >> 4) & 0x07;
1529 data->fan_div[4] = reg_array_tmp[2] & 0x07;
1530 data->fan_div[5] = (reg_array_tmp[2] >> 4) & 0x07;
1531 data->fan_div[6] = reg_array_tmp[3] & 0x07;
1532
1533 /* Update the realtime status */
1534 data->alarms = w83792d_read_value(client, W83792D_REG_ALARM1) +
1535 (w83792d_read_value(client, W83792D_REG_ALARM2) << 8) +
1536 (w83792d_read_value(client, W83792D_REG_ALARM3) << 16);
1537
1538 /* Update CaseOpen status and it's CLR_CHS. */
1539 data->chassis = (w83792d_read_value(client,
1540 W83792D_REG_CHASSIS) >> 5) & 0x01;
1541 data->chassis_clear = (w83792d_read_value(client,
1542 W83792D_REG_CHASSIS_CLR) >> 7) & 0x01;
1543
1544 /* Update Thermal Cruise/Smart Fan I target value */
1545 for (i = 0; i < 3; i++) {
1546 data->thermal_cruise[i] =
1547 w83792d_read_value(client,
1548 W83792D_REG_THERMAL[i]) & 0x7f;
1549 }
1550
1551 /* Update Smart Fan I/II tolerance */
1552 reg_tmp = w83792d_read_value(client, W83792D_REG_TOLERANCE[0]);
1553 data->tolerance[0] = reg_tmp & 0x0f;
1554 data->tolerance[1] = (reg_tmp >> 4) & 0x0f;
1555 data->tolerance[2] = w83792d_read_value(client,
1556 W83792D_REG_TOLERANCE[2]) & 0x0f;
1557
1558 /* Update Smart Fan II temperature points */
1559 for (i = 0; i < 3; i++) {
1560 for (j = 0; j < 4; j++) {
1561 data->sf2_points[i][j] = w83792d_read_value(
1562 client,W83792D_REG_POINTS[i][j]) & 0x7f;
1563 }
1564 }
1565
1566 /* Update Smart Fan II duty cycle levels */
1567 for (i = 0; i < 3; i++) {
1568 reg_tmp = w83792d_read_value(client,
1569 W83792D_REG_LEVELS[i][0]);
1570 data->sf2_levels[i][0] = reg_tmp & 0x0f;
1571 data->sf2_levels[i][1] = (reg_tmp >> 4) & 0x0f;
1572 reg_tmp = w83792d_read_value(client,
1573 W83792D_REG_LEVELS[i][2]);
1574 data->sf2_levels[i][2] = (reg_tmp >> 4) & 0x0f;
1575 data->sf2_levels[i][3] = reg_tmp & 0x0f;
1576 }
1577
1578 data->last_updated = jiffies;
1579 data->valid = 1;
1580 }
1581
1582 up(&data->update_lock);
1583
1584#ifdef DEBUG
1585 w83792d_print_debug(data, dev);
1586#endif
1587
1588 return data;
1589}
1590
1591#ifdef DEBUG
1592static void w83792d_print_debug(struct w83792d_data *data, struct device *dev)
1593{
1594 int i=0, j=0;
1595 dev_dbg(dev, "==========The following is the debug message...========\n");
1596 dev_dbg(dev, "9 set of Voltages: =====>\n");
1597 for (i=0; i<9; i++) {
1598 dev_dbg(dev, "vin[%d] is: 0x%x\n", i, data->in[i]);
1599 dev_dbg(dev, "vin[%d] max is: 0x%x\n", i, data->in_max[i]);
1600 dev_dbg(dev, "vin[%d] min is: 0x%x\n", i, data->in_min[i]);
1601 }
1602 dev_dbg(dev, "Low Bit1 is: 0x%x\n", data->low_bits[0]);
1603 dev_dbg(dev, "Low Bit2 is: 0x%x\n", data->low_bits[1]);
1604 dev_dbg(dev, "7 set of Fan Counts and Duty Cycles: =====>\n");
1605 for (i=0; i<7; i++) {
1606 dev_dbg(dev, "fan[%d] is: 0x%x\n", i, data->fan[i]);
1607 dev_dbg(dev, "fan[%d] min is: 0x%x\n", i, data->fan_min[i]);
1608 dev_dbg(dev, "pwm[%d] is: 0x%x\n", i, data->pwm[i]);
1609 dev_dbg(dev, "pwm_mode[%d] is: 0x%x\n", i, data->pwm_mode[i]);
1610 }
1611 dev_dbg(dev, "3 set of Temperatures: =====>\n");
1612 for (i=0; i<3; i++) {
1613 dev_dbg(dev, "temp1[%d] is: 0x%x\n", i, data->temp1[i]);
1614 }
1615
1616 for (i=0; i<2; i++) {
1617 for (j=0; j<6; j++) {
1618 dev_dbg(dev, "temp_add[%d][%d] is: 0x%x\n", i, j,
1619 data->temp_add[i][j]);
1620 }
1621 }
1622
1623 for (i=0; i<7; i++) {
1624 dev_dbg(dev, "fan_div[%d] is: 0x%x\n", i, data->fan_div[i]);
1625 }
1626 dev_dbg(dev, "==========End of the debug message...==================\n");
1627 dev_dbg(dev, "\n");
1628}
1629#endif
1630
1631static int __init
1632sensors_w83792d_init(void)
1633{
1634 return i2c_add_driver(&w83792d_driver);
1635}
1636
1637static void __exit
1638sensors_w83792d_exit(void)
1639{
1640 i2c_del_driver(&w83792d_driver);
1641}
1642
1643MODULE_AUTHOR("Chunhao Huang @ Winbond <DZShen@Winbond.com.tw>");
1644MODULE_DESCRIPTION("W83792AD/D driver for linux-2.6");
1645MODULE_LICENSE("GPL");
1646
1647module_init(sensors_w83792d_init);
1648module_exit(sensors_w83792d_exit);
1649
diff --git a/drivers/hwmon/w83l785ts.c b/drivers/hwmon/w83l785ts.c
index 4469d52aba4..133e34ab1d0 100644
--- a/drivers/hwmon/w83l785ts.c
+++ b/drivers/hwmon/w83l785ts.c
@@ -36,7 +36,8 @@
36#include <linux/slab.h> 36#include <linux/slab.h>
37#include <linux/jiffies.h> 37#include <linux/jiffies.h>
38#include <linux/i2c.h> 38#include <linux/i2c.h>
39#include <linux/i2c-sensor.h> 39#include <linux/hwmon.h>
40#include <linux/err.h>
40 41
41/* How many retries on register read error */ 42/* How many retries on register read error */
42#define MAX_RETRIES 5 43#define MAX_RETRIES 5
@@ -47,13 +48,12 @@
47 */ 48 */
48 49
49static unsigned short normal_i2c[] = { 0x2e, I2C_CLIENT_END }; 50static unsigned short normal_i2c[] = { 0x2e, I2C_CLIENT_END };
50static unsigned int normal_isa[] = { I2C_CLIENT_ISA_END };
51 51
52/* 52/*
53 * Insmod parameters 53 * Insmod parameters
54 */ 54 */
55 55
56SENSORS_INSMOD_1(w83l785ts); 56I2C_CLIENT_INSMOD_1(w83l785ts);
57 57
58/* 58/*
59 * The W83L785TS-S registers 59 * The W83L785TS-S registers
@@ -105,6 +105,7 @@ static struct i2c_driver w83l785ts_driver = {
105 105
106struct w83l785ts_data { 106struct w83l785ts_data {
107 struct i2c_client client; 107 struct i2c_client client;
108 struct class_device *class_dev;
108 struct semaphore update_lock; 109 struct semaphore update_lock;
109 char valid; /* zero until following fields are valid */ 110 char valid; /* zero until following fields are valid */
110 unsigned long last_updated; /* in jiffies */ 111 unsigned long last_updated; /* in jiffies */
@@ -140,7 +141,7 @@ static int w83l785ts_attach_adapter(struct i2c_adapter *adapter)
140{ 141{
141 if (!(adapter->class & I2C_CLASS_HWMON)) 142 if (!(adapter->class & I2C_CLASS_HWMON))
142 return 0; 143 return 0;
143 return i2c_detect(adapter, &addr_data, w83l785ts_detect); 144 return i2c_probe(adapter, &addr_data, w83l785ts_detect);
144} 145}
145 146
146/* 147/*
@@ -239,11 +240,19 @@ static int w83l785ts_detect(struct i2c_adapter *adapter, int address, int kind)
239 */ 240 */
240 241
241 /* Register sysfs hooks */ 242 /* Register sysfs hooks */
243 data->class_dev = hwmon_device_register(&new_client->dev);
244 if (IS_ERR(data->class_dev)) {
245 err = PTR_ERR(data->class_dev);
246 goto exit_detach;
247 }
248
242 device_create_file(&new_client->dev, &dev_attr_temp1_input); 249 device_create_file(&new_client->dev, &dev_attr_temp1_input);
243 device_create_file(&new_client->dev, &dev_attr_temp1_max); 250 device_create_file(&new_client->dev, &dev_attr_temp1_max);
244 251
245 return 0; 252 return 0;
246 253
254exit_detach:
255 i2c_detach_client(new_client);
247exit_free: 256exit_free:
248 kfree(data); 257 kfree(data);
249exit: 258exit:
@@ -252,15 +261,15 @@ exit:
252 261
253static int w83l785ts_detach_client(struct i2c_client *client) 262static int w83l785ts_detach_client(struct i2c_client *client)
254{ 263{
264 struct w83l785ts_data *data = i2c_get_clientdata(client);
255 int err; 265 int err;
256 266
257 if ((err = i2c_detach_client(client))) { 267 hwmon_device_unregister(data->class_dev);
258 dev_err(&client->dev, "Client deregistration failed, " 268
259 "client not detached.\n"); 269 if ((err = i2c_detach_client(client)))
260 return err; 270 return err;
261 }
262 271
263 kfree(i2c_get_clientdata(client)); 272 kfree(data);
264 return 0; 273 return 0;
265} 274}
266 275
diff --git a/drivers/i2c/Makefile b/drivers/i2c/Makefile
index cd170395a8c..71c5a854ac5 100644
--- a/drivers/i2c/Makefile
+++ b/drivers/i2c/Makefile
@@ -4,12 +4,8 @@
4 4
5obj-$(CONFIG_I2C) += i2c-core.o 5obj-$(CONFIG_I2C) += i2c-core.o
6obj-$(CONFIG_I2C_CHARDEV) += i2c-dev.o 6obj-$(CONFIG_I2C_CHARDEV) += i2c-dev.o
7obj-$(CONFIG_I2C_SENSOR) += i2c-sensor.o
8obj-y += busses/ chips/ algos/ 7obj-y += busses/ chips/ algos/
9 8
10i2c-sensor-objs := i2c-sensor-detect.o i2c-sensor-vid.o
11
12
13ifeq ($(CONFIG_I2C_DEBUG_CORE),y) 9ifeq ($(CONFIG_I2C_DEBUG_CORE),y)
14EXTRA_CFLAGS += -DDEBUG 10EXTRA_CFLAGS += -DDEBUG
15endif 11endif
diff --git a/drivers/i2c/algos/i2c-algo-bit.c b/drivers/i2c/algos/i2c-algo-bit.c
index fb5b732238e..df05df1a0ef 100644
--- a/drivers/i2c/algos/i2c-algo-bit.c
+++ b/drivers/i2c/algos/i2c-algo-bit.c
@@ -519,8 +519,6 @@ static u32 bit_func(struct i2c_adapter *adap)
519/* -----exported algorithm data: ------------------------------------- */ 519/* -----exported algorithm data: ------------------------------------- */
520 520
521static struct i2c_algorithm i2c_bit_algo = { 521static struct i2c_algorithm i2c_bit_algo = {
522 .name = "Bit-shift algorithm",
523 .id = I2C_ALGO_BIT,
524 .master_xfer = bit_xfer, 522 .master_xfer = bit_xfer,
525 .functionality = bit_func, 523 .functionality = bit_func,
526}; 524};
@@ -541,8 +539,6 @@ int i2c_bit_add_bus(struct i2c_adapter *adap)
541 DEB2(dev_dbg(&adap->dev, "hw routines registered.\n")); 539 DEB2(dev_dbg(&adap->dev, "hw routines registered.\n"));
542 540
543 /* register new adapter to i2c module... */ 541 /* register new adapter to i2c module... */
544
545 adap->id |= i2c_bit_algo.id;
546 adap->algo = &i2c_bit_algo; 542 adap->algo = &i2c_bit_algo;
547 543
548 adap->timeout = 100; /* default values, should */ 544 adap->timeout = 100; /* default values, should */
diff --git a/drivers/i2c/algos/i2c-algo-ite.c b/drivers/i2c/algos/i2c-algo-ite.c
index e6cae39f47a..2db7bfc8522 100644
--- a/drivers/i2c/algos/i2c-algo-ite.c
+++ b/drivers/i2c/algos/i2c-algo-ite.c
@@ -713,8 +713,6 @@ static u32 iic_func(struct i2c_adapter *adap)
713/* -----exported algorithm data: ------------------------------------- */ 713/* -----exported algorithm data: ------------------------------------- */
714 714
715static struct i2c_algorithm iic_algo = { 715static struct i2c_algorithm iic_algo = {
716 .name = "ITE IIC algorithm",
717 .id = I2C_ALGO_IIC,
718 .master_xfer = iic_xfer, 716 .master_xfer = iic_xfer,
719 .algo_control = algo_control, /* ioctl */ 717 .algo_control = algo_control, /* ioctl */
720 .functionality = iic_func, 718 .functionality = iic_func,
@@ -738,8 +736,6 @@ int i2c_iic_add_bus(struct i2c_adapter *adap)
738 adap->name)); 736 adap->name));
739 737
740 /* register new adapter to i2c module... */ 738 /* register new adapter to i2c module... */
741
742 adap->id |= iic_algo.id;
743 adap->algo = &iic_algo; 739 adap->algo = &iic_algo;
744 740
745 adap->timeout = 100; /* default values, should */ 741 adap->timeout = 100; /* default values, should */
diff --git a/drivers/i2c/algos/i2c-algo-pca.c b/drivers/i2c/algos/i2c-algo-pca.c
index cc3a952401f..beb10edfe9c 100644
--- a/drivers/i2c/algos/i2c-algo-pca.c
+++ b/drivers/i2c/algos/i2c-algo-pca.c
@@ -187,12 +187,14 @@ static int pca_xfer(struct i2c_adapter *i2c_adap,
187 int numbytes = 0; 187 int numbytes = 0;
188 int state; 188 int state;
189 int ret; 189 int ret;
190 int timeout = 100;
190 191
191 state = pca_status(adap); 192 while ((state = pca_status(adap)) != 0xf8 && timeout--) {
192 if ( state != 0xF8 ) { 193 msleep(10);
193 dev_dbg(&i2c_adap->dev, "bus is not idle. status is %#04x\n", state ); 194 }
194 /* FIXME: what to do. Force stop ? */ 195 if (state != 0xf8) {
195 return -EREMOTEIO; 196 dev_dbg(&i2c_adap->dev, "bus is not idle. status is %#04x\n", state);
197 return -EIO;
196 } 198 }
197 199
198 DEB1("{{{ XFER %d messages\n", num); 200 DEB1("{{{ XFER %d messages\n", num);
@@ -354,8 +356,6 @@ static int pca_init(struct i2c_algo_pca_data *adap)
354} 356}
355 357
356static struct i2c_algorithm pca_algo = { 358static struct i2c_algorithm pca_algo = {
357 .name = "PCA9564 algorithm",
358 .id = I2C_ALGO_PCA,
359 .master_xfer = pca_xfer, 359 .master_xfer = pca_xfer,
360 .functionality = pca_func, 360 .functionality = pca_func,
361}; 361};
@@ -369,8 +369,6 @@ int i2c_pca_add_bus(struct i2c_adapter *adap)
369 int rval; 369 int rval;
370 370
371 /* register new adapter to i2c module... */ 371 /* register new adapter to i2c module... */
372
373 adap->id |= pca_algo.id;
374 adap->algo = &pca_algo; 372 adap->algo = &pca_algo;
375 373
376 adap->timeout = 100; /* default values, should */ 374 adap->timeout = 100; /* default values, should */
diff --git a/drivers/i2c/algos/i2c-algo-pcf.c b/drivers/i2c/algos/i2c-algo-pcf.c
index 8d087dac32a..6e498df1f71 100644
--- a/drivers/i2c/algos/i2c-algo-pcf.c
+++ b/drivers/i2c/algos/i2c-algo-pcf.c
@@ -459,8 +459,6 @@ static u32 pcf_func(struct i2c_adapter *adap)
459/* -----exported algorithm data: ------------------------------------- */ 459/* -----exported algorithm data: ------------------------------------- */
460 460
461static struct i2c_algorithm pcf_algo = { 461static struct i2c_algorithm pcf_algo = {
462 .name = "PCF8584 algorithm",
463 .id = I2C_ALGO_PCF,
464 .master_xfer = pcf_xfer, 462 .master_xfer = pcf_xfer,
465 .functionality = pcf_func, 463 .functionality = pcf_func,
466}; 464};
@@ -476,8 +474,6 @@ int i2c_pcf_add_bus(struct i2c_adapter *adap)
476 DEB2(dev_dbg(&adap->dev, "hw routines registered.\n")); 474 DEB2(dev_dbg(&adap->dev, "hw routines registered.\n"));
477 475
478 /* register new adapter to i2c module... */ 476 /* register new adapter to i2c module... */
479
480 adap->id |= pcf_algo.id;
481 adap->algo = &pcf_algo; 477 adap->algo = &pcf_algo;
482 478
483 adap->timeout = 100; /* default values, should */ 479 adap->timeout = 100; /* default values, should */
diff --git a/drivers/i2c/algos/i2c-algo-sgi.c b/drivers/i2c/algos/i2c-algo-sgi.c
index 422721b241e..932c4fa86c7 100644
--- a/drivers/i2c/algos/i2c-algo-sgi.c
+++ b/drivers/i2c/algos/i2c-algo-sgi.c
@@ -149,7 +149,7 @@ static int sgi_xfer(struct i2c_adapter *i2c_adap, struct i2c_msg *msgs,
149 err = i2c_write(adap, p->buf, p->len); 149 err = i2c_write(adap, p->buf, p->len);
150 } 150 }
151 151
152 return err; 152 return (err < 0) ? err : i;
153} 153}
154 154
155static u32 sgi_func(struct i2c_adapter *adap) 155static u32 sgi_func(struct i2c_adapter *adap)
@@ -158,8 +158,6 @@ static u32 sgi_func(struct i2c_adapter *adap)
158} 158}
159 159
160static struct i2c_algorithm sgi_algo = { 160static struct i2c_algorithm sgi_algo = {
161 .name = "SGI algorithm",
162 .id = I2C_ALGO_SGI,
163 .master_xfer = sgi_xfer, 161 .master_xfer = sgi_xfer,
164 .functionality = sgi_func, 162 .functionality = sgi_func,
165}; 163};
@@ -169,7 +167,6 @@ static struct i2c_algorithm sgi_algo = {
169 */ 167 */
170int i2c_sgi_add_bus(struct i2c_adapter *adap) 168int i2c_sgi_add_bus(struct i2c_adapter *adap)
171{ 169{
172 adap->id |= sgi_algo.id;
173 adap->algo = &sgi_algo; 170 adap->algo = &sgi_algo;
174 171
175 return i2c_add_adapter(adap); 172 return i2c_add_adapter(adap);
diff --git a/drivers/i2c/algos/i2c-algo-sibyte.c b/drivers/i2c/algos/i2c-algo-sibyte.c
index f2785499237..8ed5ad12552 100644
--- a/drivers/i2c/algos/i2c-algo-sibyte.c
+++ b/drivers/i2c/algos/i2c-algo-sibyte.c
@@ -135,8 +135,6 @@ static u32 bit_func(struct i2c_adapter *adap)
135/* -----exported algorithm data: ------------------------------------- */ 135/* -----exported algorithm data: ------------------------------------- */
136 136
137static struct i2c_algorithm i2c_sibyte_algo = { 137static struct i2c_algorithm i2c_sibyte_algo = {
138 .name = "SiByte algorithm",
139 .id = I2C_ALGO_SIBYTE,
140 .smbus_xfer = smbus_xfer, 138 .smbus_xfer = smbus_xfer,
141 .algo_control = algo_control, /* ioctl */ 139 .algo_control = algo_control, /* ioctl */
142 .functionality = bit_func, 140 .functionality = bit_func,
@@ -151,8 +149,6 @@ int i2c_sibyte_add_bus(struct i2c_adapter *i2c_adap, int speed)
151 struct i2c_algo_sibyte_data *adap = i2c_adap->algo_data; 149 struct i2c_algo_sibyte_data *adap = i2c_adap->algo_data;
152 150
153 /* register new adapter to i2c module... */ 151 /* register new adapter to i2c module... */
154
155 i2c_adap->id |= i2c_sibyte_algo.id;
156 i2c_adap->algo = &i2c_sibyte_algo; 152 i2c_adap->algo = &i2c_sibyte_algo;
157 153
158 /* Set the frequency to 100 kHz */ 154 /* Set the frequency to 100 kHz */
diff --git a/drivers/i2c/busses/Kconfig b/drivers/i2c/busses/Kconfig
index 916ba5e40a9..6e9da137222 100644
--- a/drivers/i2c/busses/Kconfig
+++ b/drivers/i2c/busses/Kconfig
@@ -182,14 +182,8 @@ config I2C_IOP3XX
182 will be called i2c-iop3xx. 182 will be called i2c-iop3xx.
183 183
184config I2C_ISA 184config I2C_ISA
185 tristate "ISA Bus support" 185 tristate
186 depends on I2C 186 depends on I2C
187 help
188 If you say yes to this option, support will be included for i2c
189 interfaces that are on the ISA bus.
190
191 This driver can also be built as a module. If so, the module
192 will be called i2c-isa.
193 187
194config I2C_ITE 188config I2C_ITE
195 tristate "ITE I2C Adapter" 189 tristate "ITE I2C Adapter"
diff --git a/drivers/i2c/busses/i2c-ali1535.c b/drivers/i2c/busses/i2c-ali1535.c
index f634a0780cf..f021acd2674 100644
--- a/drivers/i2c/busses/i2c-ali1535.c
+++ b/drivers/i2c/busses/i2c-ali1535.c
@@ -472,8 +472,6 @@ static u32 ali1535_func(struct i2c_adapter *adapter)
472} 472}
473 473
474static struct i2c_algorithm smbus_algorithm = { 474static struct i2c_algorithm smbus_algorithm = {
475 .name = "Non-i2c SMBus adapter",
476 .id = I2C_ALGO_SMBUS,
477 .smbus_xfer = ali1535_access, 475 .smbus_xfer = ali1535_access,
478 .functionality = ali1535_func, 476 .functionality = ali1535_func,
479}; 477};
diff --git a/drivers/i2c/busses/i2c-ali1563.c b/drivers/i2c/busses/i2c-ali1563.c
index fdd881aee61..86947504aea 100644
--- a/drivers/i2c/busses/i2c-ali1563.c
+++ b/drivers/i2c/busses/i2c-ali1563.c
@@ -366,8 +366,6 @@ static void ali1563_shutdown(struct pci_dev *dev)
366} 366}
367 367
368static struct i2c_algorithm ali1563_algorithm = { 368static struct i2c_algorithm ali1563_algorithm = {
369 .name = "Non-i2c SMBus adapter",
370 .id = I2C_ALGO_SMBUS,
371 .smbus_xfer = ali1563_access, 369 .smbus_xfer = ali1563_access,
372 .functionality = ali1563_func, 370 .functionality = ali1563_func,
373}; 371};
diff --git a/drivers/i2c/busses/i2c-ali15x3.c b/drivers/i2c/busses/i2c-ali15x3.c
index 0f781a1a332..b3f50bff39a 100644
--- a/drivers/i2c/busses/i2c-ali15x3.c
+++ b/drivers/i2c/busses/i2c-ali15x3.c
@@ -462,8 +462,6 @@ static u32 ali15x3_func(struct i2c_adapter *adapter)
462} 462}
463 463
464static struct i2c_algorithm smbus_algorithm = { 464static struct i2c_algorithm smbus_algorithm = {
465 .name = "Non-I2C SMBus adapter",
466 .id = I2C_ALGO_SMBUS,
467 .smbus_xfer = ali15x3_access, 465 .smbus_xfer = ali15x3_access,
468 .functionality = ali15x3_func, 466 .functionality = ali15x3_func,
469}; 467};
diff --git a/drivers/i2c/busses/i2c-amd756.c b/drivers/i2c/busses/i2c-amd756.c
index 6347ebc6fb5..6ad0603384b 100644
--- a/drivers/i2c/busses/i2c-amd756.c
+++ b/drivers/i2c/busses/i2c-amd756.c
@@ -295,8 +295,6 @@ static u32 amd756_func(struct i2c_adapter *adapter)
295} 295}
296 296
297static struct i2c_algorithm smbus_algorithm = { 297static struct i2c_algorithm smbus_algorithm = {
298 .name = "Non-I2C SMBus adapter",
299 .id = I2C_ALGO_SMBUS,
300 .smbus_xfer = amd756_access, 298 .smbus_xfer = amd756_access,
301 .functionality = amd756_func, 299 .functionality = amd756_func,
302}; 300};
diff --git a/drivers/i2c/busses/i2c-amd8111.c b/drivers/i2c/busses/i2c-amd8111.c
index d6644481d2a..45ea24ba14d 100644
--- a/drivers/i2c/busses/i2c-amd8111.c
+++ b/drivers/i2c/busses/i2c-amd8111.c
@@ -323,8 +323,6 @@ static u32 amd8111_func(struct i2c_adapter *adapter)
323} 323}
324 324
325static struct i2c_algorithm smbus_algorithm = { 325static struct i2c_algorithm smbus_algorithm = {
326 .name = "Non-I2C SMBus 2.0 adapter",
327 .id = I2C_ALGO_SMBUS,
328 .smbus_xfer = amd8111_access, 326 .smbus_xfer = amd8111_access,
329 .functionality = amd8111_func, 327 .functionality = amd8111_func,
330}; 328};
diff --git a/drivers/i2c/busses/i2c-au1550.c b/drivers/i2c/busses/i2c-au1550.c
index a7ff112e49b..d06edce03bf 100644
--- a/drivers/i2c/busses/i2c-au1550.c
+++ b/drivers/i2c/busses/i2c-au1550.c
@@ -283,8 +283,6 @@ au1550_func(struct i2c_adapter *adap)
283} 283}
284 284
285static struct i2c_algorithm au1550_algo = { 285static struct i2c_algorithm au1550_algo = {
286 .name = "Au1550 algorithm",
287 .id = I2C_ALGO_AU1550,
288 .master_xfer = au1550_xfer, 286 .master_xfer = au1550_xfer,
289 .functionality = au1550_func, 287 .functionality = au1550_func,
290}; 288};
diff --git a/drivers/i2c/busses/i2c-i801.c b/drivers/i2c/busses/i2c-i801.c
index 1ab41313ce5..709beab7660 100644
--- a/drivers/i2c/busses/i2c-i801.c
+++ b/drivers/i2c/busses/i2c-i801.c
@@ -535,8 +535,6 @@ static u32 i801_func(struct i2c_adapter *adapter)
535} 535}
536 536
537static struct i2c_algorithm smbus_algorithm = { 537static struct i2c_algorithm smbus_algorithm = {
538 .name = "Non-I2C SMBus adapter",
539 .id = I2C_ALGO_SMBUS,
540 .smbus_xfer = i801_access, 538 .smbus_xfer = i801_access,
541 .functionality = i801_func, 539 .functionality = i801_func,
542}; 540};
diff --git a/drivers/i2c/busses/i2c-ibm_iic.c b/drivers/i2c/busses/i2c-ibm_iic.c
index 93ca36dc777..a3ed9590f02 100644
--- a/drivers/i2c/busses/i2c-ibm_iic.c
+++ b/drivers/i2c/busses/i2c-ibm_iic.c
@@ -627,8 +627,6 @@ static u32 iic_func(struct i2c_adapter *adap)
627} 627}
628 628
629static struct i2c_algorithm iic_algo = { 629static struct i2c_algorithm iic_algo = {
630 .name = "IBM IIC algorithm",
631 .id = I2C_ALGO_OCP,
632 .master_xfer = iic_xfer, 630 .master_xfer = iic_xfer,
633 .functionality = iic_func 631 .functionality = iic_func
634}; 632};
@@ -727,7 +725,7 @@ static int __devinit iic_probe(struct ocp_device *ocp){
727 adap = &dev->adap; 725 adap = &dev->adap;
728 strcpy(adap->name, "IBM IIC"); 726 strcpy(adap->name, "IBM IIC");
729 i2c_set_adapdata(adap, dev); 727 i2c_set_adapdata(adap, dev);
730 adap->id = I2C_HW_OCP | iic_algo.id; 728 adap->id = I2C_HW_OCP;
731 adap->algo = &iic_algo; 729 adap->algo = &iic_algo;
732 adap->client_register = NULL; 730 adap->client_register = NULL;
733 adap->client_unregister = NULL; 731 adap->client_unregister = NULL;
diff --git a/drivers/i2c/busses/i2c-iop3xx.c b/drivers/i2c/busses/i2c-iop3xx.c
index 6b682e903f0..7bd9102db70 100644
--- a/drivers/i2c/busses/i2c-iop3xx.c
+++ b/drivers/i2c/busses/i2c-iop3xx.c
@@ -399,8 +399,6 @@ iop3xx_i2c_func(struct i2c_adapter *adap)
399} 399}
400 400
401static struct i2c_algorithm iop3xx_i2c_algo = { 401static struct i2c_algorithm iop3xx_i2c_algo = {
402 .name = "IOP3xx I2C algorithm",
403 .id = I2C_ALGO_IOP3XX,
404 .master_xfer = iop3xx_i2c_master_xfer, 402 .master_xfer = iop3xx_i2c_master_xfer,
405 .algo_control = iop3xx_i2c_algo_control, 403 .algo_control = iop3xx_i2c_algo_control,
406 .functionality = iop3xx_i2c_func, 404 .functionality = iop3xx_i2c_func,
diff --git a/drivers/i2c/busses/i2c-isa.c b/drivers/i2c/busses/i2c-isa.c
index 00e7f7157b7..bdc6806dafa 100644
--- a/drivers/i2c/busses/i2c-isa.c
+++ b/drivers/i2c/busses/i2c-isa.c
@@ -1,6 +1,8 @@
1/* 1/*
2 i2c-isa.c - Part of lm_sensors, Linux kernel modules for hardware 2 i2c-isa.c - an i2c-core-like thing for ISA hardware monitoring chips
3 monitoring 3 Copyright (C) 2005 Jean Delvare <khali@linux-fr.org>
4
5 Based on the i2c-isa pseudo-adapter from the lm_sensors project
4 Copyright (c) 1998, 1999 Frodo Looijaard <frodol@dds.nl> 6 Copyright (c) 1998, 1999 Frodo Looijaard <frodol@dds.nl>
5 7
6 This program is free software; you can redistribute it and/or modify 8 This program is free software; you can redistribute it and/or modify
@@ -18,30 +20,36 @@
18 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. 20 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
19*/ 21*/
20 22
21/* This implements an i2c algorithm/adapter for ISA bus. Not that this is 23/* This implements an i2c-core-like thing for ISA hardware monitoring
22 on first sight very useful; almost no functionality is preserved. 24 chips. Such chips are linked to the i2c subsystem for historical
23 Except that it makes writing drivers for chips which can be on both 25 reasons (because the early ISA hardware monitoring chips such as the
24 the SMBus and the ISA bus very much easier. See lm78.c for an example 26 LM78 had both an I2C and an ISA interface). They used to be
25 of this. */ 27 registered with the main i2c-core, but as a first step in the
28 direction of a clean separation between I2C and ISA chip drivers,
29 we now have this separate core for ISA ones. It is significantly
30 more simple than the real one, of course, because we don't have to
31 handle multiple busses: there is only one (fake) ISA adapter.
32 It is worth noting that we still rely on i2c-core for some things
33 at the moment - but hopefully this won't last. */
26 34
27#include <linux/init.h> 35#include <linux/init.h>
28#include <linux/module.h> 36#include <linux/module.h>
29#include <linux/kernel.h> 37#include <linux/kernel.h>
30#include <linux/errno.h> 38#include <linux/errno.h>
31#include <linux/i2c.h> 39#include <linux/i2c.h>
40#include <linux/i2c-isa.h>
32 41
33static u32 isa_func(struct i2c_adapter *adapter); 42static u32 isa_func(struct i2c_adapter *adapter);
34 43
35/* This is the actual algorithm we define */ 44/* This is the actual algorithm we define */
36static struct i2c_algorithm isa_algorithm = { 45static struct i2c_algorithm isa_algorithm = {
37 .name = "ISA bus algorithm",
38 .id = I2C_ALGO_ISA,
39 .functionality = isa_func, 46 .functionality = isa_func,
40}; 47};
41 48
42/* There can only be one... */ 49/* There can only be one... */
43static struct i2c_adapter isa_adapter = { 50static struct i2c_adapter isa_adapter = {
44 .owner = THIS_MODULE, 51 .owner = THIS_MODULE,
52 .id = I2C_HW_ISA,
45 .class = I2C_CLASS_HWMON, 53 .class = I2C_CLASS_HWMON,
46 .algo = &isa_algorithm, 54 .algo = &isa_algorithm,
47 .name = "ISA main adapter", 55 .name = "ISA main adapter",
@@ -53,17 +61,146 @@ static u32 isa_func(struct i2c_adapter *adapter)
53 return 0; 61 return 0;
54} 62}
55 63
64
65/* Copied from i2c-core */
66static ssize_t show_adapter_name(struct device *dev,
67 struct device_attribute *attr, char *buf)
68{
69 struct i2c_adapter *adap = dev_to_i2c_adapter(dev);
70 return sprintf(buf, "%s\n", adap->name);
71}
72static DEVICE_ATTR(name, S_IRUGO, show_adapter_name, NULL);
73
74static int i2c_isa_device_probe(struct device *dev)
75{
76 return -ENODEV;
77}
78
79static int i2c_isa_device_remove(struct device *dev)
80{
81 return 0;
82}
83
84
85/* We implement an interface which resembles i2c_{add,del}_driver,
86 but for i2c-isa drivers. We don't have to remember and handle lists
87 of drivers and adapters so this is much more simple, of course. */
88
89int i2c_isa_add_driver(struct i2c_driver *driver)
90{
91 int res;
92
93 /* Add the driver to the list of i2c drivers in the driver core */
94 driver->driver.name = driver->name;
95 driver->driver.bus = &i2c_bus_type;
96 driver->driver.probe = i2c_isa_device_probe;
97 driver->driver.remove = i2c_isa_device_remove;
98 res = driver_register(&driver->driver);
99 if (res)
100 return res;
101 dev_dbg(&isa_adapter.dev, "Driver %s registered\n", driver->name);
102
103 /* Now look for clients */
104 driver->attach_adapter(&isa_adapter);
105
106 return 0;
107}
108
109int i2c_isa_del_driver(struct i2c_driver *driver)
110{
111 struct list_head *item, *_n;
112 struct i2c_client *client;
113 int res;
114
115 /* Detach all clients belonging to this one driver */
116 list_for_each_safe(item, _n, &isa_adapter.clients) {
117 client = list_entry(item, struct i2c_client, list);
118 if (client->driver != driver)
119 continue;
120 dev_dbg(&isa_adapter.dev, "Detaching client %s at 0x%x\n",
121 client->name, client->addr);
122 if ((res = driver->detach_client(client))) {
123 dev_err(&isa_adapter.dev, "Failed, driver "
124 "%s not unregistered!\n",
125 driver->name);
126 return res;
127 }
128 }
129
130 /* Get the driver off the core list */
131 driver_unregister(&driver->driver);
132 dev_dbg(&isa_adapter.dev, "Driver %s unregistered\n", driver->name);
133
134 return 0;
135}
136
137
56static int __init i2c_isa_init(void) 138static int __init i2c_isa_init(void)
57{ 139{
58 return i2c_add_adapter(&isa_adapter); 140 init_MUTEX(&isa_adapter.clist_lock);
141 INIT_LIST_HEAD(&isa_adapter.clients);
142
143 isa_adapter.nr = ANY_I2C_ISA_BUS;
144 isa_adapter.dev.parent = &platform_bus;
145 sprintf(isa_adapter.dev.bus_id, "i2c-%d", isa_adapter.nr);
146 isa_adapter.dev.driver = &i2c_adapter_driver;
147 isa_adapter.dev.release = &i2c_adapter_dev_release;
148 device_register(&isa_adapter.dev);
149 device_create_file(&isa_adapter.dev, &dev_attr_name);
150
151 /* Add this adapter to the i2c_adapter class */
152 memset(&isa_adapter.class_dev, 0x00, sizeof(struct class_device));
153 isa_adapter.class_dev.dev = &isa_adapter.dev;
154 isa_adapter.class_dev.class = &i2c_adapter_class;
155 strlcpy(isa_adapter.class_dev.class_id, isa_adapter.dev.bus_id,
156 BUS_ID_SIZE);
157 class_device_register(&isa_adapter.class_dev);
158
159 dev_dbg(&isa_adapter.dev, "%s registered\n", isa_adapter.name);
160
161 return 0;
59} 162}
60 163
61static void __exit i2c_isa_exit(void) 164static void __exit i2c_isa_exit(void)
62{ 165{
63 i2c_del_adapter(&isa_adapter); 166#ifdef DEBUG
167 struct list_head *item, *_n;
168 struct i2c_client *client = NULL;
169#endif
170
171 /* There should be no more active client */
172#ifdef DEBUG
173 dev_dbg(&isa_adapter.dev, "Looking for clients\n");
174 list_for_each_safe(item, _n, &isa_adapter.clients) {
175 client = list_entry(item, struct i2c_client, list);
176 dev_err(&isa_adapter.dev, "Driver %s still has an active "
177 "ISA client at 0x%x\n", client->driver->name,
178 client->addr);
179 }
180 if (client != NULL)
181 return;
182#endif
183
184 /* Clean up the sysfs representation */
185 dev_dbg(&isa_adapter.dev, "Unregistering from sysfs\n");
186 init_completion(&isa_adapter.dev_released);
187 init_completion(&isa_adapter.class_dev_released);
188 class_device_unregister(&isa_adapter.class_dev);
189 device_remove_file(&isa_adapter.dev, &dev_attr_name);
190 device_unregister(&isa_adapter.dev);
191
192 /* Wait for sysfs to drop all references */
193 dev_dbg(&isa_adapter.dev, "Waiting for sysfs completion\n");
194 wait_for_completion(&isa_adapter.dev_released);
195 wait_for_completion(&isa_adapter.class_dev_released);
196
197 dev_dbg(&isa_adapter.dev, "%s unregistered\n", isa_adapter.name);
64} 198}
65 199
66MODULE_AUTHOR("Frodo Looijaard <frodol@dds.nl>"); 200EXPORT_SYMBOL(i2c_isa_add_driver);
201EXPORT_SYMBOL(i2c_isa_del_driver);
202
203MODULE_AUTHOR("Jean Delvare <khali@linux-fr.org>");
67MODULE_DESCRIPTION("ISA bus access through i2c"); 204MODULE_DESCRIPTION("ISA bus access through i2c");
68MODULE_LICENSE("GPL"); 205MODULE_LICENSE("GPL");
69 206
diff --git a/drivers/i2c/busses/i2c-keywest.c b/drivers/i2c/busses/i2c-keywest.c
index 94ae808314f..37b49c2daf5 100644
--- a/drivers/i2c/busses/i2c-keywest.c
+++ b/drivers/i2c/busses/i2c-keywest.c
@@ -87,12 +87,9 @@ static const char *__kw_state_names[] = {
87}; 87};
88#endif /* DEBUG */ 88#endif /* DEBUG */
89 89
90static int probe;
91
92MODULE_AUTHOR("Benjamin Herrenschmidt <benh@kernel.crashing.org>"); 90MODULE_AUTHOR("Benjamin Herrenschmidt <benh@kernel.crashing.org>");
93MODULE_DESCRIPTION("I2C driver for Apple's Keywest"); 91MODULE_DESCRIPTION("I2C driver for Apple's Keywest");
94MODULE_LICENSE("GPL"); 92MODULE_LICENSE("GPL");
95module_param(probe, bool, 0);
96 93
97#ifdef POLLED_MODE 94#ifdef POLLED_MODE
98/* Don't schedule, the g5 fan controller is too 95/* Don't schedule, the g5 fan controller is too
@@ -498,8 +495,6 @@ keywest_func(struct i2c_adapter * adapter)
498 495
499/* For now, we only handle combined mode (smbus) */ 496/* For now, we only handle combined mode (smbus) */
500static struct i2c_algorithm keywest_algorithm = { 497static struct i2c_algorithm keywest_algorithm = {
501 .name = "Keywest i2c",
502 .id = I2C_ALGO_SMBUS,
503 .smbus_xfer = keywest_smbus_xfer, 498 .smbus_xfer = keywest_smbus_xfer,
504 .master_xfer = keywest_xfer, 499 .master_xfer = keywest_xfer,
505 .functionality = keywest_func, 500 .functionality = keywest_func,
@@ -621,7 +616,6 @@ create_iface(struct device_node *np, struct device *dev)
621 sprintf(chan->adapter.name, "%s %d", np->parent->name, i); 616 sprintf(chan->adapter.name, "%s %d", np->parent->name, i);
622 chan->iface = iface; 617 chan->iface = iface;
623 chan->chan_no = i; 618 chan->chan_no = i;
624 chan->adapter.id = I2C_ALGO_SMBUS;
625 chan->adapter.algo = &keywest_algorithm; 619 chan->adapter.algo = &keywest_algorithm;
626 chan->adapter.algo_data = NULL; 620 chan->adapter.algo_data = NULL;
627 chan->adapter.client_register = NULL; 621 chan->adapter.client_register = NULL;
@@ -635,15 +629,6 @@ create_iface(struct device_node *np, struct device *dev)
635 chan->adapter.name); 629 chan->adapter.name);
636 i2c_set_adapdata(&chan->adapter, NULL); 630 i2c_set_adapdata(&chan->adapter, NULL);
637 } 631 }
638 if (probe) {
639 printk("Probe: ");
640 for (addr = 0x00; addr <= 0x7f; addr++) {
641 if (i2c_smbus_xfer(&chan->adapter,addr,
642 0,0,0,I2C_SMBUS_QUICK,NULL) >= 0)
643 printk("%02x ", addr);
644 }
645 printk("\n");
646 }
647 } 632 }
648 633
649 printk(KERN_INFO "Found KeyWest i2c on \"%s\", %d channel%s, stepping: %d bits\n", 634 printk(KERN_INFO "Found KeyWest i2c on \"%s\", %d channel%s, stepping: %d bits\n",
diff --git a/drivers/i2c/busses/i2c-mpc.c b/drivers/i2c/busses/i2c-mpc.c
index 9ad3e9262e8..f065583ddcf 100644
--- a/drivers/i2c/busses/i2c-mpc.c
+++ b/drivers/i2c/busses/i2c-mpc.c
@@ -272,8 +272,6 @@ static u32 mpc_functionality(struct i2c_adapter *adap)
272} 272}
273 273
274static struct i2c_algorithm mpc_algo = { 274static struct i2c_algorithm mpc_algo = {
275 .name = "MPC algorithm",
276 .id = I2C_ALGO_MPC107,
277 .master_xfer = mpc_xfer, 275 .master_xfer = mpc_xfer,
278 .functionality = mpc_functionality, 276 .functionality = mpc_functionality,
279}; 277};
@@ -281,7 +279,7 @@ static struct i2c_algorithm mpc_algo = {
281static struct i2c_adapter mpc_ops = { 279static struct i2c_adapter mpc_ops = {
282 .owner = THIS_MODULE, 280 .owner = THIS_MODULE,
283 .name = "MPC adapter", 281 .name = "MPC adapter",
284 .id = I2C_ALGO_MPC107 | I2C_HW_MPC107, 282 .id = I2C_HW_MPC107,
285 .algo = &mpc_algo, 283 .algo = &mpc_algo,
286 .class = I2C_CLASS_HWMON, 284 .class = I2C_CLASS_HWMON,
287 .timeout = 1, 285 .timeout = 1,
diff --git a/drivers/i2c/busses/i2c-mv64xxx.c b/drivers/i2c/busses/i2c-mv64xxx.c
index 5b852782d2f..99abca45fec 100644
--- a/drivers/i2c/busses/i2c-mv64xxx.c
+++ b/drivers/i2c/busses/i2c-mv64xxx.c
@@ -423,18 +423,16 @@ static int
423mv64xxx_i2c_xfer(struct i2c_adapter *adap, struct i2c_msg msgs[], int num) 423mv64xxx_i2c_xfer(struct i2c_adapter *adap, struct i2c_msg msgs[], int num)
424{ 424{
425 struct mv64xxx_i2c_data *drv_data = i2c_get_adapdata(adap); 425 struct mv64xxx_i2c_data *drv_data = i2c_get_adapdata(adap);
426 int i, rc = 0; 426 int i, rc;
427 427
428 for (i=0; i<num; i++) 428 for (i=0; i<num; i++)
429 if ((rc = mv64xxx_i2c_execute_msg(drv_data, &msgs[i])) != 0) 429 if ((rc = mv64xxx_i2c_execute_msg(drv_data, &msgs[i])) < 0)
430 break; 430 return rc;
431 431
432 return rc; 432 return num;
433} 433}
434 434
435static struct i2c_algorithm mv64xxx_i2c_algo = { 435static struct i2c_algorithm mv64xxx_i2c_algo = {
436 .name = MV64XXX_I2C_CTLR_NAME " algorithm",
437 .id = I2C_ALGO_MV64XXX,
438 .master_xfer = mv64xxx_i2c_xfer, 436 .master_xfer = mv64xxx_i2c_xfer,
439 .functionality = mv64xxx_i2c_functionality, 437 .functionality = mv64xxx_i2c_functionality,
440}; 438};
@@ -523,7 +521,7 @@ mv64xxx_i2c_probe(struct device *dev)
523 drv_data->freq_m = pdata->freq_m; 521 drv_data->freq_m = pdata->freq_m;
524 drv_data->freq_n = pdata->freq_n; 522 drv_data->freq_n = pdata->freq_n;
525 drv_data->irq = platform_get_irq(pd, 0); 523 drv_data->irq = platform_get_irq(pd, 0);
526 drv_data->adapter.id = I2C_ALGO_MV64XXX | I2C_HW_MV64XXX; 524 drv_data->adapter.id = I2C_HW_MV64XXX;
527 drv_data->adapter.algo = &mv64xxx_i2c_algo; 525 drv_data->adapter.algo = &mv64xxx_i2c_algo;
528 drv_data->adapter.owner = THIS_MODULE; 526 drv_data->adapter.owner = THIS_MODULE;
529 drv_data->adapter.class = I2C_CLASS_HWMON; 527 drv_data->adapter.class = I2C_CLASS_HWMON;
diff --git a/drivers/i2c/busses/i2c-nforce2.c b/drivers/i2c/busses/i2c-nforce2.c
index 74eb89aa935..e0b7a913431 100644
--- a/drivers/i2c/busses/i2c-nforce2.c
+++ b/drivers/i2c/busses/i2c-nforce2.c
@@ -110,8 +110,6 @@ static u32 nforce2_func(struct i2c_adapter *adapter);
110 110
111 111
112static struct i2c_algorithm smbus_algorithm = { 112static struct i2c_algorithm smbus_algorithm = {
113 .name = "Non-I2C SMBus adapter",
114 .id = I2C_ALGO_SMBUS,
115 .smbus_xfer = nforce2_access, 113 .smbus_xfer = nforce2_access,
116 .functionality = nforce2_func, 114 .functionality = nforce2_func,
117}; 115};
@@ -131,7 +129,6 @@ static s32 nforce2_access(struct i2c_adapter * adap, u16 addr,
131 struct nforce2_smbus *smbus = adap->algo_data; 129 struct nforce2_smbus *smbus = adap->algo_data;
132 unsigned char protocol, pec, temp; 130 unsigned char protocol, pec, temp;
133 unsigned char len = 0; /* to keep the compiler quiet */ 131 unsigned char len = 0; /* to keep the compiler quiet */
134 int timeout = 0;
135 int i; 132 int i;
136 133
137 protocol = (read_write == I2C_SMBUS_READ) ? NVIDIA_SMB_PRTCL_READ : 134 protocol = (read_write == I2C_SMBUS_READ) ? NVIDIA_SMB_PRTCL_READ :
@@ -191,29 +188,10 @@ static s32 nforce2_access(struct i2c_adapter * adap, u16 addr,
191 case I2C_SMBUS_PROC_CALL: 188 case I2C_SMBUS_PROC_CALL:
192 dev_err(&adap->dev, "I2C_SMBUS_PROC_CALL not supported!\n"); 189 dev_err(&adap->dev, "I2C_SMBUS_PROC_CALL not supported!\n");
193 return -1; 190 return -1;
194 /*
195 outb_p(command, NVIDIA_SMB_CMD);
196 outb_p(data->word, NVIDIA_SMB_DATA);
197 outb_p(data->word >> 8, NVIDIA_SMB_DATA + 1);
198 protocol = NVIDIA_SMB_PRTCL_PROC_CALL | pec;
199 read_write = I2C_SMBUS_READ;
200 break;
201 */
202 191
203 case I2C_SMBUS_BLOCK_PROC_CALL: 192 case I2C_SMBUS_BLOCK_PROC_CALL:
204 dev_err(&adap->dev, "I2C_SMBUS_BLOCK_PROC_CALL not supported!\n"); 193 dev_err(&adap->dev, "I2C_SMBUS_BLOCK_PROC_CALL not supported!\n");
205 return -1; 194 return -1;
206 /*
207 protocol |= pec;
208 len = min_t(u8, data->block[0], 31);
209 outb_p(command, NVIDIA_SMB_CMD);
210 outb_p(len, NVIDIA_SMB_BCNT);
211 for (i = 0; i < len; i++)
212 outb_p(data->block[i + 1], NVIDIA_SMB_DATA + i);
213 protocol = NVIDIA_SMB_PRTCL_BLOCK_PROC_CALL | pec;
214 read_write = I2C_SMBUS_READ;
215 break;
216 */
217 195
218 case I2C_SMBUS_WORD_DATA_PEC: 196 case I2C_SMBUS_WORD_DATA_PEC:
219 case I2C_SMBUS_BLOCK_DATA_PEC: 197 case I2C_SMBUS_BLOCK_DATA_PEC:
@@ -232,12 +210,6 @@ static s32 nforce2_access(struct i2c_adapter * adap, u16 addr,
232 210
233 temp = inb_p(NVIDIA_SMB_STS); 211 temp = inb_p(NVIDIA_SMB_STS);
234 212
235#if 0
236 do {
237 i2c_do_pause(1);
238 temp = inb_p(NVIDIA_SMB_STS);
239 } while (((temp & NVIDIA_SMB_STS_DONE) == 0) && (timeout++ < MAX_TIMEOUT));
240#endif
241 if (~temp & NVIDIA_SMB_STS_DONE) { 213 if (~temp & NVIDIA_SMB_STS_DONE) {
242 udelay(500); 214 udelay(500);
243 temp = inb_p(NVIDIA_SMB_STS); 215 temp = inb_p(NVIDIA_SMB_STS);
@@ -247,9 +219,10 @@ static s32 nforce2_access(struct i2c_adapter * adap, u16 addr,
247 temp = inb_p(NVIDIA_SMB_STS); 219 temp = inb_p(NVIDIA_SMB_STS);
248 } 220 }
249 221
250 if ((timeout >= MAX_TIMEOUT) || (~temp & NVIDIA_SMB_STS_DONE) 222 if ((~temp & NVIDIA_SMB_STS_DONE) || (temp & NVIDIA_SMB_STS_STATUS)) {
251 || (temp & NVIDIA_SMB_STS_STATUS)) 223 dev_dbg(&adap->dev, "SMBus Timeout! (0x%02x)\n", temp);
252 return -1; 224 return -1;
225 }
253 226
254 if (read_write == I2C_SMBUS_WRITE) 227 if (read_write == I2C_SMBUS_WRITE)
255 return 0; 228 return 0;
diff --git a/drivers/i2c/busses/i2c-piix4.c b/drivers/i2c/busses/i2c-piix4.c
index 6d34ee381ce..6d48a4da7be 100644
--- a/drivers/i2c/busses/i2c-piix4.c
+++ b/drivers/i2c/busses/i2c-piix4.c
@@ -399,8 +399,6 @@ static u32 piix4_func(struct i2c_adapter *adapter)
399} 399}
400 400
401static struct i2c_algorithm smbus_algorithm = { 401static struct i2c_algorithm smbus_algorithm = {
402 .name = "Non-I2C SMBus adapter",
403 .id = I2C_ALGO_SMBUS,
404 .smbus_xfer = piix4_access, 402 .smbus_xfer = piix4_access,
405 .functionality = piix4_func, 403 .functionality = piix4_func,
406}; 404};
diff --git a/drivers/i2c/busses/i2c-s3c2410.c b/drivers/i2c/busses/i2c-s3c2410.c
index a3b38257cc3..73a092fb0e7 100644
--- a/drivers/i2c/busses/i2c-s3c2410.c
+++ b/drivers/i2c/busses/i2c-s3c2410.c
@@ -568,7 +568,6 @@ static u32 s3c24xx_i2c_func(struct i2c_adapter *adap)
568/* i2c bus registration info */ 568/* i2c bus registration info */
569 569
570static struct i2c_algorithm s3c24xx_i2c_algorithm = { 570static struct i2c_algorithm s3c24xx_i2c_algorithm = {
571 .name = "S3C2410-I2C-Algorithm",
572 .master_xfer = s3c24xx_i2c_xfer, 571 .master_xfer = s3c24xx_i2c_xfer,
573 .functionality = s3c24xx_i2c_func, 572 .functionality = s3c24xx_i2c_func,
574}; 573};
diff --git a/drivers/i2c/busses/i2c-sis5595.c b/drivers/i2c/busses/i2c-sis5595.c
index bbd5e4e52f0..080318d6f54 100644
--- a/drivers/i2c/busses/i2c-sis5595.c
+++ b/drivers/i2c/busses/i2c-sis5595.c
@@ -357,8 +357,6 @@ static u32 sis5595_func(struct i2c_adapter *adapter)
357} 357}
358 358
359static struct i2c_algorithm smbus_algorithm = { 359static struct i2c_algorithm smbus_algorithm = {
360 .name = "Non-I2C SMBus adapter",
361 .id = I2C_ALGO_SMBUS,
362 .smbus_xfer = sis5595_access, 360 .smbus_xfer = sis5595_access,
363 .functionality = sis5595_func, 361 .functionality = sis5595_func,
364}; 362};
diff --git a/drivers/i2c/busses/i2c-sis630.c b/drivers/i2c/busses/i2c-sis630.c
index f58455e7689..86f0f448fa0 100644
--- a/drivers/i2c/busses/i2c-sis630.c
+++ b/drivers/i2c/busses/i2c-sis630.c
@@ -448,8 +448,6 @@ exit:
448 448
449 449
450static struct i2c_algorithm smbus_algorithm = { 450static struct i2c_algorithm smbus_algorithm = {
451 .name = "Non-I2C SMBus adapter",
452 .id = I2C_ALGO_SMBUS,
453 .smbus_xfer = sis630_access, 451 .smbus_xfer = sis630_access,
454 .functionality = sis630_func, 452 .functionality = sis630_func,
455}; 453};
diff --git a/drivers/i2c/busses/i2c-sis96x.c b/drivers/i2c/busses/i2c-sis96x.c
index 6484792e23a..ead2ff3cf60 100644
--- a/drivers/i2c/busses/i2c-sis96x.c
+++ b/drivers/i2c/busses/i2c-sis96x.c
@@ -249,8 +249,6 @@ static u32 sis96x_func(struct i2c_adapter *adapter)
249} 249}
250 250
251static struct i2c_algorithm smbus_algorithm = { 251static struct i2c_algorithm smbus_algorithm = {
252 .name = "Non-I2C SMBus adapter",
253 .id = I2C_ALGO_SMBUS,
254 .smbus_xfer = sis96x_access, 252 .smbus_xfer = sis96x_access,
255 .functionality = sis96x_func, 253 .functionality = sis96x_func,
256}; 254};
diff --git a/drivers/i2c/busses/i2c-stub.c b/drivers/i2c/busses/i2c-stub.c
index 00d94e88695..73f481e93a3 100644
--- a/drivers/i2c/busses/i2c-stub.c
+++ b/drivers/i2c/busses/i2c-stub.c
@@ -109,8 +109,6 @@ static u32 stub_func(struct i2c_adapter *adapter)
109} 109}
110 110
111static struct i2c_algorithm smbus_algorithm = { 111static struct i2c_algorithm smbus_algorithm = {
112 .name = "Non-I2C SMBus adapter",
113 .id = I2C_ALGO_SMBUS,
114 .functionality = stub_func, 112 .functionality = stub_func,
115 .smbus_xfer = stub_xfer, 113 .smbus_xfer = stub_xfer,
116}; 114};
diff --git a/drivers/i2c/busses/i2c-viapro.c b/drivers/i2c/busses/i2c-viapro.c
index 6b5008005c6..99d209e0485 100644
--- a/drivers/i2c/busses/i2c-viapro.c
+++ b/drivers/i2c/busses/i2c-viapro.c
@@ -286,8 +286,6 @@ static u32 vt596_func(struct i2c_adapter *adapter)
286} 286}
287 287
288static struct i2c_algorithm smbus_algorithm = { 288static struct i2c_algorithm smbus_algorithm = {
289 .name = "Non-I2C SMBus adapter",
290 .id = I2C_ALGO_SMBUS,
291 .smbus_xfer = vt596_access, 289 .smbus_xfer = vt596_access,
292 .functionality = vt596_func, 290 .functionality = vt596_func,
293}; 291};
diff --git a/drivers/i2c/busses/scx200_acb.c b/drivers/i2c/busses/scx200_acb.c
index a18bdd9aa7b..a1d580e0536 100644
--- a/drivers/i2c/busses/scx200_acb.c
+++ b/drivers/i2c/busses/scx200_acb.c
@@ -395,8 +395,6 @@ static u32 scx200_acb_func(struct i2c_adapter *adapter)
395 395
396/* For now, we only handle combined mode (smbus) */ 396/* For now, we only handle combined mode (smbus) */
397static struct i2c_algorithm scx200_acb_algorithm = { 397static struct i2c_algorithm scx200_acb_algorithm = {
398 .name = "NatSemi SCx200 ACCESS.bus",
399 .id = I2C_ALGO_SMBUS,
400 .smbus_xfer = scx200_acb_smbus_xfer, 398 .smbus_xfer = scx200_acb_smbus_xfer,
401 .functionality = scx200_acb_func, 399 .functionality = scx200_acb_func,
402}; 400};
@@ -456,7 +454,7 @@ static int __init scx200_acb_create(int base, int index)
456 i2c_set_adapdata(adapter, iface); 454 i2c_set_adapdata(adapter, iface);
457 snprintf(adapter->name, I2C_NAME_SIZE, "SCx200 ACB%d", index); 455 snprintf(adapter->name, I2C_NAME_SIZE, "SCx200 ACB%d", index);
458 adapter->owner = THIS_MODULE; 456 adapter->owner = THIS_MODULE;
459 adapter->id = I2C_ALGO_SMBUS; 457 adapter->id = I2C_HW_SMBUS_SCX200;
460 adapter->algo = &scx200_acb_algorithm; 458 adapter->algo = &scx200_acb_algorithm;
461 adapter->class = I2C_CLASS_HWMON; 459 adapter->class = I2C_CLASS_HWMON;
462 460
diff --git a/drivers/i2c/chips/Kconfig b/drivers/i2c/chips/Kconfig
index 43f70dbfc03..6bd44a44cd2 100644
--- a/drivers/i2c/chips/Kconfig
+++ b/drivers/i2c/chips/Kconfig
@@ -2,17 +2,12 @@
2# Miscellaneous I2C chip drivers configuration 2# Miscellaneous I2C chip drivers configuration
3# 3#
4 4
5config I2C_SENSOR
6 tristate
7 default n
8
9menu "Miscellaneous I2C Chip support" 5menu "Miscellaneous I2C Chip support"
10 depends on I2C 6 depends on I2C
11 7
12config SENSORS_DS1337 8config SENSORS_DS1337
13 tristate "Dallas Semiconductor DS1337 and DS1339 Real Time Clock" 9 tristate "Dallas Semiconductor DS1337 and DS1339 Real Time Clock"
14 depends on I2C && EXPERIMENTAL 10 depends on I2C && EXPERIMENTAL
15 select I2C_SENSOR
16 help 11 help
17 If you say yes here you get support for Dallas Semiconductor 12 If you say yes here you get support for Dallas Semiconductor
18 DS1337 and DS1339 real-time clock chips. 13 DS1337 and DS1339 real-time clock chips.
@@ -23,7 +18,6 @@ config SENSORS_DS1337
23config SENSORS_DS1374 18config SENSORS_DS1374
24 tristate "Maxim/Dallas Semiconductor DS1374 Real Time Clock" 19 tristate "Maxim/Dallas Semiconductor DS1374 Real Time Clock"
25 depends on I2C && EXPERIMENTAL 20 depends on I2C && EXPERIMENTAL
26 select I2C_SENSOR
27 help 21 help
28 If you say yes here you get support for Dallas Semiconductor 22 If you say yes here you get support for Dallas Semiconductor
29 DS1374 real-time clock chips. 23 DS1374 real-time clock chips.
@@ -34,7 +28,6 @@ config SENSORS_DS1374
34config SENSORS_EEPROM 28config SENSORS_EEPROM
35 tristate "EEPROM reader" 29 tristate "EEPROM reader"
36 depends on I2C && EXPERIMENTAL 30 depends on I2C && EXPERIMENTAL
37 select I2C_SENSOR
38 help 31 help
39 If you say yes here you get read-only access to the EEPROM data 32 If you say yes here you get read-only access to the EEPROM data
40 available on modern memory DIMMs and Sony Vaio laptops. Such 33 available on modern memory DIMMs and Sony Vaio laptops. Such
@@ -46,7 +39,6 @@ config SENSORS_EEPROM
46config SENSORS_PCF8574 39config SENSORS_PCF8574
47 tristate "Philips PCF8574 and PCF8574A" 40 tristate "Philips PCF8574 and PCF8574A"
48 depends on I2C && EXPERIMENTAL 41 depends on I2C && EXPERIMENTAL
49 select I2C_SENSOR
50 help 42 help
51 If you say yes here you get support for Philips PCF8574 and 43 If you say yes here you get support for Philips PCF8574 and
52 PCF8574A chips. 44 PCF8574A chips.
@@ -67,7 +59,6 @@ config SENSORS_PCA9539
67config SENSORS_PCF8591 59config SENSORS_PCF8591
68 tristate "Philips PCF8591" 60 tristate "Philips PCF8591"
69 depends on I2C && EXPERIMENTAL 61 depends on I2C && EXPERIMENTAL
70 select I2C_SENSOR
71 help 62 help
72 If you say yes here you get support for Philips PCF8591 chips. 63 If you say yes here you get support for Philips PCF8591 chips.
73 64
@@ -77,7 +68,6 @@ config SENSORS_PCF8591
77config SENSORS_RTC8564 68config SENSORS_RTC8564
78 tristate "Epson 8564 RTC chip" 69 tristate "Epson 8564 RTC chip"
79 depends on I2C && EXPERIMENTAL 70 depends on I2C && EXPERIMENTAL
80 select I2C_SENSOR
81 help 71 help
82 If you say yes here you get support for the Epson 8564 RTC chip. 72 If you say yes here you get support for the Epson 8564 RTC chip.
83 73
diff --git a/drivers/i2c/chips/ds1337.c b/drivers/i2c/chips/ds1337.c
index 82cf959989f..9d3175c0339 100644
--- a/drivers/i2c/chips/ds1337.c
+++ b/drivers/i2c/chips/ds1337.c
@@ -17,7 +17,6 @@
17#include <linux/init.h> 17#include <linux/init.h>
18#include <linux/slab.h> 18#include <linux/slab.h>
19#include <linux/i2c.h> 19#include <linux/i2c.h>
20#include <linux/i2c-sensor.h>
21#include <linux/string.h> 20#include <linux/string.h>
22#include <linux/rtc.h> /* get the user-level API */ 21#include <linux/rtc.h> /* get the user-level API */
23#include <linux/bcd.h> 22#include <linux/bcd.h>
@@ -39,9 +38,8 @@
39 * Functions declaration 38 * Functions declaration
40 */ 39 */
41static unsigned short normal_i2c[] = { 0x68, I2C_CLIENT_END }; 40static unsigned short normal_i2c[] = { 0x68, I2C_CLIENT_END };
42static unsigned int normal_isa[] = { I2C_CLIENT_ISA_END };
43 41
44SENSORS_INSMOD_1(ds1337); 42I2C_CLIENT_INSMOD_1(ds1337);
45 43
46static int ds1337_attach_adapter(struct i2c_adapter *adapter); 44static int ds1337_attach_adapter(struct i2c_adapter *adapter);
47static int ds1337_detect(struct i2c_adapter *adapter, int address, int kind); 45static int ds1337_detect(struct i2c_adapter *adapter, int address, int kind);
@@ -227,7 +225,7 @@ int ds1337_do_command(int bus, int cmd, void *arg)
227 225
228static int ds1337_attach_adapter(struct i2c_adapter *adapter) 226static int ds1337_attach_adapter(struct i2c_adapter *adapter)
229{ 227{
230 return i2c_detect(adapter, &addr_data, ds1337_detect); 228 return i2c_probe(adapter, &addr_data, ds1337_detect);
231} 229}
232 230
233/* 231/*
@@ -354,11 +352,8 @@ static int ds1337_detach_client(struct i2c_client *client)
354 int err; 352 int err;
355 struct ds1337_data *data = i2c_get_clientdata(client); 353 struct ds1337_data *data = i2c_get_clientdata(client);
356 354
357 if ((err = i2c_detach_client(client))) { 355 if ((err = i2c_detach_client(client)))
358 dev_err(&client->dev, "Client deregistration failed, "
359 "client not detached.\n");
360 return err; 356 return err;
361 }
362 357
363 list_del(&data->list); 358 list_del(&data->list);
364 kfree(data); 359 kfree(data);
diff --git a/drivers/i2c/chips/ds1374.c b/drivers/i2c/chips/ds1374.c
index a445736d883..0936327a946 100644
--- a/drivers/i2c/chips/ds1374.c
+++ b/drivers/i2c/chips/ds1374.c
@@ -53,7 +53,6 @@ static struct i2c_client_address_data addr_data = {
53 .normal_i2c = normal_addr, 53 .normal_i2c = normal_addr,
54 .probe = ignore, 54 .probe = ignore,
55 .ignore = ignore, 55 .ignore = ignore,
56 .force = ignore,
57}; 56};
58 57
59static ulong ds1374_read_rtc(void) 58static ulong ds1374_read_rtc(void)
@@ -166,7 +165,7 @@ static void ds1374_set_tlet(ulong arg)
166 "can't confirm time set from rtc chip\n"); 165 "can't confirm time set from rtc chip\n");
167} 166}
168 167
169ulong new_time; 168static ulong new_time;
170 169
171DECLARE_TASKLET_DISABLED(ds1374_tasklet, ds1374_set_tlet, (ulong) & new_time); 170DECLARE_TASKLET_DISABLED(ds1374_tasklet, ds1374_set_tlet, (ulong) & new_time);
172 171
diff --git a/drivers/i2c/chips/eeprom.c b/drivers/i2c/chips/eeprom.c
index a2da31b0dd7..d58403a4790 100644
--- a/drivers/i2c/chips/eeprom.c
+++ b/drivers/i2c/chips/eeprom.c
@@ -33,15 +33,13 @@
33#include <linux/sched.h> 33#include <linux/sched.h>
34#include <linux/jiffies.h> 34#include <linux/jiffies.h>
35#include <linux/i2c.h> 35#include <linux/i2c.h>
36#include <linux/i2c-sensor.h>
37 36
38/* Addresses to scan */ 37/* Addresses to scan */
39static unsigned short normal_i2c[] = { 0x50, 0x51, 0x52, 0x53, 0x54, 38static unsigned short normal_i2c[] = { 0x50, 0x51, 0x52, 0x53, 0x54,
40 0x55, 0x56, 0x57, I2C_CLIENT_END }; 39 0x55, 0x56, 0x57, I2C_CLIENT_END };
41static unsigned int normal_isa[] = { I2C_CLIENT_ISA_END };
42 40
43/* Insmod parameters */ 41/* Insmod parameters */
44SENSORS_INSMOD_1(eeprom); 42I2C_CLIENT_INSMOD_1(eeprom);
45 43
46 44
47/* Size of EEPROM in bytes */ 45/* Size of EEPROM in bytes */
@@ -153,21 +151,16 @@ static struct bin_attribute eeprom_attr = {
153 151
154static int eeprom_attach_adapter(struct i2c_adapter *adapter) 152static int eeprom_attach_adapter(struct i2c_adapter *adapter)
155{ 153{
156 return i2c_detect(adapter, &addr_data, eeprom_detect); 154 return i2c_probe(adapter, &addr_data, eeprom_detect);
157} 155}
158 156
159/* This function is called by i2c_detect */ 157/* This function is called by i2c_probe */
160int eeprom_detect(struct i2c_adapter *adapter, int address, int kind) 158int eeprom_detect(struct i2c_adapter *adapter, int address, int kind)
161{ 159{
162 struct i2c_client *new_client; 160 struct i2c_client *new_client;
163 struct eeprom_data *data; 161 struct eeprom_data *data;
164 int err = 0; 162 int err = 0;
165 163
166 /* prevent 24RF08 corruption */
167 if (kind < 0)
168 i2c_smbus_xfer(adapter, address, 0, 0, 0,
169 I2C_SMBUS_QUICK, NULL);
170
171 /* There are three ways we can read the EEPROM data: 164 /* There are three ways we can read the EEPROM data:
172 (1) I2C block reads (faster, but unsupported by most adapters) 165 (1) I2C block reads (faster, but unsupported by most adapters)
173 (2) Consecutive byte reads (100% overhead) 166 (2) Consecutive byte reads (100% overhead)
@@ -231,10 +224,8 @@ static int eeprom_detach_client(struct i2c_client *client)
231 int err; 224 int err;
232 225
233 err = i2c_detach_client(client); 226 err = i2c_detach_client(client);
234 if (err) { 227 if (err)
235 dev_err(&client->dev, "Client deregistration failed, client not detached.\n");
236 return err; 228 return err;
237 }
238 229
239 kfree(i2c_get_clientdata(client)); 230 kfree(i2c_get_clientdata(client));
240 231
diff --git a/drivers/i2c/chips/isp1301_omap.c b/drivers/i2c/chips/isp1301_omap.c
index 354a2629567..8ee56d4b389 100644
--- a/drivers/i2c/chips/isp1301_omap.c
+++ b/drivers/i2c/chips/isp1301_omap.c
@@ -1489,7 +1489,7 @@ static int isp1301_probe(struct i2c_adapter *bus, int address, int kind)
1489 if (the_transceiver) 1489 if (the_transceiver)
1490 return 0; 1490 return 0;
1491 1491
1492 isp = kcalloc(1, sizeof *isp, GFP_KERNEL); 1492 isp = kzalloc(sizeof *isp, GFP_KERNEL);
1493 if (!isp) 1493 if (!isp)
1494 return 0; 1494 return 0;
1495 1495
diff --git a/drivers/i2c/chips/m41t00.c b/drivers/i2c/chips/m41t00.c
index 778d7e12859..3f14528a52a 100644
--- a/drivers/i2c/chips/m41t00.c
+++ b/drivers/i2c/chips/m41t00.c
@@ -42,7 +42,6 @@ static struct i2c_client_address_data addr_data = {
42 .normal_i2c = normal_addr, 42 .normal_i2c = normal_addr,
43 .probe = ignore, 43 .probe = ignore,
44 .ignore = ignore, 44 .ignore = ignore,
45 .force = ignore,
46}; 45};
47 46
48ulong 47ulong
@@ -145,7 +144,7 @@ m41t00_set_tlet(ulong arg)
145 return; 144 return;
146} 145}
147 146
148ulong new_time; 147static ulong new_time;
149 148
150DECLARE_TASKLET_DISABLED(m41t00_tasklet, m41t00_set_tlet, (ulong)&new_time); 149DECLARE_TASKLET_DISABLED(m41t00_tasklet, m41t00_set_tlet, (ulong)&new_time);
151 150
diff --git a/drivers/i2c/chips/max6875.c b/drivers/i2c/chips/max6875.c
index 0230375f72e..9e1aeb69abf 100644
--- a/drivers/i2c/chips/max6875.c
+++ b/drivers/i2c/chips/max6875.c
@@ -5,97 +5,60 @@
5 5
6 Based on i2c/chips/eeprom.c 6 Based on i2c/chips/eeprom.c
7 7
8 The MAX6875 has two EEPROM sections: config and user. 8 The MAX6875 has a bank of registers and two banks of EEPROM.
9 At reset, the config EEPROM is read into the registers. 9 Address ranges are defined as follows:
10 * 0x0000 - 0x0046 = configuration registers
11 * 0x8000 - 0x8046 = configuration EEPROM
12 * 0x8100 - 0x82FF = user EEPROM
10 13
11 This driver make 3 binary files available in sysfs: 14 This driver makes the user EEPROM available for read.
12 reg_config - direct access to the registers
13 eeprom_config - acesses configuration eeprom space
14 eeprom_user - free for application use
15 15
16 In our application, we put device serial & model numbers in user eeprom. 16 The registers & config EEPROM should be accessed via i2c-dev.
17 17
18 Notes: 18 The MAX6875 ignores the lowest address bit, so each chip responds to
19 1) The datasheet says that register 0x44 / EEPROM 0x8044 should NOT 19 two addresses - 0x50/0x51 and 0x52/0x53.
20 be overwritten, so the driver explicitly prevents that. 20
21 2) It's a good idea to keep the config (0x45) locked in config EEPROM. 21 Note that the MAX6875 uses i2c_smbus_write_byte_data() to set the read
22 You can temporarily enable config writes by changing register 0x45. 22 address, so this driver is destructive if loaded for the wrong EEPROM chip.
23 23
24 This program is free software; you can redistribute it and/or modify 24 This program is free software; you can redistribute it and/or modify
25 it under the terms of the GNU General Public License as published by 25 it under the terms of the GNU General Public License as published by
26 the Free Software Foundation; version 2 of the License. 26 the Free Software Foundation; version 2 of the License.
27*/ 27*/
28 28
29#include <linux/config.h>
30#include <linux/kernel.h> 29#include <linux/kernel.h>
31#include <linux/init.h> 30#include <linux/init.h>
32#include <linux/module.h> 31#include <linux/module.h>
33#include <linux/slab.h> 32#include <linux/slab.h>
34#include <linux/sched.h>
35#include <linux/delay.h>
36#include <linux/i2c.h> 33#include <linux/i2c.h>
37#include <linux/i2c-sensor.h> 34#include <asm/semaphore.h>
38 35
39/* Addresses to scan */ 36/* Do not scan - the MAX6875 access method will write to some EEPROM chips */
40/* No address scanned by default, as this could corrupt standard EEPROMS. */
41static unsigned short normal_i2c[] = {I2C_CLIENT_END}; 37static unsigned short normal_i2c[] = {I2C_CLIENT_END};
42static unsigned int normal_isa[] = {I2C_CLIENT_ISA_END};
43 38
44/* Insmod parameters */ 39/* Insmod parameters */
45SENSORS_INSMOD_1(max6875); 40I2C_CLIENT_INSMOD_1(max6875);
46
47/* this param will prevent 'accidental' writes to the eeprom */
48static int allow_write = 0;
49module_param(allow_write, int, 0);
50MODULE_PARM_DESC(allow_write,
51 "Enable write access:\n"
52 "*0: Read only\n"
53 " 1: Read/Write access");
54 41
55/* The MAX6875 can only read/write 16 bytes at a time */ 42/* The MAX6875 can only read/write 16 bytes at a time */
56#define SLICE_SIZE 16 43#define SLICE_SIZE 16
57#define SLICE_BITS 4 44#define SLICE_BITS 4
58 45
59/* CONFIG EEPROM is at addresses 0x8000 - 0x8045, registers are at 0 - 0x45 */
60#define CONFIG_EEPROM_BASE 0x8000
61#define CONFIG_EEPROM_SIZE 0x0046
62#define CONFIG_EEPROM_SLICES 5
63
64/* USER EEPROM is at addresses 0x8100 - 0x82FF */ 46/* USER EEPROM is at addresses 0x8100 - 0x82FF */
65#define USER_EEPROM_BASE 0x8100 47#define USER_EEPROM_BASE 0x8100
66#define USER_EEPROM_SIZE 0x0200 48#define USER_EEPROM_SIZE 0x0200
67#define USER_EEPROM_SLICES 32 49#define USER_EEPROM_SLICES 32
68 50
69/* MAX6875 commands */ 51/* MAX6875 commands */
70#define MAX6875_CMD_BLOCK_WRITE 0x83 52#define MAX6875_CMD_BLK_READ 0x84
71#define MAX6875_CMD_BLOCK_READ 0x84
72#define MAX6875_CMD_REBOOT 0x88
73
74enum max6875_area_type {
75 max6875_register_config=0,
76 max6875_eeprom_config,
77 max6875_eeprom_user,
78 max6857_max
79};
80
81struct eeprom_block {
82 enum max6875_area_type type;
83 u8 slices;
84 u32 size;
85 u32 valid;
86 u32 base;
87 unsigned long *updated;
88 u8 *data;
89};
90 53
91/* Each client has this additional data */ 54/* Each client has this additional data */
92struct max6875_data { 55struct max6875_data {
93 struct i2c_client client; 56 struct i2c_client client;
94 struct semaphore update_lock; 57 struct semaphore update_lock;
95 struct eeprom_block blocks[max6857_max]; 58
96 /* the above structs point into the arrays below */ 59 u32 valid;
97 u8 data[USER_EEPROM_SIZE + (CONFIG_EEPROM_SIZE*2)]; 60 u8 data[USER_EEPROM_SIZE];
98 unsigned long last_updated[USER_EEPROM_SLICES + (CONFIG_EEPROM_SLICES*2)]; 61 unsigned long last_updated[USER_EEPROM_SLICES];
99}; 62};
100 63
101static int max6875_attach_adapter(struct i2c_adapter *adapter); 64static int max6875_attach_adapter(struct i2c_adapter *adapter);
@@ -111,337 +74,160 @@ static struct i2c_driver max6875_driver = {
111 .detach_client = max6875_detach_client, 74 .detach_client = max6875_detach_client,
112}; 75};
113 76
114static int max6875_update_slice(struct i2c_client *client, 77static void max6875_update_slice(struct i2c_client *client, int slice)
115 struct eeprom_block *blk,
116 int slice)
117{ 78{
118 struct max6875_data *data = i2c_get_clientdata(client); 79 struct max6875_data *data = i2c_get_clientdata(client);
119 int i, j, addr, count; 80 int i, j, addr;
120 u8 rdbuf[SLICE_SIZE]; 81 u8 *buf;
121 int retval = 0;
122 82
123 if (slice >= blk->slices) 83 if (slice >= USER_EEPROM_SLICES)
124 return -1; 84 return;
125 85
126 down(&data->update_lock); 86 down(&data->update_lock);
127 87
128 if (!(blk->valid & (1 << slice)) || 88 buf = &data->data[slice << SLICE_BITS];
129 (jiffies - blk->updated[slice] > 300 * HZ) ||
130 (jiffies < blk->updated[slice])) {
131 dev_dbg(&client->dev, "Starting eeprom update, slice %u, base %u\n",
132 slice, blk->base);
133 89
134 addr = blk->base + (slice << SLICE_BITS); 90 if (!(data->valid & (1 << slice)) ||
135 count = blk->size - (slice << SLICE_BITS); 91 time_after(jiffies, data->last_updated[slice])) {
136 if (count > SLICE_SIZE) {
137 count = SLICE_SIZE;
138 }
139 92
140 /* Preset the read address */ 93 dev_dbg(&client->dev, "Starting update of slice %u\n", slice);
141 if (addr < 0x100) { 94
142 /* select the register */ 95 data->valid &= ~(1 << slice);
143 if (i2c_smbus_write_byte(client, addr & 0xFF)) { 96
144 dev_dbg(&client->dev, "max6875 register select has failed!\n"); 97 addr = USER_EEPROM_BASE + (slice << SLICE_BITS);
145 retval = -1; 98
146 goto exit; 99 /* select the eeprom address */
147 } 100 if (i2c_smbus_write_byte_data(client, addr >> 8, addr & 0xFF)) {
148 } else { 101 dev_err(&client->dev, "address set failed\n");
149 /* select the eeprom */ 102 goto exit_up;
150 if (i2c_smbus_write_byte_data(client, addr >> 8, addr & 0xFF)) {
151 dev_dbg(&client->dev, "max6875 address set has failed!\n");
152 retval = -1;
153 goto exit;
154 }
155 } 103 }
156 104
157 if (i2c_check_functionality(client->adapter, I2C_FUNC_SMBUS_READ_I2C_BLOCK)) { 105 if (i2c_check_functionality(client->adapter,
158 if (i2c_smbus_read_i2c_block_data(client, MAX6875_CMD_BLOCK_READ, 106 I2C_FUNC_SMBUS_READ_I2C_BLOCK)) {
159 rdbuf) != SLICE_SIZE) 107 if (i2c_smbus_read_i2c_block_data(client,
160 { 108 MAX6875_CMD_BLK_READ,
161 retval = -1; 109 buf) != SLICE_SIZE) {
162 goto exit; 110 goto exit_up;
163 } 111 }
164
165 memcpy(&blk->data[slice << SLICE_BITS], rdbuf, count);
166 } else { 112 } else {
167 for (i = 0; i < count; i++) { 113 for (i = 0; i < SLICE_SIZE; i++) {
168 j = i2c_smbus_read_byte(client); 114 j = i2c_smbus_read_byte(client);
169 if (j < 0) 115 if (j < 0) {
170 { 116 goto exit_up;
171 retval = -1;
172 goto exit;
173 } 117 }
174 blk->data[(slice << SLICE_BITS) + i] = (u8) j; 118 buf[i] = j;
175 } 119 }
176 } 120 }
177 blk->updated[slice] = jiffies; 121 data->last_updated[slice] = jiffies;
178 blk->valid |= (1 << slice); 122 data->valid |= (1 << slice);
179 } 123 }
180 exit: 124exit_up:
181 up(&data->update_lock); 125 up(&data->update_lock);
182 return retval;
183} 126}
184 127
185static ssize_t max6875_read(struct kobject *kobj, char *buf, loff_t off, size_t count, 128static ssize_t max6875_read(struct kobject *kobj, char *buf, loff_t off,
186 enum max6875_area_type area_type) 129 size_t count)
187{ 130{
188 struct i2c_client *client = to_i2c_client(container_of(kobj, struct device, kobj)); 131 struct i2c_client *client = kobj_to_i2c_client(kobj);
189 struct max6875_data *data = i2c_get_clientdata(client); 132 struct max6875_data *data = i2c_get_clientdata(client);
190 struct eeprom_block *blk; 133 int slice, max_slice;
191 int slice;
192
193 blk = &data->blocks[area_type];
194 134
195 if (off > blk->size) 135 if (off > USER_EEPROM_SIZE)
196 return 0; 136 return 0;
197 if (off + count > blk->size)
198 count = blk->size - off;
199 137
200 /* Only refresh slices which contain requested bytes */ 138 if (off + count > USER_EEPROM_SIZE)
201 for (slice = (off >> SLICE_BITS); slice <= ((off + count - 1) >> SLICE_BITS); slice++) 139 count = USER_EEPROM_SIZE - off;
202 max6875_update_slice(client, blk, slice);
203 140
204 memcpy(buf, &blk->data[off], count); 141 /* refresh slices which contain requested bytes */
142 max_slice = (off + count - 1) >> SLICE_BITS;
143 for (slice = (off >> SLICE_BITS); slice <= max_slice; slice++)
144 max6875_update_slice(client, slice);
205 145
206 return count; 146 memcpy(buf, &data->data[off], count);
207}
208
209static ssize_t max6875_user_read(struct kobject *kobj, char *buf, loff_t off, size_t count)
210{
211 return max6875_read(kobj, buf, off, count, max6875_eeprom_user);
212}
213
214static ssize_t max6875_config_read(struct kobject *kobj, char *buf, loff_t off, size_t count)
215{
216 return max6875_read(kobj, buf, off, count, max6875_eeprom_config);
217}
218
219static ssize_t max6875_cfgreg_read(struct kobject *kobj, char *buf, loff_t off, size_t count)
220{
221 return max6875_read(kobj, buf, off, count, max6875_register_config);
222}
223
224
225static ssize_t max6875_write(struct kobject *kobj, char *buf, loff_t off, size_t count,
226 enum max6875_area_type area_type)
227{
228 struct i2c_client *client = to_i2c_client(container_of(kobj, struct device, kobj));
229 struct max6875_data *data = i2c_get_clientdata(client);
230 struct eeprom_block *blk;
231 int slice, addr, retval;
232 ssize_t sent = 0;
233
234 blk = &data->blocks[area_type];
235
236 if (off > blk->size)
237 return 0;
238 if ((off + count) > blk->size)
239 count = blk->size - off;
240
241 if (down_interruptible(&data->update_lock))
242 return -EAGAIN;
243
244 /* writing to a register is done with i2c_smbus_write_byte_data() */
245 if (blk->type == max6875_register_config) {
246 for (sent = 0; sent < count; sent++) {
247 addr = off + sent;
248 if (addr == 0x44)
249 continue;
250
251 retval = i2c_smbus_write_byte_data(client, addr, buf[sent]);
252 }
253 } else {
254 int cmd, val;
255
256 /* We are writing to EEPROM */
257 for (sent = 0; sent < count; sent++) {
258 addr = blk->base + off + sent;
259 cmd = addr >> 8;
260 val = (addr & 0xff) | (buf[sent] << 8); // reversed
261
262 if (addr == 0x8044)
263 continue;
264
265 retval = i2c_smbus_write_word_data(client, cmd, val);
266
267 if (retval) {
268 goto error_exit;
269 }
270 147
271 /* A write takes up to 11 ms */ 148 return count;
272 msleep(11);
273 }
274 }
275
276 /* Invalidate the scratch buffer */
277 for (slice = (off >> SLICE_BITS); slice <= ((off + count - 1) >> SLICE_BITS); slice++)
278 blk->valid &= ~(1 << slice);
279
280 error_exit:
281 up(&data->update_lock);
282
283 return sent;
284}
285
286static ssize_t max6875_user_write(struct kobject *kobj, char *buf, loff_t off, size_t count)
287{
288 return max6875_write(kobj, buf, off, count, max6875_eeprom_user);
289}
290
291static ssize_t max6875_config_write(struct kobject *kobj, char *buf, loff_t off, size_t count)
292{
293 return max6875_write(kobj, buf, off, count, max6875_eeprom_config);
294}
295
296static ssize_t max6875_cfgreg_write(struct kobject *kobj, char *buf, loff_t off, size_t count)
297{
298 return max6875_write(kobj, buf, off, count, max6875_register_config);
299} 149}
300 150
301static struct bin_attribute user_eeprom_attr = { 151static struct bin_attribute user_eeprom_attr = {
302 .attr = { 152 .attr = {
303 .name = "eeprom_user", 153 .name = "eeprom",
304 .mode = S_IRUGO | S_IWUSR | S_IWGRP, 154 .mode = S_IRUGO,
305 .owner = THIS_MODULE,
306 },
307 .size = USER_EEPROM_SIZE,
308 .read = max6875_user_read,
309 .write = max6875_user_write,
310};
311
312static struct bin_attribute config_eeprom_attr = {
313 .attr = {
314 .name = "eeprom_config",
315 .mode = S_IRUGO | S_IWUSR,
316 .owner = THIS_MODULE,
317 },
318 .size = CONFIG_EEPROM_SIZE,
319 .read = max6875_config_read,
320 .write = max6875_config_write,
321};
322
323static struct bin_attribute config_register_attr = {
324 .attr = {
325 .name = "reg_config",
326 .mode = S_IRUGO | S_IWUSR,
327 .owner = THIS_MODULE, 155 .owner = THIS_MODULE,
328 }, 156 },
329 .size = CONFIG_EEPROM_SIZE, 157 .size = USER_EEPROM_SIZE,
330 .read = max6875_cfgreg_read, 158 .read = max6875_read,
331 .write = max6875_cfgreg_write,
332}; 159};
333 160
334static int max6875_attach_adapter(struct i2c_adapter *adapter) 161static int max6875_attach_adapter(struct i2c_adapter *adapter)
335{ 162{
336 return i2c_detect(adapter, &addr_data, max6875_detect); 163 return i2c_probe(adapter, &addr_data, max6875_detect);
337} 164}
338 165
339/* This function is called by i2c_detect */ 166/* This function is called by i2c_probe */
340static int max6875_detect(struct i2c_adapter *adapter, int address, int kind) 167static int max6875_detect(struct i2c_adapter *adapter, int address, int kind)
341{ 168{
342 struct i2c_client *new_client; 169 struct i2c_client *real_client;
170 struct i2c_client *fake_client;
343 struct max6875_data *data; 171 struct max6875_data *data;
344 int err = 0; 172 int err = 0;
345 173
346 /* Prevent 24RF08 corruption (in case of user error) */ 174 if (!i2c_check_functionality(adapter, I2C_FUNC_SMBUS_WRITE_BYTE_DATA
347 if (kind < 0) 175 | I2C_FUNC_SMBUS_READ_BYTE))
348 i2c_smbus_xfer(adapter, address, 0, 0, 0, 176 return 0;
349 I2C_SMBUS_QUICK, NULL); 177
350 178 /* Only check even addresses */
351 /* There are three ways we can read the EEPROM data: 179 if (address & 1)
352 (1) I2C block reads (faster, but unsupported by most adapters) 180 return 0;
353 (2) Consecutive byte reads (100% overhead) 181
354 (3) Regular byte data reads (200% overhead) 182 if (!(data = kmalloc(sizeof(struct max6875_data), GFP_KERNEL)))
355 The third method is not implemented by this driver because all 183 return -ENOMEM;
356 known adapters support at least the second. */
357 if (!i2c_check_functionality(adapter, I2C_FUNC_SMBUS_READ_BYTE_DATA |
358 I2C_FUNC_SMBUS_BYTE |
359 I2C_FUNC_SMBUS_WRITE_BYTE_DATA))
360 goto exit;
361
362 /* OK. For now, we presume we have a valid client. We now create the
363 client structure, even though we cannot fill it completely yet.
364 But it allows us to access eeprom_{read,write}_value. */
365 if (!(data = kmalloc(sizeof(struct max6875_data), GFP_KERNEL))) {
366 err = -ENOMEM;
367 goto exit;
368 }
369 memset(data, 0, sizeof(struct max6875_data)); 184 memset(data, 0, sizeof(struct max6875_data));
370 185
371 new_client = &data->client; 186 /* A fake client is created on the odd address */
372 i2c_set_clientdata(new_client, data); 187 if (!(fake_client = kmalloc(sizeof(struct i2c_client), GFP_KERNEL))) {
373 new_client->addr = address; 188 err = -ENOMEM;
374 new_client->adapter = adapter; 189 goto exit_kfree1;
375 new_client->driver = &max6875_driver; 190 }
376 new_client->flags = 0; 191 memset(fake_client, 0, sizeof(struct i2c_client));
377 192
378 /* Setup the user section */ 193 /* Init real i2c_client */
379 data->blocks[max6875_eeprom_user].type = max6875_eeprom_user; 194 real_client = &data->client;
380 data->blocks[max6875_eeprom_user].slices = USER_EEPROM_SLICES; 195 i2c_set_clientdata(real_client, data);
381 data->blocks[max6875_eeprom_user].size = USER_EEPROM_SIZE; 196 real_client->addr = address;
382 data->blocks[max6875_eeprom_user].base = USER_EEPROM_BASE; 197 real_client->adapter = adapter;
383 data->blocks[max6875_eeprom_user].data = data->data; 198 real_client->driver = &max6875_driver;
384 data->blocks[max6875_eeprom_user].updated = data->last_updated; 199 real_client->flags = 0;
385 200 strlcpy(real_client->name, "max6875", I2C_NAME_SIZE);
386 /* Setup the config section */
387 data->blocks[max6875_eeprom_config].type = max6875_eeprom_config;
388 data->blocks[max6875_eeprom_config].slices = CONFIG_EEPROM_SLICES;
389 data->blocks[max6875_eeprom_config].size = CONFIG_EEPROM_SIZE;
390 data->blocks[max6875_eeprom_config].base = CONFIG_EEPROM_BASE;
391 data->blocks[max6875_eeprom_config].data = &data->data[USER_EEPROM_SIZE];
392 data->blocks[max6875_eeprom_config].updated = &data->last_updated[USER_EEPROM_SLICES];
393
394 /* Setup the register section */
395 data->blocks[max6875_register_config].type = max6875_register_config;
396 data->blocks[max6875_register_config].slices = CONFIG_EEPROM_SLICES;
397 data->blocks[max6875_register_config].size = CONFIG_EEPROM_SIZE;
398 data->blocks[max6875_register_config].base = 0;
399 data->blocks[max6875_register_config].data = &data->data[USER_EEPROM_SIZE+CONFIG_EEPROM_SIZE];
400 data->blocks[max6875_register_config].updated = &data->last_updated[USER_EEPROM_SLICES+CONFIG_EEPROM_SLICES];
401
402 /* Init the data */
403 memset(data->data, 0xff, sizeof(data->data));
404
405 /* Fill in the remaining client fields */
406 strlcpy(new_client->name, "max6875", I2C_NAME_SIZE);
407 init_MUTEX(&data->update_lock); 201 init_MUTEX(&data->update_lock);
408 202
409 /* Verify that the chip is really what we think it is */ 203 /* Init fake client data */
410 if ((max6875_update_slice(new_client, &data->blocks[max6875_eeprom_config], 4) < 0) || 204 /* set the client data to the i2c_client so that it will get freed */
411 (max6875_update_slice(new_client, &data->blocks[max6875_register_config], 4) < 0)) 205 i2c_set_clientdata(fake_client, fake_client);
412 goto exit_kfree; 206 fake_client->addr = address | 1;
413 207 fake_client->adapter = adapter;
414 /* 0x41,0x42 must be zero and 0x40 must match in eeprom and registers */ 208 fake_client->driver = &max6875_driver;
415 if ((data->blocks[max6875_eeprom_config].data[0x41] != 0) || 209 fake_client->flags = 0;
416 (data->blocks[max6875_eeprom_config].data[0x42] != 0) || 210 strlcpy(fake_client->name, "max6875 subclient", I2C_NAME_SIZE);
417 (data->blocks[max6875_register_config].data[0x41] != 0) || 211
418 (data->blocks[max6875_register_config].data[0x42] != 0) || 212 /* Prevent 24RF08 corruption (in case of user error) */
419 (data->blocks[max6875_eeprom_config].data[0x40] != 213 i2c_smbus_write_quick(real_client, 0);
420 data->blocks[max6875_register_config].data[0x40])) 214
421 goto exit_kfree; 215 if ((err = i2c_attach_client(real_client)) != 0)
422 216 goto exit_kfree2;
423 /* Tell the I2C layer a new client has arrived */ 217
424 if ((err = i2c_attach_client(new_client))) 218 if ((err = i2c_attach_client(fake_client)) != 0)
425 goto exit_kfree; 219 goto exit_detach;
426 220
427 /* create the sysfs eeprom files with the correct permissions */ 221 sysfs_create_bin_file(&real_client->dev.kobj, &user_eeprom_attr);
428 if (allow_write == 0) {
429 user_eeprom_attr.attr.mode &= ~S_IWUGO;
430 user_eeprom_attr.write = NULL;
431 config_eeprom_attr.attr.mode &= ~S_IWUGO;
432 config_eeprom_attr.write = NULL;
433 config_register_attr.attr.mode &= ~S_IWUGO;
434 config_register_attr.write = NULL;
435 }
436 sysfs_create_bin_file(&new_client->dev.kobj, &user_eeprom_attr);
437 sysfs_create_bin_file(&new_client->dev.kobj, &config_eeprom_attr);
438 sysfs_create_bin_file(&new_client->dev.kobj, &config_register_attr);
439 222
440 return 0; 223 return 0;
441 224
442exit_kfree: 225exit_detach:
226 i2c_detach_client(real_client);
227exit_kfree2:
228 kfree(fake_client);
229exit_kfree1:
443 kfree(data); 230 kfree(data);
444exit:
445 return err; 231 return err;
446} 232}
447 233
@@ -450,13 +236,9 @@ static int max6875_detach_client(struct i2c_client *client)
450 int err; 236 int err;
451 237
452 err = i2c_detach_client(client); 238 err = i2c_detach_client(client);
453 if (err) { 239 if (err)
454 dev_err(&client->dev, "Client deregistration failed, client not detached.\n");
455 return err; 240 return err;
456 }
457
458 kfree(i2c_get_clientdata(client)); 241 kfree(i2c_get_clientdata(client));
459
460 return 0; 242 return 0;
461} 243}
462 244
diff --git a/drivers/i2c/chips/pca9539.c b/drivers/i2c/chips/pca9539.c
index 9f3ad45daae..225577fdda4 100644
--- a/drivers/i2c/chips/pca9539.c
+++ b/drivers/i2c/chips/pca9539.c
@@ -13,14 +13,12 @@
13#include <linux/slab.h> 13#include <linux/slab.h>
14#include <linux/i2c.h> 14#include <linux/i2c.h>
15#include <linux/hwmon-sysfs.h> 15#include <linux/hwmon-sysfs.h>
16#include <linux/i2c-sensor.h>
17 16
18/* Addresses to scan */ 17/* Addresses to scan */
19static unsigned short normal_i2c[] = {0x74, 0x75, 0x76, 0x77, I2C_CLIENT_END}; 18static unsigned short normal_i2c[] = {0x74, 0x75, 0x76, 0x77, I2C_CLIENT_END};
20static unsigned int normal_isa[] = {I2C_CLIENT_ISA_END};
21 19
22/* Insmod parameters */ 20/* Insmod parameters */
23SENSORS_INSMOD_1(pca9539); 21I2C_CLIENT_INSMOD_1(pca9539);
24 22
25enum pca9539_cmd 23enum pca9539_cmd
26{ 24{
@@ -109,10 +107,10 @@ static struct attribute_group pca9539_defattr_group = {
109 107
110static int pca9539_attach_adapter(struct i2c_adapter *adapter) 108static int pca9539_attach_adapter(struct i2c_adapter *adapter)
111{ 109{
112 return i2c_detect(adapter, &addr_data, pca9539_detect); 110 return i2c_probe(adapter, &addr_data, pca9539_detect);
113} 111}
114 112
115/* This function is called by i2c_detect */ 113/* This function is called by i2c_probe */
116static int pca9539_detect(struct i2c_adapter *adapter, int address, int kind) 114static int pca9539_detect(struct i2c_adapter *adapter, int address, int kind)
117{ 115{
118 struct i2c_client *new_client; 116 struct i2c_client *new_client;
@@ -164,10 +162,8 @@ static int pca9539_detach_client(struct i2c_client *client)
164{ 162{
165 int err; 163 int err;
166 164
167 if ((err = i2c_detach_client(client))) { 165 if ((err = i2c_detach_client(client)))
168 dev_err(&client->dev, "Client deregistration failed.\n");
169 return err; 166 return err;
170 }
171 167
172 kfree(i2c_get_clientdata(client)); 168 kfree(i2c_get_clientdata(client));
173 return 0; 169 return 0;
diff --git a/drivers/i2c/chips/pcf8574.c b/drivers/i2c/chips/pcf8574.c
index cfcf6465408..6525743ff9f 100644
--- a/drivers/i2c/chips/pcf8574.c
+++ b/drivers/i2c/chips/pcf8574.c
@@ -39,16 +39,14 @@
39#include <linux/init.h> 39#include <linux/init.h>
40#include <linux/slab.h> 40#include <linux/slab.h>
41#include <linux/i2c.h> 41#include <linux/i2c.h>
42#include <linux/i2c-sensor.h>
43 42
44/* Addresses to scan */ 43/* Addresses to scan */
45static unsigned short normal_i2c[] = { 0x20, 0x21, 0x22, 0x23, 0x24, 0x25, 0x26, 0x27, 44static unsigned short normal_i2c[] = { 0x20, 0x21, 0x22, 0x23, 0x24, 0x25, 0x26, 0x27,
46 0x38, 0x39, 0x3a, 0x3b, 0x3c, 0x3d, 0x3e, 0x3f, 45 0x38, 0x39, 0x3a, 0x3b, 0x3c, 0x3d, 0x3e, 0x3f,
47 I2C_CLIENT_END }; 46 I2C_CLIENT_END };
48static unsigned int normal_isa[] = { I2C_CLIENT_ISA_END };
49 47
50/* Insmod parameters */ 48/* Insmod parameters */
51SENSORS_INSMOD_2(pcf8574, pcf8574a); 49I2C_CLIENT_INSMOD_2(pcf8574, pcf8574a);
52 50
53/* Initial values */ 51/* Initial values */
54#define PCF8574_INIT 255 /* All outputs on (input mode) */ 52#define PCF8574_INIT 255 /* All outputs on (input mode) */
@@ -113,10 +111,10 @@ static DEVICE_ATTR(write, S_IWUSR | S_IRUGO, show_write, set_write);
113 111
114static int pcf8574_attach_adapter(struct i2c_adapter *adapter) 112static int pcf8574_attach_adapter(struct i2c_adapter *adapter)
115{ 113{
116 return i2c_detect(adapter, &addr_data, pcf8574_detect); 114 return i2c_probe(adapter, &addr_data, pcf8574_detect);
117} 115}
118 116
119/* This function is called by i2c_detect */ 117/* This function is called by i2c_probe */
120int pcf8574_detect(struct i2c_adapter *adapter, int address, int kind) 118int pcf8574_detect(struct i2c_adapter *adapter, int address, int kind)
121{ 119{
122 struct i2c_client *new_client; 120 struct i2c_client *new_client;
@@ -186,11 +184,8 @@ static int pcf8574_detach_client(struct i2c_client *client)
186{ 184{
187 int err; 185 int err;
188 186
189 if ((err = i2c_detach_client(client))) { 187 if ((err = i2c_detach_client(client)))
190 dev_err(&client->dev,
191 "Client deregistration failed, client not detached.\n");
192 return err; 188 return err;
193 }
194 189
195 kfree(i2c_get_clientdata(client)); 190 kfree(i2c_get_clientdata(client));
196 return 0; 191 return 0;
diff --git a/drivers/i2c/chips/pcf8591.c b/drivers/i2c/chips/pcf8591.c
index db812ade856..80f1df9a450 100644
--- a/drivers/i2c/chips/pcf8591.c
+++ b/drivers/i2c/chips/pcf8591.c
@@ -24,15 +24,13 @@
24#include <linux/init.h> 24#include <linux/init.h>
25#include <linux/slab.h> 25#include <linux/slab.h>
26#include <linux/i2c.h> 26#include <linux/i2c.h>
27#include <linux/i2c-sensor.h>
28 27
29/* Addresses to scan */ 28/* Addresses to scan */
30static unsigned short normal_i2c[] = { 0x48, 0x49, 0x4a, 0x4b, 0x4c, 29static unsigned short normal_i2c[] = { 0x48, 0x49, 0x4a, 0x4b, 0x4c,
31 0x4d, 0x4e, 0x4f, I2C_CLIENT_END }; 30 0x4d, 0x4e, 0x4f, I2C_CLIENT_END };
32static unsigned int normal_isa[] = { I2C_CLIENT_ISA_END };
33 31
34/* Insmod parameters */ 32/* Insmod parameters */
35SENSORS_INSMOD_1(pcf8591); 33I2C_CLIENT_INSMOD_1(pcf8591);
36 34
37static int input_mode; 35static int input_mode;
38module_param(input_mode, int, 0); 36module_param(input_mode, int, 0);
@@ -164,10 +162,10 @@ static DEVICE_ATTR(out0_enable, S_IWUSR | S_IRUGO,
164 */ 162 */
165static int pcf8591_attach_adapter(struct i2c_adapter *adapter) 163static int pcf8591_attach_adapter(struct i2c_adapter *adapter)
166{ 164{
167 return i2c_detect(adapter, &addr_data, pcf8591_detect); 165 return i2c_probe(adapter, &addr_data, pcf8591_detect);
168} 166}
169 167
170/* This function is called by i2c_detect */ 168/* This function is called by i2c_probe */
171int pcf8591_detect(struct i2c_adapter *adapter, int address, int kind) 169int pcf8591_detect(struct i2c_adapter *adapter, int address, int kind)
172{ 170{
173 struct i2c_client *new_client; 171 struct i2c_client *new_client;
@@ -241,11 +239,8 @@ static int pcf8591_detach_client(struct i2c_client *client)
241{ 239{
242 int err; 240 int err;
243 241
244 if ((err = i2c_detach_client(client))) { 242 if ((err = i2c_detach_client(client)))
245 dev_err(&client->dev,
246 "Client deregistration failed, client not detached.\n");
247 return err; 243 return err;
248 }
249 244
250 kfree(i2c_get_clientdata(client)); 245 kfree(i2c_get_clientdata(client));
251 return 0; 246 return 0;
diff --git a/drivers/i2c/chips/rtc8564.c b/drivers/i2c/chips/rtc8564.c
index 588fc2261a9..0b5385c892b 100644
--- a/drivers/i2c/chips/rtc8564.c
+++ b/drivers/i2c/chips/rtc8564.c
@@ -67,7 +67,6 @@ static struct i2c_client_address_data addr_data = {
67 .normal_i2c = normal_addr, 67 .normal_i2c = normal_addr,
68 .probe = ignore, 68 .probe = ignore,
69 .ignore = ignore, 69 .ignore = ignore,
70 .force = ignore,
71}; 70};
72 71
73static int rtc8564_read_mem(struct i2c_client *client, struct mem *mem); 72static int rtc8564_read_mem(struct i2c_client *client, struct mem *mem);
diff --git a/drivers/i2c/i2c-core.c b/drivers/i2c/i2c-core.c
index 4a9ead27759..dda472e5e8b 100644
--- a/drivers/i2c/i2c-core.c
+++ b/drivers/i2c/i2c-core.c
@@ -61,7 +61,7 @@ static int i2c_bus_resume(struct device * dev)
61 return rc; 61 return rc;
62} 62}
63 63
64static struct bus_type i2c_bus_type = { 64struct bus_type i2c_bus_type = {
65 .name = "i2c", 65 .name = "i2c",
66 .match = i2c_device_match, 66 .match = i2c_device_match,
67 .suspend = i2c_bus_suspend, 67 .suspend = i2c_bus_suspend,
@@ -78,13 +78,13 @@ static int i2c_device_remove(struct device *dev)
78 return 0; 78 return 0;
79} 79}
80 80
81static void i2c_adapter_dev_release(struct device *dev) 81void i2c_adapter_dev_release(struct device *dev)
82{ 82{
83 struct i2c_adapter *adap = dev_to_i2c_adapter(dev); 83 struct i2c_adapter *adap = dev_to_i2c_adapter(dev);
84 complete(&adap->dev_released); 84 complete(&adap->dev_released);
85} 85}
86 86
87static struct device_driver i2c_adapter_driver = { 87struct device_driver i2c_adapter_driver = {
88 .name = "i2c_adapter", 88 .name = "i2c_adapter",
89 .bus = &i2c_bus_type, 89 .bus = &i2c_bus_type,
90 .probe = i2c_device_probe, 90 .probe = i2c_device_probe,
@@ -97,7 +97,7 @@ static void i2c_adapter_class_dev_release(struct class_device *dev)
97 complete(&adap->class_dev_released); 97 complete(&adap->class_dev_released);
98} 98}
99 99
100static struct class i2c_adapter_class = { 100struct class i2c_adapter_class = {
101 .name = "i2c-adapter", 101 .name = "i2c-adapter",
102 .release = &i2c_adapter_class_dev_release, 102 .release = &i2c_adapter_class_dev_release,
103}; 103};
@@ -188,6 +188,8 @@ int i2c_add_adapter(struct i2c_adapter *adap)
188 strlcpy(adap->class_dev.class_id, adap->dev.bus_id, BUS_ID_SIZE); 188 strlcpy(adap->class_dev.class_id, adap->dev.bus_id, BUS_ID_SIZE);
189 class_device_register(&adap->class_dev); 189 class_device_register(&adap->class_dev);
190 190
191 dev_dbg(&adap->dev, "adapter [%s] registered\n", adap->name);
192
191 /* inform drivers of new adapters */ 193 /* inform drivers of new adapters */
192 list_for_each(item,&drivers) { 194 list_for_each(item,&drivers) {
193 driver = list_entry(item, struct i2c_driver, list); 195 driver = list_entry(item, struct i2c_driver, list);
@@ -196,8 +198,6 @@ int i2c_add_adapter(struct i2c_adapter *adap)
196 driver->attach_adapter(adap); 198 driver->attach_adapter(adap);
197 } 199 }
198 200
199 dev_dbg(&adap->dev, "registered as adapter #%d\n", adap->nr);
200
201out_unlock: 201out_unlock:
202 up(&core_lists); 202 up(&core_lists);
203 return res; 203 return res;
@@ -220,8 +220,8 @@ int i2c_del_adapter(struct i2c_adapter *adap)
220 break; 220 break;
221 } 221 }
222 if (adap_from_list != adap) { 222 if (adap_from_list != adap) {
223 pr_debug("I2C: Attempting to delete an unregistered " 223 pr_debug("i2c-core: attempting to delete unregistered "
224 "adapter\n"); 224 "adapter [%s]\n", adap->name);
225 res = -EINVAL; 225 res = -EINVAL;
226 goto out_unlock; 226 goto out_unlock;
227 } 227 }
@@ -230,9 +230,8 @@ int i2c_del_adapter(struct i2c_adapter *adap)
230 driver = list_entry(item, struct i2c_driver, list); 230 driver = list_entry(item, struct i2c_driver, list);
231 if (driver->detach_adapter) 231 if (driver->detach_adapter)
232 if ((res = driver->detach_adapter(adap))) { 232 if ((res = driver->detach_adapter(adap))) {
233 dev_warn(&adap->dev, "can't detach adapter " 233 dev_err(&adap->dev, "detach_adapter failed "
234 "while detaching driver %s: driver " 234 "for driver [%s]\n", driver->name);
235 "not detached!\n", driver->name);
236 goto out_unlock; 235 goto out_unlock;
237 } 236 }
238 } 237 }
@@ -247,9 +246,8 @@ int i2c_del_adapter(struct i2c_adapter *adap)
247 * must be deleted, as this would cause invalid states. 246 * must be deleted, as this would cause invalid states.
248 */ 247 */
249 if ((res=client->driver->detach_client(client))) { 248 if ((res=client->driver->detach_client(client))) {
250 dev_err(&adap->dev, "adapter not " 249 dev_err(&adap->dev, "detach_client failed for client "
251 "unregistered, because client at " 250 "[%s] at address 0x%02x\n", client->name,
252 "address %02x can't be detached. ",
253 client->addr); 251 client->addr);
254 goto out_unlock; 252 goto out_unlock;
255 } 253 }
@@ -270,7 +268,7 @@ int i2c_del_adapter(struct i2c_adapter *adap)
270 /* free dynamically allocated bus id */ 268 /* free dynamically allocated bus id */
271 idr_remove(&i2c_adapter_idr, adap->nr); 269 idr_remove(&i2c_adapter_idr, adap->nr);
272 270
273 dev_dbg(&adap->dev, "adapter unregistered\n"); 271 dev_dbg(&adap->dev, "adapter [%s] unregistered\n", adap->name);
274 272
275 out_unlock: 273 out_unlock:
276 up(&core_lists); 274 up(&core_lists);
@@ -303,7 +301,7 @@ int i2c_add_driver(struct i2c_driver *driver)
303 goto out_unlock; 301 goto out_unlock;
304 302
305 list_add_tail(&driver->list,&drivers); 303 list_add_tail(&driver->list,&drivers);
306 pr_debug("i2c-core: driver %s registered.\n", driver->name); 304 pr_debug("i2c-core: driver [%s] registered\n", driver->name);
307 305
308 /* now look for instances of driver on our adapters */ 306 /* now look for instances of driver on our adapters */
309 if (driver->flags & I2C_DF_NOTIFY) { 307 if (driver->flags & I2C_DF_NOTIFY) {
@@ -331,21 +329,17 @@ int i2c_del_driver(struct i2c_driver *driver)
331 /* Have a look at each adapter, if clients of this driver are still 329 /* Have a look at each adapter, if clients of this driver are still
332 * attached. If so, detach them to be able to kill the driver 330 * attached. If so, detach them to be able to kill the driver
333 * afterwards. 331 * afterwards.
334 */ 332 *
335 pr_debug("i2c-core: unregister_driver - looking for clients.\n"); 333 * Removing clients does not depend on the notify flag, else
336 /* removing clients does not depend on the notify flag, else
337 * invalid operation might (will!) result, when using stale client 334 * invalid operation might (will!) result, when using stale client
338 * pointers. 335 * pointers.
339 */ 336 */
340 list_for_each(item1,&adapters) { 337 list_for_each(item1,&adapters) {
341 adap = list_entry(item1, struct i2c_adapter, list); 338 adap = list_entry(item1, struct i2c_adapter, list);
342 dev_dbg(&adap->dev, "examining adapter\n");
343 if (driver->detach_adapter) { 339 if (driver->detach_adapter) {
344 if ((res = driver->detach_adapter(adap))) { 340 if ((res = driver->detach_adapter(adap))) {
345 dev_warn(&adap->dev, "while unregistering " 341 dev_err(&adap->dev, "detach_adapter failed "
346 "dummy driver %s, adapter could " 342 "for driver [%s]\n", driver->name);
347 "not be detached properly; driver "
348 "not unloaded!",driver->name);
349 goto out_unlock; 343 goto out_unlock;
350 } 344 }
351 } else { 345 } else {
@@ -353,16 +347,13 @@ int i2c_del_driver(struct i2c_driver *driver)
353 client = list_entry(item2, struct i2c_client, list); 347 client = list_entry(item2, struct i2c_client, list);
354 if (client->driver != driver) 348 if (client->driver != driver)
355 continue; 349 continue;
356 pr_debug("i2c-core.o: detaching client %s:\n", client->name); 350 dev_dbg(&adap->dev, "detaching client [%s] "
351 "at 0x%02x\n", client->name,
352 client->addr);
357 if ((res = driver->detach_client(client))) { 353 if ((res = driver->detach_client(client))) {
358 dev_err(&adap->dev, "while " 354 dev_err(&adap->dev, "detach_client "
359 "unregistering driver " 355 "failed for client [%s] at "
360 "`%s', the client at " 356 "0x%02x\n", client->name,
361 "address %02x of "
362 "adapter could not "
363 "be detached; driver "
364 "not unloaded!",
365 driver->name,
366 client->addr); 357 client->addr);
367 goto out_unlock; 358 goto out_unlock;
368 } 359 }
@@ -372,7 +363,7 @@ int i2c_del_driver(struct i2c_driver *driver)
372 363
373 driver_unregister(&driver->driver); 364 driver_unregister(&driver->driver);
374 list_del(&driver->list); 365 list_del(&driver->list);
375 pr_debug("i2c-core: driver unregistered: %s\n", driver->name); 366 pr_debug("i2c-core: driver [%s] unregistered\n", driver->name);
376 367
377 out_unlock: 368 out_unlock:
378 up(&core_lists); 369 up(&core_lists);
@@ -417,15 +408,12 @@ int i2c_attach_client(struct i2c_client *client)
417 408
418 if (adapter->client_register) { 409 if (adapter->client_register) {
419 if (adapter->client_register(client)) { 410 if (adapter->client_register(client)) {
420 dev_warn(&adapter->dev, "warning: client_register " 411 dev_dbg(&adapter->dev, "client_register "
421 "seems to have failed for client %02x\n", 412 "failed for client [%s] at 0x%02x\n",
422 client->addr); 413 client->name, client->addr);
423 } 414 }
424 } 415 }
425 416
426 dev_dbg(&adapter->dev, "client [%s] registered to adapter\n",
427 client->name);
428
429 if (client->flags & I2C_CLIENT_ALLOW_USE) 417 if (client->flags & I2C_CLIENT_ALLOW_USE)
430 client->usage_count = 0; 418 client->usage_count = 0;
431 419
@@ -436,7 +424,8 @@ int i2c_attach_client(struct i2c_client *client)
436 424
437 snprintf(&client->dev.bus_id[0], sizeof(client->dev.bus_id), 425 snprintf(&client->dev.bus_id[0], sizeof(client->dev.bus_id),
438 "%d-%04x", i2c_adapter_id(adapter), client->addr); 426 "%d-%04x", i2c_adapter_id(adapter), client->addr);
439 pr_debug("registering %s\n", client->dev.bus_id); 427 dev_dbg(&adapter->dev, "client [%s] registered with bus id %s\n",
428 client->name, client->dev.bus_id);
440 device_register(&client->dev); 429 device_register(&client->dev);
441 device_create_file(&client->dev, &dev_attr_client_name); 430 device_create_file(&client->dev, &dev_attr_client_name);
442 431
@@ -449,8 +438,12 @@ int i2c_detach_client(struct i2c_client *client)
449 struct i2c_adapter *adapter = client->adapter; 438 struct i2c_adapter *adapter = client->adapter;
450 int res = 0; 439 int res = 0;
451 440
452 if ((client->flags & I2C_CLIENT_ALLOW_USE) && (client->usage_count > 0)) 441 if ((client->flags & I2C_CLIENT_ALLOW_USE)
442 && (client->usage_count > 0)) {
443 dev_warn(&client->dev, "Client [%s] still busy, "
444 "can't detach\n", client->name);
453 return -EBUSY; 445 return -EBUSY;
446 }
454 447
455 if (adapter->client_unregister) { 448 if (adapter->client_unregister) {
456 res = adapter->client_unregister(client); 449 res = adapter->client_unregister(client);
@@ -669,98 +662,128 @@ int i2c_control(struct i2c_client *client,
669 * Will not work for 10-bit addresses! 662 * Will not work for 10-bit addresses!
670 * ---------------------------------------------------- 663 * ----------------------------------------------------
671 */ 664 */
665static int i2c_probe_address(struct i2c_adapter *adapter, int addr, int kind,
666 int (*found_proc) (struct i2c_adapter *, int, int))
667{
668 int err;
669
670 /* Make sure the address is valid */
671 if (addr < 0x03 || addr > 0x77) {
672 dev_warn(&adapter->dev, "Invalid probe address 0x%02x\n",
673 addr);
674 return -EINVAL;
675 }
676
677 /* Skip if already in use */
678 if (i2c_check_addr(adapter, addr))
679 return 0;
680
681 /* Make sure there is something at this address, unless forced */
682 if (kind < 0) {
683 if (i2c_smbus_xfer(adapter, addr, 0, 0, 0,
684 I2C_SMBUS_QUICK, NULL) < 0)
685 return 0;
686
687 /* prevent 24RF08 corruption */
688 if ((addr & ~0x0f) == 0x50)
689 i2c_smbus_xfer(adapter, addr, 0, 0, 0,
690 I2C_SMBUS_QUICK, NULL);
691 }
692
693 /* Finally call the custom detection function */
694 err = found_proc(adapter, addr, kind);
695
696 /* -ENODEV can be returned if there is a chip at the given address
697 but it isn't supported by this chip driver. We catch it here as
698 this isn't an error. */
699 return (err == -ENODEV) ? 0 : err;
700}
701
672int i2c_probe(struct i2c_adapter *adapter, 702int i2c_probe(struct i2c_adapter *adapter,
673 struct i2c_client_address_data *address_data, 703 struct i2c_client_address_data *address_data,
674 int (*found_proc) (struct i2c_adapter *, int, int)) 704 int (*found_proc) (struct i2c_adapter *, int, int))
675{ 705{
676 int addr,i,found,err; 706 int i, err;
677 int adap_id = i2c_adapter_id(adapter); 707 int adap_id = i2c_adapter_id(adapter);
678 708
679 /* Forget it if we can't probe using SMBUS_QUICK */ 709 /* Forget it if we can't probe using SMBUS_QUICK */
680 if (! i2c_check_functionality(adapter,I2C_FUNC_SMBUS_QUICK)) 710 if (! i2c_check_functionality(adapter,I2C_FUNC_SMBUS_QUICK))
681 return -1; 711 return -1;
682 712
683 for (addr = 0x00; addr <= 0x7f; addr++) { 713 /* Force entries are done first, and are not affected by ignore
684 714 entries */
685 /* Skip if already in use */ 715 if (address_data->forces) {
686 if (i2c_check_addr(adapter,addr)) 716 unsigned short **forces = address_data->forces;
687 continue; 717 int kind;
688 718
689 /* If it is in one of the force entries, we don't do any detection 719 for (kind = 0; forces[kind]; kind++) {
690 at all */ 720 for (i = 0; forces[kind][i] != I2C_CLIENT_END;
691 found = 0; 721 i += 2) {
692 722 if (forces[kind][i] == adap_id
693 for (i = 0; !found && (address_data->force[i] != I2C_CLIENT_END); i += 2) { 723 || forces[kind][i] == ANY_I2C_BUS) {
694 if (((adap_id == address_data->force[i]) || 724 dev_dbg(&adapter->dev, "found force "
695 (address_data->force[i] == ANY_I2C_BUS)) && 725 "parameter for adapter %d, "
696 (addr == address_data->force[i+1])) { 726 "addr 0x%02x, kind %d\n",
697 dev_dbg(&adapter->dev, "found force parameter for adapter %d, addr %04x\n", 727 adap_id, forces[kind][i + 1],
698 adap_id, addr); 728 kind);
699 if ((err = found_proc(adapter,addr,0))) 729 err = i2c_probe_address(adapter,
700 return err; 730 forces[kind][i + 1],
701 found = 1; 731 kind, found_proc);
702 } 732 if (err)
703 } 733 return err;
704 if (found) 734 }
705 continue;
706
707 /* If this address is in one of the ignores, we can forget about
708 it right now */
709 for (i = 0;
710 !found && (address_data->ignore[i] != I2C_CLIENT_END);
711 i += 2) {
712 if (((adap_id == address_data->ignore[i]) ||
713 ((address_data->ignore[i] == ANY_I2C_BUS))) &&
714 (addr == address_data->ignore[i+1])) {
715 dev_dbg(&adapter->dev, "found ignore parameter for adapter %d, "
716 "addr %04x\n", adap_id ,addr);
717 found = 1;
718 } 735 }
719 } 736 }
720 if (found) 737 }
721 continue;
722 738
723 /* Now, we will do a detection, but only if it is in the normal or 739 /* Probe entries are done second, and are not affected by ignore
724 probe entries */ 740 entries either */
725 for (i = 0; 741 for (i = 0; address_data->probe[i] != I2C_CLIENT_END; i += 2) {
726 !found && (address_data->normal_i2c[i] != I2C_CLIENT_END); 742 if (address_data->probe[i] == adap_id
727 i += 1) { 743 || address_data->probe[i] == ANY_I2C_BUS) {
728 if (addr == address_data->normal_i2c[i]) { 744 dev_dbg(&adapter->dev, "found probe parameter for "
729 found = 1; 745 "adapter %d, addr 0x%02x\n", adap_id,
730 dev_dbg(&adapter->dev, "found normal i2c entry for adapter %d, " 746 address_data->probe[i + 1]);
731 "addr %02x\n", adap_id, addr); 747 err = i2c_probe_address(adapter,
732 } 748 address_data->probe[i + 1],
749 -1, found_proc);
750 if (err)
751 return err;
733 } 752 }
753 }
734 754
735 for (i = 0; 755 /* Normal entries are done last, unless shadowed by an ignore entry */
736 !found && (address_data->probe[i] != I2C_CLIENT_END); 756 for (i = 0; address_data->normal_i2c[i] != I2C_CLIENT_END; i += 1) {
737 i += 2) { 757 int j, ignore;
738 if (((adap_id == address_data->probe[i]) || 758
739 ((address_data->probe[i] == ANY_I2C_BUS))) && 759 ignore = 0;
740 (addr == address_data->probe[i+1])) { 760 for (j = 0; address_data->ignore[j] != I2C_CLIENT_END;
741 found = 1; 761 j += 2) {
742 dev_dbg(&adapter->dev, "found probe parameter for adapter %d, " 762 if ((address_data->ignore[j] == adap_id ||
743 "addr %04x\n", adap_id,addr); 763 address_data->ignore[j] == ANY_I2C_BUS)
764 && address_data->ignore[j + 1]
765 == address_data->normal_i2c[i]) {
766 dev_dbg(&adapter->dev, "found ignore "
767 "parameter for adapter %d, "
768 "addr 0x%02x\n", adap_id,
769 address_data->ignore[j + 1]);
744 } 770 }
771 ignore = 1;
772 break;
745 } 773 }
746 if (!found) 774 if (ignore)
747 continue; 775 continue;
748 776
749 /* OK, so we really should examine this address. First check 777 dev_dbg(&adapter->dev, "found normal entry for adapter %d, "
750 whether there is some client here at all! */ 778 "addr 0x%02x\n", adap_id,
751 if (i2c_smbus_xfer(adapter,addr,0,0,0,I2C_SMBUS_QUICK,NULL) >= 0) 779 address_data->normal_i2c[i]);
752 if ((err = found_proc(adapter,addr,-1))) 780 err = i2c_probe_address(adapter, address_data->normal_i2c[i],
753 return err; 781 -1, found_proc);
782 if (err)
783 return err;
754 } 784 }
755 return 0;
756}
757 785
758/* 786 return 0;
759 * return id number for a specific adapter
760 */
761int i2c_adapter_id(struct i2c_adapter *adap)
762{
763 return adap->nr;
764} 787}
765 788
766struct i2c_adapter* i2c_get_adapter(int id) 789struct i2c_adapter* i2c_get_adapter(int id)
@@ -1171,6 +1194,12 @@ s32 i2c_smbus_xfer(struct i2c_adapter * adapter, u16 addr, unsigned short flags,
1171} 1194}
1172 1195
1173 1196
1197/* Next four are needed by i2c-isa */
1198EXPORT_SYMBOL_GPL(i2c_adapter_dev_release);
1199EXPORT_SYMBOL_GPL(i2c_adapter_driver);
1200EXPORT_SYMBOL_GPL(i2c_adapter_class);
1201EXPORT_SYMBOL_GPL(i2c_bus_type);
1202
1174EXPORT_SYMBOL(i2c_add_adapter); 1203EXPORT_SYMBOL(i2c_add_adapter);
1175EXPORT_SYMBOL(i2c_del_adapter); 1204EXPORT_SYMBOL(i2c_del_adapter);
1176EXPORT_SYMBOL(i2c_add_driver); 1205EXPORT_SYMBOL(i2c_add_driver);
@@ -1186,7 +1215,6 @@ EXPORT_SYMBOL(i2c_master_send);
1186EXPORT_SYMBOL(i2c_master_recv); 1215EXPORT_SYMBOL(i2c_master_recv);
1187EXPORT_SYMBOL(i2c_control); 1216EXPORT_SYMBOL(i2c_control);
1188EXPORT_SYMBOL(i2c_transfer); 1217EXPORT_SYMBOL(i2c_transfer);
1189EXPORT_SYMBOL(i2c_adapter_id);
1190EXPORT_SYMBOL(i2c_get_adapter); 1218EXPORT_SYMBOL(i2c_get_adapter);
1191EXPORT_SYMBOL(i2c_put_adapter); 1219EXPORT_SYMBOL(i2c_put_adapter);
1192EXPORT_SYMBOL(i2c_probe); 1220EXPORT_SYMBOL(i2c_probe);
diff --git a/drivers/i2c/i2c-dev.c b/drivers/i2c/i2c-dev.c
index bc5d557e5dd..aa7a4fadef6 100644
--- a/drivers/i2c/i2c-dev.c
+++ b/drivers/i2c/i2c-dev.c
@@ -434,7 +434,8 @@ static int i2cdev_attach_adapter(struct i2c_adapter *adap)
434 434
435 devfs_mk_cdev(MKDEV(I2C_MAJOR, i2c_dev->minor), 435 devfs_mk_cdev(MKDEV(I2C_MAJOR, i2c_dev->minor),
436 S_IFCHR|S_IRUSR|S_IWUSR, "i2c/%d", i2c_dev->minor); 436 S_IFCHR|S_IRUSR|S_IWUSR, "i2c/%d", i2c_dev->minor);
437 dev_dbg(&adap->dev, "Registered as minor %d\n", i2c_dev->minor); 437 pr_debug("i2c-dev: adapter [%s] registered as minor %d\n",
438 adap->name, i2c_dev->minor);
438 439
439 /* register this i2c device with the driver core */ 440 /* register this i2c device with the driver core */
440 i2c_dev->adap = adap; 441 i2c_dev->adap = adap;
@@ -471,7 +472,7 @@ static int i2cdev_detach_adapter(struct i2c_adapter *adap)
471 wait_for_completion(&i2c_dev->released); 472 wait_for_completion(&i2c_dev->released);
472 kfree(i2c_dev); 473 kfree(i2c_dev);
473 474
474 dev_dbg(&adap->dev, "Adapter unregistered\n"); 475 pr_debug("i2c-dev: adapter [%s] unregistered\n", adap->name);
475 return 0; 476 return 0;
476} 477}
477 478
diff --git a/drivers/i2c/i2c-sensor-detect.c b/drivers/i2c/i2c-sensor-detect.c
deleted file mode 100644
index f99a8161a9f..00000000000
--- a/drivers/i2c/i2c-sensor-detect.c
+++ /dev/null
@@ -1,145 +0,0 @@
1/*
2 i2c-sensor-detect.c - Part of lm_sensors, Linux kernel modules for hardware
3 monitoring
4 Copyright (c) 1998 - 2001 Frodo Looijaard <frodol@dds.nl> and
5 Mark D. Studebaker <mdsxyz123@yahoo.com>
6
7 This program is free software; you can redistribute it and/or modify
8 it under the terms of the GNU General Public License as published by
9 the Free Software Foundation; either version 2 of the License, or
10 (at your option) any later version.
11
12 This program is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
16
17 You should have received a copy of the GNU General Public License
18 along with this program; if not, write to the Free Software
19 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
20*/
21
22#include <linux/module.h>
23#include <linux/kernel.h>
24#include <linux/i2c.h>
25#include <linux/i2c-sensor.h>
26
27static unsigned short empty[] = {I2C_CLIENT_END};
28static unsigned int empty_isa[] = {I2C_CLIENT_ISA_END};
29
30/* Very inefficient for ISA detects, and won't work for 10-bit addresses! */
31int i2c_detect(struct i2c_adapter *adapter,
32 struct i2c_address_data *address_data,
33 int (*found_proc) (struct i2c_adapter *, int, int))
34{
35 int addr, i, found, j, err;
36 struct i2c_force_data *this_force;
37 int is_isa = i2c_is_isa_adapter(adapter);
38 int adapter_id =
39 is_isa ? ANY_I2C_ISA_BUS : i2c_adapter_id(adapter);
40 unsigned short *normal_i2c;
41 unsigned int *normal_isa;
42 unsigned short *probe;
43 unsigned short *ignore;
44
45 /* Forget it if we can't probe using SMBUS_QUICK */
46 if ((!is_isa) &&
47 !i2c_check_functionality(adapter, I2C_FUNC_SMBUS_QUICK))
48 return -1;
49
50 /* Use default "empty" list if the adapter doesn't specify any */
51 normal_i2c = probe = ignore = empty;
52 normal_isa = empty_isa;
53 if (address_data->normal_i2c)
54 normal_i2c = address_data->normal_i2c;
55 if (address_data->normal_isa)
56 normal_isa = address_data->normal_isa;
57 if (address_data->probe)
58 probe = address_data->probe;
59 if (address_data->ignore)
60 ignore = address_data->ignore;
61
62 for (addr = 0x00; addr <= (is_isa ? 0xffff : 0x7f); addr++) {
63 if (!is_isa && i2c_check_addr(adapter, addr))
64 continue;
65
66 /* If it is in one of the force entries, we don't do any
67 detection at all */
68 found = 0;
69 for (i = 0; !found && (this_force = address_data->forces + i, this_force->force); i++) {
70 for (j = 0; !found && (this_force->force[j] != I2C_CLIENT_END); j += 2) {
71 if ( ((adapter_id == this_force->force[j]) ||
72 ((this_force->force[j] == ANY_I2C_BUS) && !is_isa)) &&
73 (addr == this_force->force[j + 1]) ) {
74 dev_dbg(&adapter->dev, "found force parameter for adapter %d, addr %04x\n", adapter_id, addr);
75 if ((err = found_proc(adapter, addr, this_force->kind)))
76 return err;
77 found = 1;
78 }
79 }
80 }
81 if (found)
82 continue;
83
84 /* If this address is in one of the ignores, we can forget about it
85 right now */
86 for (i = 0; !found && (ignore[i] != I2C_CLIENT_END); i += 2) {
87 if ( ((adapter_id == ignore[i]) ||
88 ((ignore[i] == ANY_I2C_BUS) &&
89 !is_isa)) &&
90 (addr == ignore[i + 1])) {
91 dev_dbg(&adapter->dev, "found ignore parameter for adapter %d, addr %04x\n", adapter_id, addr);
92 found = 1;
93 }
94 }
95 if (found)
96 continue;
97
98 /* Now, we will do a detection, but only if it is in the normal or
99 probe entries */
100 if (is_isa) {
101 for (i = 0; !found && (normal_isa[i] != I2C_CLIENT_ISA_END); i += 1) {
102 if (addr == normal_isa[i]) {
103 dev_dbg(&adapter->dev, "found normal isa entry for adapter %d, addr %04x\n", adapter_id, addr);
104 found = 1;
105 }
106 }
107 } else {
108 for (i = 0; !found && (normal_i2c[i] != I2C_CLIENT_END); i += 1) {
109 if (addr == normal_i2c[i]) {
110 found = 1;
111 dev_dbg(&adapter->dev, "found normal i2c entry for adapter %d, addr %02x\n", adapter_id, addr);
112 }
113 }
114 }
115
116 for (i = 0;
117 !found && (probe[i] != I2C_CLIENT_END);
118 i += 2) {
119 if (((adapter_id == probe[i]) ||
120 ((probe[i] == ANY_I2C_BUS) && !is_isa))
121 && (addr == probe[i + 1])) {
122 dev_dbg(&adapter->dev, "found probe parameter for adapter %d, addr %04x\n", adapter_id, addr);
123 found = 1;
124 }
125 }
126 if (!found)
127 continue;
128
129 /* OK, so we really should examine this address. First check
130 whether there is some client here at all! */
131 if (is_isa ||
132 (i2c_smbus_xfer (adapter, addr, 0, 0, 0, I2C_SMBUS_QUICK, NULL) >= 0))
133 if ((err = found_proc(adapter, addr, -1)))
134 return err;
135 }
136 return 0;
137}
138
139EXPORT_SYMBOL(i2c_detect);
140
141MODULE_AUTHOR("Frodo Looijaard <frodol@dds.nl>, "
142 "Rudolf Marek <r.marek@sh.cvut.cz>");
143
144MODULE_DESCRIPTION("i2c-sensor driver");
145MODULE_LICENSE("GPL");
diff --git a/drivers/i2c/i2c-sensor-vid.c b/drivers/i2c/i2c-sensor-vid.c
deleted file mode 100644
index 922e22f054b..00000000000
--- a/drivers/i2c/i2c-sensor-vid.c
+++ /dev/null
@@ -1,98 +0,0 @@
1/*
2 i2c-sensor-vid.c - Part of lm_sensors, Linux kernel modules for hardware
3 monitoring
4
5 Copyright (c) 2004 Rudolf Marek <r.marek@sh.cvut.cz>
6
7 This program is free software; you can redistribute it and/or modify
8 it under the terms of the GNU General Public License as published by
9 the Free Software Foundation; either version 2 of the License, or
10 (at your option) any later version.
11
12 This program is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
16
17 You should have received a copy of the GNU General Public License
18 along with this program; if not, write to the Free Software
19 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
20*/
21
22#include <linux/config.h>
23#include <linux/module.h>
24#include <linux/kernel.h>
25
26struct vrm_model {
27 u8 vendor;
28 u8 eff_family;
29 u8 eff_model;
30 int vrm_type;
31};
32
33#define ANY 0xFF
34
35#ifdef CONFIG_X86
36
37static struct vrm_model vrm_models[] = {
38 {X86_VENDOR_AMD, 0x6, ANY, 90}, /* Athlon Duron etc */
39 {X86_VENDOR_AMD, 0xF, ANY, 24}, /* Athlon 64, Opteron */
40 {X86_VENDOR_INTEL, 0x6, 0x9, 85}, /* 0.13um too */
41 {X86_VENDOR_INTEL, 0x6, 0xB, 85}, /* 0xB Tualatin */
42 {X86_VENDOR_INTEL, 0x6, ANY, 82}, /* any P6 */
43 {X86_VENDOR_INTEL, 0x7, ANY, 0}, /* Itanium */
44 {X86_VENDOR_INTEL, 0xF, 0x3, 100}, /* P4 Prescott */
45 {X86_VENDOR_INTEL, 0xF, ANY, 90}, /* P4 before Prescott */
46 {X86_VENDOR_INTEL, 0x10,ANY, 0}, /* Itanium 2 */
47 {X86_VENDOR_UNKNOWN, ANY, ANY, 0} /* stop here */
48 };
49
50static int find_vrm(u8 eff_family, u8 eff_model, u8 vendor)
51{
52 int i = 0;
53
54 while (vrm_models[i].vendor!=X86_VENDOR_UNKNOWN) {
55 if (vrm_models[i].vendor==vendor)
56 if ((vrm_models[i].eff_family==eff_family)&& \
57 ((vrm_models[i].eff_model==eff_model)|| \
58 (vrm_models[i].eff_model==ANY)))
59 return vrm_models[i].vrm_type;
60 i++;
61 }
62
63 return 0;
64}
65
66int i2c_which_vrm(void)
67{
68 struct cpuinfo_x86 *c = cpu_data;
69 u32 eax;
70 u8 eff_family, eff_model;
71 int vrm_ret;
72
73 if (c->x86 < 6) return 0; /* any CPU with familly lower than 6
74 dont have VID and/or CPUID */
75 eax = cpuid_eax(1);
76 eff_family = ((eax & 0x00000F00)>>8);
77 eff_model = ((eax & 0x000000F0)>>4);
78 if (eff_family == 0xF) { /* use extended model & family */
79 eff_family += ((eax & 0x00F00000)>>20);
80 eff_model += ((eax & 0x000F0000)>>16)<<4;
81 }
82 vrm_ret = find_vrm(eff_family,eff_model,c->x86_vendor);
83 if (vrm_ret == 0)
84 printk(KERN_INFO "i2c-sensor.o: Unknown VRM version of your"
85 " x86 CPU\n");
86 return vrm_ret;
87}
88
89/* and now for something completely different for Non-x86 world*/
90#else
91int i2c_which_vrm(void)
92{
93 printk(KERN_INFO "i2c-sensor.o: Unknown VRM version of your CPU\n");
94 return 0;
95}
96#endif
97
98EXPORT_SYMBOL(i2c_which_vrm);
diff --git a/drivers/ide/ide-disk.c b/drivers/ide/ide-disk.c
index c9d3a00a3c0..234f5de3e92 100644
--- a/drivers/ide/ide-disk.c
+++ b/drivers/ide/ide-disk.c
@@ -754,7 +754,7 @@ static int idedisk_issue_flush(request_queue_t *q, struct gendisk *disk,
754 754
755 idedisk_prepare_flush(q, rq); 755 idedisk_prepare_flush(q, rq);
756 756
757 ret = blk_execute_rq(q, disk, rq); 757 ret = blk_execute_rq(q, disk, rq, 0);
758 758
759 /* 759 /*
760 * if we failed and caller wants error offset, get it 760 * if we failed and caller wants error offset, get it
diff --git a/drivers/ide/ide-io.c b/drivers/ide/ide-io.c
index 248e3cc8b35..f174aee659e 100644
--- a/drivers/ide/ide-io.c
+++ b/drivers/ide/ide-io.c
@@ -150,7 +150,7 @@ static void ide_complete_power_step(ide_drive_t *drive, struct request *rq, u8 s
150 150
151 switch (rq->pm->pm_step) { 151 switch (rq->pm->pm_step) {
152 case ide_pm_flush_cache: /* Suspend step 1 (flush cache) complete */ 152 case ide_pm_flush_cache: /* Suspend step 1 (flush cache) complete */
153 if (rq->pm->pm_state == 4) 153 if (rq->pm->pm_state == PM_EVENT_FREEZE)
154 rq->pm->pm_step = ide_pm_state_completed; 154 rq->pm->pm_step = ide_pm_state_completed;
155 else 155 else
156 rq->pm->pm_step = idedisk_pm_standby; 156 rq->pm->pm_step = idedisk_pm_standby;
diff --git a/drivers/ide/ide.c b/drivers/ide/ide.c
index dae1bd5b8c3..73ca8f73917 100644
--- a/drivers/ide/ide.c
+++ b/drivers/ide/ide.c
@@ -1229,7 +1229,7 @@ static int generic_ide_suspend(struct device *dev, pm_message_t state)
1229 rq.special = &args; 1229 rq.special = &args;
1230 rq.pm = &rqpm; 1230 rq.pm = &rqpm;
1231 rqpm.pm_step = ide_pm_state_start_suspend; 1231 rqpm.pm_step = ide_pm_state_start_suspend;
1232 rqpm.pm_state = state; 1232 rqpm.pm_state = state.event;
1233 1233
1234 return ide_do_drive_cmd(drive, &rq, ide_wait); 1234 return ide_do_drive_cmd(drive, &rq, ide_wait);
1235} 1235}
@@ -1248,7 +1248,7 @@ static int generic_ide_resume(struct device *dev)
1248 rq.special = &args; 1248 rq.special = &args;
1249 rq.pm = &rqpm; 1249 rq.pm = &rqpm;
1250 rqpm.pm_step = ide_pm_state_start_resume; 1250 rqpm.pm_step = ide_pm_state_start_resume;
1251 rqpm.pm_state = 0; 1251 rqpm.pm_state = PM_EVENT_ON;
1252 1252
1253 return ide_do_drive_cmd(drive, &rq, ide_head_wait); 1253 return ide_do_drive_cmd(drive, &rq, ide_head_wait);
1254} 1254}
diff --git a/drivers/ide/pci/sc1200.c b/drivers/ide/pci/sc1200.c
index 10592cec6c4..24e21b2838c 100644
--- a/drivers/ide/pci/sc1200.c
+++ b/drivers/ide/pci/sc1200.c
@@ -350,9 +350,9 @@ static int sc1200_suspend (struct pci_dev *dev, pm_message_t state)
350{ 350{
351 ide_hwif_t *hwif = NULL; 351 ide_hwif_t *hwif = NULL;
352 352
353 printk("SC1200: suspend(%u)\n", state); 353 printk("SC1200: suspend(%u)\n", state.event);
354 354
355 if (state == 0) { 355 if (state.event == PM_EVENT_ON) {
356 // we only save state when going from full power to less 356 // we only save state when going from full power to less
357 357
358 // 358 //
@@ -386,8 +386,8 @@ static int sc1200_suspend (struct pci_dev *dev, pm_message_t state)
386 /* You don't need to iterate over disks -- sysfs should have done that for you already */ 386 /* You don't need to iterate over disks -- sysfs should have done that for you already */
387 387
388 pci_disable_device(dev); 388 pci_disable_device(dev);
389 pci_set_power_state(dev,state); 389 pci_set_power_state(dev, pci_choose_state(dev, state));
390 dev->current_state = state; 390 dev->current_state = state.event;
391 return 0; 391 return 0;
392} 392}
393 393
@@ -396,8 +396,8 @@ static int sc1200_resume (struct pci_dev *dev)
396 ide_hwif_t *hwif = NULL; 396 ide_hwif_t *hwif = NULL;
397 397
398printk("SC1200: resume\n"); 398printk("SC1200: resume\n");
399 pci_set_power_state(dev,0); // bring chip back from sleep state 399 pci_set_power_state(dev, PCI_D0); // bring chip back from sleep state
400 dev->current_state = 0; 400 dev->current_state = PM_EVENT_ON;
401 pci_enable_device(dev); 401 pci_enable_device(dev);
402 // 402 //
403 // loop over all interfaces that are part of this pci device: 403 // loop over all interfaces that are part of this pci device:
diff --git a/drivers/ide/ppc/pmac.c b/drivers/ide/ppc/pmac.c
index ea65b070a36..87d1f8a1f41 100644
--- a/drivers/ide/ppc/pmac.c
+++ b/drivers/ide/ppc/pmac.c
@@ -1504,12 +1504,12 @@ pmac_ide_macio_attach(struct macio_dev *mdev, const struct of_device_id *match)
1504} 1504}
1505 1505
1506static int 1506static int
1507pmac_ide_macio_suspend(struct macio_dev *mdev, u32 state) 1507pmac_ide_macio_suspend(struct macio_dev *mdev, pm_message_t state)
1508{ 1508{
1509 ide_hwif_t *hwif = (ide_hwif_t *)dev_get_drvdata(&mdev->ofdev.dev); 1509 ide_hwif_t *hwif = (ide_hwif_t *)dev_get_drvdata(&mdev->ofdev.dev);
1510 int rc = 0; 1510 int rc = 0;
1511 1511
1512 if (state != mdev->ofdev.dev.power.power_state && state >= 2) { 1512 if (state.event != mdev->ofdev.dev.power.power_state.event && state.event >= PM_EVENT_SUSPEND) {
1513 rc = pmac_ide_do_suspend(hwif); 1513 rc = pmac_ide_do_suspend(hwif);
1514 if (rc == 0) 1514 if (rc == 0)
1515 mdev->ofdev.dev.power.power_state = state; 1515 mdev->ofdev.dev.power.power_state = state;
@@ -1524,10 +1524,10 @@ pmac_ide_macio_resume(struct macio_dev *mdev)
1524 ide_hwif_t *hwif = (ide_hwif_t *)dev_get_drvdata(&mdev->ofdev.dev); 1524 ide_hwif_t *hwif = (ide_hwif_t *)dev_get_drvdata(&mdev->ofdev.dev);
1525 int rc = 0; 1525 int rc = 0;
1526 1526
1527 if (mdev->ofdev.dev.power.power_state != 0) { 1527 if (mdev->ofdev.dev.power.power_state.event != PM_EVENT_ON) {
1528 rc = pmac_ide_do_resume(hwif); 1528 rc = pmac_ide_do_resume(hwif);
1529 if (rc == 0) 1529 if (rc == 0)
1530 mdev->ofdev.dev.power.power_state = 0; 1530 mdev->ofdev.dev.power.power_state = PMSG_ON;
1531 } 1531 }
1532 1532
1533 return rc; 1533 return rc;
@@ -1608,12 +1608,12 @@ pmac_ide_pci_attach(struct pci_dev *pdev, const struct pci_device_id *id)
1608} 1608}
1609 1609
1610static int 1610static int
1611pmac_ide_pci_suspend(struct pci_dev *pdev, u32 state) 1611pmac_ide_pci_suspend(struct pci_dev *pdev, pm_message_t state)
1612{ 1612{
1613 ide_hwif_t *hwif = (ide_hwif_t *)pci_get_drvdata(pdev); 1613 ide_hwif_t *hwif = (ide_hwif_t *)pci_get_drvdata(pdev);
1614 int rc = 0; 1614 int rc = 0;
1615 1615
1616 if (state != pdev->dev.power.power_state && state >= 2) { 1616 if (state.event != pdev->dev.power.power_state.event && state.event >= 2) {
1617 rc = pmac_ide_do_suspend(hwif); 1617 rc = pmac_ide_do_suspend(hwif);
1618 if (rc == 0) 1618 if (rc == 0)
1619 pdev->dev.power.power_state = state; 1619 pdev->dev.power.power_state = state;
@@ -1628,10 +1628,10 @@ pmac_ide_pci_resume(struct pci_dev *pdev)
1628 ide_hwif_t *hwif = (ide_hwif_t *)pci_get_drvdata(pdev); 1628 ide_hwif_t *hwif = (ide_hwif_t *)pci_get_drvdata(pdev);
1629 int rc = 0; 1629 int rc = 0;
1630 1630
1631 if (pdev->dev.power.power_state != 0) { 1631 if (pdev->dev.power.power_state.event != PM_EVENT_ON) {
1632 rc = pmac_ide_do_resume(hwif); 1632 rc = pmac_ide_do_resume(hwif);
1633 if (rc == 0) 1633 if (rc == 0)
1634 pdev->dev.power.power_state = 0; 1634 pdev->dev.power.power_state = PMSG_ON;
1635 } 1635 }
1636 1636
1637 return rc; 1637 return rc;
diff --git a/drivers/ieee1394/nodemgr.c b/drivers/ieee1394/nodemgr.c
index bebcc47ab06..b23322523ef 100644
--- a/drivers/ieee1394/nodemgr.c
+++ b/drivers/ieee1394/nodemgr.c
@@ -1068,6 +1068,8 @@ static int nodemgr_hotplug(struct class_device *cdev, char **envp, int num_envp,
1068 struct unit_directory *ud; 1068 struct unit_directory *ud;
1069 int i = 0; 1069 int i = 0;
1070 int length = 0; 1070 int length = 0;
1071 /* ieee1394:venNmoNspNverN */
1072 char buf[8 + 1 + 3 + 8 + 2 + 8 + 2 + 8 + 3 + 8 + 1];
1071 1073
1072 if (!cdev) 1074 if (!cdev)
1073 return -ENODEV; 1075 return -ENODEV;
@@ -1094,6 +1096,12 @@ do { \
1094 PUT_ENVP("GUID=%016Lx", (unsigned long long)ud->ne->guid); 1096 PUT_ENVP("GUID=%016Lx", (unsigned long long)ud->ne->guid);
1095 PUT_ENVP("SPECIFIER_ID=%06x", ud->specifier_id); 1097 PUT_ENVP("SPECIFIER_ID=%06x", ud->specifier_id);
1096 PUT_ENVP("VERSION=%06x", ud->version); 1098 PUT_ENVP("VERSION=%06x", ud->version);
1099 snprintf(buf, sizeof(buf), "ieee1394:ven%08Xmo%08Xsp%08Xver%08X",
1100 ud->vendor_id,
1101 ud->model_id,
1102 ud->specifier_id,
1103 ud->version);
1104 PUT_ENVP("MODALIAS=%s", buf);
1097 1105
1098#undef PUT_ENVP 1106#undef PUT_ENVP
1099 1107
diff --git a/drivers/ieee1394/pcilynx.c b/drivers/ieee1394/pcilynx.c
index 36074e6eeeb..6b1ab875333 100644
--- a/drivers/ieee1394/pcilynx.c
+++ b/drivers/ieee1394/pcilynx.c
@@ -1464,26 +1464,6 @@ static int __devinit add_card(struct pci_dev *dev,
1464 { 0x50, I2C_M_RD, 20, (unsigned char*) lynx->bus_info_block } 1464 { 0x50, I2C_M_RD, 20, (unsigned char*) lynx->bus_info_block }
1465 }; 1465 };
1466 1466
1467
1468#ifdef CONFIG_IEEE1394_VERBOSEDEBUG
1469 union i2c_smbus_data data;
1470
1471 if (i2c_smbus_xfer(i2c_ad, 80, 0, I2C_SMBUS_WRITE, 0, I2C_SMBUS_BYTE,NULL))
1472 PRINT(KERN_ERR, lynx->id,"eeprom read start has failed");
1473 else
1474 {
1475 u16 addr;
1476 for (addr=0x00; addr < 0x100; addr++) {
1477 if (i2c_smbus_xfer(i2c_ad, 80, 0, I2C_SMBUS_READ, 0, I2C_SMBUS_BYTE,& data)) {
1478 PRINT(KERN_ERR, lynx->id, "unable to read i2c %x", addr);
1479 break;
1480 }
1481 else
1482 PRINT(KERN_DEBUG, lynx->id,"got serial eeprom data at %x: %x",addr, data.byte);
1483 }
1484 }
1485#endif
1486
1487 /* we use i2c_transfer, because i2c_smbus_read_block_data does not work properly and we 1467 /* we use i2c_transfer, because i2c_smbus_read_block_data does not work properly and we
1488 do it more efficiently in one transaction rather then using several reads */ 1468 do it more efficiently in one transaction rather then using several reads */
1489 if (i2c_transfer(i2c_ad, msg, 2) < 0) { 1469 if (i2c_transfer(i2c_ad, msg, 2) < 0) {
diff --git a/drivers/infiniband/core/sysfs.c b/drivers/infiniband/core/sysfs.c
index fae1c2dcee5..211ba3223f6 100644
--- a/drivers/infiniband/core/sysfs.c
+++ b/drivers/infiniband/core/sysfs.c
@@ -463,7 +463,7 @@ alloc_group_attrs(ssize_t (*show)(struct ib_port *,
463 return NULL; 463 return NULL;
464 464
465 for (i = 0; i < len; i++) { 465 for (i = 0; i < len; i++) {
466 element = kcalloc(1, sizeof(struct port_table_attribute), 466 element = kzalloc(sizeof(struct port_table_attribute),
467 GFP_KERNEL); 467 GFP_KERNEL);
468 if (!element) 468 if (!element)
469 goto err; 469 goto err;
diff --git a/drivers/input/evdev.c b/drivers/input/evdev.c
index 20e3a165989..19c14c4beb4 100644
--- a/drivers/input/evdev.c
+++ b/drivers/input/evdev.c
@@ -160,6 +160,8 @@ struct input_event_compat {
160# define COMPAT_TEST IS_IA32_PROCESS(ia64_task_regs(current)) 160# define COMPAT_TEST IS_IA32_PROCESS(ia64_task_regs(current))
161#elif defined(CONFIG_ARCH_S390) 161#elif defined(CONFIG_ARCH_S390)
162# define COMPAT_TEST test_thread_flag(TIF_31BIT) 162# define COMPAT_TEST test_thread_flag(TIF_31BIT)
163#elif defined(CONFIG_MIPS)
164# define COMPAT_TEST (current->thread.mflags & MF_32BIT_ADDR)
163#else 165#else
164# define COMPAT_TEST test_thread_flag(TIF_32BIT) 166# define COMPAT_TEST test_thread_flag(TIF_32BIT)
165#endif 167#endif
@@ -391,6 +393,7 @@ static long evdev_ioctl(struct file *file, unsigned int cmd, unsigned long arg)
391 case EV_LED: bits = dev->ledbit; len = LED_MAX; break; 393 case EV_LED: bits = dev->ledbit; len = LED_MAX; break;
392 case EV_SND: bits = dev->sndbit; len = SND_MAX; break; 394 case EV_SND: bits = dev->sndbit; len = SND_MAX; break;
393 case EV_FF: bits = dev->ffbit; len = FF_MAX; break; 395 case EV_FF: bits = dev->ffbit; len = FF_MAX; break;
396 case EV_SW: bits = dev->swbit; len = SW_MAX; break;
394 default: return -EINVAL; 397 default: return -EINVAL;
395 } 398 }
396 len = NBITS(len) * sizeof(long); 399 len = NBITS(len) * sizeof(long);
@@ -419,6 +422,13 @@ static long evdev_ioctl(struct file *file, unsigned int cmd, unsigned long arg)
419 return copy_to_user(p, dev->snd, len) ? -EFAULT : len; 422 return copy_to_user(p, dev->snd, len) ? -EFAULT : len;
420 } 423 }
421 424
425 if (_IOC_NR(cmd) == _IOC_NR(EVIOCGSW(0))) {
426 int len;
427 len = NBITS(SW_MAX) * sizeof(long);
428 if (len > _IOC_SIZE(cmd)) len = _IOC_SIZE(cmd);
429 return copy_to_user(p, dev->sw, len) ? -EFAULT : len;
430 }
431
422 if (_IOC_NR(cmd) == _IOC_NR(EVIOCGNAME(0))) { 432 if (_IOC_NR(cmd) == _IOC_NR(EVIOCGNAME(0))) {
423 int len; 433 int len;
424 if (!dev->name) return -ENOENT; 434 if (!dev->name) return -ENOENT;
diff --git a/drivers/input/gameport/emu10k1-gp.c b/drivers/input/gameport/emu10k1-gp.c
index a0118038330..462f8d300aa 100644
--- a/drivers/input/gameport/emu10k1-gp.c
+++ b/drivers/input/gameport/emu10k1-gp.c
@@ -75,7 +75,7 @@ static int __devinit emu_probe(struct pci_dev *pdev, const struct pci_device_id
75 if (!request_region(ioport, iolen, "emu10k1-gp")) 75 if (!request_region(ioport, iolen, "emu10k1-gp"))
76 return -EBUSY; 76 return -EBUSY;
77 77
78 emu = kcalloc(1, sizeof(struct emu), GFP_KERNEL); 78 emu = kzalloc(sizeof(struct emu), GFP_KERNEL);
79 port = gameport_allocate_port(); 79 port = gameport_allocate_port();
80 if (!emu || !port) { 80 if (!emu || !port) {
81 printk(KERN_ERR "emu10k1-gp: Memory allocation failed\n"); 81 printk(KERN_ERR "emu10k1-gp: Memory allocation failed\n");
diff --git a/drivers/input/gameport/fm801-gp.c b/drivers/input/gameport/fm801-gp.c
index 57615bc6390..47e93daa0fa 100644
--- a/drivers/input/gameport/fm801-gp.c
+++ b/drivers/input/gameport/fm801-gp.c
@@ -83,7 +83,7 @@ static int __devinit fm801_gp_probe(struct pci_dev *pci, const struct pci_device
83 struct fm801_gp *gp; 83 struct fm801_gp *gp;
84 struct gameport *port; 84 struct gameport *port;
85 85
86 gp = kcalloc(1, sizeof(struct fm801_gp), GFP_KERNEL); 86 gp = kzalloc(sizeof(struct fm801_gp), GFP_KERNEL);
87 port = gameport_allocate_port(); 87 port = gameport_allocate_port();
88 if (!gp || !port) { 88 if (!gp || !port) {
89 printk(KERN_ERR "fm801-gp: Memory allocation failed\n"); 89 printk(KERN_ERR "fm801-gp: Memory allocation failed\n");
diff --git a/drivers/input/gameport/ns558.c b/drivers/input/gameport/ns558.c
index 70f051894a3..d2e55dc956b 100644
--- a/drivers/input/gameport/ns558.c
+++ b/drivers/input/gameport/ns558.c
@@ -142,7 +142,7 @@ static int ns558_isa_probe(int io)
142 return -EBUSY; 142 return -EBUSY;
143 } 143 }
144 144
145 ns558 = kcalloc(1, sizeof(struct ns558), GFP_KERNEL); 145 ns558 = kzalloc(sizeof(struct ns558), GFP_KERNEL);
146 port = gameport_allocate_port(); 146 port = gameport_allocate_port();
147 if (!ns558 || !port) { 147 if (!ns558 || !port) {
148 printk(KERN_ERR "ns558: Memory allocation failed.\n"); 148 printk(KERN_ERR "ns558: Memory allocation failed.\n");
@@ -215,7 +215,7 @@ static int ns558_pnp_probe(struct pnp_dev *dev, const struct pnp_device_id *did)
215 if (!request_region(ioport, iolen, "ns558-pnp")) 215 if (!request_region(ioport, iolen, "ns558-pnp"))
216 return -EBUSY; 216 return -EBUSY;
217 217
218 ns558 = kcalloc(1, sizeof(struct ns558), GFP_KERNEL); 218 ns558 = kzalloc(sizeof(struct ns558), GFP_KERNEL);
219 port = gameport_allocate_port(); 219 port = gameport_allocate_port();
220 if (!ns558 || !port) { 220 if (!ns558 || !port) {
221 printk(KERN_ERR "ns558: Memory allocation failed\n"); 221 printk(KERN_ERR "ns558: Memory allocation failed\n");
diff --git a/drivers/input/input.c b/drivers/input/input.c
index a275211c8e1..88636a20452 100644
--- a/drivers/input/input.c
+++ b/drivers/input/input.c
@@ -89,6 +89,15 @@ void input_event(struct input_dev *dev, unsigned int type, unsigned int code, in
89 89
90 break; 90 break;
91 91
92 case EV_SW:
93
94 if (code > SW_MAX || !test_bit(code, dev->swbit) || !!test_bit(code, dev->sw) == value)
95 return;
96
97 change_bit(code, dev->sw);
98
99 break;
100
92 case EV_ABS: 101 case EV_ABS:
93 102
94 if (code > ABS_MAX || !test_bit(code, dev->absbit)) 103 if (code > ABS_MAX || !test_bit(code, dev->absbit))
@@ -402,6 +411,7 @@ static void input_call_hotplug(char *verb, struct input_dev *dev)
402 SPRINTF_BIT_A2(ledbit, "LED=", LED_MAX, EV_LED); 411 SPRINTF_BIT_A2(ledbit, "LED=", LED_MAX, EV_LED);
403 SPRINTF_BIT_A2(sndbit, "SND=", SND_MAX, EV_SND); 412 SPRINTF_BIT_A2(sndbit, "SND=", SND_MAX, EV_SND);
404 SPRINTF_BIT_A2(ffbit, "FF=", FF_MAX, EV_FF); 413 SPRINTF_BIT_A2(ffbit, "FF=", FF_MAX, EV_FF);
414 SPRINTF_BIT_A2(swbit, "SW=", SW_MAX, EV_SW);
405 415
406 envp[i++] = NULL; 416 envp[i++] = NULL;
407 417
@@ -490,6 +500,7 @@ static int input_devices_read(char *buf, char **start, off_t pos, int count, int
490 SPRINTF_BIT_B2(ledbit, "LED=", LED_MAX, EV_LED); 500 SPRINTF_BIT_B2(ledbit, "LED=", LED_MAX, EV_LED);
491 SPRINTF_BIT_B2(sndbit, "SND=", SND_MAX, EV_SND); 501 SPRINTF_BIT_B2(sndbit, "SND=", SND_MAX, EV_SND);
492 SPRINTF_BIT_B2(ffbit, "FF=", FF_MAX, EV_FF); 502 SPRINTF_BIT_B2(ffbit, "FF=", FF_MAX, EV_FF);
503 SPRINTF_BIT_B2(swbit, "SW=", SW_MAX, EV_SW);
493 504
494 len += sprintf(buf + len, "\n"); 505 len += sprintf(buf + len, "\n");
495 506
diff --git a/drivers/input/joystick/a3d.c b/drivers/input/joystick/a3d.c
index bf34f75b946..bf65430181f 100644
--- a/drivers/input/joystick/a3d.c
+++ b/drivers/input/joystick/a3d.c
@@ -269,7 +269,7 @@ static int a3d_connect(struct gameport *gameport, struct gameport_driver *drv)
269 int i; 269 int i;
270 int err; 270 int err;
271 271
272 if (!(a3d = kcalloc(1, sizeof(struct a3d), GFP_KERNEL))) 272 if (!(a3d = kzalloc(sizeof(struct a3d), GFP_KERNEL)))
273 return -ENOMEM; 273 return -ENOMEM;
274 274
275 a3d->gameport = gameport; 275 a3d->gameport = gameport;
diff --git a/drivers/input/joystick/adi.c b/drivers/input/joystick/adi.c
index 265962956c6..cf35ae638a0 100644
--- a/drivers/input/joystick/adi.c
+++ b/drivers/input/joystick/adi.c
@@ -469,7 +469,7 @@ static int adi_connect(struct gameport *gameport, struct gameport_driver *drv)
469 int i; 469 int i;
470 int err; 470 int err;
471 471
472 if (!(port = kcalloc(1, sizeof(struct adi_port), GFP_KERNEL))) 472 if (!(port = kzalloc(sizeof(struct adi_port), GFP_KERNEL)))
473 return -ENOMEM; 473 return -ENOMEM;
474 474
475 port->gameport = gameport; 475 port->gameport = gameport;
diff --git a/drivers/input/joystick/analog.c b/drivers/input/joystick/analog.c
index c3a5739030c..64b1313a3c6 100644
--- a/drivers/input/joystick/analog.c
+++ b/drivers/input/joystick/analog.c
@@ -655,7 +655,7 @@ static int analog_connect(struct gameport *gameport, struct gameport_driver *drv
655 int i; 655 int i;
656 int err; 656 int err;
657 657
658 if (!(port = kcalloc(1, sizeof(struct analog_port), GFP_KERNEL))) 658 if (!(port = kzalloc(sizeof(struct analog_port), GFP_KERNEL)))
659 return - ENOMEM; 659 return - ENOMEM;
660 660
661 err = analog_init_port(gameport, drv, port); 661 err = analog_init_port(gameport, drv, port);
diff --git a/drivers/input/joystick/cobra.c b/drivers/input/joystick/cobra.c
index a6002205328..0b2e9fa2657 100644
--- a/drivers/input/joystick/cobra.c
+++ b/drivers/input/joystick/cobra.c
@@ -163,7 +163,7 @@ static int cobra_connect(struct gameport *gameport, struct gameport_driver *drv)
163 int i, j; 163 int i, j;
164 int err; 164 int err;
165 165
166 if (!(cobra = kcalloc(1, sizeof(struct cobra), GFP_KERNEL))) 166 if (!(cobra = kzalloc(sizeof(struct cobra), GFP_KERNEL)))
167 return -ENOMEM; 167 return -ENOMEM;
168 168
169 cobra->gameport = gameport; 169 cobra->gameport = gameport;
diff --git a/drivers/input/joystick/db9.c b/drivers/input/joystick/db9.c
index fbd3eed07f9..2a3e4bb2da5 100644
--- a/drivers/input/joystick/db9.c
+++ b/drivers/input/joystick/db9.c
@@ -572,7 +572,7 @@ static struct db9 __init *db9_probe(int *config, int nargs)
572 } 572 }
573 } 573 }
574 574
575 if (!(db9 = kcalloc(1, sizeof(struct db9), GFP_KERNEL))) { 575 if (!(db9 = kzalloc(sizeof(struct db9), GFP_KERNEL))) {
576 parport_put_port(pp); 576 parport_put_port(pp);
577 return NULL; 577 return NULL;
578 } 578 }
diff --git a/drivers/input/joystick/gamecon.c b/drivers/input/joystick/gamecon.c
index 95bbdd302aa..5427bf9fc86 100644
--- a/drivers/input/joystick/gamecon.c
+++ b/drivers/input/joystick/gamecon.c
@@ -554,7 +554,7 @@ static struct gc __init *gc_probe(int *config, int nargs)
554 return NULL; 554 return NULL;
555 } 555 }
556 556
557 if (!(gc = kcalloc(1, sizeof(struct gc), GFP_KERNEL))) { 557 if (!(gc = kzalloc(sizeof(struct gc), GFP_KERNEL))) {
558 parport_put_port(pp); 558 parport_put_port(pp);
559 return NULL; 559 return NULL;
560 } 560 }
diff --git a/drivers/input/joystick/gf2k.c b/drivers/input/joystick/gf2k.c
index 7d969420066..8e4f92b115e 100644
--- a/drivers/input/joystick/gf2k.c
+++ b/drivers/input/joystick/gf2k.c
@@ -242,7 +242,7 @@ static int gf2k_connect(struct gameport *gameport, struct gameport_driver *drv)
242 unsigned char data[GF2K_LENGTH]; 242 unsigned char data[GF2K_LENGTH];
243 int i, err; 243 int i, err;
244 244
245 if (!(gf2k = kcalloc(1, sizeof(struct gf2k), GFP_KERNEL))) 245 if (!(gf2k = kzalloc(sizeof(struct gf2k), GFP_KERNEL)))
246 return -ENOMEM; 246 return -ENOMEM;
247 247
248 gf2k->gameport = gameport; 248 gf2k->gameport = gameport;
diff --git a/drivers/input/joystick/grip.c b/drivers/input/joystick/grip.c
index d1500d2562d..9d3f910dd56 100644
--- a/drivers/input/joystick/grip.c
+++ b/drivers/input/joystick/grip.c
@@ -301,7 +301,7 @@ static int grip_connect(struct gameport *gameport, struct gameport_driver *drv)
301 int i, j, t; 301 int i, j, t;
302 int err; 302 int err;
303 303
304 if (!(grip = kcalloc(1, sizeof(struct grip), GFP_KERNEL))) 304 if (!(grip = kzalloc(sizeof(struct grip), GFP_KERNEL)))
305 return -ENOMEM; 305 return -ENOMEM;
306 306
307 grip->gameport = gameport; 307 grip->gameport = gameport;
diff --git a/drivers/input/joystick/grip_mp.c b/drivers/input/joystick/grip_mp.c
index 0da7bd133cc..da17eee6f57 100644
--- a/drivers/input/joystick/grip_mp.c
+++ b/drivers/input/joystick/grip_mp.c
@@ -607,7 +607,7 @@ static int grip_connect(struct gameport *gameport, struct gameport_driver *drv)
607 struct grip_mp *grip; 607 struct grip_mp *grip;
608 int err; 608 int err;
609 609
610 if (!(grip = kcalloc(1, sizeof(struct grip_mp), GFP_KERNEL))) 610 if (!(grip = kzalloc(sizeof(struct grip_mp), GFP_KERNEL)))
611 return -ENOMEM; 611 return -ENOMEM;
612 612
613 grip->gameport = gameport; 613 grip->gameport = gameport;
diff --git a/drivers/input/joystick/guillemot.c b/drivers/input/joystick/guillemot.c
index f93da7bc082..6a70ec429f0 100644
--- a/drivers/input/joystick/guillemot.c
+++ b/drivers/input/joystick/guillemot.c
@@ -183,7 +183,7 @@ static int guillemot_connect(struct gameport *gameport, struct gameport_driver *
183 int i, t; 183 int i, t;
184 int err; 184 int err;
185 185
186 if (!(guillemot = kcalloc(1, sizeof(struct guillemot), GFP_KERNEL))) 186 if (!(guillemot = kzalloc(sizeof(struct guillemot), GFP_KERNEL)))
187 return -ENOMEM; 187 return -ENOMEM;
188 188
189 guillemot->gameport = gameport; 189 guillemot->gameport = gameport;
diff --git a/drivers/input/joystick/interact.c b/drivers/input/joystick/interact.c
index 9d3f8c38cb0..d7b3472bd68 100644
--- a/drivers/input/joystick/interact.c
+++ b/drivers/input/joystick/interact.c
@@ -212,7 +212,7 @@ static int interact_connect(struct gameport *gameport, struct gameport_driver *d
212 int i, t; 212 int i, t;
213 int err; 213 int err;
214 214
215 if (!(interact = kcalloc(1, sizeof(struct interact), GFP_KERNEL))) 215 if (!(interact = kzalloc(sizeof(struct interact), GFP_KERNEL)))
216 return -ENOMEM; 216 return -ENOMEM;
217 217
218 interact->gameport = gameport; 218 interact->gameport = gameport;
diff --git a/drivers/input/joystick/sidewinder.c b/drivers/input/joystick/sidewinder.c
index 47144a7ed9e..9e0353721a3 100644
--- a/drivers/input/joystick/sidewinder.c
+++ b/drivers/input/joystick/sidewinder.c
@@ -590,7 +590,7 @@ static int sw_connect(struct gameport *gameport, struct gameport_driver *drv)
590 590
591 comment[0] = 0; 591 comment[0] = 0;
592 592
593 sw = kcalloc(1, sizeof(struct sw), GFP_KERNEL); 593 sw = kzalloc(sizeof(struct sw), GFP_KERNEL);
594 buf = kmalloc(SW_LENGTH, GFP_KERNEL); 594 buf = kmalloc(SW_LENGTH, GFP_KERNEL);
595 idbuf = kmalloc(SW_LENGTH, GFP_KERNEL); 595 idbuf = kmalloc(SW_LENGTH, GFP_KERNEL);
596 if (!sw || !buf || !idbuf) { 596 if (!sw || !buf || !idbuf) {
diff --git a/drivers/input/joystick/tmdc.c b/drivers/input/joystick/tmdc.c
index 9eb9954cac6..7431efc4330 100644
--- a/drivers/input/joystick/tmdc.c
+++ b/drivers/input/joystick/tmdc.c
@@ -262,7 +262,7 @@ static int tmdc_connect(struct gameport *gameport, struct gameport_driver *drv)
262 int i, j, k, l, m; 262 int i, j, k, l, m;
263 int err; 263 int err;
264 264
265 if (!(tmdc = kcalloc(1, sizeof(struct tmdc), GFP_KERNEL))) 265 if (!(tmdc = kzalloc(sizeof(struct tmdc), GFP_KERNEL)))
266 return -ENOMEM; 266 return -ENOMEM;
267 267
268 tmdc->gameport = gameport; 268 tmdc->gameport = gameport;
diff --git a/drivers/input/joystick/turbografx.c b/drivers/input/joystick/turbografx.c
index 28100d461cb..0c5b9c8297c 100644
--- a/drivers/input/joystick/turbografx.c
+++ b/drivers/input/joystick/turbografx.c
@@ -178,7 +178,7 @@ static struct tgfx __init *tgfx_probe(int *config, int nargs)
178 return NULL; 178 return NULL;
179 } 179 }
180 180
181 if (!(tgfx = kcalloc(1, sizeof(struct tgfx), GFP_KERNEL))) { 181 if (!(tgfx = kzalloc(sizeof(struct tgfx), GFP_KERNEL))) {
182 parport_put_port(pp); 182 parport_put_port(pp);
183 return NULL; 183 return NULL;
184 } 184 }
diff --git a/drivers/input/keyboard/corgikbd.c b/drivers/input/keyboard/corgikbd.c
index a8551711e8d..cd4b6e79501 100644
--- a/drivers/input/keyboard/corgikbd.c
+++ b/drivers/input/keyboard/corgikbd.c
@@ -16,6 +16,7 @@
16#include <linux/init.h> 16#include <linux/init.h>
17#include <linux/input.h> 17#include <linux/input.h>
18#include <linux/interrupt.h> 18#include <linux/interrupt.h>
19#include <linux/jiffies.h>
19#include <linux/module.h> 20#include <linux/module.h>
20#include <linux/slab.h> 21#include <linux/slab.h>
21#include <asm/irq.h> 22#include <asm/irq.h>
@@ -32,7 +33,6 @@
32/* zero code, 124 scancodes + 3 hinge combinations */ 33/* zero code, 124 scancodes + 3 hinge combinations */
33#define NR_SCANCODES ( SCANCODE(KB_ROWS-1,KB_COLS-1) +1 +1 +3 ) 34#define NR_SCANCODES ( SCANCODE(KB_ROWS-1,KB_COLS-1) +1 +1 +3 )
34#define SCAN_INTERVAL (HZ/10) 35#define SCAN_INTERVAL (HZ/10)
35#define CORGIKBD_PRESSED 1
36 36
37#define HINGE_SCAN_INTERVAL (HZ/4) 37#define HINGE_SCAN_INTERVAL (HZ/4)
38 38
@@ -73,25 +73,13 @@ struct corgikbd {
73 struct input_dev input; 73 struct input_dev input;
74 char phys[32]; 74 char phys[32];
75 75
76 unsigned char state[ARRAY_SIZE(corgikbd_keycode)];
77 spinlock_t lock; 76 spinlock_t lock;
78
79 struct timer_list timer; 77 struct timer_list timer;
80 struct timer_list htimer; 78 struct timer_list htimer;
81};
82 79
83static void handle_scancode(unsigned int pressed,unsigned int scancode, struct corgikbd *corgikbd_data) 80 unsigned int suspended;
84{ 81 unsigned long suspend_jiffies;
85 if (pressed && !(corgikbd_data->state[scancode] & CORGIKBD_PRESSED)) { 82};
86 corgikbd_data->state[scancode] |= CORGIKBD_PRESSED;
87 input_report_key(&corgikbd_data->input, corgikbd_data->keycode[scancode], 1);
88 if (corgikbd_data->keycode[scancode] == CORGI_KEY_OFF)
89 input_event(&corgikbd_data->input, EV_PWR, CORGI_KEY_OFF, 1);
90 } else if (!pressed && corgikbd_data->state[scancode] & CORGIKBD_PRESSED) {
91 corgikbd_data->state[scancode] &= ~CORGIKBD_PRESSED;
92 input_report_key(&corgikbd_data->input, corgikbd_data->keycode[scancode], 0);
93 }
94}
95 83
96#define KB_DISCHARGE_DELAY 10 84#define KB_DISCHARGE_DELAY 10
97#define KB_ACTIVATE_DELAY 10 85#define KB_ACTIVATE_DELAY 10
@@ -105,36 +93,36 @@ static void handle_scancode(unsigned int pressed,unsigned int scancode, struct c
105 */ 93 */
106static inline void corgikbd_discharge_all(void) 94static inline void corgikbd_discharge_all(void)
107{ 95{
108 // STROBE All HiZ 96 /* STROBE All HiZ */
109 GPCR2 = CORGI_GPIO_ALL_STROBE_BIT; 97 GPCR2 = CORGI_GPIO_ALL_STROBE_BIT;
110 GPDR2 &= ~CORGI_GPIO_ALL_STROBE_BIT; 98 GPDR2 &= ~CORGI_GPIO_ALL_STROBE_BIT;
111} 99}
112 100
113static inline void corgikbd_activate_all(void) 101static inline void corgikbd_activate_all(void)
114{ 102{
115 // STROBE ALL -> High 103 /* STROBE ALL -> High */
116 GPSR2 = CORGI_GPIO_ALL_STROBE_BIT; 104 GPSR2 = CORGI_GPIO_ALL_STROBE_BIT;
117 GPDR2 |= CORGI_GPIO_ALL_STROBE_BIT; 105 GPDR2 |= CORGI_GPIO_ALL_STROBE_BIT;
118 106
119 udelay(KB_DISCHARGE_DELAY); 107 udelay(KB_DISCHARGE_DELAY);
120 108
121 // Clear any interrupts we may have triggered when altering the GPIO lines 109 /* Clear any interrupts we may have triggered when altering the GPIO lines */
122 GEDR1 = CORGI_GPIO_HIGH_SENSE_BIT; 110 GEDR1 = CORGI_GPIO_HIGH_SENSE_BIT;
123 GEDR2 = CORGI_GPIO_LOW_SENSE_BIT; 111 GEDR2 = CORGI_GPIO_LOW_SENSE_BIT;
124} 112}
125 113
126static inline void corgikbd_activate_col(int col) 114static inline void corgikbd_activate_col(int col)
127{ 115{
128 // STROBE col -> High, not col -> HiZ 116 /* STROBE col -> High, not col -> HiZ */
129 GPSR2 = CORGI_GPIO_STROBE_BIT(col); 117 GPSR2 = CORGI_GPIO_STROBE_BIT(col);
130 GPDR2 = (GPDR2 & ~CORGI_GPIO_ALL_STROBE_BIT) | CORGI_GPIO_STROBE_BIT(col); 118 GPDR2 = (GPDR2 & ~CORGI_GPIO_ALL_STROBE_BIT) | CORGI_GPIO_STROBE_BIT(col);
131} 119}
132 120
133static inline void corgikbd_reset_col(int col) 121static inline void corgikbd_reset_col(int col)
134{ 122{
135 // STROBE col -> Low 123 /* STROBE col -> Low */
136 GPCR2 = CORGI_GPIO_STROBE_BIT(col); 124 GPCR2 = CORGI_GPIO_STROBE_BIT(col);
137 // STROBE col -> out, not col -> HiZ 125 /* STROBE col -> out, not col -> HiZ */
138 GPDR2 = (GPDR2 & ~CORGI_GPIO_ALL_STROBE_BIT) | CORGI_GPIO_STROBE_BIT(col); 126 GPDR2 = (GPDR2 & ~CORGI_GPIO_ALL_STROBE_BIT) | CORGI_GPIO_STROBE_BIT(col);
139} 127}
140 128
@@ -149,10 +137,13 @@ static inline void corgikbd_reset_col(int col)
149/* Scan the hardware keyboard and push any changes up through the input layer */ 137/* Scan the hardware keyboard and push any changes up through the input layer */
150static void corgikbd_scankeyboard(struct corgikbd *corgikbd_data, struct pt_regs *regs) 138static void corgikbd_scankeyboard(struct corgikbd *corgikbd_data, struct pt_regs *regs)
151{ 139{
152 unsigned int row, col, rowd, scancode; 140 unsigned int row, col, rowd;
153 unsigned long flags; 141 unsigned long flags;
154 unsigned int num_pressed; 142 unsigned int num_pressed;
155 143
144 if (corgikbd_data->suspended)
145 return;
146
156 spin_lock_irqsave(&corgikbd_data->lock, flags); 147 spin_lock_irqsave(&corgikbd_data->lock, flags);
157 148
158 if (regs) 149 if (regs)
@@ -173,10 +164,21 @@ static void corgikbd_scankeyboard(struct corgikbd *corgikbd_data, struct pt_regs
173 164
174 rowd = GET_ROWS_STATUS(col); 165 rowd = GET_ROWS_STATUS(col);
175 for (row = 0; row < KB_ROWS; row++) { 166 for (row = 0; row < KB_ROWS; row++) {
167 unsigned int scancode, pressed;
168
176 scancode = SCANCODE(row, col); 169 scancode = SCANCODE(row, col);
177 handle_scancode((rowd & KB_ROWMASK(row)), scancode, corgikbd_data); 170 pressed = rowd & KB_ROWMASK(row);
178 if (rowd & KB_ROWMASK(row)) 171
172 input_report_key(&corgikbd_data->input, corgikbd_data->keycode[scancode], pressed);
173
174 if (pressed)
179 num_pressed++; 175 num_pressed++;
176
177 if (pressed && (corgikbd_data->keycode[scancode] == CORGI_KEY_OFF)
178 && time_after(jiffies, corgikbd_data->suspend_jiffies + HZ)) {
179 input_event(&corgikbd_data->input, EV_PWR, CORGI_KEY_OFF, 1);
180 corgikbd_data->suspend_jiffies=jiffies;
181 }
180 } 182 }
181 corgikbd_reset_col(col); 183 corgikbd_reset_col(col);
182 } 184 }
@@ -221,8 +223,11 @@ static void corgikbd_timer_callback(unsigned long data)
221 * The hinge switches generate no interrupt so they need to be 223 * The hinge switches generate no interrupt so they need to be
222 * monitored by a timer. 224 * monitored by a timer.
223 * 225 *
224 * When we detect changes, we debounce it and then pass the three 226 * We debounce the switches and pass them to the input system.
225 * positions the system can take as keypresses to the input system. 227 *
228 * gprr == 0x00 - Keyboard with Landscape Screen
229 * 0x08 - No Keyboard with Portrait Screen
230 * 0x0c - Keyboard and Screen Closed
226 */ 231 */
227 232
228#define HINGE_STABLE_COUNT 2 233#define HINGE_STABLE_COUNT 2
@@ -235,7 +240,7 @@ static void corgikbd_hinge_timer(unsigned long data)
235 unsigned long gprr; 240 unsigned long gprr;
236 unsigned long flags; 241 unsigned long flags;
237 242
238 gprr = read_scoop_reg(SCOOP_GPRR) & (CORGI_SCP_SWA | CORGI_SCP_SWB); 243 gprr = read_scoop_reg(&corgiscoop_device.dev, SCOOP_GPRR) & (CORGI_SCP_SWA | CORGI_SCP_SWB);
239 if (gprr != sharpsl_hinge_state) { 244 if (gprr != sharpsl_hinge_state) {
240 hinge_count = 0; 245 hinge_count = 0;
241 sharpsl_hinge_state = gprr; 246 sharpsl_hinge_state = gprr;
@@ -244,9 +249,8 @@ static void corgikbd_hinge_timer(unsigned long data)
244 if (hinge_count >= HINGE_STABLE_COUNT) { 249 if (hinge_count >= HINGE_STABLE_COUNT) {
245 spin_lock_irqsave(&corgikbd_data->lock, flags); 250 spin_lock_irqsave(&corgikbd_data->lock, flags);
246 251
247 handle_scancode((sharpsl_hinge_state == 0x00), 125, corgikbd_data); /* Keyboard with Landscape Screen */ 252 input_report_switch(&corgikbd_data->input, SW_0, ((sharpsl_hinge_state & CORGI_SCP_SWA) != 0));
248 handle_scancode((sharpsl_hinge_state == 0x08), 126, corgikbd_data); /* No Keyboard with Portrait Screen */ 253 input_report_switch(&corgikbd_data->input, SW_1, ((sharpsl_hinge_state & CORGI_SCP_SWB) != 0));
249 handle_scancode((sharpsl_hinge_state == 0x0c), 127, corgikbd_data); /* Keyboard and Screen Closed */
250 input_sync(&corgikbd_data->input); 254 input_sync(&corgikbd_data->input);
251 255
252 spin_unlock_irqrestore(&corgikbd_data->lock, flags); 256 spin_unlock_irqrestore(&corgikbd_data->lock, flags);
@@ -255,19 +259,45 @@ static void corgikbd_hinge_timer(unsigned long data)
255 mod_timer(&corgikbd_data->htimer, jiffies + HINGE_SCAN_INTERVAL); 259 mod_timer(&corgikbd_data->htimer, jiffies + HINGE_SCAN_INTERVAL);
256} 260}
257 261
262#ifdef CONFIG_PM
263static int corgikbd_suspend(struct device *dev, pm_message_t state, uint32_t level)
264{
265 if (level == SUSPEND_POWER_DOWN) {
266 struct corgikbd *corgikbd = dev_get_drvdata(dev);
267 corgikbd->suspended = 1;
268 }
269 return 0;
270}
271
272static int corgikbd_resume(struct device *dev, uint32_t level)
273{
274 if (level == RESUME_POWER_ON) {
275 struct corgikbd *corgikbd = dev_get_drvdata(dev);
276
277 /* Upon resume, ignore the suspend key for a short while */
278 corgikbd->suspend_jiffies=jiffies;
279 corgikbd->suspended = 0;
280 }
281 return 0;
282}
283#else
284#define corgikbd_suspend NULL
285#define corgikbd_resume NULL
286#endif
287
258static int __init corgikbd_probe(struct device *dev) 288static int __init corgikbd_probe(struct device *dev)
259{ 289{
260 int i; 290 int i;
261 struct corgikbd *corgikbd; 291 struct corgikbd *corgikbd;
262 292
263 corgikbd = kcalloc(1, sizeof(struct corgikbd), GFP_KERNEL); 293 corgikbd = kzalloc(sizeof(struct corgikbd), GFP_KERNEL);
264 if (!corgikbd) 294 if (!corgikbd)
265 return -ENOMEM; 295 return -ENOMEM;
266 296
267 dev_set_drvdata(dev,corgikbd); 297 dev_set_drvdata(dev,corgikbd);
268 strcpy(corgikbd->phys, "corgikbd/input0"); 298 strcpy(corgikbd->phys, "corgikbd/input0");
269 299
270 spin_lock_init(corgikbd->lock); 300 spin_lock_init(&corgikbd->lock);
271 301
272 /* Init Keyboard rescan timer */ 302 /* Init Keyboard rescan timer */
273 init_timer(&corgikbd->timer); 303 init_timer(&corgikbd->timer);
@@ -279,6 +309,8 @@ static int __init corgikbd_probe(struct device *dev)
279 corgikbd->htimer.function = corgikbd_hinge_timer; 309 corgikbd->htimer.function = corgikbd_hinge_timer;
280 corgikbd->htimer.data = (unsigned long) corgikbd; 310 corgikbd->htimer.data = (unsigned long) corgikbd;
281 311
312 corgikbd->suspend_jiffies=jiffies;
313
282 init_input_dev(&corgikbd->input); 314 init_input_dev(&corgikbd->input);
283 corgikbd->input.private = corgikbd; 315 corgikbd->input.private = corgikbd;
284 corgikbd->input.name = "Corgi Keyboard"; 316 corgikbd->input.name = "Corgi Keyboard";
@@ -288,7 +320,7 @@ static int __init corgikbd_probe(struct device *dev)
288 corgikbd->input.id.vendor = 0x0001; 320 corgikbd->input.id.vendor = 0x0001;
289 corgikbd->input.id.product = 0x0001; 321 corgikbd->input.id.product = 0x0001;
290 corgikbd->input.id.version = 0x0100; 322 corgikbd->input.id.version = 0x0100;
291 corgikbd->input.evbit[0] = BIT(EV_KEY) | BIT(EV_REP) | BIT(EV_PWR); 323 corgikbd->input.evbit[0] = BIT(EV_KEY) | BIT(EV_REP) | BIT(EV_PWR) | BIT(EV_SW);
292 corgikbd->input.keycode = corgikbd->keycode; 324 corgikbd->input.keycode = corgikbd->keycode;
293 corgikbd->input.keycodesize = sizeof(unsigned char); 325 corgikbd->input.keycodesize = sizeof(unsigned char);
294 corgikbd->input.keycodemax = ARRAY_SIZE(corgikbd_keycode); 326 corgikbd->input.keycodemax = ARRAY_SIZE(corgikbd_keycode);
@@ -297,6 +329,8 @@ static int __init corgikbd_probe(struct device *dev)
297 for (i = 0; i < ARRAY_SIZE(corgikbd_keycode); i++) 329 for (i = 0; i < ARRAY_SIZE(corgikbd_keycode); i++)
298 set_bit(corgikbd->keycode[i], corgikbd->input.keybit); 330 set_bit(corgikbd->keycode[i], corgikbd->input.keybit);
299 clear_bit(0, corgikbd->input.keybit); 331 clear_bit(0, corgikbd->input.keybit);
332 set_bit(SW_0, corgikbd->input.swbit);
333 set_bit(SW_1, corgikbd->input.swbit);
300 334
301 input_register_device(&corgikbd->input); 335 input_register_device(&corgikbd->input);
302 mod_timer(&corgikbd->htimer, jiffies + HINGE_SCAN_INTERVAL); 336 mod_timer(&corgikbd->htimer, jiffies + HINGE_SCAN_INTERVAL);
@@ -343,6 +377,8 @@ static struct device_driver corgikbd_driver = {
343 .bus = &platform_bus_type, 377 .bus = &platform_bus_type,
344 .probe = corgikbd_probe, 378 .probe = corgikbd_probe,
345 .remove = corgikbd_remove, 379 .remove = corgikbd_remove,
380 .suspend = corgikbd_suspend,
381 .resume = corgikbd_resume,
346}; 382};
347 383
348static int __devinit corgikbd_init(void) 384static int __devinit corgikbd_init(void)
diff --git a/drivers/input/mouse/psmouse-base.c b/drivers/input/mouse/psmouse-base.c
index 2bb2fe78bdc..12bdd3eff92 100644
--- a/drivers/input/mouse/psmouse-base.c
+++ b/drivers/input/mouse/psmouse-base.c
@@ -883,7 +883,7 @@ static int psmouse_connect(struct serio *serio, struct serio_driver *drv)
883 psmouse_deactivate(parent); 883 psmouse_deactivate(parent);
884 } 884 }
885 885
886 if (!(psmouse = kcalloc(1, sizeof(struct psmouse), GFP_KERNEL))) { 886 if (!(psmouse = kzalloc(sizeof(struct psmouse), GFP_KERNEL))) {
887 retval = -ENOMEM; 887 retval = -ENOMEM;
888 goto out; 888 goto out;
889 } 889 }
diff --git a/drivers/input/serio/serport.c b/drivers/input/serio/serport.c
index 79ca3846915..1bd88fca054 100644
--- a/drivers/input/serio/serport.c
+++ b/drivers/input/serio/serport.c
@@ -87,7 +87,7 @@ static int serport_ldisc_open(struct tty_struct *tty)
87 if (!capable(CAP_SYS_ADMIN)) 87 if (!capable(CAP_SYS_ADMIN))
88 return -EPERM; 88 return -EPERM;
89 89
90 serport = kcalloc(1, sizeof(struct serport), GFP_KERNEL); 90 serport = kzalloc(sizeof(struct serport), GFP_KERNEL);
91 if (!serport) 91 if (!serport)
92 return -ENOMEM; 92 return -ENOMEM;
93 93
@@ -165,7 +165,7 @@ static ssize_t serport_ldisc_read(struct tty_struct * tty, struct file * file, u
165 if (test_and_set_bit(SERPORT_BUSY, &serport->flags)) 165 if (test_and_set_bit(SERPORT_BUSY, &serport->flags))
166 return -EBUSY; 166 return -EBUSY;
167 167
168 serport->serio = serio = kcalloc(1, sizeof(struct serio), GFP_KERNEL); 168 serport->serio = serio = kzalloc(sizeof(struct serio), GFP_KERNEL);
169 if (!serio) 169 if (!serio)
170 return -ENOMEM; 170 return -ENOMEM;
171 171
diff --git a/drivers/input/touchscreen/corgi_ts.c b/drivers/input/touchscreen/corgi_ts.c
index 3f8b61cfbc3..5d19261b884 100644
--- a/drivers/input/touchscreen/corgi_ts.c
+++ b/drivers/input/touchscreen/corgi_ts.c
@@ -53,11 +53,8 @@ struct corgi_ts {
53 53
54#define SyncHS() while((STATUS_HSYNC) == 0); while((STATUS_HSYNC) != 0); 54#define SyncHS() while((STATUS_HSYNC) == 0); while((STATUS_HSYNC) != 0);
55#define CCNT(a) asm volatile ("mrc p14, 0, %0, C1, C0, 0" : "=r"(a)) 55#define CCNT(a) asm volatile ("mrc p14, 0, %0, C1, C0, 0" : "=r"(a))
56#define CCNT_ON() {int pmnc = 1; asm volatile ("mcr p14, 0, %0, C0, C0, 0" : : "r"(pmnc));} 56#define PMNC_GET(x) asm volatile ("mrc p14, 0, %0, C0, C0, 0" : "=r"(x))
57#define CCNT_OFF() {int pmnc = 0; asm volatile ("mcr p14, 0, %0, C0, C0, 0" : : "r"(pmnc));} 57#define PMNC_SET(x) asm volatile ("mcr p14, 0, %0, C0, C0, 0" : : "r"(x))
58
59#define WAIT_HS_400_VGA 7013U // 17.615us
60#define WAIT_HS_400_QVGA 16622U // 41.750us
61 58
62 59
63/* ADS7846 Touch Screen Controller bit definitions */ 60/* ADS7846 Touch Screen Controller bit definitions */
@@ -69,41 +66,29 @@ struct corgi_ts {
69#define ADSCTRL_STS (1u << 7) /* Start Bit */ 66#define ADSCTRL_STS (1u << 7) /* Start Bit */
70 67
71/* External Functions */ 68/* External Functions */
72extern int w100fb_get_xres(void); 69extern unsigned long w100fb_get_hsynclen(struct device *dev);
73extern int w100fb_get_blanking(void);
74extern int w100fb_get_fastsysclk(void);
75extern unsigned int get_clk_frequency_khz(int info); 70extern unsigned int get_clk_frequency_khz(int info);
76 71
77static unsigned long calc_waittime(void) 72static unsigned long calc_waittime(void)
78{ 73{
79 int w100fb_xres = w100fb_get_xres(); 74 unsigned long hsync_len = w100fb_get_hsynclen(&corgifb_device.dev);
80 unsigned int waittime = 0;
81
82 if (w100fb_xres == 480 || w100fb_xres == 640) {
83 waittime = WAIT_HS_400_VGA * get_clk_frequency_khz(0) / 398131U;
84
85 if (w100fb_get_fastsysclk() == 100)
86 waittime = waittime * 75 / 100;
87
88 if (w100fb_xres == 640)
89 waittime *= 3;
90 75
91 return waittime; 76 if (hsync_len)
92 } 77 return get_clk_frequency_khz(0)*1000/hsync_len;
93 78 else
94 return WAIT_HS_400_QVGA * get_clk_frequency_khz(0) / 398131U; 79 return 0;
95} 80}
96 81
97static int sync_receive_data_send_cmd(int doRecive, int doSend, unsigned int address, unsigned long wait_time) 82static int sync_receive_data_send_cmd(int doRecive, int doSend, unsigned int address, unsigned long wait_time)
98{ 83{
84 unsigned long timer1 = 0, timer2, pmnc = 0;
99 int pos = 0; 85 int pos = 0;
100 unsigned long timer1 = 0, timer2;
101 int dosleep;
102 86
103 dosleep = !w100fb_get_blanking(); 87 if (wait_time && doSend) {
88 PMNC_GET(pmnc);
89 if (!(pmnc & 0x01))
90 PMNC_SET(0x01);
104 91
105 if (dosleep && doSend) {
106 CCNT_ON();
107 /* polling HSync */ 92 /* polling HSync */
108 SyncHS(); 93 SyncHS();
109 /* get CCNT */ 94 /* get CCNT */
@@ -119,11 +104,11 @@ static int sync_receive_data_send_cmd(int doRecive, int doSend, unsigned int add
119 corgi_ssp_ads7846_put(cmd); 104 corgi_ssp_ads7846_put(cmd);
120 corgi_ssp_ads7846_get(); 105 corgi_ssp_ads7846_get();
121 106
122 if (dosleep) { 107 if (wait_time) {
123 /* Wait after HSync */ 108 /* Wait after HSync */
124 CCNT(timer2); 109 CCNT(timer2);
125 if (timer2-timer1 > wait_time) { 110 if (timer2-timer1 > wait_time) {
126 /* timeout */ 111 /* too slow - timeout, try again */
127 SyncHS(); 112 SyncHS();
128 /* get OSCR */ 113 /* get OSCR */
129 CCNT(timer1); 114 CCNT(timer1);
@@ -134,8 +119,8 @@ static int sync_receive_data_send_cmd(int doRecive, int doSend, unsigned int add
134 CCNT(timer2); 119 CCNT(timer2);
135 } 120 }
136 corgi_ssp_ads7846_put(cmd); 121 corgi_ssp_ads7846_put(cmd);
137 if (dosleep) 122 if (wait_time && !(pmnc & 0x01))
138 CCNT_OFF(); 123 PMNC_SET(pmnc);
139 } 124 }
140 return pos; 125 return pos;
141} 126}
@@ -244,7 +229,7 @@ static irqreturn_t ts_interrupt(int irq, void *dev_id, struct pt_regs *regs)
244} 229}
245 230
246#ifdef CONFIG_PM 231#ifdef CONFIG_PM
247static int corgits_suspend(struct device *dev, uint32_t state, uint32_t level) 232static int corgits_suspend(struct device *dev, pm_message_t state, uint32_t level)
248{ 233{
249 if (level == SUSPEND_POWER_DOWN) { 234 if (level == SUSPEND_POWER_DOWN) {
250 struct corgi_ts *corgi_ts = dev_get_drvdata(dev); 235 struct corgi_ts *corgi_ts = dev_get_drvdata(dev);
diff --git a/drivers/isdn/hisax/hisax.h b/drivers/isdn/hisax/hisax.h
index 17cf7663c58..26c545fa223 100644
--- a/drivers/isdn/hisax/hisax.h
+++ b/drivers/isdn/hisax/hisax.h
@@ -10,7 +10,6 @@
10#include <linux/errno.h> 10#include <linux/errno.h>
11#include <linux/fs.h> 11#include <linux/fs.h>
12#include <linux/major.h> 12#include <linux/major.h>
13#include <asm/segment.h>
14#include <asm/io.h> 13#include <asm/io.h>
15#include <linux/delay.h> 14#include <linux/delay.h>
16#include <linux/kernel.h> 15#include <linux/kernel.h>
@@ -1242,6 +1241,8 @@ struct IsdnCardState {
1242 1241
1243#ifdef CONFIG_HISAX_ENTERNOW_PCI 1242#ifdef CONFIG_HISAX_ENTERNOW_PCI
1244#define CARD_FN_ENTERNOW_PCI 1 1243#define CARD_FN_ENTERNOW_PCI 1
1244#else
1245#define CARD_FN_ENTERNOW_PCI 0
1245#endif 1246#endif
1246 1247
1247#define TEI_PER_CARD 1 1248#define TEI_PER_CARD 1
diff --git a/drivers/isdn/i4l/isdn_v110.c b/drivers/isdn/i4l/isdn_v110.c
index f47f2b9846d..38619e8cd82 100644
--- a/drivers/isdn/i4l/isdn_v110.c
+++ b/drivers/isdn/i4l/isdn_v110.c
@@ -516,11 +516,11 @@ buffer_full:
516} 516}
517 517
518int 518int
519isdn_v110_stat_callback(int idx, isdn_ctrl * c) 519isdn_v110_stat_callback(int idx, isdn_ctrl *c)
520{ 520{
521 isdn_v110_stream *v = NULL; 521 isdn_v110_stream *v = NULL;
522 int i; 522 int i;
523 int ret; 523 int ret = 0;
524 524
525 if (idx < 0) 525 if (idx < 0)
526 return 0; 526 return 0;
diff --git a/drivers/macintosh/mediabay.c b/drivers/macintosh/mediabay.c
index 7c16c25fc5d..c0712a1ea5a 100644
--- a/drivers/macintosh/mediabay.c
+++ b/drivers/macintosh/mediabay.c
@@ -708,7 +708,7 @@ static int __pmac media_bay_suspend(struct macio_dev *mdev, pm_message_t state)
708{ 708{
709 struct media_bay_info *bay = macio_get_drvdata(mdev); 709 struct media_bay_info *bay = macio_get_drvdata(mdev);
710 710
711 if (state != mdev->ofdev.dev.power.power_state && state == PM_SUSPEND_MEM) { 711 if (state.event != mdev->ofdev.dev.power.power_state.event && state.event == PM_EVENT_SUSPEND) {
712 down(&bay->lock); 712 down(&bay->lock);
713 bay->sleeping = 1; 713 bay->sleeping = 1;
714 set_mb_power(bay, 0); 714 set_mb_power(bay, 0);
@@ -723,8 +723,8 @@ static int __pmac media_bay_resume(struct macio_dev *mdev)
723{ 723{
724 struct media_bay_info *bay = macio_get_drvdata(mdev); 724 struct media_bay_info *bay = macio_get_drvdata(mdev);
725 725
726 if (mdev->ofdev.dev.power.power_state != 0) { 726 if (mdev->ofdev.dev.power.power_state.event != PM_EVENT_ON) {
727 mdev->ofdev.dev.power.power_state = 0; 727 mdev->ofdev.dev.power.power_state = PMSG_ON;
728 728
729 /* We re-enable the bay using it's previous content 729 /* We re-enable the bay using it's previous content
730 only if it did not change. Note those bozo timings, 730 only if it did not change. Note those bozo timings,
diff --git a/drivers/macintosh/via-pmu.c b/drivers/macintosh/via-pmu.c
index 4a0a0ad2d03..645a2e5c70a 100644
--- a/drivers/macintosh/via-pmu.c
+++ b/drivers/macintosh/via-pmu.c
@@ -3065,7 +3065,7 @@ static int pmu_sys_suspended = 0;
3065 3065
3066static int pmu_sys_suspend(struct sys_device *sysdev, pm_message_t state) 3066static int pmu_sys_suspend(struct sys_device *sysdev, pm_message_t state)
3067{ 3067{
3068 if (state != PM_SUSPEND_DISK || pmu_sys_suspended) 3068 if (state.event != PM_EVENT_SUSPEND || pmu_sys_suspended)
3069 return 0; 3069 return 0;
3070 3070
3071 /* Suspend PMU event interrupts */ 3071 /* Suspend PMU event interrupts */
diff --git a/drivers/md/dm-crypt.c b/drivers/md/dm-crypt.c
index d0a4bab220e..b82bc315047 100644
--- a/drivers/md/dm-crypt.c
+++ b/drivers/md/dm-crypt.c
@@ -144,7 +144,7 @@ static int crypt_iv_essiv_ctr(struct crypt_config *cc, struct dm_target *ti,
144 } 144 }
145 145
146 /* Hash the cipher key with the given hash algorithm */ 146 /* Hash the cipher key with the given hash algorithm */
147 hash_tfm = crypto_alloc_tfm(opts, 0); 147 hash_tfm = crypto_alloc_tfm(opts, CRYPTO_TFM_REQ_MAY_SLEEP);
148 if (hash_tfm == NULL) { 148 if (hash_tfm == NULL) {
149 ti->error = PFX "Error initializing ESSIV hash"; 149 ti->error = PFX "Error initializing ESSIV hash";
150 return -EINVAL; 150 return -EINVAL;
@@ -172,7 +172,8 @@ static int crypt_iv_essiv_ctr(struct crypt_config *cc, struct dm_target *ti,
172 172
173 /* Setup the essiv_tfm with the given salt */ 173 /* Setup the essiv_tfm with the given salt */
174 essiv_tfm = crypto_alloc_tfm(crypto_tfm_alg_name(cc->tfm), 174 essiv_tfm = crypto_alloc_tfm(crypto_tfm_alg_name(cc->tfm),
175 CRYPTO_TFM_MODE_ECB); 175 CRYPTO_TFM_MODE_ECB |
176 CRYPTO_TFM_REQ_MAY_SLEEP);
176 if (essiv_tfm == NULL) { 177 if (essiv_tfm == NULL) {
177 ti->error = PFX "Error allocating crypto tfm for ESSIV"; 178 ti->error = PFX "Error allocating crypto tfm for ESSIV";
178 kfree(salt); 179 kfree(salt);
@@ -587,7 +588,7 @@ static int crypt_ctr(struct dm_target *ti, unsigned int argc, char **argv)
587 goto bad1; 588 goto bad1;
588 } 589 }
589 590
590 tfm = crypto_alloc_tfm(cipher, crypto_flags); 591 tfm = crypto_alloc_tfm(cipher, crypto_flags | CRYPTO_TFM_REQ_MAY_SLEEP);
591 if (!tfm) { 592 if (!tfm) {
592 ti->error = PFX "Error allocating crypto tfm"; 593 ti->error = PFX "Error allocating crypto tfm";
593 goto bad1; 594 goto bad1;
diff --git a/drivers/md/dm-io.c b/drivers/md/dm-io.c
index 45754bb6a79..9de000131a8 100644
--- a/drivers/md/dm-io.c
+++ b/drivers/md/dm-io.c
@@ -239,6 +239,11 @@ static void vm_dp_init(struct dpages *dp, void *data)
239 dp->context_ptr = data; 239 dp->context_ptr = data;
240} 240}
241 241
242static void dm_bio_destructor(struct bio *bio)
243{
244 bio_free(bio, _bios);
245}
246
242/*----------------------------------------------------------------- 247/*-----------------------------------------------------------------
243 * IO routines that accept a list of pages. 248 * IO routines that accept a list of pages.
244 *---------------------------------------------------------------*/ 249 *---------------------------------------------------------------*/
@@ -263,6 +268,7 @@ static void do_region(int rw, unsigned int region, struct io_region *where,
263 bio->bi_bdev = where->bdev; 268 bio->bi_bdev = where->bdev;
264 bio->bi_end_io = endio; 269 bio->bi_end_io = endio;
265 bio->bi_private = io; 270 bio->bi_private = io;
271 bio->bi_destructor = dm_bio_destructor;
266 bio_set_region(bio, region); 272 bio_set_region(bio, region);
267 273
268 /* 274 /*
diff --git a/drivers/md/dm.c b/drivers/md/dm.c
index d487d9deb98..930b9fc2795 100644
--- a/drivers/md/dm.c
+++ b/drivers/md/dm.c
@@ -399,6 +399,11 @@ struct clone_info {
399 unsigned short idx; 399 unsigned short idx;
400}; 400};
401 401
402static void dm_bio_destructor(struct bio *bio)
403{
404 bio_free(bio, dm_set);
405}
406
402/* 407/*
403 * Creates a little bio that is just does part of a bvec. 408 * Creates a little bio that is just does part of a bvec.
404 */ 409 */
@@ -410,6 +415,7 @@ static struct bio *split_bvec(struct bio *bio, sector_t sector,
410 struct bio_vec *bv = bio->bi_io_vec + idx; 415 struct bio_vec *bv = bio->bi_io_vec + idx;
411 416
412 clone = bio_alloc_bioset(GFP_NOIO, 1, dm_set); 417 clone = bio_alloc_bioset(GFP_NOIO, 1, dm_set);
418 clone->bi_destructor = dm_bio_destructor;
413 *clone->bi_io_vec = *bv; 419 *clone->bi_io_vec = *bv;
414 420
415 clone->bi_sector = sector; 421 clone->bi_sector = sector;
diff --git a/drivers/media/common/saa7146_i2c.c b/drivers/media/common/saa7146_i2c.c
index 781f23f0cbc..6284894505c 100644
--- a/drivers/media/common/saa7146_i2c.c
+++ b/drivers/media/common/saa7146_i2c.c
@@ -387,8 +387,6 @@ static int saa7146_i2c_xfer(struct i2c_adapter* adapter, struct i2c_msg *msg, in
387 387
388/* exported algorithm data */ 388/* exported algorithm data */
389static struct i2c_algorithm saa7146_algo = { 389static struct i2c_algorithm saa7146_algo = {
390 .name = "saa7146 i2c algorithm",
391 .id = I2C_ALGO_SAA7146,
392 .master_xfer = saa7146_i2c_xfer, 390 .master_xfer = saa7146_i2c_xfer,
393 .functionality = saa7146_i2c_func, 391 .functionality = saa7146_i2c_func,
394}; 392};
@@ -412,7 +410,7 @@ int saa7146_i2c_adapter_prepare(struct saa7146_dev *dev, struct i2c_adapter *i2c
412#endif 410#endif
413 i2c_adapter->algo = &saa7146_algo; 411 i2c_adapter->algo = &saa7146_algo;
414 i2c_adapter->algo_data = NULL; 412 i2c_adapter->algo_data = NULL;
415 i2c_adapter->id = I2C_ALGO_SAA7146; 413 i2c_adapter->id = I2C_HW_SAA7146;
416 i2c_adapter->timeout = SAA7146_I2C_TIMEOUT; 414 i2c_adapter->timeout = SAA7146_I2C_TIMEOUT;
417 i2c_adapter->retries = SAA7146_I2C_RETRIES; 415 i2c_adapter->retries = SAA7146_I2C_RETRIES;
418 } 416 }
diff --git a/drivers/media/dvb/b2c2/flexcop-i2c.c b/drivers/media/dvb/b2c2/flexcop-i2c.c
index be4266d4ae9..56495cb6cd0 100644
--- a/drivers/media/dvb/b2c2/flexcop-i2c.c
+++ b/drivers/media/dvb/b2c2/flexcop-i2c.c
@@ -172,8 +172,6 @@ static u32 flexcop_i2c_func(struct i2c_adapter *adapter)
172} 172}
173 173
174static struct i2c_algorithm flexcop_algo = { 174static struct i2c_algorithm flexcop_algo = {
175 .name = "FlexCop I2C algorithm",
176 .id = I2C_ALGO_BIT,
177 .master_xfer = flexcop_master_xfer, 175 .master_xfer = flexcop_master_xfer,
178 .functionality = flexcop_i2c_func, 176 .functionality = flexcop_i2c_func,
179}; 177};
@@ -192,7 +190,6 @@ int flexcop_i2c_init(struct flexcop_device *fc)
192 fc->i2c_adap.class = I2C_CLASS_TV_DIGITAL; 190 fc->i2c_adap.class = I2C_CLASS_TV_DIGITAL;
193 fc->i2c_adap.algo = &flexcop_algo; 191 fc->i2c_adap.algo = &flexcop_algo;
194 fc->i2c_adap.algo_data = NULL; 192 fc->i2c_adap.algo_data = NULL;
195 fc->i2c_adap.id = I2C_ALGO_BIT;
196 193
197 if ((ret = i2c_add_adapter(&fc->i2c_adap)) < 0) 194 if ((ret = i2c_add_adapter(&fc->i2c_adap)) < 0)
198 return ret; 195 return ret;
diff --git a/drivers/media/dvb/bt8xx/Kconfig b/drivers/media/dvb/bt8xx/Kconfig
index b12545f093f..1e85d16491b 100644
--- a/drivers/media/dvb/bt8xx/Kconfig
+++ b/drivers/media/dvb/bt8xx/Kconfig
@@ -1,5 +1,5 @@
1config DVB_BT8XX 1config DVB_BT8XX
2 tristate "Nebula/Pinnacle PCTV/Twinhan PCI cards" 2 tristate "BT8xx based PCI cards"
3 depends on DVB_CORE && PCI && VIDEO_BT848 3 depends on DVB_CORE && PCI && VIDEO_BT848
4 select DVB_MT352 4 select DVB_MT352
5 select DVB_SP887X 5 select DVB_SP887X
@@ -8,8 +8,8 @@ config DVB_BT8XX
8 select DVB_OR51211 8 select DVB_OR51211
9 help 9 help
10 Support for PCI cards based on the Bt8xx PCI bridge. Examples are 10 Support for PCI cards based on the Bt8xx PCI bridge. Examples are
11 the Nebula cards, the Pinnacle PCTV cards, the Twinhan DST cards and 11 the Nebula cards, the Pinnacle PCTV cards, the Twinhan DST cards,
12 pcHDTV HD2000 cards. 12 the pcHDTV HD2000 cards, and certain AVerMedia cards.
13 13
14 Since these cards have no MPEG decoder onboard, they transmit 14 Since these cards have no MPEG decoder onboard, they transmit
15 only compressed MPEG data over the PCI bus, so you need 15 only compressed MPEG data over the PCI bus, so you need
diff --git a/drivers/media/dvb/cinergyT2/cinergyT2.c b/drivers/media/dvb/cinergyT2/cinergyT2.c
index 7d8b3cad350..9ea5747b121 100644
--- a/drivers/media/dvb/cinergyT2/cinergyT2.c
+++ b/drivers/media/dvb/cinergyT2/cinergyT2.c
@@ -888,7 +888,7 @@ static int cinergyt2_suspend (struct usb_interface *intf, pm_message_t state)
888 if (down_interruptible(&cinergyt2->sem)) 888 if (down_interruptible(&cinergyt2->sem))
889 return -ERESTARTSYS; 889 return -ERESTARTSYS;
890 890
891 if (state > 0) { /* state 0 seems to mean DEVICE_PM_ON */ 891 if (state.event > PM_EVENT_ON) {
892 struct cinergyt2 *cinergyt2 = usb_get_intfdata (intf); 892 struct cinergyt2 *cinergyt2 = usb_get_intfdata (intf);
893#ifdef ENABLE_RC 893#ifdef ENABLE_RC
894 cancel_delayed_work(&cinergyt2->rc_query_work); 894 cancel_delayed_work(&cinergyt2->rc_query_work);
diff --git a/drivers/media/dvb/dvb-usb/cxusb.c b/drivers/media/dvb/dvb-usb/cxusb.c
index c3e1b661aae..9e96a188f1e 100644
--- a/drivers/media/dvb/dvb-usb/cxusb.c
+++ b/drivers/media/dvb/dvb-usb/cxusb.c
@@ -141,8 +141,6 @@ static u32 cxusb_i2c_func(struct i2c_adapter *adapter)
141} 141}
142 142
143static struct i2c_algorithm cxusb_i2c_algo = { 143static struct i2c_algorithm cxusb_i2c_algo = {
144 .name = "Conexant USB I2C algorithm",
145 .id = I2C_ALGO_BIT,
146 .master_xfer = cxusb_i2c_xfer, 144 .master_xfer = cxusb_i2c_xfer,
147 .functionality = cxusb_i2c_func, 145 .functionality = cxusb_i2c_func,
148}; 146};
diff --git a/drivers/media/dvb/dvb-usb/dibusb-common.c b/drivers/media/dvb/dvb-usb/dibusb-common.c
index 9b9d6f8ee74..00b946419b4 100644
--- a/drivers/media/dvb/dvb-usb/dibusb-common.c
+++ b/drivers/media/dvb/dvb-usb/dibusb-common.c
@@ -156,8 +156,6 @@ static u32 dibusb_i2c_func(struct i2c_adapter *adapter)
156} 156}
157 157
158struct i2c_algorithm dibusb_i2c_algo = { 158struct i2c_algorithm dibusb_i2c_algo = {
159 .name = "DiBcom USB I2C algorithm",
160 .id = I2C_ALGO_BIT,
161 .master_xfer = dibusb_i2c_xfer, 159 .master_xfer = dibusb_i2c_xfer,
162 .functionality = dibusb_i2c_func, 160 .functionality = dibusb_i2c_func,
163}; 161};
diff --git a/drivers/media/dvb/dvb-usb/digitv.c b/drivers/media/dvb/dvb-usb/digitv.c
index 9a676afc1d6..f70e0be0920 100644
--- a/drivers/media/dvb/dvb-usb/digitv.c
+++ b/drivers/media/dvb/dvb-usb/digitv.c
@@ -77,8 +77,6 @@ static u32 digitv_i2c_func(struct i2c_adapter *adapter)
77} 77}
78 78
79static struct i2c_algorithm digitv_i2c_algo = { 79static struct i2c_algorithm digitv_i2c_algo = {
80 .name = "Nebula DigiTV USB I2C algorithm",
81 .id = I2C_ALGO_BIT,
82 .master_xfer = digitv_i2c_xfer, 80 .master_xfer = digitv_i2c_xfer,
83 .functionality = digitv_i2c_func, 81 .functionality = digitv_i2c_func,
84}; 82};
diff --git a/drivers/media/dvb/dvb-usb/dvb-usb-i2c.c b/drivers/media/dvb/dvb-usb/dvb-usb-i2c.c
index 9f0a8d90d14..da970947dfc 100644
--- a/drivers/media/dvb/dvb-usb/dvb-usb-i2c.c
+++ b/drivers/media/dvb/dvb-usb/dvb-usb-i2c.c
@@ -27,7 +27,6 @@ int dvb_usb_i2c_init(struct dvb_usb_device *d)
27#endif 27#endif
28 d->i2c_adap.algo = d->props.i2c_algo; 28 d->i2c_adap.algo = d->props.i2c_algo;
29 d->i2c_adap.algo_data = NULL; 29 d->i2c_adap.algo_data = NULL;
30 d->i2c_adap.id = I2C_ALGO_BIT;
31 30
32 i2c_set_adapdata(&d->i2c_adap, d); 31 i2c_set_adapdata(&d->i2c_adap, d);
33 32
diff --git a/drivers/media/dvb/frontends/lgdt330x.c b/drivers/media/dvb/frontends/lgdt330x.c
index 1f1cd7a8d50..7142b9c51dd 100644
--- a/drivers/media/dvb/frontends/lgdt330x.c
+++ b/drivers/media/dvb/frontends/lgdt330x.c
@@ -69,8 +69,8 @@ struct lgdt330x_state
69}; 69};
70 70
71static int i2c_write_demod_bytes (struct lgdt330x_state* state, 71static int i2c_write_demod_bytes (struct lgdt330x_state* state,
72 u8 *buf, /* data bytes to send */ 72 u8 *buf, /* data bytes to send */
73 int len /* number of bytes to send */ ) 73 int len /* number of bytes to send */ )
74{ 74{
75 struct i2c_msg msg = 75 struct i2c_msg msg =
76 { .addr = state->config->demod_address, 76 { .addr = state->config->demod_address,
@@ -129,13 +129,13 @@ static int lgdt3302_SwReset(struct lgdt330x_state* state)
129 }; 129 };
130 130
131 ret = i2c_write_demod_bytes(state, 131 ret = i2c_write_demod_bytes(state,
132 reset, sizeof(reset)); 132 reset, sizeof(reset));
133 if (ret == 0) { 133 if (ret == 0) {
134 134
135 /* force reset high (inactive) and unmask interrupts */ 135 /* force reset high (inactive) and unmask interrupts */
136 reset[1] = 0x7f; 136 reset[1] = 0x7f;
137 ret = i2c_write_demod_bytes(state, 137 ret = i2c_write_demod_bytes(state,
138 reset, sizeof(reset)); 138 reset, sizeof(reset));
139 } 139 }
140 return ret; 140 return ret;
141} 141}
@@ -149,13 +149,13 @@ static int lgdt3303_SwReset(struct lgdt330x_state* state)
149 }; 149 };
150 150
151 ret = i2c_write_demod_bytes(state, 151 ret = i2c_write_demod_bytes(state,
152 reset, sizeof(reset)); 152 reset, sizeof(reset));
153 if (ret == 0) { 153 if (ret == 0) {
154 154
155 /* force reset high (inactive) */ 155 /* force reset high (inactive) */
156 reset[1] = 0x01; 156 reset[1] = 0x01;
157 ret = i2c_write_demod_bytes(state, 157 ret = i2c_write_demod_bytes(state,
158 reset, sizeof(reset)); 158 reset, sizeof(reset));
159 } 159 }
160 return ret; 160 return ret;
161} 161}
@@ -172,7 +172,6 @@ static int lgdt330x_SwReset(struct lgdt330x_state* state)
172 } 172 }
173} 173}
174 174
175
176static int lgdt330x_init(struct dvb_frontend* fe) 175static int lgdt330x_init(struct dvb_frontend* fe)
177{ 176{
178 /* Hardware reset is done using gpio[0] of cx23880x chip. 177 /* Hardware reset is done using gpio[0] of cx23880x chip.
@@ -229,13 +228,13 @@ static int lgdt330x_init(struct dvb_frontend* fe)
229 case LGDT3302: 228 case LGDT3302:
230 chip_name = "LGDT3302"; 229 chip_name = "LGDT3302";
231 err = i2c_write_demod_bytes(state, lgdt3302_init_data, 230 err = i2c_write_demod_bytes(state, lgdt3302_init_data,
232 sizeof(lgdt3302_init_data)); 231 sizeof(lgdt3302_init_data));
233 break; 232 break;
234 case LGDT3303: 233 case LGDT3303:
235 chip_name = "LGDT3303"; 234 chip_name = "LGDT3303";
236 err = i2c_write_demod_bytes(state, lgdt3303_init_data, 235 err = i2c_write_demod_bytes(state, lgdt3303_init_data,
237 sizeof(lgdt3303_init_data)); 236 sizeof(lgdt3303_init_data));
238 break; 237 break;
239 default: 238 default:
240 chip_name = "undefined"; 239 chip_name = "undefined";
241 printk (KERN_WARNING "Only LGDT3302 and LGDT3303 are supported chips.\n"); 240 printk (KERN_WARNING "Only LGDT3302 and LGDT3303 are supported chips.\n");
@@ -262,15 +261,15 @@ static int lgdt330x_read_ucblocks(struct dvb_frontend* fe, u32* ucblocks)
262 switch (state->config->demod_chip) { 261 switch (state->config->demod_chip) {
263 case LGDT3302: 262 case LGDT3302:
264 err = i2c_read_demod_bytes(state, LGDT3302_PACKET_ERR_COUNTER1, 263 err = i2c_read_demod_bytes(state, LGDT3302_PACKET_ERR_COUNTER1,
265 buf, sizeof(buf)); 264 buf, sizeof(buf));
266 break; 265 break;
267 case LGDT3303: 266 case LGDT3303:
268 err = i2c_read_demod_bytes(state, LGDT3303_PACKET_ERR_COUNTER1, 267 err = i2c_read_demod_bytes(state, LGDT3303_PACKET_ERR_COUNTER1,
269 buf, sizeof(buf)); 268 buf, sizeof(buf));
270 break; 269 break;
271 default: 270 default:
272 printk(KERN_WARNING 271 printk(KERN_WARNING
273 "Only LGDT3302 and LGDT3303 are supported chips.\n"); 272 "Only LGDT3302 and LGDT3303 are supported chips.\n");
274 err = -ENODEV; 273 err = -ENODEV;
275 } 274 }
276 275
@@ -330,7 +329,7 @@ static int lgdt330x_set_parameters(struct dvb_frontend* fe,
330 329
331 if (state->config->demod_chip == LGDT3303) { 330 if (state->config->demod_chip == LGDT3303) {
332 err = i2c_write_demod_bytes(state, lgdt3303_8vsb_44_data, 331 err = i2c_write_demod_bytes(state, lgdt3303_8vsb_44_data,
333 sizeof(lgdt3303_8vsb_44_data)); 332 sizeof(lgdt3303_8vsb_44_data));
334 } 333 }
335 break; 334 break;
336 335
@@ -378,18 +377,19 @@ static int lgdt330x_set_parameters(struct dvb_frontend* fe,
378 377
379 /* Select the requested mode */ 378 /* Select the requested mode */
380 i2c_write_demod_bytes(state, top_ctrl_cfg, 379 i2c_write_demod_bytes(state, top_ctrl_cfg,
381 sizeof(top_ctrl_cfg)); 380 sizeof(top_ctrl_cfg));
382 state->config->set_ts_params(fe, 0); 381 if (state->config->set_ts_params)
382 state->config->set_ts_params(fe, 0);
383 state->current_modulation = param->u.vsb.modulation; 383 state->current_modulation = param->u.vsb.modulation;
384 } 384 }
385 385
386 /* Change only if we are actually changing the channel */ 386 /* Tune to the specified frequency */
387 if (state->current_frequency != param->frequency) { 387 if (state->config->pll_set)
388 /* Tune to the new frequency */
389 state->config->pll_set(fe, param); 388 state->config->pll_set(fe, param);
390 /* Keep track of the new frequency */ 389
391 state->current_frequency = param->frequency; 390 /* Keep track of the new frequency */
392 } 391 state->current_frequency = param->frequency;
392
393 lgdt330x_SwReset(state); 393 lgdt330x_SwReset(state);
394 return 0; 394 return 0;
395} 395}
diff --git a/drivers/media/dvb/pluto2/pluto2.c b/drivers/media/dvb/pluto2/pluto2.c
index 706e0bcb5ed..85b437bbddc 100644
--- a/drivers/media/dvb/pluto2/pluto2.c
+++ b/drivers/media/dvb/pluto2/pluto2.c
@@ -633,7 +633,6 @@ static int __devinit pluto2_probe(struct pci_dev *pdev,
633 i2c_set_adapdata(&pluto->i2c_adap, pluto); 633 i2c_set_adapdata(&pluto->i2c_adap, pluto);
634 strcpy(pluto->i2c_adap.name, DRIVER_NAME); 634 strcpy(pluto->i2c_adap.name, DRIVER_NAME);
635 pluto->i2c_adap.owner = THIS_MODULE; 635 pluto->i2c_adap.owner = THIS_MODULE;
636 pluto->i2c_adap.id = I2C_ALGO_BIT;
637 pluto->i2c_adap.class = I2C_CLASS_TV_DIGITAL; 636 pluto->i2c_adap.class = I2C_CLASS_TV_DIGITAL;
638 pluto->i2c_adap.dev.parent = &pdev->dev; 637 pluto->i2c_adap.dev.parent = &pdev->dev;
639 pluto->i2c_adap.algo_data = &pluto->i2c_bit; 638 pluto->i2c_adap.algo_data = &pluto->i2c_bit;
diff --git a/drivers/media/dvb/ttusb-budget/dvb-ttusb-budget.c b/drivers/media/dvb/ttusb-budget/dvb-ttusb-budget.c
index aa43b5fcb8e..7daf7b1598a 100644
--- a/drivers/media/dvb/ttusb-budget/dvb-ttusb-budget.c
+++ b/drivers/media/dvb/ttusb-budget/dvb-ttusb-budget.c
@@ -1472,8 +1472,6 @@ static void frontend_init(struct ttusb* ttusb)
1472 1472
1473 1473
1474static struct i2c_algorithm ttusb_dec_algo = { 1474static struct i2c_algorithm ttusb_dec_algo = {
1475 .name = "ttusb dec i2c algorithm",
1476 .id = I2C_ALGO_BIT,
1477 .master_xfer = master_xfer, 1475 .master_xfer = master_xfer,
1478 .functionality = functionality, 1476 .functionality = functionality,
1479}; 1477};
@@ -1525,7 +1523,6 @@ static int ttusb_probe(struct usb_interface *intf, const struct usb_device_id *i
1525#endif 1523#endif
1526 ttusb->i2c_adap.algo = &ttusb_dec_algo; 1524 ttusb->i2c_adap.algo = &ttusb_dec_algo;
1527 ttusb->i2c_adap.algo_data = NULL; 1525 ttusb->i2c_adap.algo_data = NULL;
1528 ttusb->i2c_adap.id = I2C_ALGO_BIT;
1529 1526
1530 result = i2c_add_adapter(&ttusb->i2c_adap); 1527 result = i2c_add_adapter(&ttusb->i2c_adap);
1531 if (result) { 1528 if (result) {
diff --git a/drivers/media/video/Kconfig b/drivers/media/video/Kconfig
index 3f574239609..16c85c081e6 100644
--- a/drivers/media/video/Kconfig
+++ b/drivers/media/video/Kconfig
@@ -254,6 +254,7 @@ config VIDEO_SAA7134_DVB
254 select VIDEO_BUF_DVB 254 select VIDEO_BUF_DVB
255 select DVB_MT352 255 select DVB_MT352
256 select DVB_CX22702 256 select DVB_CX22702
257 select DVB_TDA1004X
257 ---help--- 258 ---help---
258 This adds support for DVB cards based on the 259 This adds support for DVB cards based on the
259 Philips saa7134 chip. 260 Philips saa7134 chip.
diff --git a/drivers/media/video/Makefile b/drivers/media/video/Makefile
index 810e7aac0a5..3e6f5347da2 100644
--- a/drivers/media/video/Makefile
+++ b/drivers/media/video/Makefile
@@ -29,7 +29,7 @@ obj-$(CONFIG_VIDEO_ZORAN_LML33R10) += saa7114.o adv7170.o zr36060.o
29obj-$(CONFIG_VIDEO_ZORAN) += zr36067.o videocodec.o 29obj-$(CONFIG_VIDEO_ZORAN) += zr36067.o videocodec.o
30obj-$(CONFIG_VIDEO_PMS) += pms.o 30obj-$(CONFIG_VIDEO_PMS) += pms.o
31obj-$(CONFIG_VIDEO_PLANB) += planb.o 31obj-$(CONFIG_VIDEO_PLANB) += planb.o
32obj-$(CONFIG_VIDEO_VINO) += vino.o 32obj-$(CONFIG_VIDEO_VINO) += vino.o saa7191.o indycam.o
33obj-$(CONFIG_VIDEO_STRADIS) += stradis.o 33obj-$(CONFIG_VIDEO_STRADIS) += stradis.o
34obj-$(CONFIG_VIDEO_CPIA) += cpia.o 34obj-$(CONFIG_VIDEO_CPIA) += cpia.o
35obj-$(CONFIG_VIDEO_CPIA_PP) += cpia_pp.o 35obj-$(CONFIG_VIDEO_CPIA_PP) += cpia_pp.o
diff --git a/drivers/media/video/adv7170.c b/drivers/media/video/adv7170.c
index 48989eda240..1ca2b67aedf 100644
--- a/drivers/media/video/adv7170.c
+++ b/drivers/media/video/adv7170.c
@@ -43,7 +43,6 @@
43#include <asm/pgtable.h> 43#include <asm/pgtable.h>
44#include <asm/page.h> 44#include <asm/page.h>
45#include <linux/sched.h> 45#include <linux/sched.h>
46#include <asm/segment.h>
47#include <linux/types.h> 46#include <linux/types.h>
48 47
49#include <linux/videodev.h> 48#include <linux/videodev.h>
@@ -391,7 +390,6 @@ static struct i2c_client_address_data addr_data = {
391 .normal_i2c = normal_i2c, 390 .normal_i2c = normal_i2c,
392 .probe = &ignore, 391 .probe = &ignore,
393 .ignore = &ignore, 392 .ignore = &ignore,
394 .force = &ignore,
395}; 393};
396 394
397static struct i2c_driver i2c_driver_adv7170; 395static struct i2c_driver i2c_driver_adv7170;
diff --git a/drivers/media/video/adv7175.c b/drivers/media/video/adv7175.c
index f898b658637..173bca1e029 100644
--- a/drivers/media/video/adv7175.c
+++ b/drivers/media/video/adv7175.c
@@ -39,7 +39,6 @@
39#include <asm/pgtable.h> 39#include <asm/pgtable.h>
40#include <asm/page.h> 40#include <asm/page.h>
41#include <linux/sched.h> 41#include <linux/sched.h>
42#include <asm/segment.h>
43#include <linux/types.h> 42#include <linux/types.h>
44 43
45#include <linux/videodev.h> 44#include <linux/videodev.h>
@@ -441,7 +440,6 @@ static struct i2c_client_address_data addr_data = {
441 .normal_i2c = normal_i2c, 440 .normal_i2c = normal_i2c,
442 .probe = &ignore, 441 .probe = &ignore,
443 .ignore = &ignore, 442 .ignore = &ignore,
444 .force = &ignore,
445}; 443};
446 444
447static struct i2c_driver i2c_driver_adv7175; 445static struct i2c_driver i2c_driver_adv7175;
diff --git a/drivers/media/video/bt819.c b/drivers/media/video/bt819.c
index 8733588f6db..3ee0afca76a 100644
--- a/drivers/media/video/bt819.c
+++ b/drivers/media/video/bt819.c
@@ -43,7 +43,6 @@
43#include <asm/pgtable.h> 43#include <asm/pgtable.h>
44#include <asm/page.h> 44#include <asm/page.h>
45#include <linux/sched.h> 45#include <linux/sched.h>
46#include <asm/segment.h>
47#include <linux/types.h> 46#include <linux/types.h>
48 47
49#include <linux/videodev.h> 48#include <linux/videodev.h>
@@ -507,7 +506,6 @@ static struct i2c_client_address_data addr_data = {
507 .normal_i2c = normal_i2c, 506 .normal_i2c = normal_i2c,
508 .probe = &ignore, 507 .probe = &ignore,
509 .ignore = &ignore, 508 .ignore = &ignore,
510 .force = &ignore,
511}; 509};
512 510
513static struct i2c_driver i2c_driver_bt819; 511static struct i2c_driver i2c_driver_bt819;
diff --git a/drivers/media/video/bt832.c b/drivers/media/video/bt832.c
index a070417e65e..76c1b63ebdf 100644
--- a/drivers/media/video/bt832.c
+++ b/drivers/media/video/bt832.c
@@ -188,7 +188,7 @@ static int bt832_probe(struct i2c_adapter *adap)
188 if (adap->class & I2C_CLASS_TV_ANALOG) 188 if (adap->class & I2C_CLASS_TV_ANALOG)
189 return i2c_probe(adap, &addr_data, bt832_attach); 189 return i2c_probe(adap, &addr_data, bt832_attach);
190#else 190#else
191 if (adap->id == (I2C_ALGO_BIT | I2C_HW_B_BT848)) 191 if (adap->id == I2C_HW_B_BT848)
192 return i2c_probe(adap, &addr_data, bt832_attach); 192 return i2c_probe(adap, &addr_data, bt832_attach);
193#endif 193#endif
194 return 0; 194 return 0;
@@ -241,7 +241,7 @@ static struct i2c_driver driver = {
241}; 241};
242static struct i2c_client client_template = 242static struct i2c_client client_template =
243{ 243{
244 I2C_DEVNAME("bt832"), 244 .name = "bt832",
245 .flags = I2C_CLIENT_ALLOW_USE, 245 .flags = I2C_CLIENT_ALLOW_USE,
246 .driver = &driver, 246 .driver = &driver,
247}; 247};
diff --git a/drivers/media/video/bt856.c b/drivers/media/video/bt856.c
index a5d529ccf3a..8eb871d0e85 100644
--- a/drivers/media/video/bt856.c
+++ b/drivers/media/video/bt856.c
@@ -43,7 +43,6 @@
43#include <asm/pgtable.h> 43#include <asm/pgtable.h>
44#include <asm/page.h> 44#include <asm/page.h>
45#include <linux/sched.h> 45#include <linux/sched.h>
46#include <asm/segment.h>
47#include <linux/types.h> 46#include <linux/types.h>
48 47
49#include <linux/videodev.h> 48#include <linux/videodev.h>
@@ -295,7 +294,6 @@ static struct i2c_client_address_data addr_data = {
295 .normal_i2c = normal_i2c, 294 .normal_i2c = normal_i2c,
296 .probe = &ignore, 295 .probe = &ignore,
297 .ignore = &ignore, 296 .ignore = &ignore,
298 .force = &ignore,
299}; 297};
300 298
301static struct i2c_driver i2c_driver_bt856; 299static struct i2c_driver i2c_driver_bt856;
diff --git a/drivers/media/video/bttv-driver.c b/drivers/media/video/bttv-driver.c
index eee9322ce21..087efb4dea0 100644
--- a/drivers/media/video/bttv-driver.c
+++ b/drivers/media/video/bttv-driver.c
@@ -4047,7 +4047,6 @@ static int bttv_suspend(struct pci_dev *pci_dev, pm_message_t state)
4047 struct bttv_buffer_set idle; 4047 struct bttv_buffer_set idle;
4048 unsigned long flags; 4048 unsigned long flags;
4049 4049
4050 dprintk("bttv%d: suspend %d\n", btv->c.nr, state);
4051 4050
4052 /* stop dma + irqs */ 4051 /* stop dma + irqs */
4053 spin_lock_irqsave(&btv->s_lock,flags); 4052 spin_lock_irqsave(&btv->s_lock,flags);
diff --git a/drivers/media/video/bttv-i2c.c b/drivers/media/video/bttv-i2c.c
index 234a8556376..706dc48df96 100644
--- a/drivers/media/video/bttv-i2c.c
+++ b/drivers/media/video/bttv-i2c.c
@@ -109,7 +109,7 @@ static struct i2c_adapter bttv_i2c_adap_sw_template = {
109#ifdef I2C_CLASS_TV_ANALOG 109#ifdef I2C_CLASS_TV_ANALOG
110 .class = I2C_CLASS_TV_ANALOG, 110 .class = I2C_CLASS_TV_ANALOG,
111#endif 111#endif
112 I2C_DEVNAME("bt848"), 112 .name = "bt848",
113 .id = I2C_HW_B_BT848, 113 .id = I2C_HW_B_BT848,
114 .client_register = attach_inform, 114 .client_register = attach_inform,
115}; 115};
@@ -270,8 +270,6 @@ static int bttv_i2c_xfer(struct i2c_adapter *i2c_adap, struct i2c_msg *msgs, int
270} 270}
271 271
272static struct i2c_algorithm bttv_algo = { 272static struct i2c_algorithm bttv_algo = {
273 .name = "bt878",
274 .id = I2C_ALGO_BIT | I2C_HW_B_BT848 /* FIXME */,
275 .master_xfer = bttv_i2c_xfer, 273 .master_xfer = bttv_i2c_xfer,
276 .algo_control = algo_control, 274 .algo_control = algo_control,
277 .functionality = functionality, 275 .functionality = functionality,
@@ -282,8 +280,8 @@ static struct i2c_adapter bttv_i2c_adap_hw_template = {
282#ifdef I2C_CLASS_TV_ANALOG 280#ifdef I2C_CLASS_TV_ANALOG
283 .class = I2C_CLASS_TV_ANALOG, 281 .class = I2C_CLASS_TV_ANALOG,
284#endif 282#endif
285 I2C_DEVNAME("bt878"), 283 .name = "bt878",
286 .id = I2C_ALGO_BIT | I2C_HW_B_BT848 /* FIXME */, 284 .id = I2C_HW_B_BT848 /* FIXME */,
287 .algo = &bttv_algo, 285 .algo = &bttv_algo,
288 .client_register = attach_inform, 286 .client_register = attach_inform,
289}; 287};
@@ -298,7 +296,7 @@ static int attach_inform(struct i2c_client *client)
298 if (bttv_debug) 296 if (bttv_debug)
299 printk(KERN_DEBUG "bttv%d: %s i2c attach [addr=0x%x,client=%s]\n", 297 printk(KERN_DEBUG "bttv%d: %s i2c attach [addr=0x%x,client=%s]\n",
300 btv->c.nr,client->driver->name,client->addr, 298 btv->c.nr,client->driver->name,client->addr,
301 i2c_clientname(client)); 299 client->name);
302 if (!client->driver->command) 300 if (!client->driver->command)
303 return 0; 301 return 0;
304 302
@@ -326,7 +324,7 @@ void bttv_call_i2c_clients(struct bttv *btv, unsigned int cmd, void *arg)
326} 324}
327 325
328static struct i2c_client bttv_i2c_client_template = { 326static struct i2c_client bttv_i2c_client_template = {
329 I2C_DEVNAME("bttv internal"), 327 .name = "bttv internal",
330}; 328};
331 329
332 330
diff --git a/drivers/media/video/cx88/cx88-i2c.c b/drivers/media/video/cx88/cx88-i2c.c
index a628a55299c..7f598039e02 100644
--- a/drivers/media/video/cx88/cx88-i2c.c
+++ b/drivers/media/video/cx88/cx88-i2c.c
@@ -95,7 +95,7 @@ static int attach_inform(struct i2c_client *client)
95 struct cx88_core *core = i2c_get_adapdata(client->adapter); 95 struct cx88_core *core = i2c_get_adapdata(client->adapter);
96 96
97 dprintk(1, "%s i2c attach [addr=0x%x,client=%s]\n", 97 dprintk(1, "%s i2c attach [addr=0x%x,client=%s]\n",
98 client->driver->name,client->addr,i2c_clientname(client)); 98 client->driver->name, client->addr, client->name);
99 if (!client->driver->command) 99 if (!client->driver->command)
100 return 0; 100 return 0;
101 101
@@ -128,7 +128,7 @@ static int detach_inform(struct i2c_client *client)
128{ 128{
129 struct cx88_core *core = i2c_get_adapdata(client->adapter); 129 struct cx88_core *core = i2c_get_adapdata(client->adapter);
130 130
131 dprintk(1, "i2c detach [client=%s]\n", i2c_clientname(client)); 131 dprintk(1, "i2c detach [client=%s]\n", client->name);
132 return 0; 132 return 0;
133} 133}
134 134
@@ -152,7 +152,7 @@ static struct i2c_algo_bit_data cx8800_i2c_algo_template = {
152/* ----------------------------------------------------------------------- */ 152/* ----------------------------------------------------------------------- */
153 153
154static struct i2c_adapter cx8800_i2c_adap_template = { 154static struct i2c_adapter cx8800_i2c_adap_template = {
155 I2C_DEVNAME("cx2388x"), 155 .name = "cx2388x",
156 .owner = THIS_MODULE, 156 .owner = THIS_MODULE,
157 .id = I2C_HW_B_CX2388x, 157 .id = I2C_HW_B_CX2388x,
158 .client_register = attach_inform, 158 .client_register = attach_inform,
@@ -160,7 +160,7 @@ static struct i2c_adapter cx8800_i2c_adap_template = {
160}; 160};
161 161
162static struct i2c_client cx8800_i2c_client_template = { 162static struct i2c_client cx8800_i2c_client_template = {
163 I2C_DEVNAME("cx88xx internal"), 163 .name = "cx88xx internal",
164}; 164};
165 165
166static char *i2c_devs[128] = { 166static char *i2c_devs[128] = {
diff --git a/drivers/media/video/indycam.c b/drivers/media/video/indycam.c
new file mode 100644
index 00000000000..b2b0384cd4b
--- /dev/null
+++ b/drivers/media/video/indycam.c
@@ -0,0 +1,412 @@
1/*
2 * indycam.c - Silicon Graphics IndyCam digital camera driver
3 *
4 * Copyright (C) 2003 Ladislav Michl <ladis@linux-mips.org>
5 * Copyright (C) 2004,2005 Mikael Nousiainen <tmnousia@cc.hut.fi>
6 *
7 * This program is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License version 2 as
9 * published by the Free Software Foundation.
10 */
11
12#include <linux/module.h>
13#include <linux/init.h>
14#include <linux/delay.h>
15#include <linux/errno.h>
16#include <linux/fs.h>
17#include <linux/kernel.h>
18#include <linux/major.h>
19#include <linux/slab.h>
20#include <linux/mm.h>
21#include <linux/sched.h>
22
23#include <linux/videodev.h>
24/* IndyCam decodes stream of photons into digital image representation ;-) */
25#include <linux/video_decoder.h>
26#include <linux/i2c.h>
27
28#include "indycam.h"
29
30//#define INDYCAM_DEBUG
31
32#define INDYCAM_MODULE_VERSION "0.0.3"
33
34MODULE_DESCRIPTION("SGI IndyCam driver");
35MODULE_VERSION(INDYCAM_MODULE_VERSION);
36MODULE_AUTHOR("Mikael Nousiainen <tmnousia@cc.hut.fi>");
37MODULE_LICENSE("GPL");
38
39#ifdef INDYCAM_DEBUG
40#define dprintk(x...) printk("IndyCam: " x);
41#define indycam_regdump(client) indycam_regdump_debug(client)
42#else
43#define dprintk(x...)
44#define indycam_regdump(client)
45#endif
46
47#define VINO_ADAPTER (I2C_ALGO_SGI | I2C_HW_SGI_VINO)
48
49struct indycam {
50 struct i2c_client *client;
51 int version;
52};
53
54static struct i2c_driver i2c_driver_indycam;
55
56static const unsigned char initseq[] = {
57 INDYCAM_CONTROL_AGCENA, /* INDYCAM_CONTROL */
58 INDYCAM_SHUTTER_DEFAULT, /* INDYCAM_SHUTTER */
59 INDYCAM_GAIN_DEFAULT, /* INDYCAM_GAIN */
60 0x00, /* INDYCAM_BRIGHTNESS (read-only) */
61 INDYCAM_RED_BALANCE_DEFAULT, /* INDYCAM_RED_BALANCE */
62 INDYCAM_BLUE_BALANCE_DEFAULT, /* INDYCAM_BLUE_BALANCE */
63 INDYCAM_RED_SATURATION_DEFAULT, /* INDYCAM_RED_SATURATION */
64 INDYCAM_BLUE_SATURATION_DEFAULT,/* INDYCAM_BLUE_SATURATION */
65};
66
67/* IndyCam register handling */
68
69static int indycam_read_reg(struct i2c_client *client, unsigned char reg,
70 unsigned char *value)
71{
72 int ret;
73
74 if (reg == INDYCAM_RESET) {
75 dprintk("indycam_read_reg(): "
76 "skipping write-only register %d\n", reg);
77 *value = 0;
78 return 0;
79 }
80
81 ret = i2c_smbus_read_byte_data(client, reg);
82 if (ret < 0) {
83 printk(KERN_ERR "IndyCam: indycam_read_reg(): read failed, "
84 "register = 0x%02x\n", reg);
85 return ret;
86 }
87
88 *value = (unsigned char)ret;
89
90 return 0;
91}
92
93static int indycam_write_reg(struct i2c_client *client, unsigned char reg,
94 unsigned char value)
95{
96 int err;
97
98 if ((reg == INDYCAM_BRIGHTNESS)
99 || (reg == INDYCAM_VERSION)) {
100 dprintk("indycam_write_reg(): "
101 "skipping read-only register %d\n", reg);
102 return 0;
103 }
104
105 dprintk("Writing Reg %d = 0x%02x\n", reg, value);
106 err = i2c_smbus_write_byte_data(client, reg, value);
107 if (err) {
108 printk(KERN_ERR "IndyCam: indycam_write_reg(): write failed, "
109 "register = 0x%02x, value = 0x%02x\n", reg, value);
110 }
111 return err;
112}
113
114static int indycam_write_block(struct i2c_client *client, unsigned char reg,
115 unsigned char length, unsigned char *data)
116{
117 unsigned char i;
118 int err;
119
120 for (i = reg; i < length; i++) {
121 err = indycam_write_reg(client, reg + i, data[i]);
122 if (err)
123 return err;
124 }
125
126 return 0;
127}
128
129/* Helper functions */
130
131#ifdef INDYCAM_DEBUG
132static void indycam_regdump_debug(struct i2c_client *client)
133{
134 int i;
135 unsigned char val;
136
137 for (i = 0; i < 9; i++) {
138 indycam_read_reg(client, i, &val);
139 dprintk("Reg %d = 0x%02x\n", i, val);
140 }
141}
142#endif
143
144static int indycam_get_controls(struct i2c_client *client,
145 struct indycam_control *ctrl)
146{
147 unsigned char ctrl_reg;
148
149 indycam_read_reg(client, INDYCAM_CONTROL, &ctrl_reg);
150 ctrl->agc = (ctrl_reg & INDYCAM_CONTROL_AGCENA)
151 ? INDYCAM_VALUE_ENABLED
152 : INDYCAM_VALUE_DISABLED;
153 ctrl->awb = (ctrl_reg & INDYCAM_CONTROL_AWBCTL)
154 ? INDYCAM_VALUE_ENABLED
155 : INDYCAM_VALUE_DISABLED;
156 indycam_read_reg(client, INDYCAM_SHUTTER,
157 (unsigned char *)&ctrl->shutter);
158 indycam_read_reg(client, INDYCAM_GAIN,
159 (unsigned char *)&ctrl->gain);
160 indycam_read_reg(client, INDYCAM_RED_BALANCE,
161 (unsigned char *)&ctrl->red_balance);
162 indycam_read_reg(client, INDYCAM_BLUE_BALANCE,
163 (unsigned char *)&ctrl->blue_balance);
164 indycam_read_reg(client, INDYCAM_RED_SATURATION,
165 (unsigned char *)&ctrl->red_saturation);
166 indycam_read_reg(client, INDYCAM_BLUE_SATURATION,
167 (unsigned char *)&ctrl->blue_saturation);
168 indycam_read_reg(client, INDYCAM_GAMMA,
169 (unsigned char *)&ctrl->gamma);
170
171 return 0;
172}
173
174static int indycam_set_controls(struct i2c_client *client,
175 struct indycam_control *ctrl)
176{
177 unsigned char ctrl_reg;
178
179 indycam_read_reg(client, INDYCAM_CONTROL, &ctrl_reg);
180 if (ctrl->agc != INDYCAM_VALUE_UNCHANGED) {
181 if (ctrl->agc)
182 ctrl_reg |= INDYCAM_CONTROL_AGCENA;
183 else
184 ctrl_reg &= ~INDYCAM_CONTROL_AGCENA;
185 }
186 if (ctrl->awb != INDYCAM_VALUE_UNCHANGED) {
187 if (ctrl->awb)
188 ctrl_reg |= INDYCAM_CONTROL_AWBCTL;
189 else
190 ctrl_reg &= ~INDYCAM_CONTROL_AWBCTL;
191 }
192 indycam_write_reg(client, INDYCAM_CONTROL, ctrl_reg);
193
194 if (ctrl->shutter >= 0)
195 indycam_write_reg(client, INDYCAM_SHUTTER, ctrl->shutter);
196 if (ctrl->gain >= 0)
197 indycam_write_reg(client, INDYCAM_GAIN, ctrl->gain);
198 if (ctrl->red_balance >= 0)
199 indycam_write_reg(client, INDYCAM_RED_BALANCE,
200 ctrl->red_balance);
201 if (ctrl->blue_balance >= 0)
202 indycam_write_reg(client, INDYCAM_BLUE_BALANCE,
203 ctrl->blue_balance);
204 if (ctrl->red_saturation >= 0)
205 indycam_write_reg(client, INDYCAM_RED_SATURATION,
206 ctrl->red_saturation);
207 if (ctrl->blue_saturation >= 0)
208 indycam_write_reg(client, INDYCAM_BLUE_SATURATION,
209 ctrl->blue_saturation);
210 if (ctrl->gamma >= 0)
211 indycam_write_reg(client, INDYCAM_GAMMA, ctrl->gamma);
212
213 return 0;
214}
215
216/* I2C-interface */
217
218static int indycam_attach(struct i2c_adapter *adap, int addr, int kind)
219{
220 int err = 0;
221 struct indycam *camera;
222 struct i2c_client *client;
223
224 printk(KERN_INFO "SGI IndyCam driver version %s\n",
225 INDYCAM_MODULE_VERSION);
226
227 client = kmalloc(sizeof(struct i2c_client), GFP_KERNEL);
228 if (!client)
229 return -ENOMEM;
230 camera = kmalloc(sizeof(struct indycam), GFP_KERNEL);
231 if (!camera) {
232 err = -ENOMEM;
233 goto out_free_client;
234 }
235
236 memset(client, 0, sizeof(struct i2c_client));
237 memset(camera, 0, sizeof(struct indycam));
238
239 client->addr = addr;
240 client->adapter = adap;
241 client->driver = &i2c_driver_indycam;
242 client->flags = 0;
243 strcpy(client->name, "IndyCam client");
244 i2c_set_clientdata(client, camera);
245
246 camera->client = client;
247
248 err = i2c_attach_client(client);
249 if (err)
250 goto out_free_camera;
251
252 camera->version = i2c_smbus_read_byte_data(client, INDYCAM_VERSION);
253 if (camera->version != CAMERA_VERSION_INDY &&
254 camera->version != CAMERA_VERSION_MOOSE) {
255 err = -ENODEV;
256 goto out_detach_client;
257 }
258 printk(KERN_INFO "IndyCam v%d.%d detected\n",
259 INDYCAM_VERSION_MAJOR(camera->version),
260 INDYCAM_VERSION_MINOR(camera->version));
261
262 indycam_regdump(client);
263
264 // initialize
265 err = indycam_write_block(client, 0, sizeof(initseq),
266 (unsigned char *)&initseq);
267 if (err) {
268 printk(KERN_ERR "IndyCam initalization failed\n");
269 err = -EIO;
270 goto out_detach_client;
271 }
272
273 indycam_regdump(client);
274
275 // white balance
276 err = indycam_write_reg(client, INDYCAM_CONTROL,
277 INDYCAM_CONTROL_AGCENA | INDYCAM_CONTROL_AWBCTL);
278 if (err) {
279 printk(KERN_ERR "IndyCam white balance "
280 "initialization failed\n");
281 err = -EIO;
282 goto out_detach_client;
283 }
284
285 indycam_regdump(client);
286
287 printk(KERN_INFO "IndyCam initialized\n");
288
289 return 0;
290
291out_detach_client:
292 i2c_detach_client(client);
293out_free_camera:
294 kfree(camera);
295out_free_client:
296 kfree(client);
297 return err;
298}
299
300static int indycam_probe(struct i2c_adapter *adap)
301{
302 /* Indy specific crap */
303 if (adap->id == VINO_ADAPTER)
304 return indycam_attach(adap, INDYCAM_ADDR, 0);
305 /* Feel free to add probe here :-) */
306 return -ENODEV;
307}
308
309static int indycam_detach(struct i2c_client *client)
310{
311 struct indycam *camera = i2c_get_clientdata(client);
312
313 i2c_detach_client(client);
314 kfree(camera);
315 kfree(client);
316 return 0;
317}
318
319static int indycam_command(struct i2c_client *client, unsigned int cmd,
320 void *arg)
321{
322 // struct indycam *camera = i2c_get_clientdata(client);
323
324 /* The old video_decoder interface just isn't enough,
325 * so we'll use some custom commands. */
326 switch (cmd) {
327 case DECODER_GET_CAPABILITIES: {
328 struct video_decoder_capability *cap = arg;
329
330 cap->flags = VIDEO_DECODER_NTSC;
331 cap->inputs = 1;
332 cap->outputs = 1;
333 break;
334 }
335 case DECODER_GET_STATUS: {
336 int *iarg = arg;
337
338 *iarg = DECODER_STATUS_GOOD | DECODER_STATUS_NTSC |
339 DECODER_STATUS_COLOR;
340 break;
341 }
342 case DECODER_SET_NORM: {
343 int *iarg = arg;
344
345 switch (*iarg) {
346 case VIDEO_MODE_NTSC:
347 break;
348 default:
349 return -EINVAL;
350 }
351 break;
352 }
353 case DECODER_SET_INPUT: {
354 int *iarg = arg;
355
356 if (*iarg != 0)
357 return -EINVAL;
358 break;
359 }
360 case DECODER_SET_OUTPUT: {
361 int *iarg = arg;
362
363 if (*iarg != 0)
364 return -EINVAL;
365 break;
366 }
367 case DECODER_ENABLE_OUTPUT: {
368 /* Always enabled */
369 break;
370 }
371 case DECODER_SET_PICTURE: {
372 // struct video_picture *pic = arg;
373 /* TODO: convert values for indycam_set_controls() */
374 break;
375 }
376 case DECODER_INDYCAM_GET_CONTROLS: {
377 struct indycam_control *ctrl = arg;
378 indycam_get_controls(client, ctrl);
379 }
380 case DECODER_INDYCAM_SET_CONTROLS: {
381 struct indycam_control *ctrl = arg;
382 indycam_set_controls(client, ctrl);
383 }
384 default:
385 return -EINVAL;
386 }
387
388 return 0;
389}
390
391static struct i2c_driver i2c_driver_indycam = {
392 .owner = THIS_MODULE,
393 .name = "indycam",
394 .id = I2C_DRIVERID_INDYCAM,
395 .flags = I2C_DF_NOTIFY,
396 .attach_adapter = indycam_probe,
397 .detach_client = indycam_detach,
398 .command = indycam_command,
399};
400
401static int __init indycam_init(void)
402{
403 return i2c_add_driver(&i2c_driver_indycam);
404}
405
406static void __exit indycam_exit(void)
407{
408 i2c_del_driver(&i2c_driver_indycam);
409}
410
411module_init(indycam_init);
412module_exit(indycam_exit);
diff --git a/drivers/media/video/indycam.h b/drivers/media/video/indycam.h
new file mode 100644
index 00000000000..d9ddb6b79a0
--- /dev/null
+++ b/drivers/media/video/indycam.h
@@ -0,0 +1,112 @@
1/*
2 * indycam.h - Silicon Graphics IndyCam digital camera driver
3 *
4 * Copyright (C) 2003 Ladislav Michl <ladis@linux-mips.org>
5 * Copyright (C) 2004,2005 Mikael Nousiainen <tmnousia@cc.hut.fi>
6 *
7 * This program is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License version 2 as
9 * published by the Free Software Foundation.
10 */
11
12#ifndef _INDYCAM_H_
13#define _INDYCAM_H_
14
15/* I2C address for the Guinness Camera */
16#define INDYCAM_ADDR 0x56
17
18/* Camera version */
19#define CAMERA_VERSION_INDY 0x10 /* v1.0 */
20#define CAMERA_VERSION_MOOSE 0x12 /* v1.2 */
21#define INDYCAM_VERSION_MAJOR(x) (((x) & 0xf0) >> 4)
22#define INDYCAM_VERSION_MINOR(x) ((x) & 0x0f)
23
24/* Register bus addresses */
25#define INDYCAM_CONTROL 0x00
26#define INDYCAM_SHUTTER 0x01
27#define INDYCAM_GAIN 0x02
28#define INDYCAM_BRIGHTNESS 0x03 /* read-only */
29#define INDYCAM_RED_BALANCE 0x04
30#define INDYCAM_BLUE_BALANCE 0x05
31#define INDYCAM_RED_SATURATION 0x06
32#define INDYCAM_BLUE_SATURATION 0x07
33#define INDYCAM_GAMMA 0x08
34#define INDYCAM_VERSION 0x0e /* read-only */
35#define INDYCAM_RESET 0x0f /* write-only */
36
37#define INDYCAM_LED 0x46
38#define INDYCAM_ORIENTATION 0x47
39#define INDYCAM_BUTTON 0x48
40
41/* Field definitions of registers */
42#define INDYCAM_CONTROL_AGCENA (1<<0) /* automatic gain control */
43#define INDYCAM_CONTROL_AWBCTL (1<<1) /* automatic white balance */
44 /* 2-3 are reserved */
45#define INDYCAM_CONTROL_EVNFLD (1<<4) /* read-only */
46
47#define INDYCAM_SHUTTER_10000 0x02 /* 1/10000 second */
48#define INDYCAM_SHUTTER_4000 0x04 /* 1/4000 second */
49#define INDYCAM_SHUTTER_2000 0x08 /* 1/2000 second */
50#define INDYCAM_SHUTTER_1000 0x10 /* 1/1000 second */
51#define INDYCAM_SHUTTER_500 0x20 /* 1/500 second */
52#define INDYCAM_SHUTTER_250 0x3f /* 1/250 second */
53#define INDYCAM_SHUTTER_125 0x7e /* 1/125 second */
54#define INDYCAM_SHUTTER_100 0x9e /* 1/100 second */
55#define INDYCAM_SHUTTER_60 0x00 /* 1/60 second */
56
57#define INDYCAM_LED_ACTIVE 0x10
58#define INDYCAM_LED_INACTIVE 0x30
59#define INDYCAM_ORIENTATION_BOTTOM_TO_TOP 0x40
60#define INDYCAM_BUTTON_RELEASED 0x10
61
62#define INDYCAM_SHUTTER_MIN 0x00
63#define INDYCAM_SHUTTER_MAX 0xff
64#define INDYCAM_GAIN_MIN 0x00
65#define INDYCAM_GAIN_MAX 0xff
66#define INDYCAM_RED_BALANCE_MIN 0x00 /* the effect is the opposite? */
67#define INDYCAM_RED_BALANCE_MAX 0xff
68#define INDYCAM_BLUE_BALANCE_MIN 0x00 /* the effect is the opposite? */
69#define INDYCAM_BLUE_BALANCE_MAX 0xff
70#define INDYCAM_RED_SATURATION_MIN 0x00
71#define INDYCAM_RED_SATURATION_MAX 0xff
72#define INDYCAM_BLUE_SATURATION_MIN 0x00
73#define INDYCAM_BLUE_SATURATION_MAX 0xff
74#define INDYCAM_GAMMA_MIN 0x00
75#define INDYCAM_GAMMA_MAX 0xff
76
77/* Driver interface definitions */
78
79#define INDYCAM_VALUE_ENABLED 1
80#define INDYCAM_VALUE_DISABLED 0
81#define INDYCAM_VALUE_UNCHANGED -1
82
83/* When setting controls, a value of -1 leaves the control unchanged. */
84struct indycam_control {
85 int agc; /* boolean */
86 int awb; /* boolean */
87 int shutter;
88 int gain;
89 int red_balance;
90 int blue_balance;
91 int red_saturation;
92 int blue_saturation;
93 int gamma;
94};
95
96#define DECODER_INDYCAM_GET_CONTROLS _IOR('d', 193, struct indycam_control)
97#define DECODER_INDYCAM_SET_CONTROLS _IOW('d', 194, struct indycam_control)
98
99/* Default values for controls */
100
101#define INDYCAM_AGC_DEFAULT INDYCAM_VALUE_ENABLED
102#define INDYCAM_AWB_DEFAULT INDYCAM_VALUE_ENABLED
103
104#define INDYCAM_SHUTTER_DEFAULT INDYCAM_SHUTTER_60
105#define INDYCAM_GAIN_DEFAULT 0x80
106#define INDYCAM_RED_BALANCE_DEFAULT 0x18
107#define INDYCAM_BLUE_BALANCE_DEFAULT 0xa4
108#define INDYCAM_RED_SATURATION_DEFAULT 0x80
109#define INDYCAM_BLUE_SATURATION_DEFAULT 0xc0
110#define INDYCAM_GAMMA_DEFAULT 0x80
111
112#endif
diff --git a/drivers/media/video/ir-kbd-i2c.c b/drivers/media/video/ir-kbd-i2c.c
index 9fc5055e001..1e273ff3f95 100644
--- a/drivers/media/video/ir-kbd-i2c.c
+++ b/drivers/media/video/ir-kbd-i2c.c
@@ -308,7 +308,7 @@ static struct i2c_driver driver = {
308 308
309static struct i2c_client client_template = 309static struct i2c_client client_template =
310{ 310{
311 I2C_DEVNAME("unset"), 311 .name = "unset",
312 .driver = &driver 312 .driver = &driver
313}; 313};
314 314
@@ -429,10 +429,10 @@ static int ir_probe(struct i2c_adapter *adap)
429 struct i2c_client c; char buf; int i,rc; 429 struct i2c_client c; char buf; int i,rc;
430 430
431 switch (adap->id) { 431 switch (adap->id) {
432 case I2C_ALGO_BIT | I2C_HW_B_BT848: 432 case I2C_HW_B_BT848:
433 probe = probe_bttv; 433 probe = probe_bttv;
434 break; 434 break;
435 case I2C_ALGO_SAA7134: 435 case I2C_HW_SAA7134:
436 probe = probe_saa7134; 436 probe = probe_saa7134;
437 break; 437 break;
438 } 438 }
diff --git a/drivers/media/video/meye.c b/drivers/media/video/meye.c
index fe194012bcc..3f2a882bc20 100644
--- a/drivers/media/video/meye.c
+++ b/drivers/media/video/meye.c
@@ -37,6 +37,7 @@
37#include <linux/delay.h> 37#include <linux/delay.h>
38#include <linux/interrupt.h> 38#include <linux/interrupt.h>
39#include <linux/vmalloc.h> 39#include <linux/vmalloc.h>
40#include <linux/dma-mapping.h>
40 41
41#include "meye.h" 42#include "meye.h"
42#include <linux/meye.h> 43#include <linux/meye.h>
@@ -121,7 +122,7 @@ static int ptable_alloc(void)
121 memset(meye.mchip_ptable, 0, sizeof(meye.mchip_ptable)); 122 memset(meye.mchip_ptable, 0, sizeof(meye.mchip_ptable));
122 123
123 /* give only 32 bit DMA addresses */ 124 /* give only 32 bit DMA addresses */
124 if (dma_set_mask(&meye.mchip_dev->dev, 0xffffffff)) 125 if (dma_set_mask(&meye.mchip_dev->dev, DMA_32BIT_MASK))
125 return -1; 126 return -1;
126 127
127 meye.mchip_ptable_toc = dma_alloc_coherent(&meye.mchip_dev->dev, 128 meye.mchip_ptable_toc = dma_alloc_coherent(&meye.mchip_dev->dev,
diff --git a/drivers/media/video/msp3400.c b/drivers/media/video/msp3400.c
index 62f1b8ddb98..ca02f6f14b0 100644
--- a/drivers/media/video/msp3400.c
+++ b/drivers/media/video/msp3400.c
@@ -1416,7 +1416,7 @@ static int msp_detach(struct i2c_client *client);
1416static int msp_probe(struct i2c_adapter *adap); 1416static int msp_probe(struct i2c_adapter *adap);
1417static int msp_command(struct i2c_client *client, unsigned int cmd, void *arg); 1417static int msp_command(struct i2c_client *client, unsigned int cmd, void *arg);
1418 1418
1419static int msp_suspend(struct device * dev, u32 state, u32 level); 1419static int msp_suspend(struct device * dev, pm_message_t state, u32 level);
1420static int msp_resume(struct device * dev, u32 level); 1420static int msp_resume(struct device * dev, u32 level);
1421 1421
1422static void msp_wake_thread(struct i2c_client *client); 1422static void msp_wake_thread(struct i2c_client *client);
@@ -1437,7 +1437,7 @@ static struct i2c_driver driver = {
1437 1437
1438static struct i2c_client client_template = 1438static struct i2c_client client_template =
1439{ 1439{
1440 I2C_DEVNAME("(unset)"), 1440 .name = "(unset)",
1441 .flags = I2C_CLIENT_ALLOW_USE, 1441 .flags = I2C_CLIENT_ALLOW_USE,
1442 .driver = &driver, 1442 .driver = &driver,
1443}; 1443};
@@ -1509,7 +1509,7 @@ static int msp_attach(struct i2c_adapter *adap, int addr, int kind)
1509 } 1509 }
1510 1510
1511 /* hello world :-) */ 1511 /* hello world :-) */
1512 printk(KERN_INFO "msp34xx: init: chip=%s",i2c_clientname(c)); 1512 printk(KERN_INFO "msp34xx: init: chip=%s", c->name);
1513 if (HAVE_NICAM(msp)) 1513 if (HAVE_NICAM(msp))
1514 printk(" +nicam"); 1514 printk(" +nicam");
1515 if (HAVE_SIMPLE(msp)) 1515 if (HAVE_SIMPLE(msp))
@@ -1817,7 +1817,7 @@ static int msp_command(struct i2c_client *client, unsigned int cmd, void *arg)
1817 return 0; 1817 return 0;
1818} 1818}
1819 1819
1820static int msp_suspend(struct device * dev, u32 state, u32 level) 1820static int msp_suspend(struct device * dev, pm_message_t state, u32 level)
1821{ 1821{
1822 struct i2c_client *c = container_of(dev, struct i2c_client, dev); 1822 struct i2c_client *c = container_of(dev, struct i2c_client, dev);
1823 1823
diff --git a/drivers/media/video/ovcamchip/ov6x20.c b/drivers/media/video/ovcamchip/ov6x20.c
index 3433619ad93..b3f4d266ced 100644
--- a/drivers/media/video/ovcamchip/ov6x20.c
+++ b/drivers/media/video/ovcamchip/ov6x20.c
@@ -164,10 +164,10 @@ static int ov6x20_init(struct i2c_client *c)
164 DDEBUG(4, &c->dev, "entered"); 164 DDEBUG(4, &c->dev, "entered");
165 165
166 switch (c->adapter->id) { 166 switch (c->adapter->id) {
167 case I2C_ALGO_SMBUS | I2C_HW_SMBUS_OV511: 167 case I2C_HW_SMBUS_OV511:
168 rc = ov_write_regvals(c, regvals_init_6x20_511); 168 rc = ov_write_regvals(c, regvals_init_6x20_511);
169 break; 169 break;
170 case I2C_ALGO_SMBUS | I2C_HW_SMBUS_OV518: 170 case I2C_HW_SMBUS_OV518:
171 rc = ov_write_regvals(c, regvals_init_6x20_518); 171 rc = ov_write_regvals(c, regvals_init_6x20_518);
172 break; 172 break;
173 default: 173 default:
@@ -338,7 +338,7 @@ static int ov6x20_mode_init(struct i2c_client *c, struct ovcamchip_window *win)
338 /******** Palette-specific regs ********/ 338 /******** Palette-specific regs ********/
339 339
340 /* OV518 needs 8 bit multiplexed in color mode, and 16 bit in B&W */ 340 /* OV518 needs 8 bit multiplexed in color mode, and 16 bit in B&W */
341 if (c->adapter->id == (I2C_ALGO_SMBUS | I2C_HW_SMBUS_OV518)) { 341 if (c->adapter->id == I2C_HW_SMBUS_OV518) {
342 if (win->format == VIDEO_PALETTE_GREY) 342 if (win->format == VIDEO_PALETTE_GREY)
343 ov_write_mask(c, 0x13, 0x00, 0x20); 343 ov_write_mask(c, 0x13, 0x00, 0x20);
344 else 344 else
diff --git a/drivers/media/video/ovcamchip/ov6x30.c b/drivers/media/video/ovcamchip/ov6x30.c
index 44a842379b4..6eab458ab79 100644
--- a/drivers/media/video/ovcamchip/ov6x30.c
+++ b/drivers/media/video/ovcamchip/ov6x30.c
@@ -301,7 +301,7 @@ static int ov6x30_mode_init(struct i2c_client *c, struct ovcamchip_window *win)
301 /******** Palette-specific regs ********/ 301 /******** Palette-specific regs ********/
302 302
303 if (win->format == VIDEO_PALETTE_GREY) { 303 if (win->format == VIDEO_PALETTE_GREY) {
304 if (c->adapter->id == (I2C_ALGO_SMBUS | I2C_HW_SMBUS_OV518)) { 304 if (c->adapter->id == I2C_HW_SMBUS_OV518) {
305 /* Do nothing - we're already in 8-bit mode */ 305 /* Do nothing - we're already in 8-bit mode */
306 } else { 306 } else {
307 ov_write_mask(c, 0x13, 0x20, 0x20); 307 ov_write_mask(c, 0x13, 0x20, 0x20);
@@ -313,7 +313,7 @@ static int ov6x30_mode_init(struct i2c_client *c, struct ovcamchip_window *win)
313 * Therefore, the OV6630 needs to be in 8-bit multiplexed 313 * Therefore, the OV6630 needs to be in 8-bit multiplexed
314 * output mode */ 314 * output mode */
315 315
316 if (c->adapter->id == (I2C_ALGO_SMBUS | I2C_HW_SMBUS_OV518)) { 316 if (c->adapter->id == I2C_HW_SMBUS_OV518) {
317 /* Do nothing - we want to stay in 8-bit mode */ 317 /* Do nothing - we want to stay in 8-bit mode */
318 /* Warning: Messing with reg 0x13 breaks OV518 color */ 318 /* Warning: Messing with reg 0x13 breaks OV518 color */
319 } else { 319 } else {
diff --git a/drivers/media/video/ovcamchip/ovcamchip_core.c b/drivers/media/video/ovcamchip/ovcamchip_core.c
index 54dd5612d3b..2de34ebf067 100644
--- a/drivers/media/video/ovcamchip/ovcamchip_core.c
+++ b/drivers/media/video/ovcamchip/ovcamchip_core.c
@@ -296,10 +296,10 @@ static int ovcamchip_attach(struct i2c_adapter *adap)
296 * attach to adapters that are known to contain OV camera chips. */ 296 * attach to adapters that are known to contain OV camera chips. */
297 297
298 switch (adap->id) { 298 switch (adap->id) {
299 case (I2C_ALGO_SMBUS | I2C_HW_SMBUS_OV511): 299 case I2C_HW_SMBUS_OV511:
300 case (I2C_ALGO_SMBUS | I2C_HW_SMBUS_OV518): 300 case I2C_HW_SMBUS_OV518:
301 case (I2C_ALGO_SMBUS | I2C_HW_SMBUS_OVFX2): 301 case I2C_HW_SMBUS_OVFX2:
302 case (I2C_ALGO_SMBUS | I2C_HW_SMBUS_W9968CF): 302 case I2C_HW_SMBUS_W9968CF:
303 PDEBUG(1, "Adapter ID 0x%06x accepted", adap->id); 303 PDEBUG(1, "Adapter ID 0x%06x accepted", adap->id);
304 break; 304 break;
305 default: 305 default:
@@ -314,7 +314,7 @@ static int ovcamchip_attach(struct i2c_adapter *adap)
314 } 314 }
315 memcpy(c, &client_template, sizeof *c); 315 memcpy(c, &client_template, sizeof *c);
316 c->adapter = adap; 316 c->adapter = adap;
317 strcpy(i2c_clientname(c), "OV????"); 317 strcpy(c->name, "OV????");
318 318
319 ov = kmalloc(sizeof *ov, GFP_KERNEL); 319 ov = kmalloc(sizeof *ov, GFP_KERNEL);
320 if (!ov) { 320 if (!ov) {
@@ -328,7 +328,7 @@ static int ovcamchip_attach(struct i2c_adapter *adap)
328 if (rc < 0) 328 if (rc < 0)
329 goto error; 329 goto error;
330 330
331 strcpy(i2c_clientname(c), chip_names[ov->subtype]); 331 strcpy(c->name, chip_names[ov->subtype]);
332 332
333 PDEBUG(1, "Camera chip detection complete"); 333 PDEBUG(1, "Camera chip detection complete");
334 334
@@ -421,7 +421,7 @@ static struct i2c_driver driver = {
421}; 421};
422 422
423static struct i2c_client client_template = { 423static struct i2c_client client_template = {
424 I2C_DEVNAME("(unset)"), 424 .name = "(unset)",
425 .driver = &driver, 425 .driver = &driver,
426}; 426};
427 427
diff --git a/drivers/media/video/saa7110.c b/drivers/media/video/saa7110.c
index 22d055d8a69..e116bdbed31 100644
--- a/drivers/media/video/saa7110.c
+++ b/drivers/media/video/saa7110.c
@@ -470,7 +470,6 @@ static struct i2c_client_address_data addr_data = {
470 .normal_i2c = normal_i2c, 470 .normal_i2c = normal_i2c,
471 .probe = &ignore, 471 .probe = &ignore,
472 .ignore = &ignore, 472 .ignore = &ignore,
473 .force = &ignore,
474}; 473};
475 474
476static struct i2c_driver i2c_driver_saa7110; 475static struct i2c_driver i2c_driver_saa7110;
diff --git a/drivers/media/video/saa7111.c b/drivers/media/video/saa7111.c
index fcd897382fc..fe8a5e45396 100644
--- a/drivers/media/video/saa7111.c
+++ b/drivers/media/video/saa7111.c
@@ -42,7 +42,6 @@
42#include <asm/pgtable.h> 42#include <asm/pgtable.h>
43#include <asm/page.h> 43#include <asm/page.h>
44#include <linux/sched.h> 44#include <linux/sched.h>
45#include <asm/segment.h>
46#include <linux/types.h> 45#include <linux/types.h>
47 46
48#include <linux/videodev.h> 47#include <linux/videodev.h>
@@ -489,7 +488,6 @@ static struct i2c_client_address_data addr_data = {
489 .normal_i2c = normal_i2c, 488 .normal_i2c = normal_i2c,
490 .probe = &ignore, 489 .probe = &ignore,
491 .ignore = &ignore, 490 .ignore = &ignore,
492 .force = &ignore,
493}; 491};
494 492
495static struct i2c_driver i2c_driver_saa7111; 493static struct i2c_driver i2c_driver_saa7111;
diff --git a/drivers/media/video/saa7114.c b/drivers/media/video/saa7114.c
index 2ba997f5ef1..d9f50e2f7b9 100644
--- a/drivers/media/video/saa7114.c
+++ b/drivers/media/video/saa7114.c
@@ -45,7 +45,6 @@
45#include <asm/pgtable.h> 45#include <asm/pgtable.h>
46#include <asm/page.h> 46#include <asm/page.h>
47#include <linux/sched.h> 47#include <linux/sched.h>
48#include <asm/segment.h>
49#include <linux/types.h> 48#include <linux/types.h>
50 49
51#include <linux/videodev.h> 50#include <linux/videodev.h>
@@ -827,7 +826,6 @@ static struct i2c_client_address_data addr_data = {
827 .normal_i2c = normal_i2c, 826 .normal_i2c = normal_i2c,
828 .probe = &ignore, 827 .probe = &ignore,
829 .ignore = &ignore, 828 .ignore = &ignore,
830 .force = &ignore,
831}; 829};
832 830
833static struct i2c_driver i2c_driver_saa7114; 831static struct i2c_driver i2c_driver_saa7114;
diff --git a/drivers/media/video/saa7134/saa6752hs.c b/drivers/media/video/saa7134/saa6752hs.c
index 79d05ea1b69..382911c6ef2 100644
--- a/drivers/media/video/saa7134/saa6752hs.c
+++ b/drivers/media/video/saa7134/saa6752hs.c
@@ -598,7 +598,7 @@ static struct i2c_driver driver = {
598 598
599static struct i2c_client client_template = 599static struct i2c_client client_template =
600{ 600{
601 I2C_DEVNAME("saa6752hs"), 601 .name = "saa6752hs",
602 .flags = I2C_CLIENT_ALLOW_USE, 602 .flags = I2C_CLIENT_ALLOW_USE,
603 .driver = &driver, 603 .driver = &driver,
604}; 604};
diff --git a/drivers/media/video/saa7134/saa7134-i2c.c b/drivers/media/video/saa7134/saa7134-i2c.c
index 1203b93a572..eae6b529713 100644
--- a/drivers/media/video/saa7134/saa7134-i2c.c
+++ b/drivers/media/video/saa7134/saa7134-i2c.c
@@ -334,7 +334,7 @@ static int attach_inform(struct i2c_client *client)
334 struct tuner_setup tun_setup; 334 struct tuner_setup tun_setup;
335 335
336 d1printk( "%s i2c attach [addr=0x%x,client=%s]\n", 336 d1printk( "%s i2c attach [addr=0x%x,client=%s]\n",
337 client->driver->name,client->addr,i2c_clientname(client)); 337 client->driver->name, client->addr, client->name);
338 338
339 if (!client->driver->command) 339 if (!client->driver->command)
340 return 0; 340 return 0;
@@ -370,8 +370,6 @@ static int attach_inform(struct i2c_client *client)
370} 370}
371 371
372static struct i2c_algorithm saa7134_algo = { 372static struct i2c_algorithm saa7134_algo = {
373 .name = "saa7134",
374 .id = I2C_ALGO_SAA7134,
375 .master_xfer = saa7134_i2c_xfer, 373 .master_xfer = saa7134_i2c_xfer,
376 .algo_control = algo_control, 374 .algo_control = algo_control,
377 .functionality = functionality, 375 .functionality = functionality,
@@ -382,14 +380,14 @@ static struct i2c_adapter saa7134_adap_template = {
382#ifdef I2C_CLASS_TV_ANALOG 380#ifdef I2C_CLASS_TV_ANALOG
383 .class = I2C_CLASS_TV_ANALOG, 381 .class = I2C_CLASS_TV_ANALOG,
384#endif 382#endif
385 I2C_DEVNAME("saa7134"), 383 .name = "saa7134",
386 .id = I2C_ALGO_SAA7134, 384 .id = I2C_HW_SAA7134,
387 .algo = &saa7134_algo, 385 .algo = &saa7134_algo,
388 .client_register = attach_inform, 386 .client_register = attach_inform,
389}; 387};
390 388
391static struct i2c_client saa7134_client_template = { 389static struct i2c_client saa7134_client_template = {
392 I2C_DEVNAME("saa7134 internal"), 390 .name = "saa7134 internal",
393}; 391};
394 392
395/* ----------------------------------------------------------- */ 393/* ----------------------------------------------------------- */
diff --git a/drivers/media/video/saa7185.c b/drivers/media/video/saa7185.c
index 108e7a4a027..132aa7943c1 100644
--- a/drivers/media/video/saa7185.c
+++ b/drivers/media/video/saa7185.c
@@ -39,7 +39,6 @@
39#include <asm/pgtable.h> 39#include <asm/pgtable.h>
40#include <asm/page.h> 40#include <asm/page.h>
41#include <linux/sched.h> 41#include <linux/sched.h>
42#include <asm/segment.h>
43#include <linux/types.h> 42#include <linux/types.h>
44 43
45#include <linux/videodev.h> 44#include <linux/videodev.h>
@@ -387,7 +386,6 @@ static struct i2c_client_address_data addr_data = {
387 .normal_i2c = normal_i2c, 386 .normal_i2c = normal_i2c,
388 .probe = &ignore, 387 .probe = &ignore,
389 .ignore = &ignore, 388 .ignore = &ignore,
390 .force = &ignore,
391}; 389};
392 390
393static struct i2c_driver i2c_driver_saa7185; 391static struct i2c_driver i2c_driver_saa7185;
diff --git a/drivers/media/video/saa7191.c b/drivers/media/video/saa7191.c
new file mode 100644
index 00000000000..454f5c1199b
--- /dev/null
+++ b/drivers/media/video/saa7191.c
@@ -0,0 +1,512 @@
1/*
2 * saa7191.c - Philips SAA7191 video decoder driver
3 *
4 * Copyright (C) 2003 Ladislav Michl <ladis@linux-mips.org>
5 * Copyright (C) 2004,2005 Mikael Nousiainen <tmnousia@cc.hut.fi>
6 *
7 * This program is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License version 2 as
9 * published by the Free Software Foundation.
10 */
11
12#include <linux/module.h>
13#include <linux/init.h>
14#include <linux/delay.h>
15#include <linux/errno.h>
16#include <linux/fs.h>
17#include <linux/kernel.h>
18#include <linux/major.h>
19#include <linux/slab.h>
20#include <linux/mm.h>
21#include <linux/sched.h>
22
23#include <linux/videodev.h>
24#include <linux/video_decoder.h>
25#include <linux/i2c.h>
26
27#include "saa7191.h"
28
29#define SAA7191_MODULE_VERSION "0.0.3"
30
31MODULE_DESCRIPTION("Philips SAA7191 video decoder driver");
32MODULE_VERSION(SAA7191_MODULE_VERSION);
33MODULE_AUTHOR("Mikael Nousiainen <tmnousia@cc.hut.fi>");
34MODULE_LICENSE("GPL");
35
36#define VINO_ADAPTER (I2C_ALGO_SGI | I2C_HW_SGI_VINO)
37
38struct saa7191 {
39 struct i2c_client *client;
40
41 /* the register values are stored here as the actual
42 * I2C-registers are write-only */
43 unsigned char reg[25];
44
45 unsigned char norm;
46 unsigned char input;
47};
48
49static struct i2c_driver i2c_driver_saa7191;
50
51static const unsigned char initseq[] = {
52 0, /* Subaddress */
53 0x50, /* SAA7191_REG_IDEL */
54 0x30, /* SAA7191_REG_HSYB */
55 0x00, /* SAA7191_REG_HSYS */
56 0xe8, /* SAA7191_REG_HCLB */
57 0xb6, /* SAA7191_REG_HCLS */
58 0xf4, /* SAA7191_REG_HPHI */
59 0x01, /* SAA7191_REG_LUMA - chrominance trap active (CVBS) */
60 0x00, /* SAA7191_REG_HUEC */
61 0xf8, /* SAA7191_REG_CKTQ */
62 0xf8, /* SAA7191_REG_CKTS */
63 0x90, /* SAA7191_REG_PLSE */
64 0x90, /* SAA7191_REG_SESE */
65 0x00, /* SAA7191_REG_GAIN */
66 0x0c, /* SAA7191_REG_STDC - not SECAM, slow time constant */
67 0x78, /* SAA7191_REG_IOCK - chrominance from CVBS, GPSW1 & 2 off */
68 0x99, /* SAA7191_REG_CTL3 - automatic field detection */
69 0x00, /* SAA7191_REG_CTL4 */
70 0x2c, /* SAA7191_REG_CHCV */
71 0x00, /* unused */
72 0x00, /* unused */
73 0x34, /* SAA7191_REG_HS6B */
74 0x0a, /* SAA7191_REG_HS6S */
75 0xf4, /* SAA7191_REG_HC6B */
76 0xce, /* SAA7191_REG_HC6S */
77 0xf4, /* SAA7191_REG_HP6I */
78};
79
80/* SAA7191 register handling */
81
82static unsigned char saa7191_read_reg(struct i2c_client *client,
83 unsigned char reg)
84{
85 return ((struct saa7191 *)i2c_get_clientdata(client))->reg[reg];
86}
87
88static int saa7191_read_status(struct i2c_client *client,
89 unsigned char *value)
90{
91 int ret;
92
93 ret = i2c_master_recv(client, value, 1);
94 if (ret < 0) {
95 printk(KERN_ERR "SAA7191: saa7191_read_status(): read failed");
96 return ret;
97 }
98
99 return 0;
100}
101
102
103static int saa7191_write_reg(struct i2c_client *client, unsigned char reg,
104 unsigned char value)
105{
106
107 ((struct saa7191 *)i2c_get_clientdata(client))->reg[reg] = value;
108 return i2c_smbus_write_byte_data(client, reg, value);
109}
110
111/* the first byte of data must be the first subaddress number (register) */
112static int saa7191_write_block(struct i2c_client *client,
113 unsigned char length, unsigned char *data)
114{
115 int i;
116 int ret;
117
118 struct saa7191 *decoder = (struct saa7191 *)i2c_get_clientdata(client);
119 for (i = 0; i < (length - 1); i++) {
120 decoder->reg[data[0] + i] = data[i + 1];
121 }
122
123 ret = i2c_master_send(client, data, length);
124 if (ret < 0) {
125 printk(KERN_ERR "SAA7191: saa7191_write_block(): "
126 "write failed");
127 return ret;
128 }
129
130 return 0;
131}
132
133/* Helper functions */
134
135static int saa7191_set_input(struct i2c_client *client, int input)
136{
137 unsigned char luma = saa7191_read_reg(client, SAA7191_REG_LUMA);
138 unsigned char iock = saa7191_read_reg(client, SAA7191_REG_IOCK);
139 int err;
140
141 switch (input) {
142 case SAA7191_INPUT_COMPOSITE: /* Set Composite input */
143 iock &= ~(SAA7191_IOCK_CHRS | SAA7191_IOCK_GPSW1
144 | SAA7191_IOCK_GPSW2);
145 /* Chrominance trap active */
146 luma &= ~SAA7191_LUMA_BYPS;
147 break;
148 case SAA7191_INPUT_SVIDEO: /* Set S-Video input */
149 iock |= SAA7191_IOCK_CHRS | SAA7191_IOCK_GPSW2;
150 /* Chrominance trap bypassed */
151 luma |= SAA7191_LUMA_BYPS;
152 break;
153 default:
154 return -EINVAL;
155 }
156
157 err = saa7191_write_reg(client, SAA7191_REG_LUMA, luma);
158 if (err)
159 return -EIO;
160 err = saa7191_write_reg(client, SAA7191_REG_IOCK, iock);
161 if (err)
162 return -EIO;
163
164 return 0;
165}
166
167static int saa7191_set_norm(struct i2c_client *client, int norm)
168{
169 struct saa7191 *decoder = i2c_get_clientdata(client);
170 unsigned char stdc = saa7191_read_reg(client, SAA7191_REG_STDC);
171 unsigned char ctl3 = saa7191_read_reg(client, SAA7191_REG_CTL3);
172 unsigned char chcv = saa7191_read_reg(client, SAA7191_REG_CHCV);
173 int err;
174
175 switch(norm) {
176 case SAA7191_NORM_AUTO: {
177 unsigned char status;
178
179 // does status depend on current norm ?
180 if (saa7191_read_status(client, &status))
181 return -EIO;
182
183 stdc &= ~SAA7191_STDC_SECS;
184 ctl3 &= ~SAA7191_CTL3_FSEL;
185 ctl3 |= SAA7191_CTL3_AUFD;
186 chcv = (status & SAA7191_STATUS_FIDT)
187 ? SAA7191_CHCV_NTSC : SAA7191_CHCV_PAL;
188 break;
189 }
190 case SAA7191_NORM_PAL:
191 stdc &= ~SAA7191_STDC_SECS;
192 ctl3 &= ~(SAA7191_CTL3_AUFD | SAA7191_CTL3_FSEL);
193 chcv = SAA7191_CHCV_PAL;
194 break;
195 case SAA7191_NORM_NTSC:
196 stdc &= ~SAA7191_STDC_SECS;
197 ctl3 &= ~SAA7191_CTL3_AUFD;
198 ctl3 |= SAA7191_CTL3_FSEL;
199 chcv = SAA7191_CHCV_NTSC;
200 break;
201 case SAA7191_NORM_SECAM:
202 stdc |= SAA7191_STDC_SECS;
203 ctl3 &= ~(SAA7191_CTL3_AUFD | SAA7191_CTL3_FSEL);
204 chcv = SAA7191_CHCV_PAL;
205 break;
206 default:
207 return -EINVAL;
208 }
209
210 err = saa7191_write_reg(client, SAA7191_REG_CTL3, ctl3);
211 if (err)
212 return -EIO;
213 err = saa7191_write_reg(client, SAA7191_REG_STDC, stdc);
214 if (err)
215 return -EIO;
216 err = saa7191_write_reg(client, SAA7191_REG_CHCV, chcv);
217 if (err)
218 return -EIO;
219
220 decoder->norm = norm;
221
222 return 0;
223}
224
225static int saa7191_get_controls(struct i2c_client *client,
226 struct saa7191_control *ctrl)
227{
228 unsigned char hue = saa7191_read_reg(client, SAA7191_REG_HUEC);
229 unsigned char stdc = saa7191_read_reg(client, SAA7191_REG_STDC);
230
231 if (hue < 0x80) {
232 hue += 0x80;
233 } else {
234 hue -= 0x80;
235 }
236 ctrl->hue = hue;
237
238 ctrl->vtrc = (stdc & SAA7191_STDC_VTRC)
239 ? SAA7191_VALUE_ENABLED : SAA7191_VALUE_DISABLED;
240
241 return 0;
242}
243
244static int saa7191_set_controls(struct i2c_client *client,
245 struct saa7191_control *ctrl)
246{
247 int err;
248
249 if (ctrl->hue >= 0) {
250 unsigned char hue = ctrl->hue & 0xff;
251 if (hue < 0x80) {
252 hue += 0x80;
253 } else {
254 hue -= 0x80;
255 }
256 err = saa7191_write_reg(client, SAA7191_REG_HUEC, hue);
257 if (err)
258 return -EIO;
259 }
260 if (ctrl->vtrc >= 0) {
261 unsigned char stdc =
262 saa7191_read_reg(client, SAA7191_REG_STDC);
263
264 if (ctrl->vtrc) {
265 stdc |= SAA7191_STDC_VTRC;
266 } else {
267 stdc &= ~SAA7191_STDC_VTRC;
268 }
269
270 err = saa7191_write_reg(client, SAA7191_REG_STDC, stdc);
271 if (err)
272 return -EIO;
273 }
274
275 return 0;
276}
277
278/* I2C-interface */
279
280static int saa7191_attach(struct i2c_adapter *adap, int addr, int kind)
281{
282 int err = 0;
283 struct saa7191 *decoder;
284 struct i2c_client *client;
285
286 printk(KERN_INFO "Philips SAA7191 driver version %s\n",
287 SAA7191_MODULE_VERSION);
288
289 client = kmalloc(sizeof(*client), GFP_KERNEL);
290 if (!client)
291 return -ENOMEM;
292 decoder = kmalloc(sizeof(*decoder), GFP_KERNEL);
293 if (!decoder) {
294 err = -ENOMEM;
295 goto out_free_client;
296 }
297
298 memset(client, 0, sizeof(struct i2c_client));
299 memset(decoder, 0, sizeof(struct saa7191));
300
301 client->addr = addr;
302 client->adapter = adap;
303 client->driver = &i2c_driver_saa7191;
304 client->flags = 0;
305 strcpy(client->name, "saa7191 client");
306 i2c_set_clientdata(client, decoder);
307
308 decoder->client = client;
309
310 err = i2c_attach_client(client);
311 if (err)
312 goto out_free_decoder;
313
314 decoder->input = SAA7191_INPUT_COMPOSITE;
315 decoder->norm = SAA7191_NORM_AUTO;
316
317 err = saa7191_write_block(client, sizeof(initseq),
318 (unsigned char *)initseq);
319 if (err) {
320 printk(KERN_ERR "SAA7191 initialization failed\n");
321 goto out_detach_client;
322 }
323
324 printk(KERN_INFO "SAA7191 initialized\n");
325
326 return 0;
327
328out_detach_client:
329 i2c_detach_client(client);
330out_free_decoder:
331 kfree(decoder);
332out_free_client:
333 kfree(client);
334 return err;
335}
336
337static int saa7191_probe(struct i2c_adapter *adap)
338{
339 /* Always connected to VINO */
340 if (adap->id == VINO_ADAPTER)
341 return saa7191_attach(adap, SAA7191_ADDR, 0);
342 /* Feel free to add probe here :-) */
343 return -ENODEV;
344}
345
346static int saa7191_detach(struct i2c_client *client)
347{
348 struct saa7191 *decoder = i2c_get_clientdata(client);
349
350 i2c_detach_client(client);
351 kfree(decoder);
352 kfree(client);
353 return 0;
354}
355
356static int saa7191_command(struct i2c_client *client, unsigned int cmd,
357 void *arg)
358{
359 struct saa7191 *decoder = i2c_get_clientdata(client);
360
361 switch (cmd) {
362 case DECODER_GET_CAPABILITIES: {
363 struct video_decoder_capability *cap = arg;
364
365 cap->flags = VIDEO_DECODER_PAL | VIDEO_DECODER_NTSC |
366 VIDEO_DECODER_SECAM | VIDEO_DECODER_AUTO;
367 cap->inputs = (client->adapter->id == VINO_ADAPTER) ? 2 : 1;
368 cap->outputs = 1;
369 break;
370 }
371 case DECODER_GET_STATUS: {
372 int *iarg = arg;
373 unsigned char status;
374 int res = 0;
375
376 if (saa7191_read_status(client, &status)) {
377 return -EIO;
378 }
379 if ((status & SAA7191_STATUS_HLCK) == 0)
380 res |= DECODER_STATUS_GOOD;
381 if (status & SAA7191_STATUS_CODE)
382 res |= DECODER_STATUS_COLOR;
383 switch (decoder->norm) {
384 case SAA7191_NORM_NTSC:
385 res |= DECODER_STATUS_NTSC;
386 break;
387 case SAA7191_NORM_PAL:
388 res |= DECODER_STATUS_PAL;
389 break;
390 case SAA7191_NORM_SECAM:
391 res |= DECODER_STATUS_SECAM;
392 break;
393 case SAA7191_NORM_AUTO:
394 default:
395 if (status & SAA7191_STATUS_FIDT)
396 res |= DECODER_STATUS_NTSC;
397 else
398 res |= DECODER_STATUS_PAL;
399 break;
400 }
401 *iarg = res;
402 break;
403 }
404 case DECODER_SET_NORM: {
405 int *iarg = arg;
406
407 switch (*iarg) {
408 case VIDEO_MODE_AUTO:
409 return saa7191_set_norm(client, SAA7191_NORM_AUTO);
410 case VIDEO_MODE_PAL:
411 return saa7191_set_norm(client, SAA7191_NORM_PAL);
412 case VIDEO_MODE_NTSC:
413 return saa7191_set_norm(client, SAA7191_NORM_NTSC);
414 case VIDEO_MODE_SECAM:
415 return saa7191_set_norm(client, SAA7191_NORM_SECAM);
416 default:
417 return -EINVAL;
418 }
419 break;
420 }
421 case DECODER_SET_INPUT: {
422 int *iarg = arg;
423
424 switch (client->adapter->id) {
425 case VINO_ADAPTER:
426 return saa7191_set_input(client, *iarg);
427 default:
428 if (*iarg != 0)
429 return -EINVAL;
430 }
431 break;
432 }
433 case DECODER_SET_OUTPUT: {
434 int *iarg = arg;
435
436 /* not much choice of outputs */
437 if (*iarg != 0)
438 return -EINVAL;
439 break;
440 }
441 case DECODER_ENABLE_OUTPUT: {
442 /* Always enabled */
443 break;
444 }
445 case DECODER_SET_PICTURE: {
446 struct video_picture *pic = arg;
447 unsigned val;
448 int err;
449
450 val = (pic->hue >> 8) - 0x80;
451 err = saa7191_write_reg(client, SAA7191_REG_HUEC, val);
452 if (err)
453 return -EIO;
454 break;
455 }
456 case DECODER_SAA7191_GET_STATUS: {
457 struct saa7191_status *status = arg;
458 unsigned char status_reg;
459
460 if (saa7191_read_status(client, &status_reg))
461 return -EIO;
462 status->signal = ((status_reg & SAA7191_STATUS_HLCK) == 0)
463 ? SAA7191_VALUE_ENABLED : SAA7191_VALUE_DISABLED;
464 status->ntsc = (status_reg & SAA7191_STATUS_FIDT)
465 ? SAA7191_VALUE_ENABLED : SAA7191_VALUE_DISABLED;
466 status->color = (status_reg & SAA7191_STATUS_CODE)
467 ? SAA7191_VALUE_ENABLED : SAA7191_VALUE_DISABLED;
468
469 status->input = decoder->input;
470 status->norm = decoder->norm;
471 }
472 case DECODER_SAA7191_SET_NORM: {
473 int *norm = arg;
474 return saa7191_set_norm(client, *norm);
475 }
476 case DECODER_SAA7191_GET_CONTROLS: {
477 struct saa7191_control *ctrl = arg;
478 return saa7191_get_controls(client, ctrl);
479 }
480 case DECODER_SAA7191_SET_CONTROLS: {
481 struct saa7191_control *ctrl = arg;
482 return saa7191_set_controls(client, ctrl);
483 }
484 default:
485 return -EINVAL;
486 }
487
488 return 0;
489}
490
491static struct i2c_driver i2c_driver_saa7191 = {
492 .owner = THIS_MODULE,
493 .name = "saa7191",
494 .id = I2C_DRIVERID_SAA7191,
495 .flags = I2C_DF_NOTIFY,
496 .attach_adapter = saa7191_probe,
497 .detach_client = saa7191_detach,
498 .command = saa7191_command
499};
500
501static int saa7191_init(void)
502{
503 return i2c_add_driver(&i2c_driver_saa7191);
504}
505
506static void saa7191_exit(void)
507{
508 i2c_del_driver(&i2c_driver_saa7191);
509}
510
511module_init(saa7191_init);
512module_exit(saa7191_exit);
diff --git a/drivers/media/video/saa7191.h b/drivers/media/video/saa7191.h
new file mode 100644
index 00000000000..27204503143
--- /dev/null
+++ b/drivers/media/video/saa7191.h
@@ -0,0 +1,139 @@
1/*
2 * saa7191.h - Philips SAA7191 video decoder driver
3 *
4 * Copyright (C) 2003 Ladislav Michl <ladis@linux-mips.org>
5 * Copyright (C) 2004,2005 Mikael Nousiainen <tmnousia@cc.hut.fi>
6 *
7 * This program is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License version 2 as
9 * published by the Free Software Foundation.
10 */
11
12#ifndef _SAA7191_H_
13#define _SAA7191_H_
14
15/* Philips SAA7191 DMSD I2C bus address */
16#define SAA7191_ADDR 0x8a
17
18/* Register subaddresses. */
19#define SAA7191_REG_IDEL 0x00
20#define SAA7191_REG_HSYB 0x01
21#define SAA7191_REG_HSYS 0x02
22#define SAA7191_REG_HCLB 0x03
23#define SAA7191_REG_HCLS 0x04
24#define SAA7191_REG_HPHI 0x05
25#define SAA7191_REG_LUMA 0x06
26#define SAA7191_REG_HUEC 0x07
27#define SAA7191_REG_CKTQ 0x08
28#define SAA7191_REG_CKTS 0x09
29#define SAA7191_REG_PLSE 0x0a
30#define SAA7191_REG_SESE 0x0b
31#define SAA7191_REG_GAIN 0x0c
32#define SAA7191_REG_STDC 0x0d
33#define SAA7191_REG_IOCK 0x0e
34#define SAA7191_REG_CTL3 0x0f
35#define SAA7191_REG_CTL4 0x10
36#define SAA7191_REG_CHCV 0x11
37#define SAA7191_REG_HS6B 0x14
38#define SAA7191_REG_HS6S 0x15
39#define SAA7191_REG_HC6B 0x16
40#define SAA7191_REG_HC6S 0x17
41#define SAA7191_REG_HP6I 0x18
42#define SAA7191_REG_STATUS 0xff /* not really a subaddress */
43
44/* Status Register definitions */
45#define SAA7191_STATUS_CODE 0x01 /* color detected flag */
46#define SAA7191_STATUS_FIDT 0x20 /* format type NTSC/PAL */
47#define SAA7191_STATUS_HLCK 0x40 /* PLL unlocked/locked */
48#define SAA7191_STATUS_STTC 0x80 /* tv/vtr time constant */
49
50/* Luminance Control Register definitions */
51#define SAA7191_LUMA_BYPS 0x80
52
53/* Chroma Gain Control Settings Register definitions */
54/* 0=automatic colour-killer enabled, 1=forced colour on */
55#define SAA7191_GAIN_COLO 0x80
56
57/* Standard/Mode Control Register definitions */
58/* tv/vtr mode bit: 0=TV mode (slow time constant),
59 * 1=VTR mode (fast time constant) */
60#define SAA7191_STDC_VTRC 0x80
61/* SECAM mode bit: 0=other standards, 1=SECAM */
62#define SAA7191_STDC_SECS 0x01
63/* the bit fields above must be or'd with this value */
64#define SAA7191_STDC_VALUE 0x0c
65
66/* I/O and Clock Control Register definitions */
67/* horizontal clock PLL: 0=PLL closed,
68 * 1=PLL circuit open and horizontal freq fixed */
69#define SAA7191_IOCK_HPLL 0x80
70/* S-VHS bit (chrominance from CVBS or from chrominance input):
71 * 0=controlled by BYPS-bit, 1=from chrominance input */
72#define SAA7191_IOCK_CHRS 0x04
73/* general purpose switch 2
74 * VINO-specific: 0=used with CVBS, 1=used with S-Video */
75#define SAA7191_IOCK_GPSW2 0x02
76/* general purpose switch 1 */
77/* VINO-specific: 0=always, 1=not used!*/
78#define SAA7191_IOCK_GPSW1 0x01
79
80/* Miscellaneous Control #1 Register definitions */
81/* automatic field detection (50/60Hz standard) */
82#define SAA7191_CTL3_AUFD 0x80
83/* field select: (if AUFD=0)
84 * 0=50Hz (625 lines), 1=60Hz (525 lines) */
85#define SAA7191_CTL3_FSEL 0x40
86/* the bit fields above must be or'd with this value */
87#define SAA7191_CTL3_VALUE 0x19
88
89/* Chrominance Gain Control Register definitions
90 * (nominal value for UV CCIR level) */
91#define SAA7191_CHCV_NTSC 0x2c
92#define SAA7191_CHCV_PAL 0x59
93
94/* Driver interface definitions */
95#define SAA7191_INPUT_COMPOSITE 0
96#define SAA7191_INPUT_SVIDEO 1
97
98#define SAA7191_NORM_AUTO 0
99#define SAA7191_NORM_PAL 1
100#define SAA7191_NORM_NTSC 2
101#define SAA7191_NORM_SECAM 3
102
103#define SAA7191_VALUE_ENABLED 1
104#define SAA7191_VALUE_DISABLED 0
105#define SAA7191_VALUE_UNCHANGED -1
106
107struct saa7191_status {
108 /* 0=no signal, 1=signal active*/
109 int signal;
110 /* 0=50hz (pal) signal, 1=60hz (ntsc) signal */
111 int ntsc;
112 /* 0=no color detected, 1=color detected */
113 int color;
114
115 /* current SAA7191_INPUT_ */
116 int input;
117 /* current SAA7191_NORM_ */
118 int norm;
119};
120
121#define SAA7191_HUE_MIN 0x00
122#define SAA7191_HUE_MAX 0xff
123#define SAA7191_HUE_DEFAULT 0x80
124
125#define SAA7191_VTRC_MIN 0x00
126#define SAA7191_VTRC_MAX 0x01
127#define SAA7191_VTRC_DEFAULT 0x00
128
129struct saa7191_control {
130 int hue;
131 int vtrc;
132};
133
134#define DECODER_SAA7191_GET_STATUS _IOR('d', 195, struct saa7191_status)
135#define DECODER_SAA7191_SET_NORM _IOW('d', 196, int)
136#define DECODER_SAA7191_GET_CONTROLS _IOR('d', 197, struct saa7191_control)
137#define DECODER_SAA7191_SET_CONTROLS _IOW('d', 198, struct saa7191_control)
138
139#endif
diff --git a/drivers/media/video/tda7432.c b/drivers/media/video/tda7432.c
index 7cb1fb3e66f..255b6088ebf 100644
--- a/drivers/media/video/tda7432.c
+++ b/drivers/media/video/tda7432.c
@@ -328,7 +328,7 @@ static int tda7432_probe(struct i2c_adapter *adap)
328 if (adap->class & I2C_CLASS_TV_ANALOG) 328 if (adap->class & I2C_CLASS_TV_ANALOG)
329 return i2c_probe(adap, &addr_data, tda7432_attach); 329 return i2c_probe(adap, &addr_data, tda7432_attach);
330#else 330#else
331 if (adap->id == (I2C_ALGO_BIT | I2C_HW_B_BT848)) 331 if (adap->id == I2C_HW_B_BT848)
332 return i2c_probe(adap, &addr_data, tda7432_attach); 332 return i2c_probe(adap, &addr_data, tda7432_attach);
333#endif 333#endif
334 return 0; 334 return 0;
@@ -513,7 +513,7 @@ static struct i2c_driver driver = {
513 513
514static struct i2c_client client_template = 514static struct i2c_client client_template =
515{ 515{
516 I2C_DEVNAME("tda7432"), 516 .name = "tda7432",
517 .driver = &driver, 517 .driver = &driver,
518}; 518};
519 519
diff --git a/drivers/media/video/tda9840.c b/drivers/media/video/tda9840.c
index c29bdfc3244..1794686612c 100644
--- a/drivers/media/video/tda9840.c
+++ b/drivers/media/video/tda9840.c
@@ -205,7 +205,7 @@ static int detect(struct i2c_adapter *adapter, int address, int kind)
205static int attach(struct i2c_adapter *adapter) 205static int attach(struct i2c_adapter *adapter)
206{ 206{
207 /* let's see whether this is a know adapter we can attach to */ 207 /* let's see whether this is a know adapter we can attach to */
208 if (adapter->id != I2C_ALGO_SAA7146) { 208 if (adapter->id != I2C_HW_SAA7146) {
209 dprintk("refusing to probe on unknown adapter [name='%s',id=0x%x]\n", adapter->name, adapter->id); 209 dprintk("refusing to probe on unknown adapter [name='%s',id=0x%x]\n", adapter->name, adapter->id);
210 return -ENODEV; 210 return -ENODEV;
211 } 211 }
@@ -231,7 +231,7 @@ static struct i2c_driver driver = {
231}; 231};
232 232
233static struct i2c_client client_template = { 233static struct i2c_client client_template = {
234 I2C_DEVNAME("tda9840"), 234 .name = "tda9840",
235 .driver = &driver, 235 .driver = &driver,
236}; 236};
237 237
diff --git a/drivers/media/video/tda9875.c b/drivers/media/video/tda9875.c
index 566e1a5ca13..7e3dcdb262b 100644
--- a/drivers/media/video/tda9875.c
+++ b/drivers/media/video/tda9875.c
@@ -262,7 +262,7 @@ static int tda9875_probe(struct i2c_adapter *adap)
262 if (adap->class & I2C_CLASS_TV_ANALOG) 262 if (adap->class & I2C_CLASS_TV_ANALOG)
263 return i2c_probe(adap, &addr_data, tda9875_attach); 263 return i2c_probe(adap, &addr_data, tda9875_attach);
264#else 264#else
265 if (adap->id == (I2C_ALGO_BIT | I2C_HW_B_BT848)) 265 if (adap->id == I2C_HW_B_BT848)
266 return i2c_probe(adap, &addr_data, tda9875_attach); 266 return i2c_probe(adap, &addr_data, tda9875_attach);
267#endif 267#endif
268 return 0; 268 return 0;
@@ -384,7 +384,7 @@ static struct i2c_driver driver = {
384 384
385static struct i2c_client client_template = 385static struct i2c_client client_template =
386{ 386{
387 I2C_DEVNAME("tda9875"), 387 .name = "tda9875",
388 .driver = &driver, 388 .driver = &driver,
389}; 389};
390 390
diff --git a/drivers/media/video/tda9887.c b/drivers/media/video/tda9887.c
index 108c3ad7d62..d60fc562aec 100644
--- a/drivers/media/video/tda9887.c
+++ b/drivers/media/video/tda9887.c
@@ -618,9 +618,9 @@ static int tda9887_probe(struct i2c_adapter *adap)
618 return i2c_probe(adap, &addr_data, tda9887_attach); 618 return i2c_probe(adap, &addr_data, tda9887_attach);
619#else 619#else
620 switch (adap->id) { 620 switch (adap->id) {
621 case I2C_ALGO_BIT | I2C_HW_B_BT848: 621 case I2C_HW_B_BT848:
622 case I2C_ALGO_BIT | I2C_HW_B_RIVA: 622 case I2C_HW_B_RIVA:
623 case I2C_ALGO_SAA7134: 623 case I2C_HW_SAA7134:
624 return i2c_probe(adap, &addr_data, tda9887_attach); 624 return i2c_probe(adap, &addr_data, tda9887_attach);
625 break; 625 break;
626 } 626 }
@@ -760,7 +760,7 @@ tda9887_command(struct i2c_client *client, unsigned int cmd, void *arg)
760 return 0; 760 return 0;
761} 761}
762 762
763static int tda9887_suspend(struct device * dev, u32 state, u32 level) 763static int tda9887_suspend(struct device * dev, pm_message_t state, u32 level)
764{ 764{
765 dprintk("tda9887: suspend\n"); 765 dprintk("tda9887: suspend\n");
766 return 0; 766 return 0;
@@ -793,7 +793,7 @@ static struct i2c_driver driver = {
793}; 793};
794static struct i2c_client client_template = 794static struct i2c_client client_template =
795{ 795{
796 I2C_DEVNAME("tda9887"), 796 .name = "tda9887",
797 .flags = I2C_CLIENT_ALLOW_USE, 797 .flags = I2C_CLIENT_ALLOW_USE,
798 .driver = &driver, 798 .driver = &driver,
799}; 799};
diff --git a/drivers/media/video/tea6415c.c b/drivers/media/video/tea6415c.c
index b44db8a7b94..ee3688348b6 100644
--- a/drivers/media/video/tea6415c.c
+++ b/drivers/media/video/tea6415c.c
@@ -86,7 +86,7 @@ static int detect(struct i2c_adapter *adapter, int address, int kind)
86static int attach(struct i2c_adapter *adapter) 86static int attach(struct i2c_adapter *adapter)
87{ 87{
88 /* let's see whether this is a know adapter we can attach to */ 88 /* let's see whether this is a know adapter we can attach to */
89 if (adapter->id != I2C_ALGO_SAA7146) { 89 if (adapter->id != I2C_HW_SAA7146) {
90 dprintk("refusing to probe on unknown adapter [name='%s',id=0x%x]\n", adapter->name, adapter->id); 90 dprintk("refusing to probe on unknown adapter [name='%s',id=0x%x]\n", adapter->name, adapter->id);
91 return -ENODEV; 91 return -ENODEV;
92 } 92 }
@@ -200,7 +200,7 @@ static struct i2c_driver driver = {
200}; 200};
201 201
202static struct i2c_client client_template = { 202static struct i2c_client client_template = {
203 I2C_DEVNAME("tea6415c"), 203 .name = "tea6415c",
204 .driver = &driver, 204 .driver = &driver,
205}; 205};
206 206
diff --git a/drivers/media/video/tea6420.c b/drivers/media/video/tea6420.c
index 48d4db7d507..17975c19da5 100644
--- a/drivers/media/video/tea6420.c
+++ b/drivers/media/video/tea6420.c
@@ -135,7 +135,7 @@ static int tea6420_detect(struct i2c_adapter *adapter, int address, int kind)
135static int attach(struct i2c_adapter *adapter) 135static int attach(struct i2c_adapter *adapter)
136{ 136{
137 /* let's see whether this is a know adapter we can attach to */ 137 /* let's see whether this is a know adapter we can attach to */
138 if (adapter->id != I2C_ALGO_SAA7146) { 138 if (adapter->id != I2C_HW_SAA7146) {
139 dprintk("refusing to probe on unknown adapter [name='%s',id=0x%x]\n", adapter->name, adapter->id); 139 dprintk("refusing to probe on unknown adapter [name='%s',id=0x%x]\n", adapter->name, adapter->id);
140 return -ENODEV; 140 return -ENODEV;
141 } 141 }
@@ -177,7 +177,7 @@ static struct i2c_driver driver = {
177}; 177};
178 178
179static struct i2c_client client_template = { 179static struct i2c_client client_template = {
180 I2C_DEVNAME("tea6420"), 180 .name = "tea6420",
181 .driver = &driver, 181 .driver = &driver,
182}; 182};
183 183
diff --git a/drivers/media/video/tuner-3036.c b/drivers/media/video/tuner-3036.c
index 7d825e510ff..79203595b9c 100644
--- a/drivers/media/video/tuner-3036.c
+++ b/drivers/media/video/tuner-3036.c
@@ -41,7 +41,6 @@ static struct i2c_client_address_data addr_data = {
41 .normal_i2c = normal_i2c, 41 .normal_i2c = normal_i2c,
42 .probe = &ignore, 42 .probe = &ignore,
43 .ignore = &ignore, 43 .ignore = &ignore,
44 .force = &ignore,
45}; 44};
46 45
47/* ---------------------------------------------------------------------- */ 46/* ---------------------------------------------------------------------- */
@@ -166,7 +165,7 @@ static int
166tuner_probe(struct i2c_adapter *adap) 165tuner_probe(struct i2c_adapter *adap)
167{ 166{
168 this_adap = 0; 167 this_adap = 0;
169 if (adap->id == (I2C_ALGO_BIT | I2C_HW_B_LP)) 168 if (adap->id == I2C_HW_B_LP)
170 return i2c_probe(adap, &addr_data, tuner_attach); 169 return i2c_probe(adap, &addr_data, tuner_attach);
171 return 0; 170 return 0;
172} 171}
diff --git a/drivers/media/video/tuner-core.c b/drivers/media/video/tuner-core.c
index f0a579827a2..3b1893c2ae3 100644
--- a/drivers/media/video/tuner-core.c
+++ b/drivers/media/video/tuner-core.c
@@ -672,7 +672,7 @@ static int tuner_command(struct i2c_client *client, unsigned int cmd, void *arg)
672 return 0; 672 return 0;
673} 673}
674 674
675static int tuner_suspend(struct device *dev, u32 state, u32 level) 675static int tuner_suspend(struct device *dev, pm_message_t state, u32 level)
676{ 676{
677 struct i2c_client *c = container_of (dev, struct i2c_client, dev); 677 struct i2c_client *c = container_of (dev, struct i2c_client, dev);
678 struct tuner *t = i2c_get_clientdata (c); 678 struct tuner *t = i2c_get_clientdata (c);
@@ -709,7 +709,7 @@ static struct i2c_driver driver = {
709 }, 709 },
710}; 710};
711static struct i2c_client client_template = { 711static struct i2c_client client_template = {
712 I2C_DEVNAME("(tuner unset)"), 712 .name = "(tuner unset)",
713 .flags = I2C_CLIENT_ALLOW_USE, 713 .flags = I2C_CLIENT_ALLOW_USE,
714 .driver = &driver, 714 .driver = &driver,
715}; 715};
diff --git a/drivers/media/video/tvaudio.c b/drivers/media/video/tvaudio.c
index f42a1efa8fc..258724b2d6d 100644
--- a/drivers/media/video/tvaudio.c
+++ b/drivers/media/video/tvaudio.c
@@ -162,24 +162,23 @@ static int chip_write(struct CHIPSTATE *chip, int subaddr, int val)
162 unsigned char buffer[2]; 162 unsigned char buffer[2];
163 163
164 if (-1 == subaddr) { 164 if (-1 == subaddr) {
165 dprintk("%s: chip_write: 0x%x\n", 165 dprintk("%s: chip_write: 0x%x\n", chip->c.name, val);
166 i2c_clientname(&chip->c), val);
167 chip->shadow.bytes[1] = val; 166 chip->shadow.bytes[1] = val;
168 buffer[0] = val; 167 buffer[0] = val;
169 if (1 != i2c_master_send(&chip->c,buffer,1)) { 168 if (1 != i2c_master_send(&chip->c,buffer,1)) {
170 printk(KERN_WARNING "%s: I/O error (write 0x%x)\n", 169 printk(KERN_WARNING "%s: I/O error (write 0x%x)\n",
171 i2c_clientname(&chip->c), val); 170 chip->c.name, val);
172 return -1; 171 return -1;
173 } 172 }
174 } else { 173 } else {
175 dprintk("%s: chip_write: reg%d=0x%x\n", 174 dprintk("%s: chip_write: reg%d=0x%x\n",
176 i2c_clientname(&chip->c), subaddr, val); 175 chip->c.name, subaddr, val);
177 chip->shadow.bytes[subaddr+1] = val; 176 chip->shadow.bytes[subaddr+1] = val;
178 buffer[0] = subaddr; 177 buffer[0] = subaddr;
179 buffer[1] = val; 178 buffer[1] = val;
180 if (2 != i2c_master_send(&chip->c,buffer,2)) { 179 if (2 != i2c_master_send(&chip->c,buffer,2)) {
181 printk(KERN_WARNING "%s: I/O error (write reg%d=0x%x)\n", 180 printk(KERN_WARNING "%s: I/O error (write reg%d=0x%x)\n",
182 i2c_clientname(&chip->c), subaddr, val); 181 chip->c.name, subaddr, val);
183 return -1; 182 return -1;
184 } 183 }
185 } 184 }
@@ -203,11 +202,10 @@ static int chip_read(struct CHIPSTATE *chip)
203 unsigned char buffer; 202 unsigned char buffer;
204 203
205 if (1 != i2c_master_recv(&chip->c,&buffer,1)) { 204 if (1 != i2c_master_recv(&chip->c,&buffer,1)) {
206 printk(KERN_WARNING "%s: I/O error (read)\n", 205 printk(KERN_WARNING "%s: I/O error (read)\n", chip->c.name);
207 i2c_clientname(&chip->c));
208 return -1; 206 return -1;
209 } 207 }
210 dprintk("%s: chip_read: 0x%x\n",i2c_clientname(&chip->c),buffer); 208 dprintk("%s: chip_read: 0x%x\n", chip->c.name, buffer);
211 return buffer; 209 return buffer;
212} 210}
213 211
@@ -222,12 +220,11 @@ static int chip_read2(struct CHIPSTATE *chip, int subaddr)
222 write[0] = subaddr; 220 write[0] = subaddr;
223 221
224 if (2 != i2c_transfer(chip->c.adapter,msgs,2)) { 222 if (2 != i2c_transfer(chip->c.adapter,msgs,2)) {
225 printk(KERN_WARNING "%s: I/O error (read2)\n", 223 printk(KERN_WARNING "%s: I/O error (read2)\n", chip->c.name);
226 i2c_clientname(&chip->c));
227 return -1; 224 return -1;
228 } 225 }
229 dprintk("%s: chip_read2: reg%d=0x%x\n", 226 dprintk("%s: chip_read2: reg%d=0x%x\n",
230 i2c_clientname(&chip->c),subaddr,read[0]); 227 chip->c.name, subaddr, read[0]);
231 return read[0]; 228 return read[0];
232} 229}
233 230
@@ -240,7 +237,7 @@ static int chip_cmd(struct CHIPSTATE *chip, char *name, audiocmd *cmd)
240 237
241 /* update our shadow register set; print bytes if (debug > 0) */ 238 /* update our shadow register set; print bytes if (debug > 0) */
242 dprintk("%s: chip_cmd(%s): reg=%d, data:", 239 dprintk("%s: chip_cmd(%s): reg=%d, data:",
243 i2c_clientname(&chip->c),name,cmd->bytes[0]); 240 chip->c.name, name, cmd->bytes[0]);
244 for (i = 1; i < cmd->count; i++) { 241 for (i = 1; i < cmd->count; i++) {
245 dprintk(" 0x%x",cmd->bytes[i]); 242 dprintk(" 0x%x",cmd->bytes[i]);
246 chip->shadow.bytes[i+cmd->bytes[0]] = cmd->bytes[i]; 243 chip->shadow.bytes[i+cmd->bytes[0]] = cmd->bytes[i];
@@ -249,7 +246,7 @@ static int chip_cmd(struct CHIPSTATE *chip, char *name, audiocmd *cmd)
249 246
250 /* send data to the chip */ 247 /* send data to the chip */
251 if (cmd->count != i2c_master_send(&chip->c,cmd->bytes,cmd->count)) { 248 if (cmd->count != i2c_master_send(&chip->c,cmd->bytes,cmd->count)) {
252 printk(KERN_WARNING "%s: I/O error (%s)\n", i2c_clientname(&chip->c), name); 249 printk(KERN_WARNING "%s: I/O error (%s)\n", chip->c.name, name);
253 return -1; 250 return -1;
254 } 251 }
255 return 0; 252 return 0;
@@ -274,9 +271,9 @@ static int chip_thread(void *data)
274 struct CHIPSTATE *chip = data; 271 struct CHIPSTATE *chip = data;
275 struct CHIPDESC *desc = chiplist + chip->type; 272 struct CHIPDESC *desc = chiplist + chip->type;
276 273
277 daemonize("%s",i2c_clientname(&chip->c)); 274 daemonize("%s", chip->c.name);
278 allow_signal(SIGTERM); 275 allow_signal(SIGTERM);
279 dprintk("%s: thread started\n", i2c_clientname(&chip->c)); 276 dprintk("%s: thread started\n", chip->c.name);
280 277
281 for (;;) { 278 for (;;) {
282 add_wait_queue(&chip->wq, &wait); 279 add_wait_queue(&chip->wq, &wait);
@@ -288,7 +285,7 @@ static int chip_thread(void *data)
288 try_to_freeze(); 285 try_to_freeze();
289 if (chip->done || signal_pending(current)) 286 if (chip->done || signal_pending(current))
290 break; 287 break;
291 dprintk("%s: thread wakeup\n", i2c_clientname(&chip->c)); 288 dprintk("%s: thread wakeup\n", chip->c.name);
292 289
293 /* don't do anything for radio or if mode != auto */ 290 /* don't do anything for radio or if mode != auto */
294 if (chip->norm == VIDEO_MODE_RADIO || chip->mode != 0) 291 if (chip->norm == VIDEO_MODE_RADIO || chip->mode != 0)
@@ -301,7 +298,7 @@ static int chip_thread(void *data)
301 mod_timer(&chip->wt, jiffies+2*HZ); 298 mod_timer(&chip->wt, jiffies+2*HZ);
302 } 299 }
303 300
304 dprintk("%s: thread exiting\n", i2c_clientname(&chip->c)); 301 dprintk("%s: thread exiting\n", chip->c.name);
305 complete_and_exit(&chip->texit, 0); 302 complete_and_exit(&chip->texit, 0);
306 return 0; 303 return 0;
307} 304}
@@ -314,7 +311,7 @@ static void generic_checkmode(struct CHIPSTATE *chip)
314 if (mode == chip->prevmode) 311 if (mode == chip->prevmode)
315 return; 312 return;
316 313
317 dprintk("%s: thread checkmode\n", i2c_clientname(&chip->c)); 314 dprintk("%s: thread checkmode\n", chip->c.name);
318 chip->prevmode = mode; 315 chip->prevmode = mode;
319 316
320 if (mode & VIDEO_SOUND_STEREO) 317 if (mode & VIDEO_SOUND_STEREO)
@@ -1098,7 +1095,7 @@ static int tda8425_initialize(struct CHIPSTATE *chip)
1098 /* extern */ TDA8425_S1_CH1, /* intern */ TDA8425_S1_OFF, 1095 /* extern */ TDA8425_S1_CH1, /* intern */ TDA8425_S1_OFF,
1099 /* off */ TDA8425_S1_OFF, /* on */ TDA8425_S1_CH2}; 1096 /* off */ TDA8425_S1_OFF, /* on */ TDA8425_S1_CH2};
1100 1097
1101 if (chip->c.adapter->id == (I2C_ALGO_BIT | I2C_HW_B_RIVA)) { 1098 if (chip->c.adapter->id == I2C_HW_B_RIVA) {
1102 memcpy (desc->inputmap, inputmap, sizeof (inputmap)); 1099 memcpy (desc->inputmap, inputmap, sizeof (inputmap));
1103 } 1100 }
1104 return 0; 1101 return 0;
@@ -1501,7 +1498,7 @@ static int chip_attach(struct i2c_adapter *adap, int addr, int kind)
1501 (desc->flags & CHIP_HAS_INPUTSEL) ? " audiomux" : ""); 1498 (desc->flags & CHIP_HAS_INPUTSEL) ? " audiomux" : "");
1502 1499
1503 /* fill required data structures */ 1500 /* fill required data structures */
1504 strcpy(i2c_clientname(&chip->c),desc->name); 1501 strcpy(chip->c.name, desc->name);
1505 chip->type = desc-chiplist; 1502 chip->type = desc-chiplist;
1506 chip->shadow.count = desc->registers+1; 1503 chip->shadow.count = desc->registers+1;
1507 chip->prevmode = -1; 1504 chip->prevmode = -1;
@@ -1538,7 +1535,7 @@ static int chip_attach(struct i2c_adapter *adap, int addr, int kind)
1538 chip->tpid = kernel_thread(chip_thread,(void *)chip,0); 1535 chip->tpid = kernel_thread(chip_thread,(void *)chip,0);
1539 if (chip->tpid < 0) 1536 if (chip->tpid < 0)
1540 printk(KERN_WARNING "%s: kernel_thread() failed\n", 1537 printk(KERN_WARNING "%s: kernel_thread() failed\n",
1541 i2c_clientname(&chip->c)); 1538 chip->c.name);
1542 wake_up_interruptible(&chip->wq); 1539 wake_up_interruptible(&chip->wq);
1543 } 1540 }
1544 return 0; 1541 return 0;
@@ -1548,16 +1545,16 @@ static int chip_probe(struct i2c_adapter *adap)
1548{ 1545{
1549 /* don't attach on saa7146 based cards, 1546 /* don't attach on saa7146 based cards,
1550 because dedicated drivers are used */ 1547 because dedicated drivers are used */
1551 if ((adap->id & I2C_ALGO_SAA7146)) 1548 if (adap->id == I2C_HW_SAA7146)
1552 return 0; 1549 return 0;
1553#ifdef I2C_CLASS_TV_ANALOG 1550#ifdef I2C_CLASS_TV_ANALOG
1554 if (adap->class & I2C_CLASS_TV_ANALOG) 1551 if (adap->class & I2C_CLASS_TV_ANALOG)
1555 return i2c_probe(adap, &addr_data, chip_attach); 1552 return i2c_probe(adap, &addr_data, chip_attach);
1556#else 1553#else
1557 switch (adap->id) { 1554 switch (adap->id) {
1558 case I2C_ALGO_BIT | I2C_HW_B_BT848: 1555 case I2C_HW_B_BT848:
1559 case I2C_ALGO_BIT | I2C_HW_B_RIVA: 1556 case I2C_HW_B_RIVA:
1560 case I2C_ALGO_SAA7134: 1557 case I2C_HW_SAA7134:
1561 return i2c_probe(adap, &addr_data, chip_attach); 1558 return i2c_probe(adap, &addr_data, chip_attach);
1562 } 1559 }
1563#endif 1560#endif
@@ -1591,7 +1588,7 @@ static int chip_command(struct i2c_client *client,
1591 struct CHIPSTATE *chip = i2c_get_clientdata(client); 1588 struct CHIPSTATE *chip = i2c_get_clientdata(client);
1592 struct CHIPDESC *desc = chiplist + chip->type; 1589 struct CHIPDESC *desc = chiplist + chip->type;
1593 1590
1594 dprintk("%s: chip_command 0x%x\n",i2c_clientname(&chip->c),cmd); 1591 dprintk("%s: chip_command 0x%x\n", chip->c.name, cmd);
1595 1592
1596 switch (cmd) { 1593 switch (cmd) {
1597 case AUDC_SET_INPUT: 1594 case AUDC_SET_INPUT:
@@ -1702,7 +1699,7 @@ static struct i2c_driver driver = {
1702 1699
1703static struct i2c_client client_template = 1700static struct i2c_client client_template =
1704{ 1701{
1705 I2C_DEVNAME("(unset)"), 1702 .name = "(unset)",
1706 .flags = I2C_CLIENT_ALLOW_USE, 1703 .flags = I2C_CLIENT_ALLOW_USE,
1707 .driver = &driver, 1704 .driver = &driver,
1708}; 1705};
diff --git a/drivers/media/video/tveeprom.c b/drivers/media/video/tveeprom.c
index 127ec38ebd6..3c3356a01cc 100644
--- a/drivers/media/video/tveeprom.c
+++ b/drivers/media/video/tveeprom.c
@@ -534,7 +534,7 @@ static int
534tveeprom_attach_adapter (struct i2c_adapter *adapter) 534tveeprom_attach_adapter (struct i2c_adapter *adapter)
535{ 535{
536 dprintk(1,"%s: id 0x%x\n",__FUNCTION__,adapter->id); 536 dprintk(1,"%s: id 0x%x\n",__FUNCTION__,adapter->id);
537 if (adapter->id != (I2C_ALGO_BIT | I2C_HW_B_BT848)) 537 if (adapter->id != I2C_HW_B_BT848)
538 return 0; 538 return 0;
539 return i2c_probe(adapter, &addr_data, tveeprom_detect_client); 539 return i2c_probe(adapter, &addr_data, tveeprom_detect_client);
540} 540}
diff --git a/drivers/media/video/tvmixer.c b/drivers/media/video/tvmixer.c
index 51b99cdbf29..a43301a154a 100644
--- a/drivers/media/video/tvmixer.c
+++ b/drivers/media/video/tvmixer.c
@@ -91,7 +91,7 @@ static int tvmixer_ioctl(struct inode *inode, struct file *file, unsigned int cm
91 if (cmd == SOUND_MIXER_INFO) { 91 if (cmd == SOUND_MIXER_INFO) {
92 mixer_info info; 92 mixer_info info;
93 strlcpy(info.id, "tv card", sizeof(info.id)); 93 strlcpy(info.id, "tv card", sizeof(info.id));
94 strlcpy(info.name, i2c_clientname(client), sizeof(info.name)); 94 strlcpy(info.name, client->name, sizeof(info.name));
95 info.modify_counter = 42 /* FIXME */; 95 info.modify_counter = 42 /* FIXME */;
96 if (copy_to_user(argp, &info, sizeof(info))) 96 if (copy_to_user(argp, &info, sizeof(info)))
97 return -EFAULT; 97 return -EFAULT;
@@ -100,7 +100,7 @@ static int tvmixer_ioctl(struct inode *inode, struct file *file, unsigned int cm
100 if (cmd == SOUND_OLD_MIXER_INFO) { 100 if (cmd == SOUND_OLD_MIXER_INFO) {
101 _old_mixer_info info; 101 _old_mixer_info info;
102 strlcpy(info.id, "tv card", sizeof(info.id)); 102 strlcpy(info.id, "tv card", sizeof(info.id));
103 strlcpy(info.name, i2c_clientname(client), sizeof(info.name)); 103 strlcpy(info.name, client->name, sizeof(info.name));
104 if (copy_to_user(argp, &info, sizeof(info))) 104 if (copy_to_user(argp, &info, sizeof(info)))
105 return -EFAULT; 105 return -EFAULT;
106 return 0; 106 return 0;
@@ -276,9 +276,9 @@ static int tvmixer_clients(struct i2c_client *client)
276#else 276#else
277 /* TV card ??? */ 277 /* TV card ??? */
278 switch (client->adapter->id) { 278 switch (client->adapter->id) {
279 case I2C_ALGO_BIT | I2C_HW_SMBUS_VOODOO3: 279 case I2C_HW_SMBUS_VOODOO3:
280 case I2C_ALGO_BIT | I2C_HW_B_BT848: 280 case I2C_HW_B_BT848:
281 case I2C_ALGO_BIT | I2C_HW_B_RIVA: 281 case I2C_HW_B_RIVA:
282 /* ok, have a look ... */ 282 /* ok, have a look ... */
283 break; 283 break;
284 default: 284 default:
@@ -295,7 +295,7 @@ static int tvmixer_clients(struct i2c_client *client)
295 devices[i].dev = NULL; 295 devices[i].dev = NULL;
296 devices[i].minor = -1; 296 devices[i].minor = -1;
297 printk("tvmixer: %s unregistered (#1)\n", 297 printk("tvmixer: %s unregistered (#1)\n",
298 i2c_clientname(client)); 298 client->name);
299 return 0; 299 return 0;
300 } 300 }
301 } 301 }
@@ -354,7 +354,7 @@ static void __exit tvmixer_cleanup_module(void)
354 if (devices[i].minor != -1) { 354 if (devices[i].minor != -1) {
355 unregister_sound_mixer(devices[i].minor); 355 unregister_sound_mixer(devices[i].minor);
356 printk("tvmixer: %s unregistered (#2)\n", 356 printk("tvmixer: %s unregistered (#2)\n",
357 i2c_clientname(devices[i].dev)); 357 devices[i].dev->name);
358 } 358 }
359 } 359 }
360} 360}
diff --git a/drivers/media/video/vino.c b/drivers/media/video/vino.c
index 76e8681d65c..d8a0f763ca1 100644
--- a/drivers/media/video/vino.c
+++ b/drivers/media/video/vino.c
@@ -1,80 +1,606 @@
1/* 1/*
2 * (incomplete) Driver for the VINO (Video In No Out) system found in SGI Indys. 2 * Driver for the VINO (Video In No Out) system found in SGI Indys.
3 * 3 *
4 * This file is subject to the terms and conditions of the GNU General Public 4 * This file is subject to the terms and conditions of the GNU General Public
5 * License version 2 as published by the Free Software Foundation. 5 * License version 2 as published by the Free Software Foundation.
6 * 6 *
7 * Copyright (C) 2004,2005 Mikael Nousiainen <tmnousia@cc.hut.fi>
8 *
9 * Based on the previous version of the driver for 2.4 kernels by:
7 * Copyright (C) 2003 Ladislav Michl <ladis@linux-mips.org> 10 * Copyright (C) 2003 Ladislav Michl <ladis@linux-mips.org>
8 */ 11 */
9 12
10#include <linux/module.h> 13/*
14 * TODO:
15 * - remove "hacks" from memory allocation code and implement nopage()
16 * - check decimation, calculating and reporting image size when
17 * using decimation
18 * - check vino_acquire_input(), vino_set_input() and channel
19 * ownership handling
20 * - report VINO error-interrupts via ioctls ?
21 * - implement picture controls (all implemented?)
22 * - use macros for boolean values (?)
23 * - implement user mode buffers and overlay (?)
24 */
25
11#include <linux/init.h> 26#include <linux/init.h>
12#include <linux/types.h> 27#include <linux/module.h>
13#include <linux/mm.h>
14#include <linux/slab.h>
15#include <linux/wrapper.h>
16#include <linux/errno.h>
17#include <linux/irq.h>
18#include <linux/delay.h> 28#include <linux/delay.h>
19#include <linux/videodev.h> 29#include <linux/errno.h>
30#include <linux/fs.h>
31#include <linux/kernel.h>
32#include <linux/mm.h>
33#include <linux/interrupt.h>
34#include <linux/dma-mapping.h>
35#include <linux/time.h>
36#include <linux/moduleparam.h>
37
38#ifdef CONFIG_KMOD
39#include <linux/kmod.h>
40#endif
41
20#include <linux/i2c.h> 42#include <linux/i2c.h>
21#include <linux/i2c-algo-sgi.h> 43#include <linux/i2c-algo-sgi.h>
22 44
23#include <asm/addrspace.h> 45#include <linux/videodev.h>
24#include <asm/system.h> 46#include <linux/videodev2.h>
25#include <asm/bootinfo.h> 47#include <linux/video_decoder.h>
26#include <asm/pgtable.h> 48
27#include <asm/paccess.h> 49#include <asm/paccess.h>
28#include <asm/io.h> 50#include <asm/io.h>
29#include <asm/sgi/ip22.h> 51#include <asm/sgi/ip22.h>
30#include <asm/sgi/hpc3.h>
31#include <asm/sgi/mc.h> 52#include <asm/sgi/mc.h>
32 53
33#include "vino.h" 54#include "vino.h"
55#include "saa7191.h"
56#include "indycam.h"
57
58/* Uncomment the following line to get lots and lots of (mostly useless)
59 * debug info.
60 * Note that the debug output also slows down the driver significantly */
61// #define VINO_DEBUG
62
63#define VINO_MODULE_VERSION "0.0.3"
64#define VINO_VERSION_CODE KERNEL_VERSION(0, 0, 3)
65
66MODULE_DESCRIPTION("SGI VINO Video4Linux2 driver");
67MODULE_VERSION(VINO_MODULE_VERSION);
68MODULE_AUTHOR("Mikael Nousiainen <tmnousia@cc.hut.fi>");
69MODULE_LICENSE("GPL");
34 70
35/* debugging? */ 71#define mem_map_reserve(p) set_bit(PG_reserved, &((p)->flags))
36#if 1 72#define mem_map_unreserve(p) clear_bit(PG_reserved, &((p)->flags))
37#define DEBUG(x...) printk(x); 73
74#ifdef VINO_DEBUG
75#define dprintk(x...) printk("VINO: " x);
38#else 76#else
39#define DEBUG(x...) 77#define dprintk(x...)
40#endif 78#endif
41 79
80#define VINO_NO_CHANNEL 0
81#define VINO_CHANNEL_A 1
82#define VINO_CHANNEL_B 2
83
84#define VINO_PAL_WIDTH 768
85#define VINO_PAL_HEIGHT 576
86#define VINO_NTSC_WIDTH 640
87#define VINO_NTSC_HEIGHT 480
88
89#define VINO_MIN_WIDTH 32
90#define VINO_MIN_HEIGHT 32
91
92#define VINO_CLIPPING_START_ODD_D1 1
93#define VINO_CLIPPING_START_ODD_PAL 1
94#define VINO_CLIPPING_START_ODD_NTSC 1
95
96#define VINO_CLIPPING_START_EVEN_D1 2
97#define VINO_CLIPPING_START_EVEN_PAL 2
98#define VINO_CLIPPING_START_EVEN_NTSC 2
99
100#define VINO_INPUT_CHANNEL_COUNT 3
101
102#define VINO_INPUT_NONE -1
103#define VINO_INPUT_COMPOSITE 0
104#define VINO_INPUT_SVIDEO 1
105#define VINO_INPUT_D1 2
106
107#define VINO_PAGE_RATIO (PAGE_SIZE / VINO_PAGE_SIZE)
108
109#define VINO_FIFO_THRESHOLD_DEFAULT 512
110
111/*#define VINO_FRAMEBUFFER_SIZE (VINO_PAL_WIDTH * VINO_PAL_HEIGHT * 4 \
112 + 2 * PAGE_SIZE)*/
113#define VINO_FRAMEBUFFER_SIZE ((VINO_PAL_WIDTH \
114 * VINO_PAL_HEIGHT * 4 \
115 + 3 * PAGE_SIZE) & ~(PAGE_SIZE - 1))
116
117#define VINO_FRAMEBUFFER_MAX_COUNT 8
118
119#define VINO_FRAMEBUFFER_UNUSED 0
120#define VINO_FRAMEBUFFER_IN_USE 1
121#define VINO_FRAMEBUFFER_READY 2
122
123#define VINO_QUEUE_ERROR -1
124#define VINO_QUEUE_MAGIC 0x20050125
125
126#define VINO_MEMORY_NONE 0
127#define VINO_MEMORY_MMAP 1
128#define VINO_MEMORY_USERPTR 2
129
130#define VINO_DUMMY_DESC_COUNT 4
131#define VINO_DESC_FETCH_DELAY 5 /* microseconds */
132
133/* the number is the index for vino_data_formats */
134#define VINO_DATA_FMT_NONE -1
135#define VINO_DATA_FMT_GREY 0
136#define VINO_DATA_FMT_RGB332 1
137#define VINO_DATA_FMT_RGB32 2
138#define VINO_DATA_FMT_YUV 3
139//#define VINO_DATA_FMT_RGB24 4
140
141#define VINO_DATA_FMT_COUNT 4
142
143#define VINO_DATA_NORM_NONE -1
144#define VINO_DATA_NORM_NTSC 0
145#define VINO_DATA_NORM_PAL 1
146#define VINO_DATA_NORM_SECAM 2
147#define VINO_DATA_NORM_D1 3
148/* The following is a special entry that can be used to
149 * autodetect the norm. */
150#define VINO_DATA_NORM_AUTO 0xff
151
152#define VINO_DATA_NORM_COUNT 4
42 153
43/* VINO ASIC registers */ 154/* Internal data structure definitions */
44struct sgi_vino *vino;
45 155
46static const char *vinostr = "VINO IndyCam/TV"; 156struct vino_input {
47static int threshold_a = 512; 157 char *name;
48static int threshold_b = 512; 158 v4l2_std_id std;
159};
160
161struct vino_clipping {
162 unsigned int left, right, top, bottom;
163};
164
165struct vino_data_format {
166 /* the description */
167 char *description;
168 /* bytes per pixel */
169 unsigned int bpp;
170 /* V4L2 fourcc code */
171 __u32 pixelformat;
172 /* V4L2 colorspace (duh!) */
173 enum v4l2_colorspace colorspace;
174};
175
176struct vino_data_norm {
177 char *description;
178 unsigned int width, height;
179 struct vino_clipping odd;
180 struct vino_clipping even;
181
182 v4l2_std_id std;
183 unsigned int fps_min, fps_max;
184 __u32 framelines;
185};
186
187struct vino_descriptor_table {
188 /* the number of PAGE_SIZE sized pages in the buffer */
189 unsigned int page_count;
190 /* virtual (kmalloc'd) pointers to the actual data
191 * (in PAGE_SIZE chunks, used with mmap streaming) */
192 unsigned long *virtual;
193
194 /* cpu address for the VINO descriptor table
195 * (contains DMA addresses, VINO_PAGE_SIZE chunks) */
196 unsigned long *dma_cpu;
197 /* dma address for the VINO descriptor table
198 * (contains DMA addresses, VINO_PAGE_SIZE chunks) */
199 dma_addr_t dma;
200};
201
202struct vino_framebuffer {
203 /* identifier nubmer */
204 unsigned int id;
205 /* the length of the whole buffer */
206 unsigned int size;
207 /* the length of actual data in buffer */
208 unsigned int data_size;
209 /* the data format */
210 unsigned int data_format;
211 /* the state of buffer data */
212 unsigned int state;
213 /* is the buffer mapped in user space? */
214 unsigned int map_count;
215 /* memory offset for mmap() */
216 unsigned int offset;
217 /* frame counter */
218 unsigned int frame_counter;
219 /* timestamp (written when image capture finishes) */
220 struct timeval timestamp;
221
222 struct vino_descriptor_table desc_table;
223
224 spinlock_t state_lock;
225};
49 226
50struct vino_device { 227struct vino_framebuffer_fifo {
51 struct video_device vdev; 228 unsigned int length;
52#define VINO_CHAN_A 1 229
53#define VINO_CHAN_B 2 230 unsigned int used;
54 int chan; 231 unsigned int head;
232 unsigned int tail;
233
234 unsigned int data[VINO_FRAMEBUFFER_MAX_COUNT];
235};
236
237struct vino_framebuffer_queue {
238 unsigned int magic;
239
240 /* VINO_MEMORY_NONE, VINO_MEMORY_MMAP or VINO_MEMORY_USERPTR */
241 unsigned int type;
242 unsigned int length;
243
244 /* data field of in and out contain index numbers for buffer */
245 struct vino_framebuffer_fifo in;
246 struct vino_framebuffer_fifo out;
247
248 struct vino_framebuffer *buffer[VINO_FRAMEBUFFER_MAX_COUNT];
249
250 spinlock_t queue_lock;
251 struct semaphore queue_sem;
252 wait_queue_head_t frame_wait_queue;
253};
254
255struct vino_channel_settings {
256 unsigned int channel;
257
258 int input;
259 unsigned int data_format;
260 unsigned int data_norm;
261 struct vino_clipping clipping;
262 unsigned int decimation;
263 unsigned int line_size;
264 unsigned int alpha;
265 unsigned int fps;
266 unsigned int framert_reg;
267
268 unsigned int fifo_threshold;
269
270 struct vino_framebuffer_queue fb_queue;
271
272 /* number of the current field */
273 unsigned int field;
274
275 /* read in progress */
276 int reading;
277 /* streaming is active */
278 int streaming;
279 /* the driver is currently processing the queue */
280 int capturing;
281
282 struct semaphore sem;
283 spinlock_t capture_lock;
284
285 unsigned int users;
286
287 /* V4L support */
288 struct video_device *v4l_device;
55}; 289};
56 290
57struct vino_client { 291struct vino_client {
292 /* the channel which owns this client:
293 * VINO_NO_CHANNEL, VINO_CHANNEL_A or VINO_CHANNEL_B */
294 unsigned int owner;
58 struct i2c_client *driver; 295 struct i2c_client *driver;
59 int owner;
60}; 296};
61 297
62struct vino_video { 298struct vino_settings {
63 struct vino_device chA; 299 struct vino_channel_settings a;
64 struct vino_device chB; 300 struct vino_channel_settings b;
65 301
66 struct vino_client decoder; 302 struct vino_client decoder;
67 struct vino_client camera; 303 struct vino_client camera;
68 304
69 struct semaphore input_lock; 305 /* a lock for vino register access */
306 spinlock_t vino_lock;
307 /* a lock for channel input changes */
308 spinlock_t input_lock;
70 309
71 /* Loaded into VINO descriptors to clear End Of Descriptors table
72 * interupt condition */
73 unsigned long dummy_page; 310 unsigned long dummy_page;
74 unsigned int dummy_buf[4] __attribute__((aligned(8))); 311 struct vino_descriptor_table dummy_desc_table;
75}; 312};
76 313
77static struct vino_video *Vino; 314/* Module parameters */
315
316/*
317 * Using vino_pixel_conversion the ARGB32-format pixels supplied
318 * by the VINO chip can be converted to more common formats
319 * like RGBA32 (or probably RGB24 in the future). This way we
320 * can give out data that can be specified correctly with
321 * the V4L2-definitions.
322 *
323 * The pixel format is specified as RGBA32 when no conversion
324 * is used.
325 *
326 * Note that this only affects the 32-bit bit depth.
327 *
328 * Use non-zero value to enable conversion.
329 */
330static int vino_pixel_conversion = 0;
331module_param_named(pixelconv, vino_pixel_conversion, int, 0);
332MODULE_PARM_DESC(pixelconv,
333 "enable pixel conversion (non-zero value enables)");
334
335/* Internal data structures */
336
337static struct sgi_vino *vino;
338
339static struct vino_settings *vino_drvdata;
340
341static const char *vino_driver_name = "vino";
342static const char *vino_driver_description = "SGI VINO";
343static const char *vino_bus_name = "GIO64 bus";
344static const char *vino_v4l_device_name_a = "SGI VINO Channel A";
345static const char *vino_v4l_device_name_b = "SGI VINO Channel B";
346
347static const struct vino_input vino_inputs[] = {
348 {
349 .name = "Composite",
350 .std = V4L2_STD_NTSC | V4L2_STD_PAL | V4L2_STD_SECAM,
351 },{
352 .name = "S-Video",
353 .std = V4L2_STD_NTSC | V4L2_STD_PAL | V4L2_STD_SECAM,
354 },{
355 .name = "D1 (IndyCam)",
356 .std = V4L2_STD_NTSC,
357 }
358};
359
360static const struct vino_data_format vino_data_formats[] = {
361 {
362 .description = "8-bit greyscale",
363 .bpp = 1,
364 .pixelformat = V4L2_PIX_FMT_GREY,
365 .colorspace = V4L2_COLORSPACE_SMPTE170M,
366 },{
367 .description = "8-bit dithered RGB 3-3-2",
368 .bpp = 1,
369 .pixelformat = V4L2_PIX_FMT_RGB332,
370 .colorspace = V4L2_COLORSPACE_SRGB,
371 },{
372 .description = "32-bit RGB",
373 .bpp = 4,
374 .pixelformat = V4L2_PIX_FMT_RGB32,
375 .colorspace = V4L2_COLORSPACE_SRGB,
376 },{
377 .description = "YUV 4:2:2",
378 .bpp = 4,
379 .pixelformat = V4L2_PIX_FMT_YUYV, // XXX: swapped?
380 .colorspace = V4L2_COLORSPACE_SMPTE170M,
381 }/*,{
382 .description = "24-bit RGB",
383 .bpp = 3,
384 .pixelformat = V4L2_PIX_FMT_RGB24,
385 .colorspace = V4L2_COLORSPACE_SRGB,
386 }*/
387};
388
389static const struct vino_data_norm vino_data_norms[] = {
390 {
391 .description = "NTSC",
392 .std = V4L2_STD_NTSC,
393 .fps_min = 6,
394 .fps_max = 30,
395 .framelines = 525,
396 .width = VINO_NTSC_WIDTH,
397 .height = VINO_NTSC_HEIGHT,
398 .odd = {
399 .top = VINO_CLIPPING_START_ODD_NTSC,
400 .left = 0,
401 .bottom = VINO_CLIPPING_START_ODD_NTSC
402 + VINO_NTSC_HEIGHT / 2 - 1,
403 .right = VINO_NTSC_WIDTH,
404 },
405 .even = {
406 .top = VINO_CLIPPING_START_EVEN_NTSC,
407 .left = 0,
408 .bottom = VINO_CLIPPING_START_EVEN_NTSC
409 + VINO_NTSC_HEIGHT / 2 - 1,
410 .right = VINO_NTSC_WIDTH,
411 },
412 },{
413 .description = "PAL",
414 .std = V4L2_STD_PAL,
415 .fps_min = 5,
416 .fps_max = 25,
417 .framelines = 625,
418 .width = VINO_PAL_WIDTH,
419 .height = VINO_PAL_HEIGHT,
420 .odd = {
421 .top = VINO_CLIPPING_START_ODD_PAL,
422 .left = 0,
423 .bottom = VINO_CLIPPING_START_ODD_PAL
424 + VINO_PAL_HEIGHT / 2 - 1,
425 .right = VINO_PAL_WIDTH,
426 },
427 .even = {
428 .top = VINO_CLIPPING_START_EVEN_PAL,
429 .left = 0,
430 .bottom = VINO_CLIPPING_START_EVEN_PAL
431 + VINO_PAL_HEIGHT / 2 - 1,
432 .right = VINO_PAL_WIDTH,
433 },
434 },{
435 .description = "SECAM",
436 .std = V4L2_STD_SECAM,
437 .fps_min = 5,
438 .fps_max = 25,
439 .framelines = 625,
440 .width = VINO_PAL_WIDTH,
441 .height = VINO_PAL_HEIGHT,
442 .odd = {
443 .top = VINO_CLIPPING_START_ODD_PAL,
444 .left = 0,
445 .bottom = VINO_CLIPPING_START_ODD_PAL
446 + VINO_PAL_HEIGHT / 2 - 1,
447 .right = VINO_PAL_WIDTH,
448 },
449 .even = {
450 .top = VINO_CLIPPING_START_EVEN_PAL,
451 .left = 0,
452 .bottom = VINO_CLIPPING_START_EVEN_PAL
453 + VINO_PAL_HEIGHT / 2 - 1,
454 .right = VINO_PAL_WIDTH,
455 },
456 },{
457 .description = "NTSC (D1 input)",
458 .std = V4L2_STD_NTSC,
459 .fps_min = 6,
460 .fps_max = 30,
461 .framelines = 525,
462 .width = VINO_NTSC_WIDTH,
463 .height = VINO_NTSC_HEIGHT,
464 .odd = {
465 .top = VINO_CLIPPING_START_ODD_D1,
466 .left = 0,
467 .bottom = VINO_CLIPPING_START_ODD_D1
468 + VINO_NTSC_HEIGHT / 2 - 1,
469 .right = VINO_NTSC_WIDTH,
470 },
471 .even = {
472 .top = VINO_CLIPPING_START_EVEN_D1,
473 .left = 0,
474 .bottom = VINO_CLIPPING_START_EVEN_D1
475 + VINO_NTSC_HEIGHT / 2 - 1,
476 .right = VINO_NTSC_WIDTH,
477 },
478 }
479};
480
481#define VINO_INDYCAM_V4L2_CONTROL_COUNT 9
482
483struct v4l2_queryctrl vino_indycam_v4l2_controls[] = {
484 {
485 .id = V4L2_CID_AUTOGAIN,
486 .type = V4L2_CTRL_TYPE_BOOLEAN,
487 .name = "Automatic Gain Control",
488 .minimum = 0,
489 .maximum = 1,
490 .step = 1,
491 .default_value = INDYCAM_AGC_DEFAULT,
492 .flags = 0,
493 .reserved = { 0, 0 },
494 },{
495 .id = V4L2_CID_AUTO_WHITE_BALANCE,
496 .type = V4L2_CTRL_TYPE_BOOLEAN,
497 .name = "Automatic White Balance",
498 .minimum = 0,
499 .maximum = 1,
500 .step = 1,
501 .default_value = INDYCAM_AWB_DEFAULT,
502 .flags = 0,
503 .reserved = { 0, 0 },
504 },{
505 .id = V4L2_CID_GAIN,
506 .type = V4L2_CTRL_TYPE_INTEGER,
507 .name = "Gain",
508 .minimum = INDYCAM_GAIN_MIN,
509 .maximum = INDYCAM_GAIN_MAX,
510 .step = 1,
511 .default_value = INDYCAM_GAIN_DEFAULT,
512 .flags = 0,
513 .reserved = { 0, 0 },
514 },{
515 .id = V4L2_CID_PRIVATE_BASE,
516 .type = V4L2_CTRL_TYPE_INTEGER,
517 .name = "Red Saturation",
518 .minimum = INDYCAM_RED_SATURATION_MIN,
519 .maximum = INDYCAM_RED_SATURATION_MAX,
520 .step = 1,
521 .default_value = INDYCAM_RED_SATURATION_DEFAULT,
522 .flags = 0,
523 .reserved = { 0, 0 },
524 },{
525 .id = V4L2_CID_PRIVATE_BASE + 1,
526 .type = V4L2_CTRL_TYPE_INTEGER,
527 .name = "Blue Saturation",
528 .minimum = INDYCAM_BLUE_SATURATION_MIN,
529 .maximum = INDYCAM_BLUE_SATURATION_MAX,
530 .step = 1,
531 .default_value = INDYCAM_BLUE_SATURATION_DEFAULT,
532 .flags = 0,
533 .reserved = { 0, 0 },
534 },{
535 .id = V4L2_CID_RED_BALANCE,
536 .type = V4L2_CTRL_TYPE_INTEGER,
537 .name = "Red Balance",
538 .minimum = INDYCAM_RED_BALANCE_MIN,
539 .maximum = INDYCAM_RED_BALANCE_MAX,
540 .step = 1,
541 .default_value = INDYCAM_RED_BALANCE_DEFAULT,
542 .flags = 0,
543 .reserved = { 0, 0 },
544 },{
545 .id = V4L2_CID_BLUE_BALANCE,
546 .type = V4L2_CTRL_TYPE_INTEGER,
547 .name = "Blue Balance",
548 .minimum = INDYCAM_BLUE_BALANCE_MIN,
549 .maximum = INDYCAM_BLUE_BALANCE_MAX,
550 .step = 1,
551 .default_value = INDYCAM_BLUE_BALANCE_DEFAULT,
552 .flags = 0,
553 .reserved = { 0, 0 },
554 },{
555 .id = V4L2_CID_EXPOSURE,
556 .type = V4L2_CTRL_TYPE_INTEGER,
557 .name = "Shutter Control",
558 .minimum = INDYCAM_SHUTTER_MIN,
559 .maximum = INDYCAM_SHUTTER_MAX,
560 .step = 1,
561 .default_value = INDYCAM_SHUTTER_DEFAULT,
562 .flags = 0,
563 .reserved = { 0, 0 },
564 },{
565 .id = V4L2_CID_GAMMA,
566 .type = V4L2_CTRL_TYPE_INTEGER,
567 .name = "Gamma",
568 .minimum = INDYCAM_GAMMA_MIN,
569 .maximum = INDYCAM_GAMMA_MAX,
570 .step = 1,
571 .default_value = INDYCAM_GAMMA_DEFAULT,
572 .flags = 0,
573 .reserved = { 0, 0 },
574 }
575};
576
577#define VINO_SAA7191_V4L2_CONTROL_COUNT 2
578
579struct v4l2_queryctrl vino_saa7191_v4l2_controls[] = {
580 {
581 .id = V4L2_CID_HUE,
582 .type = V4L2_CTRL_TYPE_INTEGER,
583 .name = "Hue",
584 .minimum = SAA7191_HUE_MIN,
585 .maximum = SAA7191_HUE_MAX,
586 .step = 1,
587 .default_value = SAA7191_HUE_DEFAULT,
588 .flags = 0,
589 .reserved = { 0, 0 },
590 },{
591 .id = V4L2_CID_PRIVATE_BASE,
592 .type = V4L2_CTRL_TYPE_BOOLEAN,
593 .name = "VTR Time Constant",
594 .minimum = SAA7191_VTRC_MIN,
595 .maximum = SAA7191_VTRC_MAX,
596 .step = 1,
597 .default_value = SAA7191_VTRC_DEFAULT,
598 .flags = 0,
599 .reserved = { 0, 0 },
600 }
601};
602
603/* VINO I2C bus functions */
78 604
79unsigned i2c_vino_getctrl(void *data) 605unsigned i2c_vino_getctrl(void *data)
80{ 606{
@@ -112,49 +638,49 @@ static struct i2c_algo_sgi_data i2c_sgi_vino_data =
112 */ 638 */
113static int i2c_vino_client_reg(struct i2c_client *client) 639static int i2c_vino_client_reg(struct i2c_client *client)
114{ 640{
115 int res = 0; 641 int ret = 0;
116 642
117 down(&Vino->input_lock); 643 spin_lock(&vino_drvdata->input_lock);
118 switch (client->driver->id) { 644 switch (client->driver->id) {
119 case I2C_DRIVERID_SAA7191: 645 case I2C_DRIVERID_SAA7191:
120 if (Vino->decoder.driver) 646 if (vino_drvdata->decoder.driver)
121 res = -EBUSY; 647 ret = -EBUSY;
122 else 648 else
123 Vino->decoder.driver = client; 649 vino_drvdata->decoder.driver = client;
124 break; 650 break;
125 case I2C_DRIVERID_INDYCAM: 651 case I2C_DRIVERID_INDYCAM:
126 if (Vino->camera.driver) 652 if (vino_drvdata->camera.driver)
127 res = -EBUSY; 653 ret = -EBUSY;
128 else 654 else
129 Vino->camera.driver = client; 655 vino_drvdata->camera.driver = client;
130 break; 656 break;
131 default: 657 default:
132 res = -ENODEV; 658 ret = -ENODEV;
133 } 659 }
134 up(&Vino->input_lock); 660 spin_unlock(&vino_drvdata->input_lock);
135 661
136 return res; 662 return ret;
137} 663}
138 664
139static int i2c_vino_client_unreg(struct i2c_client *client) 665static int i2c_vino_client_unreg(struct i2c_client *client)
140{ 666{
141 int res = 0; 667 int ret = 0;
142 668
143 down(&Vino->input_lock); 669 spin_lock(&vino_drvdata->input_lock);
144 if (client == Vino->decoder.driver) { 670 if (client == vino_drvdata->decoder.driver) {
145 if (Vino->decoder.owner) 671 if (vino_drvdata->decoder.owner != VINO_NO_CHANNEL)
146 res = -EBUSY; 672 ret = -EBUSY;
147 else 673 else
148 Vino->decoder.driver = NULL; 674 vino_drvdata->decoder.driver = NULL;
149 } else if (client == Vino->camera.driver) { 675 } else if (client == vino_drvdata->camera.driver) {
150 if (Vino->camera.owner) 676 if (vino_drvdata->camera.owner != VINO_NO_CHANNEL)
151 res = -EBUSY; 677 ret = -EBUSY;
152 else 678 else
153 Vino->camera.driver = NULL; 679 vino_drvdata->camera.driver = NULL;
154 } 680 }
155 up(&Vino->input_lock); 681 spin_unlock(&vino_drvdata->input_lock);
156 682
157 return res; 683 return ret;
158} 684}
159 685
160static struct i2c_adapter vino_i2c_adapter = 686static struct i2c_adapter vino_i2c_adapter =
@@ -176,172 +702,3591 @@ static int vino_i2c_del_bus(void)
176 return i2c_sgi_del_bus(&vino_i2c_adapter); 702 return i2c_sgi_del_bus(&vino_i2c_adapter);
177} 703}
178 704
705static int i2c_camera_command(unsigned int cmd, void *arg)
706{
707 return vino_drvdata->camera.driver->
708 driver->command(vino_drvdata->camera.driver,
709 cmd, arg);
710}
711
712static int i2c_decoder_command(unsigned int cmd, void *arg)
713{
714 return vino_drvdata->decoder.driver->
715 driver->command(vino_drvdata->decoder.driver,
716 cmd, arg);
717}
718
719/* VINO framebuffer/DMA descriptor management */
720
721static void vino_free_buffer_with_count(struct vino_framebuffer *fb,
722 unsigned int count)
723{
724 unsigned int i;
725
726 dprintk("vino_free_buffer_with_count(): count = %d\n", count);
727
728 for (i = 0; i < count; i++) {
729 mem_map_unreserve(virt_to_page(fb->desc_table.virtual[i]));
730 dma_unmap_single(NULL,
731 fb->desc_table.dma_cpu[VINO_PAGE_RATIO * i],
732 PAGE_SIZE, DMA_FROM_DEVICE);
733 free_page(fb->desc_table.virtual[i]);
734 }
735
736 dma_free_coherent(NULL,
737 VINO_PAGE_RATIO * (fb->desc_table.page_count + 4) *
738 sizeof(dma_addr_t), (void *)fb->desc_table.dma_cpu,
739 fb->desc_table.dma);
740 kfree(fb->desc_table.virtual);
741
742 memset(fb, 0, sizeof(struct vino_framebuffer));
743}
744
745static void vino_free_buffer(struct vino_framebuffer *fb)
746{
747 vino_free_buffer_with_count(fb, fb->desc_table.page_count);
748}
749
750static int vino_allocate_buffer(struct vino_framebuffer *fb,
751 unsigned int size)
752{
753 unsigned int count, i, j;
754 int ret = 0;
755
756 dprintk("vino_allocate_buffer():\n");
757
758 if (size < 1)
759 return -EINVAL;
760
761 memset(fb, 0, sizeof(struct vino_framebuffer));
762
763 count = ((size / PAGE_SIZE) + 4) & ~3;
764
765 dprintk("vino_allocate_buffer(): size = %d, count = %d\n",
766 size, count);
767
768 /* allocate memory for table with virtual (page) addresses */
769 fb->desc_table.virtual = (unsigned long *)
770 kmalloc(count * sizeof(unsigned long), GFP_KERNEL);
771 if (!fb->desc_table.virtual)
772 return -ENOMEM;
773
774 /* allocate memory for table with dma addresses
775 * (has space for four extra descriptors) */
776 fb->desc_table.dma_cpu =
777 dma_alloc_coherent(NULL, VINO_PAGE_RATIO * (count + 4) *
778 sizeof(dma_addr_t), &fb->desc_table.dma,
779 GFP_KERNEL | GFP_DMA);
780 if (!fb->desc_table.dma_cpu) {
781 ret = -ENOMEM;
782 goto out_free_virtual;
783 }
784
785 /* allocate pages for the buffer and acquire the according
786 * dma addresses */
787 for (i = 0; i < count; i++) {
788 dma_addr_t dma_data_addr;
789
790 fb->desc_table.virtual[i] =
791 get_zeroed_page(GFP_KERNEL | GFP_DMA);
792 if (!fb->desc_table.virtual[i]) {
793 ret = -ENOBUFS;
794 break;
795 }
796
797 dma_data_addr =
798 dma_map_single(NULL,
799 (void *)fb->desc_table.virtual[i],
800 PAGE_SIZE, DMA_FROM_DEVICE);
801
802 for (j = 0; j < VINO_PAGE_RATIO; j++) {
803 fb->desc_table.dma_cpu[VINO_PAGE_RATIO * i + j] =
804 dma_data_addr + VINO_PAGE_SIZE * j;
805 }
806
807 mem_map_reserve(virt_to_page(fb->desc_table.virtual[i]));
808 }
809
810 /* page_count needs to be set anyway, because the descriptor table has
811 * been allocated according to this number */
812 fb->desc_table.page_count = count;
813
814 if (ret) {
815 /* the descriptor with index i doesn't contain
816 * a valid address yet */
817 vino_free_buffer_with_count(fb, i);
818 return ret;
819 }
820
821 //fb->size = size;
822 fb->size = count * PAGE_SIZE;
823 fb->data_format = VINO_DATA_FMT_NONE;
824
825 /* set the dma stop-bit for the last (count+1)th descriptor */
826 fb->desc_table.dma_cpu[VINO_PAGE_RATIO * count] = VINO_DESC_STOP;
827 return 0;
828
829 out_free_virtual:
830 kfree(fb->desc_table.virtual);
831 return ret;
832}
833
834#if 0
835/* user buffers not fully implemented yet */
836static int vino_prepare_user_buffer(struct vino_framebuffer *fb,
837 void *user,
838 unsigned int size)
839{
840 unsigned int count, i, j;
841 int ret = 0;
842
843 dprintk("vino_prepare_user_buffer():\n");
844
845 if (size < 1)
846 return -EINVAL;
847
848 memset(fb, 0, sizeof(struct vino_framebuffer));
849
850 count = ((size / PAGE_SIZE)) & ~3;
851
852 dprintk("vino_prepare_user_buffer(): size = %d, count = %d\n",
853 size, count);
854
855 /* allocate memory for table with virtual (page) addresses */
856 fb->desc_table.virtual = (unsigned long *)
857 kmalloc(count * sizeof(unsigned long), GFP_KERNEL);
858 if (!fb->desc_table.virtual)
859 return -ENOMEM;
860
861 /* allocate memory for table with dma addresses
862 * (has space for four extra descriptors) */
863 fb->desc_table.dma_cpu =
864 dma_alloc_coherent(NULL, VINO_PAGE_RATIO * (count + 4) *
865 sizeof(dma_addr_t), &fb->desc_table.dma,
866 GFP_KERNEL | GFP_DMA);
867 if (!fb->desc_table.dma_cpu) {
868 ret = -ENOMEM;
869 goto out_free_virtual;
870 }
871
872 /* allocate pages for the buffer and acquire the according
873 * dma addresses */
874 for (i = 0; i < count; i++) {
875 dma_addr_t dma_data_addr;
876
877 fb->desc_table.virtual[i] =
878 get_zeroed_page(GFP_KERNEL | GFP_DMA);
879 if (!fb->desc_table.virtual[i]) {
880 ret = -ENOBUFS;
881 break;
882 }
883
884 dma_data_addr =
885 dma_map_single(NULL,
886 (void *)fb->desc_table.virtual[i],
887 PAGE_SIZE, DMA_FROM_DEVICE);
888
889 for (j = 0; j < VINO_PAGE_RATIO; j++) {
890 fb->desc_table.dma_cpu[VINO_PAGE_RATIO * i + j] =
891 dma_data_addr + VINO_PAGE_SIZE * j;
892 }
893
894 mem_map_reserve(virt_to_page(fb->desc_table.virtual[i]));
895 }
896
897 /* page_count needs to be set anyway, because the descriptor table has
898 * been allocated according to this number */
899 fb->desc_table.page_count = count;
900
901 if (ret) {
902 /* the descriptor with index i doesn't contain
903 * a valid address yet */
904 vino_free_buffer_with_count(fb, i);
905 return ret;
906 }
907
908 //fb->size = size;
909 fb->size = count * PAGE_SIZE;
910
911 /* set the dma stop-bit for the last (count+1)th descriptor */
912 fb->desc_table.dma_cpu[VINO_PAGE_RATIO * count] = VINO_DESC_STOP;
913 return 0;
914
915 out_free_virtual:
916 kfree(fb->desc_table.virtual);
917 return ret;
918}
919#endif
920
921static void vino_sync_buffer(struct vino_framebuffer *fb)
922{
923 int i;
924
925 dprintk("vino_sync_buffer():\n");
926
927 for (i = 0; i < fb->desc_table.page_count; i++)
928 dma_sync_single(NULL,
929 fb->desc_table.dma_cpu[VINO_PAGE_RATIO * i],
930 PAGE_SIZE, DMA_FROM_DEVICE);
931}
932
933/* Framebuffer fifo functions (need to be locked externally) */
934
935static void vino_fifo_init(struct vino_framebuffer_fifo *f,
936 unsigned int length)
937{
938 f->length = 0;
939 f->used = 0;
940 f->head = 0;
941 f->tail = 0;
942
943 if (length > VINO_FRAMEBUFFER_MAX_COUNT)
944 length = VINO_FRAMEBUFFER_MAX_COUNT;
945
946 f->length = length;
947}
948
949/* returns true/false */
950static int vino_fifo_has_id(struct vino_framebuffer_fifo *f, unsigned int id)
951{
952 unsigned int i;
953 for (i = f->head; i == (f->tail - 1); i = (i + 1) % f->length) {
954 if (f->data[i] == id)
955 return 1;
956 }
957
958 return 0;
959}
960
961/* returns true/false */
962static int vino_fifo_full(struct vino_framebuffer_fifo *f)
963{
964 return (f->used == f->length);
965}
966
967static unsigned int vino_fifo_get_used(struct vino_framebuffer_fifo *f)
968{
969 return f->used;
970}
179 971
180static void vino_interrupt(int irq, void *dev_id, struct pt_regs *regs) 972static int vino_fifo_enqueue(struct vino_framebuffer_fifo *f, unsigned int id)
181{ 973{
974 if (id >= f->length) {
975 return VINO_QUEUE_ERROR;
976 }
977
978 if (vino_fifo_has_id(f, id)) {
979 return VINO_QUEUE_ERROR;
980 }
981
982 if (f->used < f->length) {
983 f->data[f->tail] = id;
984 f->tail = (f->tail + 1) % f->length;
985 f->used++;
986 } else {
987 return VINO_QUEUE_ERROR;
988 }
989
990 return 0;
182} 991}
183 992
184static int vino_open(struct video_device *dev, int flags) 993static int vino_fifo_peek(struct vino_framebuffer_fifo *f, unsigned int *id)
185{ 994{
186 struct vino_device *videv = (struct vino_device *)dev; 995 if (f->used > 0) {
996 *id = f->data[f->head];
997 } else {
998 return VINO_QUEUE_ERROR;
999 }
187 1000
188 return 0; 1001 return 0;
189} 1002}
190 1003
191static void vino_close(struct video_device *dev) 1004static int vino_fifo_dequeue(struct vino_framebuffer_fifo *f, unsigned int *id)
192{ 1005{
193 struct vino_device *videv = (struct vino_device *)dev; 1006 if (f->used > 0) {
1007 *id = f->data[f->head];
1008 f->head = (f->head + 1) % f->length;
1009 f->used--;
1010 } else {
1011 return VINO_QUEUE_ERROR;
1012 }
1013
1014 return 0;
194} 1015}
195 1016
196static int vino_mmap(struct video_device *dev, const char *adr, 1017/* Framebuffer queue functions */
197 unsigned long size) 1018
1019/* execute with queue_lock locked */
1020static void vino_queue_free_with_count(struct vino_framebuffer_queue *q,
1021 unsigned int length)
198{ 1022{
199 struct vino_device *videv = (struct vino_device *)dev; 1023 unsigned int i;
200 1024
201 return -EINVAL; 1025 q->length = 0;
1026 memset(&q->in, 0, sizeof(struct vino_framebuffer_fifo));
1027 memset(&q->out, 0, sizeof(struct vino_framebuffer_fifo));
1028 for (i = 0; i < length; i++) {
1029 dprintk("vino_queue_free_with_count(): freeing buffer %d\n",
1030 i);
1031 vino_free_buffer(q->buffer[i]);
1032 kfree(q->buffer[i]);
1033 }
1034
1035 q->type = VINO_MEMORY_NONE;
1036 q->magic = 0;
202} 1037}
203 1038
204static int vino_ioctl(struct video_device *dev, unsigned int cmd, void *arg) 1039static void vino_queue_free(struct vino_framebuffer_queue *q)
205{ 1040{
206 struct vino_device *videv = (struct vino_device *)dev; 1041 dprintk("vino_queue_free():\n");
1042
1043 if (q->magic != VINO_QUEUE_MAGIC)
1044 return;
1045 if (q->type != VINO_MEMORY_MMAP)
1046 return;
1047
1048 down(&q->queue_sem);
1049
1050 vino_queue_free_with_count(q, q->length);
1051
1052 up(&q->queue_sem);
1053}
1054
1055static int vino_queue_init(struct vino_framebuffer_queue *q,
1056 unsigned int *length)
1057{
1058 unsigned int i;
1059 int ret = 0;
1060
1061 dprintk("vino_queue_init(): length = %d\n", *length);
1062
1063 if (q->magic == VINO_QUEUE_MAGIC) {
1064 dprintk("vino_queue_init(): queue already initialized!\n");
1065 return -EINVAL;
1066 }
1067
1068 if (q->type != VINO_MEMORY_NONE) {
1069 dprintk("vino_queue_init(): queue already initialized!\n");
1070 return -EINVAL;
1071 }
1072
1073 if (*length < 1)
1074 return -EINVAL;
1075
1076 down(&q->queue_sem);
1077
1078 if (*length > VINO_FRAMEBUFFER_MAX_COUNT)
1079 *length = VINO_FRAMEBUFFER_MAX_COUNT;
1080
1081 q->length = 0;
1082
1083 for (i = 0; i < *length; i++) {
1084 dprintk("vino_queue_init(): allocating buffer %d\n", i);
1085 q->buffer[i] = kmalloc(sizeof(struct vino_framebuffer),
1086 GFP_KERNEL);
1087 if (!q->buffer[i]) {
1088 dprintk("vino_queue_init(): kmalloc() failed\n");
1089 ret = -ENOMEM;
1090 break;
1091 }
1092
1093 ret = vino_allocate_buffer(q->buffer[i],
1094 VINO_FRAMEBUFFER_SIZE);
1095 if (ret) {
1096 kfree(q->buffer[i]);
1097 dprintk("vino_queue_init(): "
1098 "vino_allocate_buffer() failed\n");
1099 break;
1100 }
1101
1102 q->buffer[i]->id = i;
1103 if (i > 0) {
1104 q->buffer[i]->offset = q->buffer[i - 1]->offset +
1105 q->buffer[i - 1]->size;
1106 } else {
1107 q->buffer[i]->offset = 0;
1108 }
1109
1110 spin_lock_init(&q->buffer[i]->state_lock);
1111
1112 dprintk("vino_queue_init(): buffer = %d, offset = %d, "
1113 "size = %d\n", i, q->buffer[i]->offset,
1114 q->buffer[i]->size);
1115 }
1116
1117 if (ret) {
1118 vino_queue_free_with_count(q, i);
1119 *length = 0;
1120 } else {
1121 q->length = *length;
1122 vino_fifo_init(&q->in, q->length);
1123 vino_fifo_init(&q->out, q->length);
1124 q->type = VINO_MEMORY_MMAP;
1125 q->magic = VINO_QUEUE_MAGIC;
1126 }
1127
1128 up(&q->queue_sem);
1129
1130 return ret;
1131}
1132
1133static struct vino_framebuffer *vino_queue_add(struct
1134 vino_framebuffer_queue *q,
1135 unsigned int id)
1136{
1137 struct vino_framebuffer *ret = NULL;
1138 unsigned int total;
1139 unsigned long flags;
1140
1141 dprintk("vino_queue_add(): id = %d\n", id);
1142
1143 if (q->magic != VINO_QUEUE_MAGIC) {
1144 return ret;
1145 }
1146
1147 spin_lock_irqsave(&q->queue_lock, flags);
1148
1149 if (q->length == 0)
1150 goto out;
1151
1152 if (id >= q->length)
1153 goto out;
1154
1155 /* not needed?: if (vino_fifo_full(&q->out)) {
1156 goto out;
1157 }*/
1158 /* check that outgoing queue isn't already full
1159 * (or that it won't become full) */
1160 total = vino_fifo_get_used(&q->in) +
1161 vino_fifo_get_used(&q->out);
1162 if (total >= q->length)
1163 goto out;
1164
1165 if (vino_fifo_enqueue(&q->in, id))
1166 goto out;
1167
1168 ret = q->buffer[id];
1169
1170out:
1171 spin_unlock_irqrestore(&q->queue_lock, flags);
1172
1173 return ret;
1174}
1175
1176static struct vino_framebuffer *vino_queue_transfer(struct
1177 vino_framebuffer_queue *q)
1178{
1179 struct vino_framebuffer *ret = NULL;
1180 struct vino_framebuffer *fb;
1181 int id;
1182 unsigned long flags;
1183
1184 dprintk("vino_queue_transfer():\n");
1185
1186 if (q->magic != VINO_QUEUE_MAGIC) {
1187 return ret;
1188 }
1189
1190 spin_lock_irqsave(&q->queue_lock, flags);
1191
1192 if (q->length == 0)
1193 goto out;
1194
1195 // now this actually removes an entry from the incoming queue
1196 if (vino_fifo_dequeue(&q->in, &id)) {
1197 goto out;
1198 }
1199
1200 dprintk("vino_queue_transfer(): id = %d\n", id);
1201 fb = q->buffer[id];
1202
1203 // we have already checked that the outgoing queue is not full, but...
1204 if (vino_fifo_enqueue(&q->out, id)) {
1205 printk(KERN_ERR "vino_queue_transfer(): "
1206 "outgoing queue is full, this shouldn't happen!\n");
1207 goto out;
1208 }
1209
1210 ret = fb;
1211out:
1212 spin_unlock_irqrestore(&q->queue_lock, flags);
1213
1214 return ret;
1215}
1216
1217/* returns true/false */
1218static int vino_queue_incoming_contains(struct vino_framebuffer_queue *q,
1219 unsigned int id)
1220{
1221 int ret = 0;
1222 unsigned long flags;
1223
1224 if (q->magic != VINO_QUEUE_MAGIC) {
1225 return ret;
1226 }
1227
1228 spin_lock_irqsave(&q->queue_lock, flags);
1229
1230 if (q->length == 0)
1231 goto out;
1232
1233 ret = vino_fifo_has_id(&q->in, id);
1234
1235out:
1236 spin_unlock_irqrestore(&q->queue_lock, flags);
1237
1238 return ret;
1239}
1240
1241/* returns true/false */
1242static int vino_queue_outgoing_contains(struct vino_framebuffer_queue *q,
1243 unsigned int id)
1244{
1245 int ret = 0;
1246 unsigned long flags;
1247
1248 if (q->magic != VINO_QUEUE_MAGIC) {
1249 return ret;
1250 }
1251
1252 spin_lock_irqsave(&q->queue_lock, flags);
1253
1254 if (q->length == 0)
1255 goto out;
1256
1257 ret = vino_fifo_has_id(&q->out, id);
1258
1259out:
1260 spin_unlock_irqrestore(&q->queue_lock, flags);
1261
1262 return ret;
1263}
1264
1265static int vino_queue_get_incoming(struct vino_framebuffer_queue *q,
1266 unsigned int *used)
1267{
1268 int ret = 0;
1269 unsigned long flags;
1270
1271 if (q->magic != VINO_QUEUE_MAGIC) {
1272 return VINO_QUEUE_ERROR;
1273 }
1274
1275 spin_lock_irqsave(&q->queue_lock, flags);
1276
1277 if (q->length == 0) {
1278 ret = VINO_QUEUE_ERROR;
1279 goto out;
1280 }
1281
1282 *used = vino_fifo_get_used(&q->in);
1283
1284out:
1285 spin_unlock_irqrestore(&q->queue_lock, flags);
1286
1287 return ret;
1288}
1289
1290static int vino_queue_get_outgoing(struct vino_framebuffer_queue *q,
1291 unsigned int *used)
1292{
1293 int ret = 0;
1294 unsigned long flags;
1295
1296 if (q->magic != VINO_QUEUE_MAGIC) {
1297 return VINO_QUEUE_ERROR;
1298 }
1299
1300 spin_lock_irqsave(&q->queue_lock, flags);
1301
1302 if (q->length == 0) {
1303 ret = VINO_QUEUE_ERROR;
1304 goto out;
1305 }
1306
1307 *used = vino_fifo_get_used(&q->out);
1308
1309out:
1310 spin_unlock_irqrestore(&q->queue_lock, flags);
1311
1312 return ret;
1313}
1314
1315static int vino_queue_get_total(struct vino_framebuffer_queue *q,
1316 unsigned int *total)
1317{
1318 int ret = 0;
1319 unsigned long flags;
1320
1321 if (q->magic != VINO_QUEUE_MAGIC) {
1322 return VINO_QUEUE_ERROR;
1323 }
1324
1325 spin_lock_irqsave(&q->queue_lock, flags);
1326
1327 if (q->length == 0) {
1328 ret = VINO_QUEUE_ERROR;
1329 goto out;
1330 }
1331
1332 *total = vino_fifo_get_used(&q->in) +
1333 vino_fifo_get_used(&q->out);
1334
1335out:
1336 spin_unlock_irqrestore(&q->queue_lock, flags);
1337
1338 return ret;
1339}
1340
1341static struct vino_framebuffer *vino_queue_peek(struct
1342 vino_framebuffer_queue *q,
1343 unsigned int *id)
1344{
1345 struct vino_framebuffer *ret = NULL;
1346 unsigned long flags;
1347
1348 if (q->magic != VINO_QUEUE_MAGIC) {
1349 return ret;
1350 }
1351
1352 spin_lock_irqsave(&q->queue_lock, flags);
1353
1354 if (q->length == 0)
1355 goto out;
1356
1357 if (vino_fifo_peek(&q->in, id)) {
1358 goto out;
1359 }
1360
1361 ret = q->buffer[*id];
1362out:
1363 spin_unlock_irqrestore(&q->queue_lock, flags);
1364
1365 return ret;
1366}
1367
1368static struct vino_framebuffer *vino_queue_remove(struct
1369 vino_framebuffer_queue *q,
1370 unsigned int *id)
1371{
1372 struct vino_framebuffer *ret = NULL;
1373 unsigned long flags;
1374 dprintk("vino_queue_remove():\n");
1375
1376 if (q->magic != VINO_QUEUE_MAGIC) {
1377 return ret;
1378 }
1379
1380 spin_lock_irqsave(&q->queue_lock, flags);
1381
1382 if (q->length == 0)
1383 goto out;
1384
1385 if (vino_fifo_dequeue(&q->out, id)) {
1386 goto out;
1387 }
1388
1389 dprintk("vino_queue_remove(): id = %d\n", *id);
1390 ret = q->buffer[*id];
1391out:
1392 spin_unlock_irqrestore(&q->queue_lock, flags);
1393
1394 return ret;
1395}
1396
1397static struct
1398vino_framebuffer *vino_queue_get_buffer(struct vino_framebuffer_queue *q,
1399 unsigned int id)
1400{
1401 struct vino_framebuffer *ret = NULL;
1402 unsigned long flags;
1403
1404 if (q->magic != VINO_QUEUE_MAGIC) {
1405 return ret;
1406 }
1407
1408 spin_lock_irqsave(&q->queue_lock, flags);
1409
1410 if (q->length == 0)
1411 goto out;
1412
1413 if (id >= q->length)
1414 goto out;
1415
1416 ret = q->buffer[id];
1417 out:
1418 spin_unlock_irqrestore(&q->queue_lock, flags);
1419
1420 return ret;
1421}
1422
1423static unsigned int vino_queue_get_length(struct vino_framebuffer_queue *q)
1424{
1425 unsigned int length = 0;
1426 unsigned long flags;
1427
1428 if (q->magic != VINO_QUEUE_MAGIC) {
1429 return length;
1430 }
1431
1432 spin_lock_irqsave(&q->queue_lock, flags);
1433 length = q->length;
1434 spin_unlock_irqrestore(&q->queue_lock, flags);
1435
1436 return length;
1437}
1438
1439static int vino_queue_has_mapped_buffers(struct vino_framebuffer_queue *q)
1440{
1441 unsigned int i;
1442 int ret = 0;
1443 unsigned long flags;
1444
1445 if (q->magic != VINO_QUEUE_MAGIC) {
1446 return ret;
1447 }
1448
1449 spin_lock_irqsave(&q->queue_lock, flags);
1450 for (i = 0; i < q->length; i++) {
1451 if (q->buffer[i]->map_count > 0) {
1452 ret = 1;
1453 break;
1454 }
1455 }
1456 spin_unlock_irqrestore(&q->queue_lock, flags);
1457
1458 return ret;
1459}
1460
1461/* VINO functions */
1462
1463/* execute with input_lock locked */
1464static void vino_update_line_size(struct vino_channel_settings *vcs)
1465{
1466 unsigned int w = vcs->clipping.right - vcs->clipping.left;
1467 unsigned int d = vcs->decimation;
1468 unsigned int bpp = vino_data_formats[vcs->data_format].bpp;
1469 unsigned int lsize;
1470
1471 dprintk("update_line_size(): before: w = %d, d = %d, "
1472 "line_size = %d\n", w, d, vcs->line_size);
1473 /* line size must be multiple of 8 bytes */
1474 lsize = (bpp * (w / d)) & ~7;
1475 w = (lsize / bpp) * d;
1476
1477 vcs->clipping.right = vcs->clipping.left + w;
1478 vcs->line_size = lsize;
1479 dprintk("update_line_size(): after: w = %d, d = %d, "
1480 "line_size = %d\n", w, d, vcs->line_size);
1481}
1482
1483/* execute with input_lock locked */
1484static void vino_set_clipping(struct vino_channel_settings *vcs,
1485 unsigned int x, unsigned int y,
1486 unsigned int w, unsigned int h)
1487{
1488 unsigned int maxwidth, maxheight;
1489 unsigned int d;
1490
1491 maxwidth = vino_data_norms[vcs->data_norm].width;
1492 maxheight = vino_data_norms[vcs->data_norm].height;
1493 d = vcs->decimation;
1494
1495 y &= ~1; /* odd/even fields */
1496
1497 if (x > maxwidth) {
1498 x = 0;
1499 }
1500 if (y > maxheight) {
1501 y = 0;
1502 }
1503
1504 if (((w / d) < VINO_MIN_WIDTH)
1505 || ((h / d) < VINO_MIN_HEIGHT)) {
1506 w = VINO_MIN_WIDTH * d;
1507 h = VINO_MIN_HEIGHT * d;
1508 }
1509
1510 if ((x + w) > maxwidth) {
1511 w = maxwidth - x;
1512 if ((w / d) < VINO_MIN_WIDTH)
1513 x = maxwidth - VINO_MIN_WIDTH * d;
1514 }
1515 if ((y + h) > maxheight) {
1516 h = maxheight - y;
1517 if ((h / d) < VINO_MIN_HEIGHT)
1518 y = maxheight - VINO_MIN_HEIGHT * d;
1519 }
1520
1521 vcs->clipping.left = x;
1522 vcs->clipping.top = y;
1523 vcs->clipping.right = x + w;
1524 vcs->clipping.bottom = y + h;
1525
1526 vino_update_line_size(vcs);
1527
1528 dprintk("clipping %d, %d, %d, %d / %d - %d\n",
1529 vcs->clipping.left, vcs->clipping.top, vcs->clipping.right,
1530 vcs->clipping.bottom, vcs->decimation, vcs->line_size);
1531}
1532
1533/* execute with input_lock locked */
1534static void vino_set_default_clipping(struct vino_channel_settings *vcs)
1535{
1536 vino_set_clipping(vcs, 0, 0, vino_data_norms[vcs->data_norm].width,
1537 vino_data_norms[vcs->data_norm].height);
1538}
1539
1540/* execute with input_lock locked */
1541static void vino_set_scaling(struct vino_channel_settings *vcs,
1542 unsigned int w, unsigned int h)
1543{
1544 unsigned int x, y, curw, curh, d;
1545
1546 x = vcs->clipping.left;
1547 y = vcs->clipping.top;
1548 curw = vcs->clipping.right - vcs->clipping.left;
1549 curh = vcs->clipping.bottom - vcs->clipping.top;
1550
1551 d = max(curw / w, curh / h);
1552
1553 dprintk("scaling w: %d, h: %d, curw: %d, curh: %d, d: %d\n",
1554 w, h, curw, curh, d);
1555
1556 if (d < 1) {
1557 d = 1;
1558 }
1559 if (d > 8) {
1560 d = 8;
1561 }
1562
1563 vcs->decimation = d;
1564 vino_set_clipping(vcs, x, y, w * d, h * d);
1565
1566 dprintk("scaling %d, %d, %d, %d / %d - %d\n", vcs->clipping.left,
1567 vcs->clipping.top, vcs->clipping.right, vcs->clipping.bottom,
1568 vcs->decimation, vcs->line_size);
1569}
1570
1571/* execute with input_lock locked */
1572static void vino_reset_scaling(struct vino_channel_settings *vcs)
1573{
1574 vino_set_scaling(vcs, vcs->clipping.right - vcs->clipping.left,
1575 vcs->clipping.bottom - vcs->clipping.top);
1576}
1577
1578/* execute with input_lock locked */
1579static void vino_set_framerate(struct vino_channel_settings *vcs,
1580 unsigned int fps)
1581{
1582 unsigned int mask;
1583
1584 switch (vcs->data_norm) {
1585 case VINO_DATA_NORM_NTSC:
1586 case VINO_DATA_NORM_D1:
1587 fps = (unsigned int)(fps / 6) * 6; // FIXME: round!
1588
1589 if (fps < vino_data_norms[vcs->data_norm].fps_min)
1590 fps = vino_data_norms[vcs->data_norm].fps_min;
1591 if (fps > vino_data_norms[vcs->data_norm].fps_max)
1592 fps = vino_data_norms[vcs->data_norm].fps_max;
1593
1594 switch (fps) {
1595 case 6:
1596 mask = 0x003;
1597 break;
1598 case 12:
1599 mask = 0x0c3;
1600 break;
1601 case 18:
1602 mask = 0x333;
1603 break;
1604 case 24:
1605 mask = 0x3ff;
1606 break;
1607 case 30:
1608 mask = 0xfff;
1609 break;
1610 default:
1611 mask = VINO_FRAMERT_FULL;
1612 }
1613 vcs->framert_reg = VINO_FRAMERT_RT(mask);
1614 break;
1615 case VINO_DATA_NORM_PAL:
1616 case VINO_DATA_NORM_SECAM:
1617 fps = (unsigned int)(fps / 5) * 5; // FIXME: round!
1618
1619 if (fps < vino_data_norms[vcs->data_norm].fps_min)
1620 fps = vino_data_norms[vcs->data_norm].fps_min;
1621 if (fps > vino_data_norms[vcs->data_norm].fps_max)
1622 fps = vino_data_norms[vcs->data_norm].fps_max;
1623
1624 switch (fps) {
1625 case 5:
1626 mask = 0x003;
1627 break;
1628 case 10:
1629 mask = 0x0c3;
1630 break;
1631 case 15:
1632 mask = 0x333;
1633 break;
1634 case 20:
1635 mask = 0x0ff;
1636 break;
1637 case 25:
1638 mask = 0x3ff;
1639 break;
1640 default:
1641 mask = VINO_FRAMERT_FULL;
1642 }
1643 vcs->framert_reg = VINO_FRAMERT_RT(mask) | VINO_FRAMERT_PAL;
1644 break;
1645 }
1646
1647 vcs->fps = fps;
1648}
1649
1650/* execute with input_lock locked */
1651static void vino_set_default_framerate(struct vino_channel_settings *vcs)
1652{
1653 vino_set_framerate(vcs, vino_data_norms[vcs->data_norm].fps_max);
1654}
1655
1656/*
1657 * Prepare VINO for DMA transfer...
1658 * (execute only with vino_lock and input_lock locked)
1659 */
1660static int vino_dma_setup(struct vino_channel_settings *vcs,
1661 struct vino_framebuffer *fb)
1662{
1663 u32 ctrl, intr;
1664 struct sgi_vino_channel *ch;
1665 const struct vino_data_norm *norm;
1666
1667 dprintk("vino_dma_setup():\n");
1668
1669 vcs->field = 0;
1670 fb->frame_counter = 0;
1671
1672 ch = (vcs->channel == VINO_CHANNEL_A) ? &vino->a : &vino->b;
1673 norm = &vino_data_norms[vcs->data_norm];
1674
1675 ch->page_index = 0;
1676 ch->line_count = 0;
1677
1678 /* VINO line size register is set 8 bytes less than actual */
1679 ch->line_size = vcs->line_size - 8;
1680
1681 /* let VINO know where to transfer data */
1682 ch->start_desc_tbl = fb->desc_table.dma;
1683 ch->next_4_desc = fb->desc_table.dma;
1684
1685 /* give vino time to fetch the first four descriptors, 5 usec
1686 * should be more than enough time */
1687 udelay(VINO_DESC_FETCH_DELAY);
1688
1689 /* set the alpha register */
1690 ch->alpha = vcs->alpha;
1691
1692 /* set clipping registers */
1693 ch->clip_start = VINO_CLIP_ODD(norm->odd.top + vcs->clipping.top / 2) |
1694 VINO_CLIP_EVEN(norm->even.top +
1695 vcs->clipping.top / 2) |
1696 VINO_CLIP_X(vcs->clipping.left);
1697 ch->clip_end = VINO_CLIP_ODD(norm->odd.top +
1698 vcs->clipping.bottom / 2 - 1) |
1699 VINO_CLIP_EVEN(norm->even.top +
1700 vcs->clipping.bottom / 2 - 1) |
1701 VINO_CLIP_X(vcs->clipping.right);
1702 /* FIXME: end-of-field bug workaround
1703 VINO_CLIP_X(VINO_PAL_WIDTH);
1704 */
1705
1706 /* set the size of actual content in the buffer (DECIMATION !) */
1707 fb->data_size = ((vcs->clipping.right - vcs->clipping.left) /
1708 vcs->decimation) *
1709 ((vcs->clipping.bottom - vcs->clipping.top) /
1710 vcs->decimation) *
1711 vino_data_formats[vcs->data_format].bpp;
1712
1713 ch->frame_rate = vcs->framert_reg;
1714
1715 ctrl = vino->control;
1716 intr = vino->intr_status;
1717
1718 if (vcs->channel == VINO_CHANNEL_A) {
1719 /* All interrupt conditions for this channel was cleared
1720 * so clear the interrupt status register and enable
1721 * interrupts */
1722 intr &= ~VINO_INTSTAT_A;
1723 ctrl |= VINO_CTRL_A_INT;
1724
1725 /* enable synchronization */
1726 ctrl |= VINO_CTRL_A_SYNC_ENBL;
1727
1728 /* enable frame assembly */
1729 ctrl |= VINO_CTRL_A_INTERLEAVE_ENBL;
1730
1731 /* set decimation used */
1732 if (vcs->decimation < 2)
1733 ctrl &= ~VINO_CTRL_A_DEC_ENBL;
1734 else {
1735 ctrl |= VINO_CTRL_A_DEC_ENBL;
1736 ctrl &= ~VINO_CTRL_A_DEC_SCALE_MASK;
1737 ctrl |= (vcs->decimation - 1) <<
1738 VINO_CTRL_A_DEC_SCALE_SHIFT;
1739 }
1740
1741 /* select input interface */
1742 if (vcs->input == VINO_INPUT_D1)
1743 ctrl |= VINO_CTRL_A_SELECT;
1744 else
1745 ctrl &= ~VINO_CTRL_A_SELECT;
1746
1747 /* palette */
1748 ctrl &= ~(VINO_CTRL_A_LUMA_ONLY | VINO_CTRL_A_RGB |
1749 VINO_CTRL_A_DITHER);
1750 } else {
1751 intr &= ~VINO_INTSTAT_B;
1752 ctrl |= VINO_CTRL_B_INT;
1753
1754 ctrl |= VINO_CTRL_B_SYNC_ENBL;
1755 ctrl |= VINO_CTRL_B_INTERLEAVE_ENBL;
1756
1757 if (vcs->decimation < 2)
1758 ctrl &= ~VINO_CTRL_B_DEC_ENBL;
1759 else {
1760 ctrl |= VINO_CTRL_B_DEC_ENBL;
1761 ctrl &= ~VINO_CTRL_B_DEC_SCALE_MASK;
1762 ctrl |= (vcs->decimation - 1) <<
1763 VINO_CTRL_B_DEC_SCALE_SHIFT;
1764
1765 }
1766 if (vcs->input == VINO_INPUT_D1)
1767 ctrl |= VINO_CTRL_B_SELECT;
1768 else
1769 ctrl &= ~VINO_CTRL_B_SELECT;
1770
1771 ctrl &= ~(VINO_CTRL_B_LUMA_ONLY | VINO_CTRL_B_RGB |
1772 VINO_CTRL_B_DITHER);
1773 }
1774
1775 /* set palette */
1776 fb->data_format = vcs->data_format;
1777
1778 switch (vcs->data_format) {
1779 case VINO_DATA_FMT_GREY:
1780 ctrl |= (vcs->channel == VINO_CHANNEL_A) ?
1781 VINO_CTRL_A_LUMA_ONLY : VINO_CTRL_B_LUMA_ONLY;
1782 break;
1783 case VINO_DATA_FMT_RGB32:
1784 ctrl |= (vcs->channel == VINO_CHANNEL_A) ?
1785 VINO_CTRL_A_RGB : VINO_CTRL_B_RGB;
1786 break;
1787 case VINO_DATA_FMT_YUV:
1788 /* nothing needs to be done */
1789 break;
1790 case VINO_DATA_FMT_RGB332:
1791 ctrl |= (vcs->channel == VINO_CHANNEL_A) ?
1792 VINO_CTRL_A_RGB | VINO_CTRL_A_DITHER :
1793 VINO_CTRL_B_RGB | VINO_CTRL_B_DITHER;
1794 break;
1795 }
1796
1797 vino->intr_status = intr;
1798 vino->control = ctrl;
1799
1800 return 0;
1801}
1802
1803/* (execute only with vino_lock locked) */
1804static void vino_dma_start(struct vino_channel_settings *vcs)
1805{
1806 u32 ctrl = vino->control;
1807
1808 dprintk("vino_dma_start():\n");
1809 ctrl |= (vcs->channel == VINO_CHANNEL_A) ?
1810 VINO_CTRL_A_DMA_ENBL : VINO_CTRL_B_DMA_ENBL;
1811 vino->control = ctrl;
1812}
1813
1814/* (execute only with vino_lock locked) */
1815static void vino_dma_stop(struct vino_channel_settings *vcs)
1816{
1817 u32 ctrl = vino->control;
1818
1819 ctrl &= (vcs->channel == VINO_CHANNEL_A) ?
1820 ~VINO_CTRL_A_DMA_ENBL : ~VINO_CTRL_B_DMA_ENBL;
1821 vino->control = ctrl;
1822 dprintk("vino_dma_stop():\n");
1823}
1824
1825/*
1826 * Load dummy page to descriptor registers. This prevents generating of
1827 * spurious interrupts. (execute only with vino_lock locked)
1828 */
1829static void vino_clear_interrupt(struct vino_channel_settings *vcs)
1830{
1831 struct sgi_vino_channel *ch;
1832
1833 ch = (vcs->channel == VINO_CHANNEL_A) ? &vino->a : &vino->b;
1834
1835 ch->page_index = 0;
1836 ch->line_count = 0;
1837
1838 ch->start_desc_tbl = vino_drvdata->dummy_desc_table.dma;
1839 ch->next_4_desc = vino_drvdata->dummy_desc_table.dma;
1840
1841 udelay(VINO_DESC_FETCH_DELAY);
1842 dprintk("channel %c clear interrupt condition\n",
1843 (vcs->channel == VINO_CHANNEL_A) ? 'A':'B');
1844}
1845
1846static int vino_capture(struct vino_channel_settings *vcs,
1847 struct vino_framebuffer *fb)
1848{
1849 int err = 0;
1850 unsigned long flags, flags2;
1851
1852 spin_lock_irqsave(&fb->state_lock, flags);
1853
1854 if (fb->state == VINO_FRAMEBUFFER_IN_USE)
1855 err = -EBUSY;
1856 fb->state = VINO_FRAMEBUFFER_IN_USE;
1857
1858 spin_unlock_irqrestore(&fb->state_lock, flags);
1859
1860 if (err)
1861 return err;
1862
1863 spin_lock_irqsave(&vino_drvdata->vino_lock, flags);
1864 spin_lock_irqsave(&vino_drvdata->input_lock, flags2);
1865
1866 vino_dma_setup(vcs, fb);
1867 vino_dma_start(vcs);
1868
1869 spin_unlock_irqrestore(&vino_drvdata->input_lock, flags2);
1870 spin_unlock_irqrestore(&vino_drvdata->vino_lock, flags);
1871
1872 return err;
1873}
1874
1875static
1876struct vino_framebuffer *vino_capture_enqueue(struct
1877 vino_channel_settings *vcs,
1878 unsigned int index)
1879{
1880 struct vino_framebuffer *fb;
1881 unsigned long flags;
1882
1883 dprintk("vino_capture_enqueue():\n");
1884
1885 spin_lock_irqsave(&vcs->capture_lock, flags);
1886
1887 fb = vino_queue_add(&vcs->fb_queue, index);
1888 if (fb == NULL) {
1889 dprintk("vino_capture_enqueue(): vino_queue_add() failed, "
1890 "queue full?\n");
1891 goto out;
1892 }
1893out:
1894 spin_unlock_irqrestore(&vcs->capture_lock, flags);
1895
1896 return fb;
1897}
1898
1899static int vino_capture_next(struct vino_channel_settings *vcs, int start)
1900{
1901 struct vino_framebuffer *fb;
1902 unsigned int incoming, id;
1903 int err = 0;
1904 unsigned long flags, flags2;
1905
1906 dprintk("vino_capture_next():\n");
1907
1908 spin_lock_irqsave(&vcs->capture_lock, flags);
1909
1910 if (start) {
1911 /* start capture only if capture isn't in progress already */
1912 if (vcs->capturing) {
1913 spin_unlock_irqrestore(&vcs->capture_lock, flags);
1914 return 0;
1915 }
1916
1917 } else {
1918 /* capture next frame:
1919 * stop capture if capturing is not set */
1920 if (!vcs->capturing) {
1921 spin_unlock_irqrestore(&vcs->capture_lock, flags);
1922 return 0;
1923 }
1924 }
1925
1926 err = vino_queue_get_incoming(&vcs->fb_queue, &incoming);
1927 if (err) {
1928 dprintk("vino_capture_next(): vino_queue_get_incoming() "
1929 "failed\n");
1930 err = -EINVAL;
1931 goto out;
1932 }
1933 if (incoming == 0) {
1934 dprintk("vino_capture_next(): no buffers available\n");
1935 goto out;
1936 }
1937
1938 fb = vino_queue_peek(&vcs->fb_queue, &id);
1939 if (fb == NULL) {
1940 dprintk("vino_capture_next(): vino_queue_peek() failed\n");
1941 err = -EINVAL;
1942 goto out;
1943 }
1944
1945 spin_lock_irqsave(&fb->state_lock, flags2);
1946 fb->state = VINO_FRAMEBUFFER_UNUSED;
1947 spin_unlock_irqrestore(&fb->state_lock, flags2);
1948
1949 if (start) {
1950 vcs->capturing = 1;
1951 }
1952
1953 spin_unlock_irqrestore(&vcs->capture_lock, flags);
1954
1955 err = vino_capture(vcs, fb);
1956
1957 return err;
1958
1959out:
1960 vcs->capturing = 0;
1961 spin_unlock_irqrestore(&vcs->capture_lock, flags);
1962
1963 return err;
1964}
1965
1966static int vino_is_capturing(struct vino_channel_settings *vcs)
1967{
1968 int ret;
1969 unsigned long flags;
1970
1971 spin_lock_irqsave(&vcs->capture_lock, flags);
1972
1973 ret = vcs->capturing;
1974
1975 spin_unlock_irqrestore(&vcs->capture_lock, flags);
1976
1977 return ret;
1978}
1979
1980/* waits until a frame is captured */
1981static int vino_wait_for_frame(struct vino_channel_settings *vcs)
1982{
1983 wait_queue_t wait;
1984 int err = 0;
1985
1986 dprintk("vino_wait_for_frame():\n");
1987
1988 init_waitqueue_entry(&wait, current);
1989 /* add ourselves into wait queue */
1990 add_wait_queue(&vcs->fb_queue.frame_wait_queue, &wait);
1991 /* and set current state */
1992 set_current_state(TASK_INTERRUPTIBLE);
1993
1994 /* to ensure that schedule_timeout will return immediately
1995 * if VINO interrupt was triggred meanwhile */
1996 schedule_timeout(HZ / 10);
1997
1998 if (signal_pending(current))
1999 err = -EINTR;
2000
2001 remove_wait_queue(&vcs->fb_queue.frame_wait_queue, &wait);
2002
2003 dprintk("vino_wait_for_frame(): waiting for frame %s\n",
2004 err ? "failed" : "ok");
2005
2006 return err;
2007}
2008
2009/* the function assumes that PAGE_SIZE % 4 == 0 */
2010static void vino_convert_to_rgba(struct vino_framebuffer *fb) {
2011 unsigned char *pageptr;
2012 unsigned int page, i;
2013 unsigned char a;
2014
2015 for (page = 0; page < fb->desc_table.page_count; page++) {
2016 pageptr = (unsigned char *)fb->desc_table.virtual[page];
2017
2018 for (i = 0; i < PAGE_SIZE; i += 4) {
2019 a = pageptr[0];
2020 pageptr[0] = pageptr[3];
2021 pageptr[1] = pageptr[2];
2022 pageptr[2] = pageptr[1];
2023 pageptr[3] = a;
2024 pageptr += 4;
2025 }
2026 }
2027}
2028
2029/* checks if the buffer is in correct state and syncs data */
2030static int vino_check_buffer(struct vino_channel_settings *vcs,
2031 struct vino_framebuffer *fb)
2032{
2033 int err = 0;
2034 unsigned long flags;
2035
2036 dprintk("vino_check_buffer():\n");
2037
2038 spin_lock_irqsave(&fb->state_lock, flags);
2039 switch (fb->state) {
2040 case VINO_FRAMEBUFFER_IN_USE:
2041 err = -EIO;
2042 break;
2043 case VINO_FRAMEBUFFER_READY:
2044 vino_sync_buffer(fb);
2045 fb->state = VINO_FRAMEBUFFER_UNUSED;
2046 break;
2047 default:
2048 err = -EINVAL;
2049 }
2050 spin_unlock_irqrestore(&fb->state_lock, flags);
2051
2052 if (!err) {
2053 if (vino_pixel_conversion
2054 && (fb->data_format == VINO_DATA_FMT_RGB32)) {
2055 vino_convert_to_rgba(fb);
2056 }
2057 } else if (err && (err != -EINVAL)) {
2058 dprintk("vino_check_buffer(): buffer not ready\n");
2059
2060 spin_lock_irqsave(&vino_drvdata->vino_lock, flags);
2061 vino_dma_stop(vcs);
2062 vino_clear_interrupt(vcs);
2063 spin_unlock_irqrestore(&vino_drvdata->vino_lock, flags);
2064 }
2065
2066 return err;
2067}
2068
2069/* forcefully terminates capture */
2070static void vino_capture_stop(struct vino_channel_settings *vcs)
2071{
2072 unsigned int incoming = 0, outgoing = 0, id;
2073 unsigned long flags, flags2;
2074
2075 dprintk("vino_capture_stop():\n");
2076
2077 spin_lock_irqsave(&vcs->capture_lock, flags);
2078 /* unset capturing to stop queue processing */
2079 vcs->capturing = 0;
2080
2081 spin_lock_irqsave(&vino_drvdata->vino_lock, flags2);
2082
2083 vino_dma_stop(vcs);
2084 vino_clear_interrupt(vcs);
2085
2086 spin_unlock_irqrestore(&vino_drvdata->vino_lock, flags2);
2087
2088 /* remove all items from the queue */
2089 if (vino_queue_get_incoming(&vcs->fb_queue, &incoming)) {
2090 dprintk("vino_capture_stop(): "
2091 "vino_queue_get_incoming() failed\n");
2092 goto out;
2093 }
2094 while (incoming > 0) {
2095 vino_queue_transfer(&vcs->fb_queue);
2096
2097 if (vino_queue_get_incoming(&vcs->fb_queue, &incoming)) {
2098 dprintk("vino_capture_stop(): "
2099 "vino_queue_get_incoming() failed\n");
2100 goto out;
2101 }
2102 }
2103
2104 if (vino_queue_get_outgoing(&vcs->fb_queue, &outgoing)) {
2105 dprintk("vino_capture_stop(): "
2106 "vino_queue_get_outgoing() failed\n");
2107 goto out;
2108 }
2109 while (outgoing > 0) {
2110 vino_queue_remove(&vcs->fb_queue, &id);
2111
2112 if (vino_queue_get_outgoing(&vcs->fb_queue, &outgoing)) {
2113 dprintk("vino_capture_stop(): "
2114 "vino_queue_get_outgoing() failed\n");
2115 goto out;
2116 }
2117 }
2118
2119out:
2120 spin_unlock_irqrestore(&vcs->capture_lock, flags);
2121}
2122
2123static int vino_capture_failed(struct vino_channel_settings *vcs)
2124{
2125 struct vino_framebuffer *fb;
2126 unsigned long flags;
2127 unsigned int i;
2128 int ret;
2129
2130 dprintk("vino_capture_failed():\n");
2131
2132 spin_lock_irqsave(&vino_drvdata->vino_lock, flags);
2133
2134 vino_dma_stop(vcs);
2135 vino_clear_interrupt(vcs);
2136
2137 spin_unlock_irqrestore(&vino_drvdata->vino_lock, flags);
2138
2139 ret = vino_queue_get_incoming(&vcs->fb_queue, &i);
2140 if (ret == VINO_QUEUE_ERROR) {
2141 dprintk("vino_queue_get_incoming() failed\n");
2142 return -EINVAL;
2143 }
2144 if (i == 0) {
2145 /* no buffers to process */
2146 return 0;
2147 }
2148
2149 fb = vino_queue_peek(&vcs->fb_queue, &i);
2150 if (fb == NULL) {
2151 dprintk("vino_queue_peek() failed\n");
2152 return -EINVAL;
2153 }
2154
2155 spin_lock_irqsave(&fb->state_lock, flags);
2156 if (fb->state == VINO_FRAMEBUFFER_IN_USE) {
2157 fb->state = VINO_FRAMEBUFFER_UNUSED;
2158 vino_queue_transfer(&vcs->fb_queue);
2159 vino_queue_remove(&vcs->fb_queue, &i);
2160 /* we should actually discard the newest frame,
2161 * but who cares ... */
2162 }
2163 spin_unlock_irqrestore(&fb->state_lock, flags);
2164
2165 return 0;
2166}
2167
2168static void vino_frame_done(struct vino_channel_settings *vcs,
2169 unsigned int fc)
2170{
2171 struct vino_framebuffer *fb;
2172 unsigned long flags;
2173
2174 spin_lock_irqsave(&vcs->capture_lock, flags);
2175 fb = vino_queue_transfer(&vcs->fb_queue);
2176 if (!fb) {
2177 spin_unlock_irqrestore(&vcs->capture_lock, flags);
2178 dprintk("vino_frame_done(): vino_queue_transfer() failed!\n");
2179 return;
2180 }
2181 spin_unlock_irqrestore(&vcs->capture_lock, flags);
2182
2183 fb->frame_counter = fc;
2184 do_gettimeofday(&fb->timestamp);
2185
2186 spin_lock_irqsave(&fb->state_lock, flags);
2187 if (fb->state == VINO_FRAMEBUFFER_IN_USE)
2188 fb->state = VINO_FRAMEBUFFER_READY;
2189 spin_unlock_irqrestore(&fb->state_lock, flags);
2190
2191 wake_up(&vcs->fb_queue.frame_wait_queue);
2192
2193 vino_capture_next(vcs, 0);
2194}
2195
2196static irqreturn_t vino_interrupt(int irq, void *dev_id, struct pt_regs *regs)
2197{
2198 u32 intr;
2199 unsigned int fc_a, fc_b;
2200 int done_a = 0;
2201 int done_b = 0;
2202
2203 spin_lock(&vino_drvdata->vino_lock);
2204
2205 intr = vino->intr_status;
2206 fc_a = vino->a.field_counter / 2;
2207 fc_b = vino->b.field_counter / 2;
2208
2209 // TODO: handle error-interrupts in some special way ?
2210
2211 if (intr & VINO_INTSTAT_A) {
2212 if (intr & VINO_INTSTAT_A_EOF) {
2213 vino_drvdata->a.field++;
2214 if (vino_drvdata->a.field > 1) {
2215 vino_dma_stop(&vino_drvdata->a);
2216 vino_clear_interrupt(&vino_drvdata->a);
2217 vino_drvdata->a.field = 0;
2218 done_a = 1;
2219 }
2220 dprintk("intr: channel A end-of-field interrupt: "
2221 "%04x\n", intr);
2222 } else {
2223 vino_dma_stop(&vino_drvdata->a);
2224 vino_clear_interrupt(&vino_drvdata->a);
2225 done_a = 1;
2226 dprintk("channel A error interrupt: %04x\n", intr);
2227 }
2228 }
2229 if (intr & VINO_INTSTAT_B) {
2230 if (intr & VINO_INTSTAT_B_EOF) {
2231 vino_drvdata->b.field++;
2232 if (vino_drvdata->b.field > 1) {
2233 vino_dma_stop(&vino_drvdata->b);
2234 vino_clear_interrupt(&vino_drvdata->b);
2235 vino_drvdata->b.field = 0;
2236 done_b = 1;
2237 }
2238 dprintk("intr: channel B end-of-field interrupt: "
2239 "%04x\n", intr);
2240 } else {
2241 vino_dma_stop(&vino_drvdata->b);
2242 vino_clear_interrupt(&vino_drvdata->b);
2243 done_b = 1;
2244 dprintk("channel B error interrupt: %04x\n", intr);
2245 }
2246 }
2247
2248 /* always remember to clear interrupt status */
2249 vino->intr_status = ~intr;
2250
2251 spin_unlock(&vino_drvdata->vino_lock);
2252
2253 if (done_a) {
2254 vino_frame_done(&vino_drvdata->a, fc_a);
2255 dprintk("channel A frame done, interrupt: %d\n", intr);
2256 }
2257 if (done_b) {
2258 vino_frame_done(&vino_drvdata->b, fc_b);
2259 dprintk("channel B frame done, interrupt: %d\n", intr);
2260 }
207 2261
208 return -EINVAL; 2262 return IRQ_HANDLED;
209} 2263}
210 2264
211static const struct video_device vino_device = { 2265/* VINO video input management */
2266
2267static int vino_get_saa7191_input(int input)
2268{
2269 switch (input) {
2270 case VINO_INPUT_COMPOSITE:
2271 return SAA7191_INPUT_COMPOSITE;
2272 case VINO_INPUT_SVIDEO:
2273 return SAA7191_INPUT_SVIDEO;
2274 default:
2275 printk(KERN_ERR "VINO: vino_get_saa7191_input(): "
2276 "invalid input!\n");
2277 return -1;
2278 }
2279}
2280
2281static int vino_get_saa7191_norm(int norm)
2282{
2283 switch (norm) {
2284 case VINO_DATA_NORM_AUTO:
2285 return SAA7191_NORM_AUTO;
2286 case VINO_DATA_NORM_PAL:
2287 return SAA7191_NORM_PAL;
2288 case VINO_DATA_NORM_NTSC:
2289 return SAA7191_NORM_NTSC;
2290 case VINO_DATA_NORM_SECAM:
2291 return SAA7191_NORM_SECAM;
2292 default:
2293 printk(KERN_ERR "VINO: vino_get_saa7191_norm(): "
2294 "invalid norm!\n");
2295 return -1;
2296 }
2297}
2298
2299/* execute with input_lock locked */
2300static int vino_is_input_owner(struct vino_channel_settings *vcs)
2301{
2302 switch(vcs->input) {
2303 case VINO_INPUT_COMPOSITE:
2304 case VINO_INPUT_SVIDEO:
2305 return (vino_drvdata->decoder.owner == vcs->channel);
2306 case VINO_INPUT_D1:
2307 return (vino_drvdata->camera.owner == vcs->channel);
2308 default:
2309 return 0;
2310 }
2311}
2312
2313static int vino_acquire_input(struct vino_channel_settings *vcs)
2314{
2315 int ret = 0;
2316
2317 dprintk("vino_acquire_input():\n");
2318
2319 spin_lock(&vino_drvdata->input_lock);
2320
2321 /* First try D1 and then SAA7191 */
2322 if (vino_drvdata->camera.driver
2323 && (vino_drvdata->camera.owner == VINO_NO_CHANNEL)) {
2324 if (i2c_use_client(vino_drvdata->camera.driver)) {
2325 ret = -ENODEV;
2326 goto out;
2327 }
2328
2329 vino_drvdata->camera.owner = vcs->channel;
2330 vcs->input = VINO_INPUT_D1;
2331 vcs->data_norm = VINO_DATA_NORM_D1;
2332 } else if (vino_drvdata->decoder.driver
2333 && (vino_drvdata->decoder.owner == VINO_NO_CHANNEL)) {
2334 int saa7191_input;
2335 int saa7191_norm;
2336
2337 if (i2c_use_client(vino_drvdata->decoder.driver)) {
2338 ret = -ENODEV;
2339 goto out;
2340 }
2341
2342 vino_drvdata->decoder.owner = vcs->channel;
2343 vcs->input = VINO_INPUT_COMPOSITE;
2344 vcs->data_norm = VINO_DATA_NORM_PAL;
2345
2346 saa7191_input = vino_get_saa7191_input(vcs->input);
2347 i2c_decoder_command(DECODER_SET_INPUT, &saa7191_input);
2348
2349 saa7191_norm = vino_get_saa7191_norm(vcs->data_norm);
2350 i2c_decoder_command(DECODER_SAA7191_SET_NORM, &saa7191_norm);
2351 } else {
2352 vcs->input = (vcs->channel == VINO_CHANNEL_A) ?
2353 vino_drvdata->b.input : vino_drvdata->a.input;
2354 vcs->data_norm = (vcs->channel == VINO_CHANNEL_A) ?
2355 vino_drvdata->b.data_norm : vino_drvdata->a.data_norm;
2356 }
2357
2358 if (vcs->input == VINO_INPUT_NONE) {
2359 ret = -ENODEV;
2360 goto out;
2361 }
2362
2363 if (vino_is_input_owner(vcs)) {
2364 vino_set_default_clipping(vcs);
2365 vino_set_default_framerate(vcs);
2366 }
2367
2368 dprintk("vino_acquire_input(): %s\n", vino_inputs[vcs->input].name);
2369
2370out:
2371 spin_unlock(&vino_drvdata->input_lock);
2372
2373 return ret;
2374}
2375
2376static int vino_set_input(struct vino_channel_settings *vcs, int input)
2377{
2378 struct vino_channel_settings *vcs2 = (vcs->channel == VINO_CHANNEL_A) ?
2379 &vino_drvdata->b : &vino_drvdata->a;
2380 int ret = 0;
2381
2382 dprintk("vino_set_input():\n");
2383
2384 spin_lock(&vino_drvdata->input_lock);
2385
2386 if (vcs->input == input)
2387 goto out;
2388
2389 switch(input) {
2390 case VINO_INPUT_COMPOSITE:
2391 case VINO_INPUT_SVIDEO:
2392 if (!vino_drvdata->decoder.driver) {
2393 ret = -EINVAL;
2394 goto out;
2395 }
2396
2397 if (vino_drvdata->decoder.owner == VINO_NO_CHANNEL) {
2398 if (i2c_use_client(vino_drvdata->decoder.driver)) {
2399 ret = -ENODEV;
2400 goto out;
2401 }
2402 vino_drvdata->decoder.owner = vcs->channel;
2403 }
2404
2405 if (vino_drvdata->decoder.owner == vcs->channel) {
2406 int saa7191_input;
2407 int saa7191_norm;
2408
2409 vcs->input = input;
2410 vcs->data_norm = VINO_DATA_NORM_PAL;
2411
2412 saa7191_input = vino_get_saa7191_input(vcs->input);
2413 i2c_decoder_command(DECODER_SET_INPUT, &saa7191_input);
2414 saa7191_norm = vino_get_saa7191_norm(vcs->data_norm);
2415 i2c_decoder_command(DECODER_SAA7191_SET_NORM,
2416 &saa7191_norm);
2417 } else {
2418 if (vcs2->input != input) {
2419 ret = -EBUSY;
2420 goto out;
2421 }
2422
2423 vcs->input = input;
2424 vcs->data_norm = vcs2->data_norm;
2425 }
2426
2427 if (vino_drvdata->camera.owner == vcs->channel) {
2428 /* Transfer the ownership or release the input */
2429 if (vcs2->input == VINO_INPUT_D1) {
2430 vino_drvdata->camera.owner = vcs2->channel;
2431 } else {
2432 i2c_release_client(vino_drvdata->
2433 camera.driver);
2434 vino_drvdata->camera.owner = VINO_NO_CHANNEL;
2435 }
2436 }
2437 break;
2438 case VINO_INPUT_D1:
2439 if (!vino_drvdata->camera.driver) {
2440 ret = -EINVAL;
2441 goto out;
2442 }
2443
2444 if (vino_drvdata->camera.owner == VINO_NO_CHANNEL) {
2445 if (i2c_use_client(vino_drvdata->camera.driver)) {
2446 ret = -ENODEV;
2447 goto out;
2448 }
2449 vino_drvdata->camera.owner = vcs->channel;
2450 }
2451
2452 if (vino_drvdata->decoder.owner == vcs->channel) {
2453 /* Transfer the ownership or release the input */
2454 if ((vcs2->input == VINO_INPUT_COMPOSITE) ||
2455 (vcs2->input == VINO_INPUT_SVIDEO)) {
2456 vino_drvdata->decoder.owner = vcs2->channel;
2457 } else {
2458 i2c_release_client(vino_drvdata->
2459 decoder.driver);
2460 vino_drvdata->decoder.owner = VINO_NO_CHANNEL;
2461 }
2462 }
2463
2464 vcs->input = input;
2465 vcs->data_norm = VINO_DATA_NORM_D1;
2466 break;
2467 default:
2468 ret = -EINVAL;
2469 goto out;
2470 }
2471
2472 vino_set_default_clipping(vcs);
2473 vino_set_default_framerate(vcs);
2474
2475 dprintk("vino_set_input(): %s\n", vino_inputs[vcs->input].name);
2476
2477out:
2478 spin_unlock(&vino_drvdata->input_lock);
2479
2480 return ret;
2481}
2482
2483static void vino_release_input(struct vino_channel_settings *vcs)
2484{
2485 struct vino_channel_settings *vcs2 = (vcs->channel == VINO_CHANNEL_A) ?
2486 &vino_drvdata->b : &vino_drvdata->a;
2487
2488 dprintk("vino_release_input():\n");
2489
2490 spin_lock(&vino_drvdata->input_lock);
2491
2492 /* Release ownership of the channel
2493 * and if the other channel takes input from
2494 * the same source, transfer the ownership */
2495 if (vino_drvdata->camera.owner == vcs->channel) {
2496 if (vcs2->input == VINO_INPUT_D1) {
2497 vino_drvdata->camera.owner = vcs2->channel;
2498 } else {
2499 i2c_release_client(vino_drvdata->camera.driver);
2500 vino_drvdata->camera.owner = VINO_NO_CHANNEL;
2501 }
2502 } else if (vino_drvdata->decoder.owner == vcs->channel) {
2503 if ((vcs2->input == VINO_INPUT_COMPOSITE) ||
2504 (vcs2->input == VINO_INPUT_SVIDEO)) {
2505 vino_drvdata->decoder.owner = vcs2->channel;
2506 } else {
2507 i2c_release_client(vino_drvdata->decoder.driver);
2508 vino_drvdata->decoder.owner = VINO_NO_CHANNEL;
2509 }
2510 }
2511 vcs->input = VINO_INPUT_NONE;
2512
2513 spin_unlock(&vino_drvdata->input_lock);
2514}
2515
2516/* execute with input_lock locked */
2517static int vino_set_data_norm(struct vino_channel_settings *vcs,
2518 unsigned int data_norm)
2519{
2520 int saa7191_norm;
2521
2522 switch (vcs->input) {
2523 case VINO_INPUT_D1:
2524 /* only one "norm" supported */
2525 if (data_norm != VINO_DATA_NORM_D1)
2526 return -EINVAL;
2527 break;
2528 case VINO_INPUT_COMPOSITE:
2529 case VINO_INPUT_SVIDEO:
2530
2531 saa7191_norm = vino_get_saa7191_norm(data_norm);
2532
2533 i2c_decoder_command(DECODER_SAA7191_SET_NORM, &saa7191_norm);
2534 vcs->data_norm = data_norm;
2535 break;
2536 default:
2537 return -EINVAL;
2538 }
2539
2540 return 0;
2541}
2542
2543/* V4L2 helper functions */
2544
2545static int vino_find_data_format(__u32 pixelformat)
2546{
2547 int i;
2548
2549 for (i = 0; i < VINO_DATA_FMT_COUNT; i++) {
2550 if (vino_data_formats[i].pixelformat == pixelformat)
2551 return i;
2552 }
2553
2554 return VINO_DATA_FMT_NONE;
2555}
2556
2557static int vino_enum_data_norm(struct vino_channel_settings *vcs, __u32 index)
2558{
2559 int data_norm = VINO_DATA_NORM_NONE;
2560
2561 spin_lock(&vino_drvdata->input_lock);
2562 switch(vcs->input) {
2563 case VINO_INPUT_COMPOSITE:
2564 case VINO_INPUT_SVIDEO:
2565 if (index == 0) {
2566 data_norm = VINO_DATA_NORM_PAL;
2567 } else if (index == 1) {
2568 data_norm = VINO_DATA_NORM_NTSC;
2569 } else if (index == 2) {
2570 data_norm = VINO_DATA_NORM_SECAM;
2571 }
2572 break;
2573 case VINO_INPUT_D1:
2574 if (index == 0) {
2575 data_norm = VINO_DATA_NORM_D1;
2576 }
2577 break;
2578 }
2579 spin_unlock(&vino_drvdata->input_lock);
2580
2581 return data_norm;
2582}
2583
2584static int vino_enum_input(struct vino_channel_settings *vcs, __u32 index)
2585{
2586 int input = VINO_INPUT_NONE;
2587
2588 spin_lock(&vino_drvdata->input_lock);
2589 if (vino_drvdata->decoder.driver && vino_drvdata->camera.driver) {
2590 switch (index) {
2591 case 0:
2592 input = VINO_INPUT_COMPOSITE;
2593 break;
2594 case 1:
2595 input = VINO_INPUT_SVIDEO;
2596 break;
2597 case 2:
2598 input = VINO_INPUT_D1;
2599 break;
2600 }
2601 } else if (vino_drvdata->decoder.driver) {
2602 switch (index) {
2603 case 0:
2604 input = VINO_INPUT_COMPOSITE;
2605 break;
2606 case 1:
2607 input = VINO_INPUT_SVIDEO;
2608 break;
2609 }
2610 } else if (vino_drvdata->camera.driver) {
2611 switch (index) {
2612 case 0:
2613 input = VINO_INPUT_D1;
2614 break;
2615 }
2616 }
2617 spin_unlock(&vino_drvdata->input_lock);
2618
2619 return input;
2620}
2621
2622/* execute with input_lock locked */
2623static __u32 vino_find_input_index(struct vino_channel_settings *vcs)
2624{
2625 __u32 index = 0;
2626 // FIXME: detect when no inputs available
2627
2628 if (vino_drvdata->decoder.driver && vino_drvdata->camera.driver) {
2629 switch (vcs->input) {
2630 case VINO_INPUT_COMPOSITE:
2631 index = 0;
2632 break;
2633 case VINO_INPUT_SVIDEO:
2634 index = 1;
2635 break;
2636 case VINO_INPUT_D1:
2637 index = 2;
2638 break;
2639 }
2640 } else if (vino_drvdata->decoder.driver) {
2641 switch (vcs->input) {
2642 case VINO_INPUT_COMPOSITE:
2643 index = 0;
2644 break;
2645 case VINO_INPUT_SVIDEO:
2646 index = 1;
2647 break;
2648 }
2649 } else if (vino_drvdata->camera.driver) {
2650 switch (vcs->input) {
2651 case VINO_INPUT_D1:
2652 index = 0;
2653 break;
2654 }
2655 }
2656
2657 return index;
2658}
2659
2660/* V4L2 ioctls */
2661
2662static void vino_v4l2_querycap(struct v4l2_capability *cap)
2663{
2664 memset(cap, 0, sizeof(struct v4l2_capability));
2665
2666 strcpy(cap->driver, vino_driver_name);
2667 strcpy(cap->card, vino_driver_description);
2668 strcpy(cap->bus_info, vino_bus_name);
2669 cap->version = VINO_VERSION_CODE;
2670 cap->capabilities =
2671 V4L2_CAP_VIDEO_CAPTURE |
2672 V4L2_CAP_STREAMING;
2673 // V4L2_CAP_OVERLAY, V4L2_CAP_READWRITE
2674}
2675
2676static int vino_v4l2_enuminput(struct vino_channel_settings *vcs,
2677 struct v4l2_input *i)
2678{
2679 __u32 index = i->index;
2680 int input;
2681 dprintk("requested index = %d\n", index);
2682
2683 input = vino_enum_input(vcs, index);
2684 if (input == VINO_INPUT_NONE)
2685 return -EINVAL;
2686
2687 memset(i, 0, sizeof(struct v4l2_input));
2688
2689 i->index = index;
2690 i->type = V4L2_INPUT_TYPE_CAMERA;
2691 i->std = vino_inputs[input].std;
2692 strcpy(i->name, vino_inputs[input].name);
2693
2694 if ((input == VINO_INPUT_COMPOSITE)
2695 || (input == VINO_INPUT_SVIDEO)) {
2696 struct saa7191_status status;
2697 i2c_decoder_command(DECODER_SAA7191_GET_STATUS, &status);
2698 i->status |= status.signal ? 0 : V4L2_IN_ST_NO_SIGNAL;
2699 i->status |= status.color ? 0 : V4L2_IN_ST_NO_COLOR;
2700 }
2701
2702 return 0;
2703}
2704
2705static int vino_v4l2_g_input(struct vino_channel_settings *vcs,
2706 struct v4l2_input *i)
2707{
2708 __u32 index;
2709 int input;
2710
2711 spin_lock(&vino_drvdata->input_lock);
2712 input = vcs->input;
2713 index = vino_find_input_index(vcs);
2714 spin_unlock(&vino_drvdata->input_lock);
2715
2716 dprintk("input = %d\n", input);
2717
2718 if (input == VINO_INPUT_NONE) {
2719 return -EINVAL;
2720 }
2721
2722 memset(i, 0, sizeof(struct v4l2_input));
2723
2724 i->index = index;
2725 i->type = V4L2_INPUT_TYPE_CAMERA;
2726 i->std = vino_inputs[input].std;
2727 strcpy(i->name, vino_inputs[input].name);
2728
2729 return 0;
2730}
2731
2732static int vino_v4l2_s_input(struct vino_channel_settings *vcs,
2733 struct v4l2_input *i)
2734{
2735 int input;
2736 dprintk("requested input = %d\n", i->index);
2737
2738 input = vino_enum_input(vcs, i->index);
2739 if (input == VINO_INPUT_NONE)
2740 return -EINVAL;
2741
2742 return vino_set_input(vcs, input);
2743}
2744
2745static int vino_v4l2_enumstd(struct vino_channel_settings *vcs,
2746 struct v4l2_standard *s)
2747{
2748 int index = s->index;
2749 int data_norm = vino_enum_data_norm(vcs, index);
2750 dprintk("standard index = %d\n", index);
2751
2752 if (data_norm == VINO_DATA_NORM_NONE)
2753 return -EINVAL;
2754
2755 dprintk("standard name = %s\n",
2756 vino_data_norms[data_norm].description);
2757
2758 memset(s, 0, sizeof(struct v4l2_standard));
2759 s->index = index;
2760
2761 s->id = vino_data_norms[data_norm].std;
2762 s->frameperiod.numerator = 1;
2763 s->frameperiod.denominator =
2764 vino_data_norms[data_norm].fps_max;
2765 s->framelines =
2766 vino_data_norms[data_norm].framelines;
2767 strcpy(s->name,
2768 vino_data_norms[data_norm].description);
2769
2770 return 0;
2771}
2772
2773static int vino_v4l2_g_std(struct vino_channel_settings *vcs,
2774 v4l2_std_id *std)
2775{
2776 spin_lock(&vino_drvdata->input_lock);
2777 dprintk("current standard = %d\n", vcs->data_norm);
2778 *std = vino_data_norms[vcs->data_norm].std;
2779 spin_unlock(&vino_drvdata->input_lock);
2780
2781 return 0;
2782}
2783
2784static int vino_v4l2_s_std(struct vino_channel_settings *vcs,
2785 v4l2_std_id *std)
2786{
2787 int ret = 0;
2788
2789 spin_lock(&vino_drvdata->input_lock);
2790
2791 /* check if the standard is valid for the current input */
2792 if (vino_is_input_owner(vcs)
2793 && (vino_inputs[vcs->input].std & (*std))) {
2794 dprintk("standard accepted\n");
2795
2796 /* change the video norm for SAA7191
2797 * and accept NTSC for D1 (do nothing) */
2798
2799 if (vcs->input == VINO_INPUT_D1)
2800 goto out;
2801
2802 if ((*std) & V4L2_STD_PAL) {
2803 vino_set_data_norm(vcs, VINO_DATA_NORM_PAL);
2804 vcs->data_norm = VINO_DATA_NORM_PAL;
2805 } else if ((*std) & V4L2_STD_NTSC) {
2806 vino_set_data_norm(vcs, VINO_DATA_NORM_NTSC);
2807 vcs->data_norm = VINO_DATA_NORM_NTSC;
2808 } else if ((*std) & V4L2_STD_SECAM) {
2809 vino_set_data_norm(vcs, VINO_DATA_NORM_SECAM);
2810 vcs->data_norm = VINO_DATA_NORM_SECAM;
2811 } else {
2812 ret = -EINVAL;
2813 }
2814 } else {
2815 ret = -EINVAL;
2816 }
2817
2818out:
2819 spin_unlock(&vino_drvdata->input_lock);
2820
2821 return ret;
2822}
2823
2824static int vino_v4l2_enum_fmt(struct vino_channel_settings *vcs,
2825 struct v4l2_fmtdesc *fd)
2826{
2827 enum v4l2_buf_type type = fd->type;
2828 int index = fd->index;
2829 dprintk("format index = %d\n", index);
2830
2831 switch (fd->type) {
2832 case V4L2_BUF_TYPE_VIDEO_CAPTURE:
2833 if ((fd->index < 0) ||
2834 (fd->index >= VINO_DATA_FMT_COUNT))
2835 return -EINVAL;
2836 dprintk("format name = %s\n",
2837 vino_data_formats[index].description);
2838
2839 memset(fd, 0, sizeof(struct v4l2_fmtdesc));
2840 fd->index = index;
2841 fd->type = type;
2842 fd->pixelformat = vino_data_formats[index].pixelformat;
2843 strcpy(fd->description, vino_data_formats[index].description);
2844 break;
2845 case V4L2_BUF_TYPE_VIDEO_OVERLAY:
2846 default:
2847 return -EINVAL;
2848 }
2849
2850 return 0;
2851}
2852
2853static int vino_v4l2_try_fmt(struct vino_channel_settings *vcs,
2854 struct v4l2_format *f)
2855{
2856 struct vino_channel_settings tempvcs;
2857
2858 switch (f->type) {
2859 case V4L2_BUF_TYPE_VIDEO_CAPTURE: {
2860 struct v4l2_pix_format *pf = &f->fmt.pix;
2861
2862 dprintk("requested: w = %d, h = %d\n",
2863 pf->width, pf->height);
2864
2865 spin_lock(&vino_drvdata->input_lock);
2866 memcpy(&tempvcs, vcs, sizeof(struct vino_channel_settings));
2867 spin_unlock(&vino_drvdata->input_lock);
2868
2869 tempvcs.data_format = vino_find_data_format(pf->pixelformat);
2870 if (tempvcs.data_format == VINO_DATA_FMT_NONE) {
2871 tempvcs.data_format = VINO_DATA_FMT_RGB32;
2872 pf->pixelformat =
2873 vino_data_formats[tempvcs.data_format].
2874 pixelformat;
2875 }
2876
2877 /* data format must be set before clipping/scaling */
2878 vino_set_scaling(&tempvcs, pf->width, pf->height);
2879
2880 dprintk("data format = %s\n",
2881 vino_data_formats[tempvcs.data_format].description);
2882
2883 pf->width = (tempvcs.clipping.right - tempvcs.clipping.left) /
2884 tempvcs.decimation;
2885 pf->height = (tempvcs.clipping.bottom - tempvcs.clipping.top) /
2886 tempvcs.decimation;
2887
2888 pf->field = V4L2_FIELD_INTERLACED;
2889 pf->bytesperline = tempvcs.line_size;
2890 pf->sizeimage = tempvcs.line_size *
2891 (tempvcs.clipping.bottom - tempvcs.clipping.top) /
2892 tempvcs.decimation;
2893 pf->colorspace =
2894 vino_data_formats[tempvcs.data_format].colorspace;
2895
2896 pf->priv = 0;
2897 break;
2898 }
2899 case V4L2_BUF_TYPE_VIDEO_OVERLAY:
2900 default:
2901 return -EINVAL;
2902 }
2903
2904 return 0;
2905}
2906
2907static int vino_v4l2_g_fmt(struct vino_channel_settings *vcs,
2908 struct v4l2_format *f)
2909{
2910 switch (f->type) {
2911 case V4L2_BUF_TYPE_VIDEO_CAPTURE: {
2912 struct v4l2_pix_format *pf = &f->fmt.pix;
2913 spin_lock(&vino_drvdata->input_lock);
2914
2915 pf->width = (vcs->clipping.right - vcs->clipping.left) /
2916 vcs->decimation;
2917 pf->height = (vcs->clipping.bottom - vcs->clipping.top) /
2918 vcs->decimation;
2919 pf->pixelformat =
2920 vino_data_formats[vcs->data_format].pixelformat;
2921
2922 pf->field = V4L2_FIELD_INTERLACED;
2923 pf->bytesperline = vcs->line_size;
2924 pf->sizeimage = vcs->line_size *
2925 (vcs->clipping.bottom - vcs->clipping.top) /
2926 vcs->decimation;
2927 pf->colorspace =
2928 vino_data_formats[vcs->data_format].colorspace;
2929
2930 pf->priv = 0;
2931
2932 spin_unlock(&vino_drvdata->input_lock);
2933 break;
2934 }
2935 case V4L2_BUF_TYPE_VIDEO_OVERLAY:
2936 default:
2937 return -EINVAL;
2938 }
2939
2940 return 0;
2941}
2942
2943static int vino_v4l2_s_fmt(struct vino_channel_settings *vcs,
2944 struct v4l2_format *f)
2945{
2946 int data_format;
2947
2948 switch (f->type) {
2949 case V4L2_BUF_TYPE_VIDEO_CAPTURE: {
2950 struct v4l2_pix_format *pf = &f->fmt.pix;
2951 spin_lock(&vino_drvdata->input_lock);
2952
2953 if (!vino_is_input_owner(vcs)) {
2954 spin_unlock(&vino_drvdata->input_lock);
2955 return -EINVAL;
2956 }
2957
2958 data_format = vino_find_data_format(pf->pixelformat);
2959 if (data_format == VINO_DATA_FMT_NONE) {
2960 vcs->data_format = VINO_DATA_FMT_RGB32;
2961 pf->pixelformat =
2962 vino_data_formats[vcs->data_format].
2963 pixelformat;
2964 } else {
2965 vcs->data_format = data_format;
2966 }
2967
2968 /* data format must be set before clipping/scaling */
2969 vino_set_scaling(vcs, pf->width, pf->height);
2970
2971 dprintk("data format = %s\n",
2972 vino_data_formats[vcs->data_format].description);
2973
2974 pf->width = vcs->clipping.right - vcs->clipping.left;
2975 pf->height = vcs->clipping.bottom - vcs->clipping.top;
2976
2977 pf->field = V4L2_FIELD_INTERLACED;
2978 pf->bytesperline = vcs->line_size;
2979 pf->sizeimage = vcs->line_size *
2980 (vcs->clipping.bottom - vcs->clipping.top) /
2981 vcs->decimation;
2982 pf->colorspace =
2983 vino_data_formats[vcs->data_format].colorspace;
2984
2985 pf->priv = 0;
2986
2987 spin_unlock(&vino_drvdata->input_lock);
2988 break;
2989 }
2990 case V4L2_BUF_TYPE_VIDEO_OVERLAY:
2991 default:
2992 return -EINVAL;
2993 }
2994
2995 return 0;
2996}
2997
2998static int vino_v4l2_cropcap(struct vino_channel_settings *vcs,
2999 struct v4l2_cropcap *ccap)
3000{
3001 const struct vino_data_norm *norm;
3002
3003 switch (ccap->type) {
3004 case V4L2_BUF_TYPE_VIDEO_CAPTURE:
3005 spin_lock(&vino_drvdata->input_lock);
3006 norm = &vino_data_norms[vcs->data_norm];
3007 spin_unlock(&vino_drvdata->input_lock);
3008
3009 ccap->bounds.left = 0;
3010 ccap->bounds.top = 0;
3011 ccap->bounds.width = norm->width;
3012 ccap->bounds.height = norm->height;
3013 memcpy(&ccap->defrect, &ccap->bounds,
3014 sizeof(struct v4l2_rect));
3015
3016 ccap->pixelaspect.numerator = 1;
3017 ccap->pixelaspect.denominator = 1;
3018 break;
3019 case V4L2_BUF_TYPE_VIDEO_OVERLAY:
3020 default:
3021 return -EINVAL;
3022 }
3023
3024 return 0;
3025}
3026
3027static int vino_v4l2_g_crop(struct vino_channel_settings *vcs,
3028 struct v4l2_crop *c)
3029{
3030 switch (c->type) {
3031 case V4L2_BUF_TYPE_VIDEO_CAPTURE:
3032 spin_lock(&vino_drvdata->input_lock);
3033
3034 c->c.left = vcs->clipping.left;
3035 c->c.top = vcs->clipping.top;
3036 c->c.width = vcs->clipping.right - vcs->clipping.left;
3037 c->c.height = vcs->clipping.bottom - vcs->clipping.top;
3038
3039 spin_unlock(&vino_drvdata->input_lock);
3040 break;
3041 case V4L2_BUF_TYPE_VIDEO_OVERLAY:
3042 default:
3043 return -EINVAL;
3044 }
3045
3046 return 0;
3047}
3048
3049static int vino_v4l2_s_crop(struct vino_channel_settings *vcs,
3050 struct v4l2_crop *c)
3051{
3052 switch (c->type) {
3053 case V4L2_BUF_TYPE_VIDEO_CAPTURE:
3054 spin_lock(&vino_drvdata->input_lock);
3055
3056 if (!vino_is_input_owner(vcs)) {
3057 spin_unlock(&vino_drvdata->input_lock);
3058 return -EINVAL;
3059 }
3060 vino_set_clipping(vcs, c->c.left, c->c.top,
3061 c->c.width, c->c.height);
3062
3063 spin_unlock(&vino_drvdata->input_lock);
3064 break;
3065 case V4L2_BUF_TYPE_VIDEO_OVERLAY:
3066 default:
3067 return -EINVAL;
3068 }
3069
3070 return 0;
3071}
3072
3073static int vino_v4l2_g_parm(struct vino_channel_settings *vcs,
3074 struct v4l2_streamparm *sp)
3075{
3076 switch (sp->type) {
3077 case V4L2_BUF_TYPE_VIDEO_CAPTURE: {
3078 struct v4l2_captureparm *cp = &sp->parm.capture;
3079 memset(cp, 0, sizeof(struct v4l2_captureparm));
3080
3081 cp->capability = V4L2_CAP_TIMEPERFRAME;
3082 cp->timeperframe.numerator = 1;
3083
3084 spin_lock(&vino_drvdata->input_lock);
3085 cp->timeperframe.denominator = vcs->fps;
3086 spin_unlock(&vino_drvdata->input_lock);
3087
3088 // TODO: cp->readbuffers = xxx;
3089 break;
3090 }
3091 case V4L2_BUF_TYPE_VIDEO_OVERLAY:
3092 default:
3093 return -EINVAL;
3094 }
3095
3096 return 0;
3097}
3098
3099static int vino_v4l2_s_parm(struct vino_channel_settings *vcs,
3100 struct v4l2_streamparm *sp)
3101{
3102 switch (sp->type) {
3103 case V4L2_BUF_TYPE_VIDEO_CAPTURE: {
3104 struct v4l2_captureparm *cp = &sp->parm.capture;
3105
3106 spin_lock(&vino_drvdata->input_lock);
3107 if (!vino_is_input_owner(vcs)) {
3108 spin_unlock(&vino_drvdata->input_lock);
3109 return -EINVAL;
3110 }
3111
3112 if ((cp->timeperframe.numerator == 0) ||
3113 (cp->timeperframe.denominator == 0)) {
3114 /* reset framerate */
3115 vino_set_default_framerate(vcs);
3116 } else {
3117 vino_set_framerate(vcs, cp->timeperframe.denominator /
3118 cp->timeperframe.numerator);
3119 }
3120 spin_unlock(&vino_drvdata->input_lock);
3121
3122 // TODO: set buffers according to cp->readbuffers
3123 break;
3124 }
3125 case V4L2_BUF_TYPE_VIDEO_OVERLAY:
3126 default:
3127 return -EINVAL;
3128 }
3129
3130 return 0;
3131}
3132
3133static int vino_v4l2_reqbufs(struct vino_channel_settings *vcs,
3134 struct v4l2_requestbuffers *rb)
3135{
3136 if (vcs->reading)
3137 return -EBUSY;
3138
3139 switch (rb->type) {
3140 case V4L2_BUF_TYPE_VIDEO_CAPTURE: {
3141 // TODO: check queue type
3142 if (rb->memory != V4L2_MEMORY_MMAP) {
3143 dprintk("type not mmap\n");
3144 return -EINVAL;
3145 }
3146
3147 if (vino_is_capturing(vcs)) {
3148 dprintk("busy, capturing\n");
3149 return -EBUSY;
3150 }
3151
3152 dprintk("count = %d\n", rb->count);
3153 if (rb->count > 0) {
3154 if (vino_queue_has_mapped_buffers(&vcs->fb_queue)) {
3155 dprintk("busy, buffers still mapped\n");
3156 return -EBUSY;
3157 } else {
3158 vino_queue_free(&vcs->fb_queue);
3159 vino_queue_init(&vcs->fb_queue, &rb->count);
3160 }
3161 } else {
3162 vino_capture_stop(vcs);
3163 vino_queue_free(&vcs->fb_queue);
3164 }
3165 break;
3166 }
3167 case V4L2_BUF_TYPE_VIDEO_OVERLAY:
3168 default:
3169 return -EINVAL;
3170 }
3171
3172 return 0;
3173}
3174
3175static void vino_v4l2_get_buffer_status(struct vino_channel_settings *vcs,
3176 struct vino_framebuffer *fb,
3177 struct v4l2_buffer *b)
3178{
3179 if (vino_queue_outgoing_contains(&vcs->fb_queue,
3180 fb->id)) {
3181 b->flags &= ~V4L2_BUF_FLAG_QUEUED;
3182 b->flags |= V4L2_BUF_FLAG_DONE;
3183 } else if (vino_queue_incoming_contains(&vcs->fb_queue,
3184 fb->id)) {
3185 b->flags &= ~V4L2_BUF_FLAG_DONE;
3186 b->flags |= V4L2_BUF_FLAG_QUEUED;
3187 } else {
3188 b->flags &= ~(V4L2_BUF_FLAG_DONE |
3189 V4L2_BUF_FLAG_QUEUED);
3190 }
3191
3192 b->flags &= ~(V4L2_BUF_FLAG_TIMECODE);
3193
3194 if (fb->map_count > 0)
3195 b->flags |= V4L2_BUF_FLAG_MAPPED;
3196
3197 b->index = fb->id;
3198 b->memory = (vcs->fb_queue.type == VINO_MEMORY_MMAP) ?
3199 V4L2_MEMORY_MMAP : V4L2_MEMORY_USERPTR;
3200 b->m.offset = fb->offset;
3201 b->bytesused = fb->data_size;
3202 b->length = fb->size;
3203 b->field = V4L2_FIELD_INTERLACED;
3204 b->sequence = fb->frame_counter;
3205 memcpy(&b->timestamp, &fb->timestamp,
3206 sizeof(struct timeval));
3207 // b->input ?
3208
3209 dprintk("buffer %d: length = %d, bytesused = %d, offset = %d\n",
3210 fb->id, fb->size, fb->data_size, fb->offset);
3211}
3212
3213static int vino_v4l2_querybuf(struct vino_channel_settings *vcs,
3214 struct v4l2_buffer *b)
3215{
3216 if (vcs->reading)
3217 return -EBUSY;
3218
3219 switch (b->type) {
3220 case V4L2_BUF_TYPE_VIDEO_CAPTURE: {
3221 struct vino_framebuffer *fb;
3222
3223 // TODO: check queue type
3224 if (b->index >= vino_queue_get_length(&vcs->fb_queue)) {
3225 dprintk("invalid index = %d\n",
3226 b->index);
3227 return -EINVAL;
3228 }
3229
3230 fb = vino_queue_get_buffer(&vcs->fb_queue,
3231 b->index);
3232 if (fb == NULL) {
3233 dprintk("vino_queue_get_buffer() failed");
3234 return -EINVAL;
3235 }
3236
3237 vino_v4l2_get_buffer_status(vcs, fb, b);
3238 break;
3239 }
3240 case V4L2_BUF_TYPE_VIDEO_OVERLAY:
3241 default:
3242 return -EINVAL;
3243 }
3244
3245 return 0;
3246}
3247
3248static int vino_v4l2_qbuf(struct vino_channel_settings *vcs,
3249 struct v4l2_buffer *b)
3250{
3251 if (vcs->reading)
3252 return -EBUSY;
3253
3254 switch (b->type) {
3255 case V4L2_BUF_TYPE_VIDEO_CAPTURE: {
3256 struct vino_framebuffer *fb;
3257 int ret;
3258
3259 // TODO: check queue type
3260 if (b->memory != V4L2_MEMORY_MMAP) {
3261 dprintk("type not mmap\n");
3262 return -EINVAL;
3263 }
3264
3265 fb = vino_capture_enqueue(vcs, b->index);
3266 if (fb == NULL)
3267 return -EINVAL;
3268
3269 vino_v4l2_get_buffer_status(vcs, fb, b);
3270
3271 if (vcs->streaming) {
3272 ret = vino_capture_next(vcs, 1);
3273 if (ret)
3274 return ret;
3275 }
3276 break;
3277 }
3278 case V4L2_BUF_TYPE_VIDEO_OVERLAY:
3279 default:
3280 return -EINVAL;
3281 }
3282
3283 return 0;
3284}
3285
3286static int vino_v4l2_dqbuf(struct vino_channel_settings *vcs,
3287 struct v4l2_buffer *b,
3288 unsigned int nonblocking)
3289{
3290 if (vcs->reading)
3291 return -EBUSY;
3292
3293 switch (b->type) {
3294 case V4L2_BUF_TYPE_VIDEO_CAPTURE: {
3295 struct vino_framebuffer *fb;
3296 unsigned int incoming, outgoing;
3297 int err;
3298
3299 // TODO: check queue type
3300
3301 err = vino_queue_get_incoming(&vcs->fb_queue, &incoming);
3302 if (err) {
3303 dprintk("vino_queue_get_incoming() failed\n");
3304 return -EIO;
3305 }
3306 err = vino_queue_get_outgoing(&vcs->fb_queue, &outgoing);
3307 if (err) {
3308 dprintk("vino_queue_get_outgoing() failed\n");
3309 return -EIO;
3310 }
3311
3312 dprintk("incoming = %d, outgoing = %d\n", incoming, outgoing);
3313
3314 if (outgoing == 0) {
3315 if (incoming == 0) {
3316 dprintk("no incoming or outgoing buffers\n");
3317 return -EINVAL;
3318 }
3319 if (nonblocking) {
3320 dprintk("non-blocking I/O was selected and "
3321 "there are no buffers to dequeue\n");
3322 return -EAGAIN;
3323 }
3324
3325 err = vino_wait_for_frame(vcs);
3326 if (err) {
3327 err = vino_wait_for_frame(vcs);
3328 if (err) {
3329 /* interrupted */
3330 vino_capture_failed(vcs);
3331 return -EIO;
3332 }
3333 }
3334 }
3335
3336 fb = vino_queue_remove(&vcs->fb_queue, &b->index);
3337 if (fb == NULL) {
3338 dprintk("vino_queue_remove() failed\n");
3339 return -EINVAL;
3340 }
3341
3342 err = vino_check_buffer(vcs, fb);
3343 if (err)
3344 return -EIO;
3345
3346 vino_v4l2_get_buffer_status(vcs, fb, b);
3347 break;
3348 }
3349 case V4L2_BUF_TYPE_VIDEO_OVERLAY:
3350 default:
3351 return -EINVAL;
3352 }
3353
3354 return 0;
3355}
3356
3357static int vino_v4l2_streamon(struct vino_channel_settings *vcs)
3358{
3359 unsigned int incoming;
3360 int ret;
3361 if (vcs->reading)
3362 return -EBUSY;
3363
3364 if (vcs->streaming)
3365 return 0;
3366
3367 // TODO: check queue type
3368
3369 if (vino_queue_get_length(&vcs->fb_queue) < 1) {
3370 dprintk("no buffers allocated\n");
3371 return -EINVAL;
3372 }
3373
3374 ret = vino_queue_get_incoming(&vcs->fb_queue, &incoming);
3375 if (ret) {
3376 dprintk("vino_queue_get_incoming() failed\n");
3377 return -EINVAL;
3378 }
3379
3380 vcs->streaming = 1;
3381
3382 if (incoming > 0) {
3383 ret = vino_capture_next(vcs, 1);
3384 if (ret) {
3385 vcs->streaming = 0;
3386
3387 dprintk("couldn't start capture\n");
3388 return -EINVAL;
3389 }
3390 }
3391
3392 return 0;
3393}
3394
3395static int vino_v4l2_streamoff(struct vino_channel_settings *vcs)
3396{
3397 if (vcs->reading)
3398 return -EBUSY;
3399
3400 if (!vcs->streaming)
3401 return 0;
3402
3403 vino_capture_stop(vcs);
3404 vcs->streaming = 0;
3405
3406 return 0;
3407}
3408
3409static int vino_v4l2_queryctrl(struct vino_channel_settings *vcs,
3410 struct v4l2_queryctrl *queryctrl)
3411{
3412 int i;
3413 int err = 0;
3414
3415 spin_lock(&vino_drvdata->input_lock);
3416
3417 switch (vcs->input) {
3418 case VINO_INPUT_D1:
3419 for (i = 0; i < VINO_INDYCAM_V4L2_CONTROL_COUNT; i++) {
3420 if (vino_indycam_v4l2_controls[i].id ==
3421 queryctrl->id) {
3422 memcpy(queryctrl,
3423 &vino_indycam_v4l2_controls[i],
3424 sizeof(struct v4l2_queryctrl));
3425 goto found;
3426 }
3427 }
3428
3429 err = -EINVAL;
3430 break;
3431 case VINO_INPUT_COMPOSITE:
3432 case VINO_INPUT_SVIDEO:
3433 for (i = 0; i < VINO_SAA7191_V4L2_CONTROL_COUNT; i++) {
3434 if (vino_saa7191_v4l2_controls[i].id ==
3435 queryctrl->id) {
3436 memcpy(queryctrl,
3437 &vino_saa7191_v4l2_controls[i],
3438 sizeof(struct v4l2_queryctrl));
3439 goto found;
3440 }
3441 }
3442
3443 err = -EINVAL;
3444 break;
3445 default:
3446 err = -EINVAL;
3447 }
3448
3449 found:
3450 spin_unlock(&vino_drvdata->input_lock);
3451
3452 return err;
3453}
3454
3455static int vino_v4l2_g_ctrl(struct vino_channel_settings *vcs,
3456 struct v4l2_control *control)
3457{
3458 struct indycam_control indycam_ctrl;
3459 struct saa7191_control saa7191_ctrl;
3460 int err = 0;
3461
3462 spin_lock(&vino_drvdata->input_lock);
3463
3464 switch (vcs->input) {
3465 case VINO_INPUT_D1:
3466 i2c_camera_command(DECODER_INDYCAM_GET_CONTROLS,
3467 &indycam_ctrl);
3468
3469 switch(control->id) {
3470 case V4L2_CID_AUTOGAIN:
3471 control->value = indycam_ctrl.agc;
3472 break;
3473 case V4L2_CID_AUTO_WHITE_BALANCE:
3474 control->value = indycam_ctrl.awb;
3475 break;
3476 case V4L2_CID_GAIN:
3477 control->value = indycam_ctrl.gain;
3478 break;
3479 case V4L2_CID_PRIVATE_BASE:
3480 control->value = indycam_ctrl.red_saturation;
3481 break;
3482 case V4L2_CID_PRIVATE_BASE + 1:
3483 control->value = indycam_ctrl.blue_saturation;
3484 break;
3485 case V4L2_CID_RED_BALANCE:
3486 control->value = indycam_ctrl.red_balance;
3487 break;
3488 case V4L2_CID_BLUE_BALANCE:
3489 control->value = indycam_ctrl.blue_balance;
3490 break;
3491 case V4L2_CID_EXPOSURE:
3492 control->value = indycam_ctrl.shutter;
3493 break;
3494 case V4L2_CID_GAMMA:
3495 control->value = indycam_ctrl.gamma;
3496 break;
3497 default:
3498 err = -EINVAL;
3499 }
3500 break;
3501 case VINO_INPUT_COMPOSITE:
3502 case VINO_INPUT_SVIDEO:
3503 i2c_decoder_command(DECODER_SAA7191_GET_CONTROLS,
3504 &saa7191_ctrl);
3505
3506 switch(control->id) {
3507 case V4L2_CID_HUE:
3508 control->value = saa7191_ctrl.hue;
3509 break;
3510 case V4L2_CID_PRIVATE_BASE:
3511 control->value = saa7191_ctrl.vtrc;
3512 break;
3513 default:
3514 err = -EINVAL;
3515 }
3516 break;
3517 default:
3518 err = -EINVAL;
3519 }
3520
3521 spin_unlock(&vino_drvdata->input_lock);
3522
3523 return err;
3524}
3525
3526static int vino_v4l2_s_ctrl(struct vino_channel_settings *vcs,
3527 struct v4l2_control *control)
3528{
3529 struct indycam_control indycam_ctrl;
3530 struct saa7191_control saa7191_ctrl;
3531 int i;
3532 int err = 0;
3533
3534 spin_lock(&vino_drvdata->input_lock);
3535
3536 switch (vcs->input) {
3537 case VINO_INPUT_D1:
3538 for (i = 0; i < VINO_INDYCAM_V4L2_CONTROL_COUNT; i++) {
3539 if (vino_indycam_v4l2_controls[i].id ==
3540 control->id) {
3541 if ((control->value >=
3542 vino_indycam_v4l2_controls[i].minimum)
3543 && (control->value <=
3544 vino_indycam_v4l2_controls[i].
3545 maximum)) {
3546 goto ok1;
3547 } else {
3548 err = -ERANGE;
3549 goto error;
3550 }
3551 }
3552 }
3553 err = -EINVAL;
3554 goto error;
3555
3556ok1:
3557 indycam_ctrl.agc = INDYCAM_VALUE_UNCHANGED;
3558 indycam_ctrl.awb = INDYCAM_VALUE_UNCHANGED;
3559 indycam_ctrl.shutter = INDYCAM_VALUE_UNCHANGED;
3560 indycam_ctrl.gain = INDYCAM_VALUE_UNCHANGED;
3561 indycam_ctrl.red_balance = INDYCAM_VALUE_UNCHANGED;
3562 indycam_ctrl.blue_balance = INDYCAM_VALUE_UNCHANGED;
3563 indycam_ctrl.red_saturation = INDYCAM_VALUE_UNCHANGED;
3564 indycam_ctrl.blue_saturation = INDYCAM_VALUE_UNCHANGED;
3565 indycam_ctrl.gamma = INDYCAM_VALUE_UNCHANGED;
3566
3567 switch(control->id) {
3568 case V4L2_CID_AUTOGAIN:
3569 indycam_ctrl.agc = control->value;
3570 break;
3571 case V4L2_CID_AUTO_WHITE_BALANCE:
3572 indycam_ctrl.awb = control->value;
3573 break;
3574 case V4L2_CID_GAIN:
3575 indycam_ctrl.gain = control->value;
3576 break;
3577 case V4L2_CID_PRIVATE_BASE:
3578 indycam_ctrl.red_saturation = control->value;
3579 break;
3580 case V4L2_CID_PRIVATE_BASE + 1:
3581 indycam_ctrl.blue_saturation = control->value;
3582 break;
3583 case V4L2_CID_RED_BALANCE:
3584 indycam_ctrl.red_balance = control->value;
3585 break;
3586 case V4L2_CID_BLUE_BALANCE:
3587 indycam_ctrl.blue_balance = control->value;
3588 break;
3589 case V4L2_CID_EXPOSURE:
3590 indycam_ctrl.shutter = control->value;
3591 break;
3592 case V4L2_CID_GAMMA:
3593 indycam_ctrl.gamma = control->value;
3594 break;
3595 default:
3596 err = -EINVAL;
3597 }
3598
3599 if (!err)
3600 i2c_camera_command(DECODER_INDYCAM_SET_CONTROLS,
3601 &indycam_ctrl);
3602 break;
3603 case VINO_INPUT_COMPOSITE:
3604 case VINO_INPUT_SVIDEO:
3605 for (i = 0; i < VINO_SAA7191_V4L2_CONTROL_COUNT; i++) {
3606 if (vino_saa7191_v4l2_controls[i].id ==
3607 control->id) {
3608 if ((control->value >=
3609 vino_saa7191_v4l2_controls[i].minimum)
3610 && (control->value <=
3611 vino_saa7191_v4l2_controls[i].
3612 maximum)) {
3613 goto ok2;
3614 } else {
3615 err = -ERANGE;
3616 goto error;
3617 }
3618 }
3619 }
3620 err = -EINVAL;
3621 goto error;
3622
3623ok2:
3624 saa7191_ctrl.hue = SAA7191_VALUE_UNCHANGED;
3625 saa7191_ctrl.vtrc = SAA7191_VALUE_UNCHANGED;
3626
3627 switch(control->id) {
3628 case V4L2_CID_HUE:
3629 saa7191_ctrl.hue = control->value;
3630 break;
3631 case V4L2_CID_PRIVATE_BASE:
3632 saa7191_ctrl.vtrc = control->value;
3633 break;
3634 default:
3635 err = -EINVAL;
3636 }
3637
3638 if (!err)
3639 i2c_decoder_command(DECODER_SAA7191_SET_CONTROLS,
3640 &saa7191_ctrl);
3641 break;
3642 default:
3643 err = -EINVAL;
3644 }
3645
3646error:
3647 spin_unlock(&vino_drvdata->input_lock);
3648
3649 return err;
3650}
3651
3652/* File operations */
3653
3654static int vino_open(struct inode *inode, struct file *file)
3655{
3656 struct video_device *dev = video_devdata(file);
3657 struct vino_channel_settings *vcs = video_get_drvdata(dev);
3658 int ret = 0;
3659 dprintk("open(): channel = %c\n",
3660 (vcs->channel == VINO_CHANNEL_A) ? 'A' : 'B');
3661
3662 down(&vcs->sem);
3663
3664 if (vcs->users) {
3665 dprintk("open(): driver busy\n");
3666 ret = -EBUSY;
3667 goto out;
3668 }
3669
3670 ret = vino_acquire_input(vcs);
3671 if (ret) {
3672 dprintk("open(): vino_acquire_input() failed\n");
3673 goto out;
3674 }
3675
3676 vcs->users++;
3677
3678 out:
3679 up(&vcs->sem);
3680
3681 dprintk("open(): %s!\n", ret ? "failed" : "complete");
3682
3683 return ret;
3684}
3685
3686static int vino_close(struct inode *inode, struct file *file)
3687{
3688 struct video_device *dev = video_devdata(file);
3689 struct vino_channel_settings *vcs = video_get_drvdata(dev);
3690 dprintk("close():\n");
3691
3692 down(&vcs->sem);
3693
3694 vcs->users--;
3695
3696 if (!vcs->users) {
3697 vino_release_input(vcs);
3698
3699 /* stop DMA and free buffers */
3700 vino_capture_stop(vcs);
3701 vino_queue_free(&vcs->fb_queue);
3702 }
3703
3704 up(&vcs->sem);
3705
3706 return 0;
3707}
3708
3709static void vino_vm_open(struct vm_area_struct *vma)
3710{
3711 struct vino_framebuffer *fb = vma->vm_private_data;
3712
3713 fb->map_count++;
3714 dprintk("vino_vm_open(): count = %d\n", fb->map_count);
3715}
3716
3717static void vino_vm_close(struct vm_area_struct *vma)
3718{
3719 struct vino_framebuffer *fb = vma->vm_private_data;
3720
3721 fb->map_count--;
3722 dprintk("vino_vm_close(): count = %d\n", fb->map_count);
3723}
3724
3725static struct vm_operations_struct vino_vm_ops = {
3726 .open = vino_vm_open,
3727 .close = vino_vm_close,
3728};
3729
3730static int vino_mmap(struct file *file, struct vm_area_struct *vma)
3731{
3732 struct video_device *dev = video_devdata(file);
3733 struct vino_channel_settings *vcs = video_get_drvdata(dev);
3734
3735 unsigned long start = vma->vm_start;
3736 unsigned long size = vma->vm_end - vma->vm_start;
3737 unsigned long offset = vma->vm_pgoff << PAGE_SHIFT;
3738
3739 struct vino_framebuffer *fb = NULL;
3740 unsigned int i, length;
3741 int ret = 0;
3742
3743 dprintk("mmap():\n");
3744
3745 // TODO: reject mmap if already mapped
3746
3747 if (down_interruptible(&vcs->sem))
3748 return -EINTR;
3749
3750 if (vcs->reading) {
3751 ret = -EBUSY;
3752 goto out;
3753 }
3754
3755 // TODO: check queue type
3756
3757 if (!(vma->vm_flags & VM_WRITE)) {
3758 dprintk("mmap(): app bug: PROT_WRITE please\n");
3759 ret = -EINVAL;
3760 goto out;
3761 }
3762 if (!(vma->vm_flags & VM_SHARED)) {
3763 dprintk("mmap(): app bug: MAP_SHARED please\n");
3764 ret = -EINVAL;
3765 goto out;
3766 }
3767
3768 /* find the correct buffer using offset */
3769 length = vino_queue_get_length(&vcs->fb_queue);
3770 if (length == 0) {
3771 dprintk("mmap(): queue not initialized\n");
3772 ret = -EINVAL;
3773 goto out;
3774 }
3775
3776 for (i = 0; i < length; i++) {
3777 fb = vino_queue_get_buffer(&vcs->fb_queue, i);
3778 if (fb == NULL) {
3779 dprintk("mmap(): vino_queue_get_buffer() failed\n");
3780 ret = -EINVAL;
3781 goto out;
3782 }
3783
3784 if (fb->offset == offset)
3785 goto found;
3786 }
3787
3788 dprintk("mmap(): invalid offset = %lu\n", offset);
3789 ret = -EINVAL;
3790 goto out;
3791
3792found:
3793 dprintk("mmap(): buffer = %d\n", i);
3794
3795 if (size > (fb->desc_table.page_count * PAGE_SIZE)) {
3796 dprintk("mmap(): failed: size = %lu > %lu\n",
3797 size, fb->desc_table.page_count * PAGE_SIZE);
3798 ret = -EINVAL;
3799 goto out;
3800 }
3801
3802 for (i = 0; i < fb->desc_table.page_count; i++) {
3803 unsigned long pfn =
3804 virt_to_phys((void *)fb->desc_table.virtual[i]) >>
3805 PAGE_SHIFT;
3806
3807 if (size < PAGE_SIZE)
3808 break;
3809
3810 // protection was: PAGE_READONLY
3811 if (remap_pfn_range(vma, start, pfn, PAGE_SIZE,
3812 vma->vm_page_prot)) {
3813 dprintk("mmap(): remap_pfn_range() failed\n");
3814 ret = -EAGAIN;
3815 goto out;
3816 }
3817
3818 start += PAGE_SIZE;
3819 size -= PAGE_SIZE;
3820 }
3821
3822 fb->map_count = 1;
3823
3824 vma->vm_flags |= VM_DONTEXPAND | VM_RESERVED;
3825 vma->vm_flags &= ~VM_IO;
3826 vma->vm_private_data = fb;
3827 vma->vm_file = file;
3828 vma->vm_ops = &vino_vm_ops;
3829
3830out:
3831 up(&vcs->sem);
3832
3833 return ret;
3834}
3835
3836static unsigned int vino_poll(struct file *file, poll_table *pt)
3837{
3838 struct video_device *dev = video_devdata(file);
3839 struct vino_channel_settings *vcs = video_get_drvdata(dev);
3840 unsigned int outgoing;
3841 unsigned int ret = 0;
3842
3843 // lock mutex (?)
3844 // TODO: this has to be corrected for different read modes
3845
3846 dprintk("poll():\n");
3847
3848 if (vino_queue_get_outgoing(&vcs->fb_queue, &outgoing)) {
3849 dprintk("poll(): vino_queue_get_outgoing() failed\n");
3850 ret = POLLERR;
3851 goto error;
3852 }
3853 if (outgoing > 0)
3854 goto over;
3855
3856 poll_wait(file, &vcs->fb_queue.frame_wait_queue, pt);
3857
3858 if (vino_queue_get_outgoing(&vcs->fb_queue, &outgoing)) {
3859 dprintk("poll(): vino_queue_get_outgoing() failed\n");
3860 ret = POLLERR;
3861 goto error;
3862 }
3863
3864over:
3865 dprintk("poll(): data %savailable\n",
3866 (outgoing > 0) ? "" : "not ");
3867 if (outgoing > 0) {
3868 ret = POLLIN | POLLRDNORM;
3869 }
3870
3871error:
3872
3873 return ret;
3874}
3875
3876static int vino_do_ioctl(struct inode *inode, struct file *file,
3877 unsigned int cmd, void *arg)
3878{
3879 struct video_device *dev = video_devdata(file);
3880 struct vino_channel_settings *vcs = video_get_drvdata(dev);
3881
3882 switch (_IOC_TYPE(cmd)) {
3883 case 'v':
3884 dprintk("ioctl(): V4L1 unsupported (0x%08x)\n", cmd);
3885 break;
3886 case 'V':
3887 dprintk("ioctl(): V4L2 %s (0x%08x)\n",
3888 v4l2_ioctl_names[_IOC_NR(cmd)], cmd);
3889 break;
3890 default:
3891 dprintk("ioctl(): unsupported command 0x%08x\n", cmd);
3892 }
3893
3894 switch (cmd) {
3895 /* TODO: V4L1 interface (use compatibility layer?) */
3896 /* V4L2 interface */
3897 case VIDIOC_QUERYCAP: {
3898 vino_v4l2_querycap(arg);
3899 break;
3900 }
3901 case VIDIOC_ENUMINPUT: {
3902 return vino_v4l2_enuminput(vcs, arg);
3903 }
3904 case VIDIOC_G_INPUT: {
3905 return vino_v4l2_g_input(vcs, arg);
3906 }
3907 case VIDIOC_S_INPUT: {
3908 return vino_v4l2_s_input(vcs, arg);
3909 }
3910 case VIDIOC_ENUMSTD: {
3911 return vino_v4l2_enumstd(vcs, arg);
3912 }
3913 case VIDIOC_G_STD: {
3914 return vino_v4l2_g_std(vcs, arg);
3915 }
3916 case VIDIOC_S_STD: {
3917 return vino_v4l2_s_std(vcs, arg);
3918 }
3919 case VIDIOC_ENUM_FMT: {
3920 return vino_v4l2_enum_fmt(vcs, arg);
3921 }
3922 case VIDIOC_TRY_FMT: {
3923 return vino_v4l2_try_fmt(vcs, arg);
3924 }
3925 case VIDIOC_G_FMT: {
3926 return vino_v4l2_g_fmt(vcs, arg);
3927 }
3928 case VIDIOC_S_FMT: {
3929 return vino_v4l2_s_fmt(vcs, arg);
3930 }
3931 case VIDIOC_CROPCAP: {
3932 return vino_v4l2_cropcap(vcs, arg);
3933 }
3934 case VIDIOC_G_CROP: {
3935 return vino_v4l2_g_crop(vcs, arg);
3936 }
3937 case VIDIOC_S_CROP: {
3938 return vino_v4l2_s_crop(vcs, arg);
3939 }
3940 case VIDIOC_G_PARM: {
3941 return vino_v4l2_g_parm(vcs, arg);
3942 }
3943 case VIDIOC_S_PARM: {
3944 return vino_v4l2_s_parm(vcs, arg);
3945 }
3946 case VIDIOC_REQBUFS: {
3947 return vino_v4l2_reqbufs(vcs, arg);
3948 }
3949 case VIDIOC_QUERYBUF: {
3950 return vino_v4l2_querybuf(vcs, arg);
3951 }
3952 case VIDIOC_QBUF: {
3953 return vino_v4l2_qbuf(vcs, arg);
3954 }
3955 case VIDIOC_DQBUF: {
3956 return vino_v4l2_dqbuf(vcs, arg, file->f_flags & O_NONBLOCK);
3957 }
3958 case VIDIOC_STREAMON: {
3959 return vino_v4l2_streamon(vcs);
3960 }
3961 case VIDIOC_STREAMOFF: {
3962 return vino_v4l2_streamoff(vcs);
3963 }
3964 case VIDIOC_QUERYCTRL: {
3965 return vino_v4l2_queryctrl(vcs, arg);
3966 }
3967 case VIDIOC_G_CTRL: {
3968 return vino_v4l2_g_ctrl(vcs, arg);
3969 }
3970 case VIDIOC_S_CTRL: {
3971 return vino_v4l2_s_ctrl(vcs, arg);
3972 }
3973 default:
3974 return -ENOIOCTLCMD;
3975 }
3976
3977 return 0;
3978}
3979
3980static int vino_ioctl(struct inode *inode, struct file *file,
3981 unsigned int cmd, unsigned long arg)
3982{
3983 struct video_device *dev = video_devdata(file);
3984 struct vino_channel_settings *vcs = video_get_drvdata(dev);
3985 int ret;
3986
3987 if (down_interruptible(&vcs->sem))
3988 return -EINTR;
3989
3990 ret = video_usercopy(inode, file, cmd, arg, vino_do_ioctl);
3991
3992 up(&vcs->sem);
3993
3994 return ret;
3995}
3996
3997/* Initialization and cleanup */
3998
3999// __initdata
4000static int vino_init_stage = 0;
4001
4002static struct file_operations vino_fops = {
212 .owner = THIS_MODULE, 4003 .owner = THIS_MODULE,
213 .type = VID_TYPE_CAPTURE | VID_TYPE_SUBCAPTURE,
214 .hardware = VID_HARDWARE_VINO,
215 .name = "VINO",
216 .open = vino_open, 4004 .open = vino_open,
217 .close = vino_close, 4005 .release = vino_close,
218 .ioctl = vino_ioctl, 4006 .ioctl = vino_ioctl,
219 .mmap = vino_mmap, 4007 .mmap = vino_mmap,
4008 .poll = vino_poll,
4009 .llseek = no_llseek,
220}; 4010};
221 4011
222static int __init vino_init(void) 4012static struct video_device v4l_device_template = {
4013 .name = "NOT SET",
4014 //.type = VID_TYPE_CAPTURE | VID_TYPE_SUBCAPTURE |
4015 // VID_TYPE_CLIPPING | VID_TYPE_SCALES, VID_TYPE_OVERLAY
4016 .hardware = VID_HARDWARE_VINO,
4017 .fops = &vino_fops,
4018 .minor = -1,
4019};
4020
4021static void vino_module_cleanup(int stage)
4022{
4023 switch(stage) {
4024 case 10:
4025 video_unregister_device(vino_drvdata->b.v4l_device);
4026 vino_drvdata->b.v4l_device = NULL;
4027 case 9:
4028 video_unregister_device(vino_drvdata->a.v4l_device);
4029 vino_drvdata->a.v4l_device = NULL;
4030 case 8:
4031 vino_i2c_del_bus();
4032 case 7:
4033 free_irq(SGI_VINO_IRQ, NULL);
4034 case 6:
4035 if (vino_drvdata->b.v4l_device) {
4036 video_device_release(vino_drvdata->b.v4l_device);
4037 vino_drvdata->b.v4l_device = NULL;
4038 }
4039 case 5:
4040 if (vino_drvdata->a.v4l_device) {
4041 video_device_release(vino_drvdata->a.v4l_device);
4042 vino_drvdata->a.v4l_device = NULL;
4043 }
4044 case 4:
4045 /* all entries in dma_cpu dummy table have the same address */
4046 dma_unmap_single(NULL,
4047 vino_drvdata->dummy_desc_table.dma_cpu[0],
4048 PAGE_SIZE, DMA_FROM_DEVICE);
4049 dma_free_coherent(NULL, VINO_DUMMY_DESC_COUNT
4050 * sizeof(dma_addr_t),
4051 (void *)vino_drvdata->
4052 dummy_desc_table.dma_cpu,
4053 vino_drvdata->dummy_desc_table.dma);
4054 case 3:
4055 free_page(vino_drvdata->dummy_page);
4056 case 2:
4057 kfree(vino_drvdata);
4058 case 1:
4059 iounmap(vino);
4060 case 0:
4061 break;
4062 default:
4063 dprintk("vino_module_cleanup(): invalid cleanup stage = %d\n",
4064 stage);
4065 }
4066}
4067
4068static int vino_probe(void)
223{ 4069{
224 unsigned long rev; 4070 unsigned long rev_id;
225 int i, ret = 0;
226 4071
227 /* VINO is Indy specific beast */ 4072 if (ip22_is_fullhouse()) {
228 if (ip22_is_fullhouse()) 4073 printk(KERN_ERR "VINO doesn't exist in IP22 Fullhouse\n");
229 return -ENODEV; 4074 return -ENODEV;
4075 }
230 4076
231 /*
232 * VINO is in the EISA address space, so the sysid register will tell
233 * us if the EISA_PRESENT pin on MC has been pulled low.
234 *
235 * If EISA_PRESENT is not set we definitely don't have a VINO equiped
236 * system.
237 */
238 if (!(sgimc->systemid & SGIMC_SYSID_EPRESENT)) { 4077 if (!(sgimc->systemid & SGIMC_SYSID_EPRESENT)) {
239 printk(KERN_ERR "VINO not found\n"); 4078 printk(KERN_ERR "VINO is not found (EISA BUS not present)\n");
240 return -ENODEV; 4079 return -ENODEV;
241 } 4080 }
242 4081
243 vino = (struct sgi_vino *)ioremap(VINO_BASE, sizeof(struct sgi_vino)); 4082 vino = (struct sgi_vino *)ioremap(VINO_BASE, sizeof(struct sgi_vino));
244 if (!vino) 4083 if (!vino) {
4084 printk(KERN_ERR "VINO: ioremap() failed\n");
245 return -EIO; 4085 return -EIO;
4086 }
4087 vino_init_stage++;
246 4088
247 /* Okay, once we know that VINO is present we'll read its revision 4089 if (get_dbe(rev_id, &(vino->rev_id))) {
248 * safe way. One never knows... */ 4090 printk(KERN_ERR "Failed to read VINO revision register\n");
249 if (get_dbe(rev, &(vino->rev_id))) { 4091 vino_module_cleanup(vino_init_stage);
250 printk(KERN_ERR "VINO: failed to read revision register\n"); 4092 return -ENODEV;
251 ret = -ENODEV;
252 goto out_unmap;
253 } 4093 }
254 if (VINO_ID_VALUE(rev) != VINO_CHIP_ID) { 4094
255 printk(KERN_ERR "VINO is not VINO (Rev/ID: 0x%04lx)\n", rev); 4095 if (VINO_ID_VALUE(rev_id) != VINO_CHIP_ID) {
256 ret = -ENODEV; 4096 printk(KERN_ERR "Unknown VINO chip ID (Rev/ID: 0x%02lx)\n",
257 goto out_unmap; 4097 rev_id);
4098 vino_module_cleanup(vino_init_stage);
4099 return -ENODEV;
258 } 4100 }
259 printk(KERN_INFO "VINO Rev: 0x%02lx\n", VINO_REV_NUM(rev));
260 4101
261 Vino = (struct vino_video *) 4102 printk(KERN_INFO "VINO with chip ID %ld, revision %ld found\n",
262 kmalloc(sizeof(struct vino_video), GFP_KERNEL); 4103 VINO_ID_VALUE(rev_id), VINO_REV_NUM(rev_id));
263 if (!Vino) { 4104
264 ret = -ENOMEM; 4105 return 0;
265 goto out_unmap; 4106}
4107
4108static int vino_init(void)
4109{
4110 dma_addr_t dma_dummy_address;
4111 int i;
4112
4113 vino_drvdata = (struct vino_settings *)
4114 kmalloc(sizeof(struct vino_settings), GFP_KERNEL);
4115 if (!vino_drvdata) {
4116 vino_module_cleanup(vino_init_stage);
4117 return -ENOMEM;
266 } 4118 }
4119 memset(vino_drvdata, 0, sizeof(struct vino_settings));
4120 vino_init_stage++;
267 4121
268 Vino->dummy_page = get_zeroed_page(GFP_KERNEL | GFP_DMA); 4122 /* create a dummy dma descriptor */
269 if (!Vino->dummy_page) { 4123 vino_drvdata->dummy_page = get_zeroed_page(GFP_KERNEL | GFP_DMA);
270 ret = -ENOMEM; 4124 if (!vino_drvdata->dummy_page) {
271 goto out_free_vino; 4125 vino_module_cleanup(vino_init_stage);
4126 return -ENOMEM;
272 } 4127 }
273 for (i = 0; i < 4; i++) 4128 vino_init_stage++;
274 Vino->dummy_buf[i] = PHYSADDR(Vino->dummy_page); 4129
4130 // TODO: use page_count in dummy_desc_table
4131
4132 vino_drvdata->dummy_desc_table.dma_cpu =
4133 dma_alloc_coherent(NULL,
4134 VINO_DUMMY_DESC_COUNT * sizeof(dma_addr_t),
4135 &vino_drvdata->dummy_desc_table.dma,
4136 GFP_KERNEL | GFP_DMA);
4137 if (!vino_drvdata->dummy_desc_table.dma_cpu) {
4138 vino_module_cleanup(vino_init_stage);
4139 return -ENOMEM;
4140 }
4141 vino_init_stage++;
4142
4143 dma_dummy_address = dma_map_single(NULL,
4144 (void *)vino_drvdata->dummy_page,
4145 PAGE_SIZE, DMA_FROM_DEVICE);
4146 for (i = 0; i < VINO_DUMMY_DESC_COUNT; i++) {
4147 vino_drvdata->dummy_desc_table.dma_cpu[i] = dma_dummy_address;
4148 }
4149
4150 /* initialize VINO */
275 4151
276 vino->control = 0; 4152 vino->control = 0;
277 /* prevent VINO from throwing spurious interrupts */ 4153 vino->a.next_4_desc = vino_drvdata->dummy_desc_table.dma;
278 vino->a.next_4_desc = PHYSADDR(Vino->dummy_buf); 4154 vino->b.next_4_desc = vino_drvdata->dummy_desc_table.dma;
279 vino->b.next_4_desc = PHYSADDR(Vino->dummy_buf); 4155 udelay(VINO_DESC_FETCH_DELAY);
280 udelay(5); 4156
281 vino->intr_status = 0; 4157 vino->intr_status = 0;
282 /* set threshold level */
283 vino->a.fifo_thres = threshold_a;
284 vino->b.fifo_thres = threshold_b;
285 4158
286 init_MUTEX(&Vino->input_lock); 4159 vino->a.fifo_thres = VINO_FIFO_THRESHOLD_DEFAULT;
4160 vino->b.fifo_thres = VINO_FIFO_THRESHOLD_DEFAULT;
4161
4162 return 0;
4163}
4164
4165static int vino_init_channel_settings(struct vino_channel_settings *vcs,
4166 unsigned int channel, const char *name)
4167{
4168 vcs->channel = channel;
4169 vcs->input = VINO_INPUT_NONE;
4170 vcs->alpha = 0;
4171 vcs->users = 0;
4172 vcs->data_format = VINO_DATA_FMT_GREY;
4173 vcs->data_norm = VINO_DATA_NORM_NTSC;
4174 vcs->decimation = 1;
4175 vino_set_default_clipping(vcs);
4176 vino_set_default_framerate(vcs);
4177
4178 vcs->capturing = 0;
4179
4180 init_MUTEX(&vcs->sem);
4181 spin_lock_init(&vcs->capture_lock);
4182
4183 init_MUTEX(&vcs->fb_queue.queue_sem);
4184 spin_lock_init(&vcs->fb_queue.queue_lock);
4185 init_waitqueue_head(&vcs->fb_queue.frame_wait_queue);
4186
4187 vcs->v4l_device = video_device_alloc();
4188 if (!vcs->v4l_device) {
4189 vino_module_cleanup(vino_init_stage);
4190 return -ENOMEM;
4191 }
4192 vino_init_stage++;
4193
4194 memcpy(vcs->v4l_device, &v4l_device_template,
4195 sizeof(struct video_device));
4196 strcpy(vcs->v4l_device->name, name);
4197 vcs->v4l_device->release = video_device_release;
4198
4199 video_set_drvdata(vcs->v4l_device, vcs);
4200
4201 return 0;
4202}
4203
4204static int __init vino_module_init(void)
4205{
4206 int ret;
4207
4208 printk(KERN_INFO "SGI VINO driver version %s\n",
4209 VINO_MODULE_VERSION);
4210
4211 ret = vino_probe();
4212 if (ret)
4213 return ret;
4214
4215 ret = vino_init();
4216 if (ret)
4217 return ret;
4218
4219 /* initialize data structures */
287 4220
288 if (request_irq(SGI_VINO_IRQ, vino_interrupt, 0, vinostr, NULL)) { 4221 spin_lock_init(&vino_drvdata->vino_lock);
289 printk(KERN_ERR "VINO: irq%02d registration failed\n", 4222 spin_lock_init(&vino_drvdata->input_lock);
4223
4224 ret = vino_init_channel_settings(&vino_drvdata->a, VINO_CHANNEL_A,
4225 vino_v4l_device_name_a);
4226 if (ret)
4227 return ret;
4228
4229 ret = vino_init_channel_settings(&vino_drvdata->b, VINO_CHANNEL_B,
4230 vino_v4l_device_name_b);
4231 if (ret)
4232 return ret;
4233
4234 /* initialize hardware and register V4L devices */
4235
4236 ret = request_irq(SGI_VINO_IRQ, vino_interrupt, 0,
4237 vino_driver_description, NULL);
4238 if (ret) {
4239 printk(KERN_ERR "VINO: requesting IRQ %02d failed\n",
290 SGI_VINO_IRQ); 4240 SGI_VINO_IRQ);
291 ret = -EAGAIN; 4241 vino_module_cleanup(vino_init_stage);
292 goto out_free_page; 4242 return -EAGAIN;
293 } 4243 }
4244 vino_init_stage++;
294 4245
295 ret = vino_i2c_add_bus(); 4246 ret = vino_i2c_add_bus();
296 if (ret) { 4247 if (ret) {
297 printk(KERN_ERR "VINO: I2C bus registration failed\n"); 4248 printk(KERN_ERR "VINO I2C bus registration failed\n");
298 goto out_free_irq; 4249 vino_module_cleanup(vino_init_stage);
4250 return ret;
299 } 4251 }
4252 vino_init_stage++;
300 4253
301 if (video_register_device(&Vino->chA.vdev, VFL_TYPE_GRABBER, -1) < 0) { 4254 ret = video_register_device(vino_drvdata->a.v4l_device,
302 printk("%s, chnl %d: device registration failed.\n", 4255 VFL_TYPE_GRABBER, -1);
303 Vino->chA.vdev.name, Vino->chA.chan); 4256 if (ret < 0) {
304 ret = -EINVAL; 4257 printk(KERN_ERR "VINO channel A Video4Linux-device "
305 goto out_i2c_del_bus; 4258 "registration failed\n");
4259 vino_module_cleanup(vino_init_stage);
4260 return -EINVAL;
306 } 4261 }
307 if (video_register_device(&Vino->chB.vdev, VFL_TYPE_GRABBER, -1) < 0) { 4262 vino_init_stage++;
308 printk("%s, chnl %d: device registration failed.\n", 4263
309 Vino->chB.vdev.name, Vino->chB.chan); 4264 ret = video_register_device(vino_drvdata->b.v4l_device,
310 ret = -EINVAL; 4265 VFL_TYPE_GRABBER, -1);
311 goto out_unregister_vdev; 4266 if (ret < 0) {
4267 printk(KERN_ERR "VINO channel B Video4Linux-device "
4268 "registration failed\n");
4269 vino_module_cleanup(vino_init_stage);
4270 return -EINVAL;
312 } 4271 }
4272 vino_init_stage++;
313 4273
314 return 0; 4274#if defined(CONFIG_KMOD) && defined(MODULE)
4275 request_module("saa7191");
4276 request_module("indycam");
4277#endif
315 4278
316out_unregister_vdev: 4279 dprintk("init complete!\n");
317 video_unregister_device(&Vino->chA.vdev);
318out_i2c_del_bus:
319 vino_i2c_del_bus();
320out_free_irq:
321 free_irq(SGI_VINO_IRQ, NULL);
322out_free_page:
323 free_page(Vino->dummy_page);
324out_free_vino:
325 kfree(Vino);
326out_unmap:
327 iounmap(vino);
328 4280
329 return ret; 4281 return 0;
330} 4282}
331 4283
332static void __exit vino_exit(void) 4284static void __exit vino_module_exit(void)
333{ 4285{
334 video_unregister_device(&Vino->chA.vdev); 4286 dprintk("exiting, stage = %d ...\n", vino_init_stage);
335 video_unregister_device(&Vino->chB.vdev); 4287 vino_module_cleanup(vino_init_stage);
336 vino_i2c_del_bus(); 4288 dprintk("cleanup complete, exit!\n");
337 free_irq(SGI_VINO_IRQ, NULL);
338 free_page(Vino->dummy_page);
339 kfree(Vino);
340 iounmap(vino);
341} 4289}
342 4290
343module_init(vino_init); 4291module_init(vino_module_init);
344module_exit(vino_exit); 4292module_exit(vino_module_exit);
345
346MODULE_DESCRIPTION("Video4Linux driver for SGI Indy VINO (IndyCam)");
347MODULE_LICENSE("GPL");
diff --git a/drivers/media/video/vino.h b/drivers/media/video/vino.h
index d2fce472f35..de2d615ae7c 100644
--- a/drivers/media/video/vino.h
+++ b/drivers/media/video/vino.h
@@ -1,13 +1,19 @@
1/* 1/*
2 * Driver for the VINO (Video In No Out) system found in SGI Indys.
3 *
4 * This file is subject to the terms and conditions of the GNU General Public
5 * License version 2 as published by the Free Software Foundation.
6 *
2 * Copyright (C) 1999 Ulf Karlsson <ulfc@bun.falkenberg.se> 7 * Copyright (C) 1999 Ulf Karlsson <ulfc@bun.falkenberg.se>
3 * Copyright (C) 2003 Ladislav Michl <ladis@linux-mips.org> 8 * Copyright (C) 2003 Ladislav Michl <ladis@linux-mips.org>
4 */ 9 */
5 10
6#ifndef VINO_H 11#ifndef _VINO_H_
7#define VINO_H 12#define _VINO_H_
8 13
9#define VINO_BASE 0x00080000 /* Vino is in the EISA address space, 14#define VINO_BASE 0x00080000 /* Vino is in the EISA address space,
10 * but it is not an EISA bus card */ 15 * but it is not an EISA bus card */
16#define VINO_PAGE_SIZE 4096
11 17
12struct sgi_vino_channel { 18struct sgi_vino_channel {
13 u32 _pad_alpha; 19 u32 _pad_alpha;
@@ -21,8 +27,9 @@ struct sgi_vino_channel {
21 u32 _pad_clip_end; 27 u32 _pad_clip_end;
22 volatile u32 clip_end; 28 volatile u32 clip_end;
23 29
30#define VINO_FRAMERT_FULL 0xfff
24#define VINO_FRAMERT_PAL (1<<0) /* 0=NTSC 1=PAL */ 31#define VINO_FRAMERT_PAL (1<<0) /* 0=NTSC 1=PAL */
25#define VINO_FRAMERT_RT(x) (((x) & 0x1fff) << 1) /* bits 1:12 */ 32#define VINO_FRAMERT_RT(x) (((x) & 0xfff) << 1) /* bits 1:12 */
26 u32 _pad_frame_rate; 33 u32 _pad_frame_rate;
27 volatile u32 frame_rate; 34 volatile u32 frame_rate;
28 35
@@ -67,18 +74,18 @@ struct sgi_vino {
67 volatile u32 rev_id; 74 volatile u32 rev_id;
68 75
69#define VINO_CTRL_LITTLE_ENDIAN (1<<0) 76#define VINO_CTRL_LITTLE_ENDIAN (1<<0)
70#define VINO_CTRL_A_FIELD_TRANS_INT (1<<1) /* Field transferred int */ 77#define VINO_CTRL_A_EOF_INT (1<<1) /* Field transferred int */
71#define VINO_CTRL_A_FIFO_OF_INT (1<<2) /* FIFO overflow int */ 78#define VINO_CTRL_A_FIFO_INT (1<<2) /* FIFO overflow int */
72#define VINO_CTRL_A_END_DESC_TBL_INT (1<<3) /* End of desc table int */ 79#define VINO_CTRL_A_EOD_INT (1<<3) /* End of desc table int */
73#define VINO_CTRL_A_INT (VINO_CTRL_A_FIELD_TRANS_INT | \ 80#define VINO_CTRL_A_INT (VINO_CTRL_A_EOF_INT | \
74 VINO_CTRL_A_FIFO_OF_INT | \ 81 VINO_CTRL_A_FIFO_INT | \
75 VINO_CTRL_A_END_DESC_TBL_INT) 82 VINO_CTRL_A_EOD_INT)
76#define VINO_CTRL_B_FIELD_TRANS_INT (1<<4) /* Field transferred int */ 83#define VINO_CTRL_B_EOF_INT (1<<4) /* Field transferred int */
77#define VINO_CTRL_B_FIFO_OF_INT (1<<5) /* FIFO overflow int */ 84#define VINO_CTRL_B_FIFO_INT (1<<5) /* FIFO overflow int */
78#define VINO_CTRL_B_END_DESC_TBL_INT (1<<6) /* End of desc table int */ 85#define VINO_CTRL_B_EOD_INT (1<<6) /* End of desc table int */
79#define VINO_CTRL_B_INT (VINO_CTRL_B_FIELD_TRANS_INT | \ 86#define VINO_CTRL_B_INT (VINO_CTRL_B_EOF_INT | \
80 VINO_CTRL_B_FIFO_OF_INT | \ 87 VINO_CTRL_B_FIFO_INT | \
81 VINO_CTRL_B_END_DESC_TBL_INT) 88 VINO_CTRL_B_EOD_INT)
82#define VINO_CTRL_A_DMA_ENBL (1<<7) 89#define VINO_CTRL_A_DMA_ENBL (1<<7)
83#define VINO_CTRL_A_INTERLEAVE_ENBL (1<<8) 90#define VINO_CTRL_A_INTERLEAVE_ENBL (1<<8)
84#define VINO_CTRL_A_SYNC_ENBL (1<<9) 91#define VINO_CTRL_A_SYNC_ENBL (1<<9)
@@ -104,18 +111,18 @@ struct sgi_vino {
104 u32 _pad_control; 111 u32 _pad_control;
105 volatile u32 control; 112 volatile u32 control;
106 113
107#define VINO_INTSTAT_A_FIELD_TRANS (1<<0) /* Field transferred int */ 114#define VINO_INTSTAT_A_EOF (1<<0) /* Field transferred int */
108#define VINO_INTSTAT_A_FIFO_OF (1<<1) /* FIFO overflow int */ 115#define VINO_INTSTAT_A_FIFO (1<<1) /* FIFO overflow int */
109#define VINO_INTSTAT_A_END_DESC_TBL (1<<2) /* End of desc table int */ 116#define VINO_INTSTAT_A_EOD (1<<2) /* End of desc table int */
110#define VINO_INTSTAT_A (VINO_INTSTAT_A_FIELD_TRANS | \ 117#define VINO_INTSTAT_A (VINO_INTSTAT_A_EOF | \
111 VINO_INTSTAT_A_FIFO_OF | \ 118 VINO_INTSTAT_A_FIFO | \
112 VINO_INTSTAT_A_END_DESC_TBL) 119 VINO_INTSTAT_A_EOD)
113#define VINO_INTSTAT_B_FIELD_TRANS (1<<3) /* Field transferred int */ 120#define VINO_INTSTAT_B_EOF (1<<3) /* Field transferred int */
114#define VINO_INTSTAT_B_FIFO_OF (1<<4) /* FIFO overflow int */ 121#define VINO_INTSTAT_B_FIFO (1<<4) /* FIFO overflow int */
115#define VINO_INTSTAT_B_END_DESC_TBL (1<<5) /* End of desc table int */ 122#define VINO_INTSTAT_B_EOD (1<<5) /* End of desc table int */
116#define VINO_INTSTAT_B (VINO_INTSTAT_B_FIELD_TRANS | \ 123#define VINO_INTSTAT_B (VINO_INTSTAT_B_EOF | \
117 VINO_INTSTAT_B_FIFO_OF | \ 124 VINO_INTSTAT_B_FIFO | \
118 VINO_INTSTAT_B_END_DESC_TBL) 125 VINO_INTSTAT_B_EOD)
119 u32 _pad_intr_status; 126 u32 _pad_intr_status;
120 volatile u32 intr_status; 127 volatile u32 intr_status;
121 128
diff --git a/drivers/media/video/vpx3220.c b/drivers/media/video/vpx3220.c
index 5dbd9f6bf35..4437bdebe24 100644
--- a/drivers/media/video/vpx3220.c
+++ b/drivers/media/video/vpx3220.c
@@ -576,7 +576,6 @@ static struct i2c_client_address_data addr_data = {
576 .normal_i2c = normal_i2c, 576 .normal_i2c = normal_i2c,
577 .probe = &ignore, 577 .probe = &ignore,
578 .ignore = &ignore, 578 .ignore = &ignore,
579 .force = &ignore,
580}; 579};
581 580
582static struct i2c_driver vpx3220_i2c_driver; 581static struct i2c_driver vpx3220_i2c_driver;
diff --git a/drivers/media/video/zoran_card.c b/drivers/media/video/zoran_card.c
index 25743085b2d..eed2acea177 100644
--- a/drivers/media/video/zoran_card.c
+++ b/drivers/media/video/zoran_card.c
@@ -737,7 +737,7 @@ static struct i2c_algo_bit_data zoran_i2c_bit_data_template = {
737}; 737};
738 738
739static struct i2c_adapter zoran_i2c_adapter_template = { 739static struct i2c_adapter zoran_i2c_adapter_template = {
740 I2C_DEVNAME("zr36057"), 740 .name = "zr36057",
741 .id = I2C_HW_B_ZR36067, 741 .id = I2C_HW_B_ZR36067,
742 .algo = NULL, 742 .algo = NULL,
743 .client_register = zoran_i2c_client_register, 743 .client_register = zoran_i2c_client_register,
diff --git a/drivers/message/fusion/lsi/mpi.h b/drivers/message/fusion/lsi/mpi.h
index 9f98334e507..b61e3d17507 100644
--- a/drivers/message/fusion/lsi/mpi.h
+++ b/drivers/message/fusion/lsi/mpi.h
@@ -6,7 +6,7 @@
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.07 9 * mpi.h Version: 01.05.08
10 * 10 *
11 * Version History 11 * Version History
12 * --------------- 12 * ---------------
@@ -71,6 +71,9 @@
71 * 03-11-05 01.05.07 Removed function codes for SCSI IO 32 and 71 * 03-11-05 01.05.07 Removed function codes for SCSI IO 32 and
72 * TargetAssistExtended requests. 72 * TargetAssistExtended requests.
73 * Removed EEDP IOCStatus codes. 73 * Removed EEDP IOCStatus codes.
74 * 06-24-05 01.05.08 Added function codes for SCSI IO 32 and
75 * TargetAssistExtended requests.
76 * Added EEDP IOCStatus codes.
74 * -------------------------------------------------------------------------- 77 * --------------------------------------------------------------------------
75 */ 78 */
76 79
@@ -101,7 +104,7 @@
101/* Note: The major versions of 0xe0 through 0xff are reserved */ 104/* Note: The major versions of 0xe0 through 0xff are reserved */
102 105
103/* versioning for this MPI header set */ 106/* versioning for this MPI header set */
104#define MPI_HEADER_VERSION_UNIT (0x09) 107#define MPI_HEADER_VERSION_UNIT (0x0A)
105#define MPI_HEADER_VERSION_DEV (0x00) 108#define MPI_HEADER_VERSION_DEV (0x00)
106#define MPI_HEADER_VERSION_UNIT_MASK (0xFF00) 109#define MPI_HEADER_VERSION_UNIT_MASK (0xFF00)
107#define MPI_HEADER_VERSION_UNIT_SHIFT (8) 110#define MPI_HEADER_VERSION_UNIT_SHIFT (8)
@@ -292,10 +295,13 @@
292#define MPI_FUNCTION_DIAG_BUFFER_POST (0x1D) 295#define MPI_FUNCTION_DIAG_BUFFER_POST (0x1D)
293#define MPI_FUNCTION_DIAG_RELEASE (0x1E) 296#define MPI_FUNCTION_DIAG_RELEASE (0x1E)
294 297
298#define MPI_FUNCTION_SCSI_IO_32 (0x1F)
299
295#define MPI_FUNCTION_LAN_SEND (0x20) 300#define MPI_FUNCTION_LAN_SEND (0x20)
296#define MPI_FUNCTION_LAN_RECEIVE (0x21) 301#define MPI_FUNCTION_LAN_RECEIVE (0x21)
297#define MPI_FUNCTION_LAN_RESET (0x22) 302#define MPI_FUNCTION_LAN_RESET (0x22)
298 303
304#define MPI_FUNCTION_TARGET_ASSIST_EXTENDED (0x23)
299#define MPI_FUNCTION_TARGET_CMD_BUF_BASE_POST (0x24) 305#define MPI_FUNCTION_TARGET_CMD_BUF_BASE_POST (0x24)
300#define MPI_FUNCTION_TARGET_CMD_BUF_LIST_POST (0x25) 306#define MPI_FUNCTION_TARGET_CMD_BUF_LIST_POST (0x25)
301 307
@@ -681,6 +687,15 @@ typedef struct _MSG_DEFAULT_REPLY
681#define MPI_IOCSTATUS_SCSI_EXT_TERMINATED (0x004C) 687#define MPI_IOCSTATUS_SCSI_EXT_TERMINATED (0x004C)
682 688
683/****************************************************************************/ 689/****************************************************************************/
690/* For use by SCSI Initiator and SCSI Target end-to-end data protection */
691/****************************************************************************/
692
693#define MPI_IOCSTATUS_EEDP_GUARD_ERROR (0x004D)
694#define MPI_IOCSTATUS_EEDP_REF_TAG_ERROR (0x004E)
695#define MPI_IOCSTATUS_EEDP_APP_TAG_ERROR (0x004F)
696
697
698/****************************************************************************/
684/* SCSI Target values */ 699/* SCSI Target values */
685/****************************************************************************/ 700/****************************************************************************/
686 701
diff --git a/drivers/message/fusion/lsi/mpi_cnfg.h b/drivers/message/fusion/lsi/mpi_cnfg.h
index 15b12b06799..d8339896f73 100644
--- a/drivers/message/fusion/lsi/mpi_cnfg.h
+++ b/drivers/message/fusion/lsi/mpi_cnfg.h
@@ -6,7 +6,7 @@
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.08 9 * mpi_cnfg.h Version: 01.05.09
10 * 10 *
11 * Version History 11 * Version History
12 * --------------- 12 * ---------------
@@ -232,6 +232,23 @@
232 * New physical mapping mode in SAS IO Unit Page 2. 232 * New physical mapping mode in SAS IO Unit Page 2.
233 * Added CONFIG_PAGE_SAS_ENCLOSURE_0. 233 * Added CONFIG_PAGE_SAS_ENCLOSURE_0.
234 * Added Slot and Enclosure fields to SAS Device Page 0. 234 * Added Slot and Enclosure fields to SAS Device Page 0.
235 * 06-24-05 01.05.09 Added EEDP defines to IOC Page 1.
236 * Added more RAID type defines to IOC Page 2.
237 * Added Port Enable Delay settings to BIOS Page 1.
238 * Added Bad Block Table Full define to RAID Volume Page 0.
239 * Added Previous State defines to RAID Physical Disk
240 * Page 0.
241 * Added Max Sata Targets define for DiscoveryStatus field
242 * of SAS IO Unit Page 0.
243 * Added Device Self Test to Control Flags of SAS IO Unit
244 * Page 1.
245 * Added Direct Attach Starting Slot Number define for SAS
246 * IO Unit Page 2.
247 * Added new fields in SAS Device Page 2 for enclosure
248 * mapping.
249 * Added OwnerDevHandle and Flags field to SAS PHY Page 0.
250 * Added IOC GPIO Flags define to SAS Enclosure Page 0.
251 * Fixed the value for MPI_SAS_IOUNIT1_CONTROL_DEV_SATA_SUPPORT.
235 * -------------------------------------------------------------------------- 252 * --------------------------------------------------------------------------
236 */ 253 */
237 254
@@ -477,6 +494,7 @@ typedef struct _MSG_CONFIG_REPLY
477#define MPI_MANUFACTPAGE_DEVICEID_FC929X (0x0626) 494#define MPI_MANUFACTPAGE_DEVICEID_FC929X (0x0626)
478#define MPI_MANUFACTPAGE_DEVICEID_FC939X (0x0642) 495#define MPI_MANUFACTPAGE_DEVICEID_FC939X (0x0642)
479#define MPI_MANUFACTPAGE_DEVICEID_FC949X (0x0640) 496#define MPI_MANUFACTPAGE_DEVICEID_FC949X (0x0640)
497#define MPI_MANUFACTPAGE_DEVICEID_FC949ES (0x0646)
480/* SCSI */ 498/* SCSI */
481#define MPI_MANUFACTPAGE_DEVID_53C1030 (0x0030) 499#define MPI_MANUFACTPAGE_DEVID_53C1030 (0x0030)
482#define MPI_MANUFACTPAGE_DEVID_53C1030ZC (0x0031) 500#define MPI_MANUFACTPAGE_DEVID_53C1030ZC (0x0031)
@@ -769,9 +787,13 @@ typedef struct _CONFIG_PAGE_IOC_1
769} CONFIG_PAGE_IOC_1, MPI_POINTER PTR_CONFIG_PAGE_IOC_1, 787} CONFIG_PAGE_IOC_1, MPI_POINTER PTR_CONFIG_PAGE_IOC_1,
770 IOCPage1_t, MPI_POINTER pIOCPage1_t; 788 IOCPage1_t, MPI_POINTER pIOCPage1_t;
771 789
772#define MPI_IOCPAGE1_PAGEVERSION (0x02) 790#define MPI_IOCPAGE1_PAGEVERSION (0x03)
773 791
774/* defines for the Flags field */ 792/* defines for the Flags field */
793#define MPI_IOCPAGE1_EEDP_MODE_MASK (0x07000000)
794#define MPI_IOCPAGE1_EEDP_MODE_OFF (0x00000000)
795#define MPI_IOCPAGE1_EEDP_MODE_T10 (0x01000000)
796#define MPI_IOCPAGE1_EEDP_MODE_LSI_1 (0x02000000)
775#define MPI_IOCPAGE1_INITIATOR_CONTEXT_REPLY_DISABLE (0x00000010) 797#define MPI_IOCPAGE1_INITIATOR_CONTEXT_REPLY_DISABLE (0x00000010)
776#define MPI_IOCPAGE1_REPLY_COALESCING (0x00000001) 798#define MPI_IOCPAGE1_REPLY_COALESCING (0x00000001)
777 799
@@ -795,6 +817,11 @@ typedef struct _CONFIG_PAGE_IOC_2_RAID_VOL
795#define MPI_RAID_VOL_TYPE_IS (0x00) 817#define MPI_RAID_VOL_TYPE_IS (0x00)
796#define MPI_RAID_VOL_TYPE_IME (0x01) 818#define MPI_RAID_VOL_TYPE_IME (0x01)
797#define MPI_RAID_VOL_TYPE_IM (0x02) 819#define MPI_RAID_VOL_TYPE_IM (0x02)
820#define MPI_RAID_VOL_TYPE_RAID_5 (0x03)
821#define MPI_RAID_VOL_TYPE_RAID_6 (0x04)
822#define MPI_RAID_VOL_TYPE_RAID_10 (0x05)
823#define MPI_RAID_VOL_TYPE_RAID_50 (0x06)
824#define MPI_RAID_VOL_TYPE_UNKNOWN (0xFF)
798 825
799/* IOC Page 2 Volume Flags values */ 826/* IOC Page 2 Volume Flags values */
800 827
@@ -820,13 +847,17 @@ typedef struct _CONFIG_PAGE_IOC_2
820} CONFIG_PAGE_IOC_2, MPI_POINTER PTR_CONFIG_PAGE_IOC_2, 847} CONFIG_PAGE_IOC_2, MPI_POINTER PTR_CONFIG_PAGE_IOC_2,
821 IOCPage2_t, MPI_POINTER pIOCPage2_t; 848 IOCPage2_t, MPI_POINTER pIOCPage2_t;
822 849
823#define MPI_IOCPAGE2_PAGEVERSION (0x02) 850#define MPI_IOCPAGE2_PAGEVERSION (0x03)
824 851
825/* IOC Page 2 Capabilities flags */ 852/* IOC Page 2 Capabilities flags */
826 853
827#define MPI_IOCPAGE2_CAP_FLAGS_IS_SUPPORT (0x00000001) 854#define MPI_IOCPAGE2_CAP_FLAGS_IS_SUPPORT (0x00000001)
828#define MPI_IOCPAGE2_CAP_FLAGS_IME_SUPPORT (0x00000002) 855#define MPI_IOCPAGE2_CAP_FLAGS_IME_SUPPORT (0x00000002)
829#define MPI_IOCPAGE2_CAP_FLAGS_IM_SUPPORT (0x00000004) 856#define MPI_IOCPAGE2_CAP_FLAGS_IM_SUPPORT (0x00000004)
857#define MPI_IOCPAGE2_CAP_FLAGS_RAID_5_SUPPORT (0x00000008)
858#define MPI_IOCPAGE2_CAP_FLAGS_RAID_6_SUPPORT (0x00000010)
859#define MPI_IOCPAGE2_CAP_FLAGS_RAID_10_SUPPORT (0x00000020)
860#define MPI_IOCPAGE2_CAP_FLAGS_RAID_50_SUPPORT (0x00000040)
830#define MPI_IOCPAGE2_CAP_FLAGS_SES_SUPPORT (0x20000000) 861#define MPI_IOCPAGE2_CAP_FLAGS_SES_SUPPORT (0x20000000)
831#define MPI_IOCPAGE2_CAP_FLAGS_SAFTE_SUPPORT (0x40000000) 862#define MPI_IOCPAGE2_CAP_FLAGS_SAFTE_SUPPORT (0x40000000)
832#define MPI_IOCPAGE2_CAP_FLAGS_CROSS_CHANNEL_SUPPORT (0x80000000) 863#define MPI_IOCPAGE2_CAP_FLAGS_CROSS_CHANNEL_SUPPORT (0x80000000)
@@ -945,7 +976,7 @@ typedef struct _CONFIG_PAGE_BIOS_1
945} CONFIG_PAGE_BIOS_1, MPI_POINTER PTR_CONFIG_PAGE_BIOS_1, 976} CONFIG_PAGE_BIOS_1, MPI_POINTER PTR_CONFIG_PAGE_BIOS_1,
946 BIOSPage1_t, MPI_POINTER pBIOSPage1_t; 977 BIOSPage1_t, MPI_POINTER pBIOSPage1_t;
947 978
948#define MPI_BIOSPAGE1_PAGEVERSION (0x01) 979#define MPI_BIOSPAGE1_PAGEVERSION (0x02)
949 980
950/* values for the BiosOptions field */ 981/* values for the BiosOptions field */
951#define MPI_BIOSPAGE1_OPTIONS_SPI_ENABLE (0x00000400) 982#define MPI_BIOSPAGE1_OPTIONS_SPI_ENABLE (0x00000400)
@@ -954,6 +985,8 @@ typedef struct _CONFIG_PAGE_BIOS_1
954#define MPI_BIOSPAGE1_OPTIONS_DISABLE_BIOS (0x00000001) 985#define MPI_BIOSPAGE1_OPTIONS_DISABLE_BIOS (0x00000001)
955 986
956/* values for the IOCSettings field */ 987/* values for the IOCSettings field */
988#define MPI_BIOSPAGE1_IOCSET_MASK_PORT_ENABLE_DELAY (0x00F00000)
989#define MPI_BIOSPAGE1_IOCSET_SHIFT_PORT_ENABLE_DELAY (20)
957#define MPI_BIOSPAGE1_IOCSET_MASK_BOOT_PREFERENCE (0x00030000) 990#define MPI_BIOSPAGE1_IOCSET_MASK_BOOT_PREFERENCE (0x00030000)
958#define MPI_BIOSPAGE1_IOCSET_ENCLOSURE_SLOT_BOOT (0x00000000) 991#define MPI_BIOSPAGE1_IOCSET_ENCLOSURE_SLOT_BOOT (0x00000000)
959#define MPI_BIOSPAGE1_IOCSET_SAS_ADDRESS_BOOT (0x00010000) 992#define MPI_BIOSPAGE1_IOCSET_SAS_ADDRESS_BOOT (0x00010000)
@@ -1167,6 +1200,7 @@ typedef struct _CONFIG_PAGE_BIOS_2
1167#define MPI_BIOSPAGE2_FORM_PCI_SLOT_NUMBER (0x03) 1200#define MPI_BIOSPAGE2_FORM_PCI_SLOT_NUMBER (0x03)
1168#define MPI_BIOSPAGE2_FORM_FC_WWN (0x04) 1201#define MPI_BIOSPAGE2_FORM_FC_WWN (0x04)
1169#define MPI_BIOSPAGE2_FORM_SAS_WWN (0x05) 1202#define MPI_BIOSPAGE2_FORM_SAS_WWN (0x05)
1203#define MPI_BIOSPAGE2_FORM_ENCLOSURE_SLOT (0x06)
1170 1204
1171 1205
1172/**************************************************************************** 1206/****************************************************************************
@@ -1957,11 +1991,11 @@ typedef struct _RAID_VOL0_STATUS
1957 RaidVol0Status_t, MPI_POINTER pRaidVol0Status_t; 1991 RaidVol0Status_t, MPI_POINTER pRaidVol0Status_t;
1958 1992
1959/* RAID Volume Page 0 VolumeStatus defines */ 1993/* RAID Volume Page 0 VolumeStatus defines */
1960
1961#define MPI_RAIDVOL0_STATUS_FLAG_ENABLED (0x01) 1994#define MPI_RAIDVOL0_STATUS_FLAG_ENABLED (0x01)
1962#define MPI_RAIDVOL0_STATUS_FLAG_QUIESCED (0x02) 1995#define MPI_RAIDVOL0_STATUS_FLAG_QUIESCED (0x02)
1963#define MPI_RAIDVOL0_STATUS_FLAG_RESYNC_IN_PROGRESS (0x04) 1996#define MPI_RAIDVOL0_STATUS_FLAG_RESYNC_IN_PROGRESS (0x04)
1964#define MPI_RAIDVOL0_STATUS_FLAG_VOLUME_INACTIVE (0x08) 1997#define MPI_RAIDVOL0_STATUS_FLAG_VOLUME_INACTIVE (0x08)
1998#define MPI_RAIDVOL0_STATUS_FLAG_BAD_BLOCK_TABLE_FULL (0x10)
1965 1999
1966#define MPI_RAIDVOL0_STATUS_STATE_OPTIMAL (0x00) 2000#define MPI_RAIDVOL0_STATUS_STATE_OPTIMAL (0x00)
1967#define MPI_RAIDVOL0_STATUS_STATE_DEGRADED (0x01) 2001#define MPI_RAIDVOL0_STATUS_STATE_DEGRADED (0x01)
@@ -2025,7 +2059,7 @@ typedef struct _CONFIG_PAGE_RAID_VOL_0
2025} CONFIG_PAGE_RAID_VOL_0, MPI_POINTER PTR_CONFIG_PAGE_RAID_VOL_0, 2059} CONFIG_PAGE_RAID_VOL_0, MPI_POINTER PTR_CONFIG_PAGE_RAID_VOL_0,
2026 RaidVolumePage0_t, MPI_POINTER pRaidVolumePage0_t; 2060 RaidVolumePage0_t, MPI_POINTER pRaidVolumePage0_t;
2027 2061
2028#define MPI_RAIDVOLPAGE0_PAGEVERSION (0x04) 2062#define MPI_RAIDVOLPAGE0_PAGEVERSION (0x05)
2029 2063
2030/* values for RAID Volume Page 0 InactiveStatus field */ 2064/* values for RAID Volume Page 0 InactiveStatus field */
2031#define MPI_RAIDVOLPAGE0_UNKNOWN_INACTIVE (0x00) 2065#define MPI_RAIDVOLPAGE0_UNKNOWN_INACTIVE (0x00)
@@ -2104,6 +2138,8 @@ typedef struct _RAID_PHYS_DISK0_STATUS
2104#define MPI_PHYSDISK0_STATUS_FLAG_OUT_OF_SYNC (0x01) 2138#define MPI_PHYSDISK0_STATUS_FLAG_OUT_OF_SYNC (0x01)
2105#define MPI_PHYSDISK0_STATUS_FLAG_QUIESCED (0x02) 2139#define MPI_PHYSDISK0_STATUS_FLAG_QUIESCED (0x02)
2106#define MPI_PHYSDISK0_STATUS_FLAG_INACTIVE_VOLUME (0x04) 2140#define MPI_PHYSDISK0_STATUS_FLAG_INACTIVE_VOLUME (0x04)
2141#define MPI_PHYSDISK0_STATUS_FLAG_OPTIMAL_PREVIOUS (0x00)
2142#define MPI_PHYSDISK0_STATUS_FLAG_NOT_OPTIMAL_PREVIOUS (0x08)
2107 2143
2108#define MPI_PHYSDISK0_STATUS_ONLINE (0x00) 2144#define MPI_PHYSDISK0_STATUS_ONLINE (0x00)
2109#define MPI_PHYSDISK0_STATUS_MISSING (0x01) 2145#define MPI_PHYSDISK0_STATUS_MISSING (0x01)
@@ -2132,7 +2168,7 @@ typedef struct _CONFIG_PAGE_RAID_PHYS_DISK_0
2132} CONFIG_PAGE_RAID_PHYS_DISK_0, MPI_POINTER PTR_CONFIG_PAGE_RAID_PHYS_DISK_0, 2168} CONFIG_PAGE_RAID_PHYS_DISK_0, MPI_POINTER PTR_CONFIG_PAGE_RAID_PHYS_DISK_0,
2133 RaidPhysDiskPage0_t, MPI_POINTER pRaidPhysDiskPage0_t; 2169 RaidPhysDiskPage0_t, MPI_POINTER pRaidPhysDiskPage0_t;
2134 2170
2135#define MPI_RAIDPHYSDISKPAGE0_PAGEVERSION (0x01) 2171#define MPI_RAIDPHYSDISKPAGE0_PAGEVERSION (0x02)
2136 2172
2137 2173
2138typedef struct _RAID_PHYS_DISK1_PATH 2174typedef struct _RAID_PHYS_DISK1_PATH
@@ -2263,7 +2299,7 @@ typedef struct _CONFIG_PAGE_SAS_IO_UNIT_0
2263} CONFIG_PAGE_SAS_IO_UNIT_0, MPI_POINTER PTR_CONFIG_PAGE_SAS_IO_UNIT_0, 2299} CONFIG_PAGE_SAS_IO_UNIT_0, MPI_POINTER PTR_CONFIG_PAGE_SAS_IO_UNIT_0,
2264 SasIOUnitPage0_t, MPI_POINTER pSasIOUnitPage0_t; 2300 SasIOUnitPage0_t, MPI_POINTER pSasIOUnitPage0_t;
2265 2301
2266#define MPI_SASIOUNITPAGE0_PAGEVERSION (0x02) 2302#define MPI_SASIOUNITPAGE0_PAGEVERSION (0x03)
2267 2303
2268/* values for SAS IO Unit Page 0 PortFlags */ 2304/* values for SAS IO Unit Page 0 PortFlags */
2269#define MPI_SAS_IOUNIT0_PORT_FLAGS_DISCOVERY_IN_PROGRESS (0x08) 2305#define MPI_SAS_IOUNIT0_PORT_FLAGS_DISCOVERY_IN_PROGRESS (0x08)
@@ -2299,6 +2335,7 @@ typedef struct _CONFIG_PAGE_SAS_IO_UNIT_0
2299#define MPI_SAS_IOUNIT0_DS_SUBTRACTIVE_LINK (0x00000200) 2335#define MPI_SAS_IOUNIT0_DS_SUBTRACTIVE_LINK (0x00000200)
2300#define MPI_SAS_IOUNIT0_DS_TABLE_LINK (0x00000400) 2336#define MPI_SAS_IOUNIT0_DS_TABLE_LINK (0x00000400)
2301#define MPI_SAS_IOUNIT0_DS_UNSUPPORTED_DEVICE (0x00000800) 2337#define MPI_SAS_IOUNIT0_DS_UNSUPPORTED_DEVICE (0x00000800)
2338#define MPI_SAS_IOUNIT0_DS_MAX_SATA_TARGETS (0x00001000)
2302 2339
2303 2340
2304typedef struct _MPI_SAS_IO_UNIT1_PHY_DATA 2341typedef struct _MPI_SAS_IO_UNIT1_PHY_DATA
@@ -2336,6 +2373,7 @@ typedef struct _CONFIG_PAGE_SAS_IO_UNIT_1
2336#define MPI_SASIOUNITPAGE1_PAGEVERSION (0x04) 2373#define MPI_SASIOUNITPAGE1_PAGEVERSION (0x04)
2337 2374
2338/* values for SAS IO Unit Page 1 ControlFlags */ 2375/* values for SAS IO Unit Page 1 ControlFlags */
2376#define MPI_SAS_IOUNIT1_CONTROL_DEVICE_SELF_TEST (0x8000)
2339#define MPI_SAS_IOUNIT1_CONTROL_SATA_3_0_MAX (0x4000) 2377#define MPI_SAS_IOUNIT1_CONTROL_SATA_3_0_MAX (0x4000)
2340#define MPI_SAS_IOUNIT1_CONTROL_SATA_1_5_MAX (0x2000) 2378#define MPI_SAS_IOUNIT1_CONTROL_SATA_1_5_MAX (0x2000)
2341#define MPI_SAS_IOUNIT1_CONTROL_SATA_SW_PRESERVE (0x1000) 2379#define MPI_SAS_IOUNIT1_CONTROL_SATA_SW_PRESERVE (0x1000)
@@ -2345,9 +2383,8 @@ typedef struct _CONFIG_PAGE_SAS_IO_UNIT_1
2345#define MPI_SAS_IOUNIT1_CONTROL_SHIFT_DEV_SUPPORT (9) 2383#define MPI_SAS_IOUNIT1_CONTROL_SHIFT_DEV_SUPPORT (9)
2346#define MPI_SAS_IOUNIT1_CONTROL_DEV_SUPPORT_BOTH (0x00) 2384#define MPI_SAS_IOUNIT1_CONTROL_DEV_SUPPORT_BOTH (0x00)
2347#define MPI_SAS_IOUNIT1_CONTROL_DEV_SAS_SUPPORT (0x01) 2385#define MPI_SAS_IOUNIT1_CONTROL_DEV_SAS_SUPPORT (0x01)
2348#define MPI_SAS_IOUNIT1_CONTROL_DEV_SATA_SUPPORT (0x10) 2386#define MPI_SAS_IOUNIT1_CONTROL_DEV_SATA_SUPPORT (0x02)
2349 2387
2350#define MPI_SAS_IOUNIT1_CONTROL_AUTO_PORT_SAME_SAS_ADDR (0x0100)
2351#define MPI_SAS_IOUNIT1_CONTROL_SATA_48BIT_LBA_REQUIRED (0x0080) 2388#define MPI_SAS_IOUNIT1_CONTROL_SATA_48BIT_LBA_REQUIRED (0x0080)
2352#define MPI_SAS_IOUNIT1_CONTROL_SATA_SMART_REQUIRED (0x0040) 2389#define MPI_SAS_IOUNIT1_CONTROL_SATA_SMART_REQUIRED (0x0040)
2353#define MPI_SAS_IOUNIT1_CONTROL_SATA_NCQ_REQUIRED (0x0020) 2390#define MPI_SAS_IOUNIT1_CONTROL_SATA_NCQ_REQUIRED (0x0020)
@@ -2390,7 +2427,7 @@ typedef struct _CONFIG_PAGE_SAS_IO_UNIT_2
2390} CONFIG_PAGE_SAS_IO_UNIT_2, MPI_POINTER PTR_CONFIG_PAGE_SAS_IO_UNIT_2, 2427} CONFIG_PAGE_SAS_IO_UNIT_2, MPI_POINTER PTR_CONFIG_PAGE_SAS_IO_UNIT_2,
2391 SasIOUnitPage2_t, MPI_POINTER pSasIOUnitPage2_t; 2428 SasIOUnitPage2_t, MPI_POINTER pSasIOUnitPage2_t;
2392 2429
2393#define MPI_SASIOUNITPAGE2_PAGEVERSION (0x03) 2430#define MPI_SASIOUNITPAGE2_PAGEVERSION (0x04)
2394 2431
2395/* values for SAS IO Unit Page 2 Status field */ 2432/* values for SAS IO Unit Page 2 Status field */
2396#define MPI_SAS_IOUNIT2_STATUS_DISABLED_PERSISTENT_MAPPINGS (0x02) 2433#define MPI_SAS_IOUNIT2_STATUS_DISABLED_PERSISTENT_MAPPINGS (0x02)
@@ -2406,6 +2443,7 @@ typedef struct _CONFIG_PAGE_SAS_IO_UNIT_2
2406#define MPI_SAS_IOUNIT2_FLAGS_ENCLOSURE_SLOT_PHYS_MAP (0x02) 2443#define MPI_SAS_IOUNIT2_FLAGS_ENCLOSURE_SLOT_PHYS_MAP (0x02)
2407 2444
2408#define MPI_SAS_IOUNIT2_FLAGS_RESERVE_ID_0_FOR_BOOT (0x10) 2445#define MPI_SAS_IOUNIT2_FLAGS_RESERVE_ID_0_FOR_BOOT (0x10)
2446#define MPI_SAS_IOUNIT2_FLAGS_DA_STARTING_SLOT (0x20)
2409 2447
2410 2448
2411typedef struct _CONFIG_PAGE_SAS_IO_UNIT_3 2449typedef struct _CONFIG_PAGE_SAS_IO_UNIT_3
@@ -2584,11 +2622,19 @@ typedef struct _CONFIG_PAGE_SAS_DEVICE_2
2584{ 2622{
2585 CONFIG_EXTENDED_PAGE_HEADER Header; /* 00h */ 2623 CONFIG_EXTENDED_PAGE_HEADER Header; /* 00h */
2586 U64 PhysicalIdentifier; /* 08h */ 2624 U64 PhysicalIdentifier; /* 08h */
2587 U32 Reserved1; /* 10h */ 2625 U32 EnclosureMapping; /* 10h */
2588} CONFIG_PAGE_SAS_DEVICE_2, MPI_POINTER PTR_CONFIG_PAGE_SAS_DEVICE_2, 2626} CONFIG_PAGE_SAS_DEVICE_2, MPI_POINTER PTR_CONFIG_PAGE_SAS_DEVICE_2,
2589 SasDevicePage2_t, MPI_POINTER pSasDevicePage2_t; 2627 SasDevicePage2_t, MPI_POINTER pSasDevicePage2_t;
2590 2628
2591#define MPI_SASDEVICE2_PAGEVERSION (0x00) 2629#define MPI_SASDEVICE2_PAGEVERSION (0x01)
2630
2631/* defines for SAS Device Page 2 EnclosureMapping field */
2632#define MPI_SASDEVICE2_ENC_MAP_MASK_MISSING_COUNT (0x0000000F)
2633#define MPI_SASDEVICE2_ENC_MAP_SHIFT_MISSING_COUNT (0)
2634#define MPI_SASDEVICE2_ENC_MAP_MASK_NUM_SLOTS (0x000007F0)
2635#define MPI_SASDEVICE2_ENC_MAP_SHIFT_NUM_SLOTS (4)
2636#define MPI_SASDEVICE2_ENC_MAP_MASK_START_INDEX (0x001FF800)
2637#define MPI_SASDEVICE2_ENC_MAP_SHIFT_START_INDEX (11)
2592 2638
2593 2639
2594/**************************************************************************** 2640/****************************************************************************
@@ -2598,7 +2644,8 @@ typedef struct _CONFIG_PAGE_SAS_DEVICE_2
2598typedef struct _CONFIG_PAGE_SAS_PHY_0 2644typedef struct _CONFIG_PAGE_SAS_PHY_0
2599{ 2645{
2600 CONFIG_EXTENDED_PAGE_HEADER Header; /* 00h */ 2646 CONFIG_EXTENDED_PAGE_HEADER Header; /* 00h */
2601 U32 Reserved1; /* 08h */ 2647 U16 OwnerDevHandle; /* 08h */
2648 U16 Reserved1; /* 0Ah */
2602 U64 SASAddress; /* 0Ch */ 2649 U64 SASAddress; /* 0Ch */
2603 U16 AttachedDevHandle; /* 14h */ 2650 U16 AttachedDevHandle; /* 14h */
2604 U8 AttachedPhyIdentifier; /* 16h */ 2651 U8 AttachedPhyIdentifier; /* 16h */
@@ -2607,12 +2654,12 @@ typedef struct _CONFIG_PAGE_SAS_PHY_0
2607 U8 ProgrammedLinkRate; /* 20h */ 2654 U8 ProgrammedLinkRate; /* 20h */
2608 U8 HwLinkRate; /* 21h */ 2655 U8 HwLinkRate; /* 21h */
2609 U8 ChangeCount; /* 22h */ 2656 U8 ChangeCount; /* 22h */
2610 U8 Reserved3; /* 23h */ 2657 U8 Flags; /* 23h */
2611 U32 PhyInfo; /* 24h */ 2658 U32 PhyInfo; /* 24h */
2612} CONFIG_PAGE_SAS_PHY_0, MPI_POINTER PTR_CONFIG_PAGE_SAS_PHY_0, 2659} CONFIG_PAGE_SAS_PHY_0, MPI_POINTER PTR_CONFIG_PAGE_SAS_PHY_0,
2613 SasPhyPage0_t, MPI_POINTER pSasPhyPage0_t; 2660 SasPhyPage0_t, MPI_POINTER pSasPhyPage0_t;
2614 2661
2615#define MPI_SASPHY0_PAGEVERSION (0x00) 2662#define MPI_SASPHY0_PAGEVERSION (0x01)
2616 2663
2617/* values for SAS PHY Page 0 ProgrammedLinkRate field */ 2664/* values for SAS PHY Page 0 ProgrammedLinkRate field */
2618#define MPI_SAS_PHY0_PRATE_MAX_RATE_MASK (0xF0) 2665#define MPI_SAS_PHY0_PRATE_MAX_RATE_MASK (0xF0)
@@ -2632,6 +2679,9 @@ typedef struct _CONFIG_PAGE_SAS_PHY_0
2632#define MPI_SAS_PHY0_HWRATE_MIN_RATE_1_5 (0x08) 2679#define MPI_SAS_PHY0_HWRATE_MIN_RATE_1_5 (0x08)
2633#define MPI_SAS_PHY0_HWRATE_MIN_RATE_3_0 (0x09) 2680#define MPI_SAS_PHY0_HWRATE_MIN_RATE_3_0 (0x09)
2634 2681
2682/* values for SAS PHY Page 0 Flags field */
2683#define MPI_SAS_PHY0_FLAGS_SGPIO_DIRECT_ATTACH_ENC (0x01)
2684
2635/* values for SAS PHY Page 0 PhyInfo field */ 2685/* values for SAS PHY Page 0 PhyInfo field */
2636#define MPI_SAS_PHY0_PHYINFO_SATA_PORT_ACTIVE (0x00004000) 2686#define MPI_SAS_PHY0_PHYINFO_SATA_PORT_ACTIVE (0x00004000)
2637#define MPI_SAS_PHY0_PHYINFO_SATA_PORT_SELECTOR (0x00002000) 2687#define MPI_SAS_PHY0_PHYINFO_SATA_PORT_SELECTOR (0x00002000)
@@ -2690,7 +2740,7 @@ typedef struct _CONFIG_PAGE_SAS_ENCLOSURE_0
2690} CONFIG_PAGE_SAS_ENCLOSURE_0, MPI_POINTER PTR_CONFIG_PAGE_SAS_ENCLOSURE_0, 2740} CONFIG_PAGE_SAS_ENCLOSURE_0, MPI_POINTER PTR_CONFIG_PAGE_SAS_ENCLOSURE_0,
2691 SasEnclosurePage0_t, MPI_POINTER pSasEnclosurePage0_t; 2741 SasEnclosurePage0_t, MPI_POINTER pSasEnclosurePage0_t;
2692 2742
2693#define MPI_SASENCLOSURE0_PAGEVERSION (0x00) 2743#define MPI_SASENCLOSURE0_PAGEVERSION (0x01)
2694 2744
2695/* values for SAS Enclosure Page 0 Flags field */ 2745/* values for SAS Enclosure Page 0 Flags field */
2696#define MPI_SAS_ENCLS0_FLAGS_SEP_BUS_ID_VALID (0x0020) 2746#define MPI_SAS_ENCLS0_FLAGS_SEP_BUS_ID_VALID (0x0020)
@@ -2702,6 +2752,7 @@ typedef struct _CONFIG_PAGE_SAS_ENCLOSURE_0
2702#define MPI_SAS_ENCLS0_FLAGS_MNG_IOC_SGPIO (0x0002) 2752#define MPI_SAS_ENCLS0_FLAGS_MNG_IOC_SGPIO (0x0002)
2703#define MPI_SAS_ENCLS0_FLAGS_MNG_EXP_SGPIO (0x0003) 2753#define MPI_SAS_ENCLS0_FLAGS_MNG_EXP_SGPIO (0x0003)
2704#define MPI_SAS_ENCLS0_FLAGS_MNG_SES_ENCLOSURE (0x0004) 2754#define MPI_SAS_ENCLS0_FLAGS_MNG_SES_ENCLOSURE (0x0004)
2755#define MPI_SAS_ENCLS0_FLAGS_MNG_IOC_GPIO (0x0005)
2705 2756
2706 2757
2707/**************************************************************************** 2758/****************************************************************************
diff --git a/drivers/message/fusion/lsi/mpi_history.txt b/drivers/message/fusion/lsi/mpi_history.txt
index c9edbee41ed..1a30ef16adb 100644
--- a/drivers/message/fusion/lsi/mpi_history.txt
+++ b/drivers/message/fusion/lsi/mpi_history.txt
@@ -6,17 +6,17 @@
6 Copyright (c) 2000-2005 LSI Logic Corporation. 6 Copyright (c) 2000-2005 LSI Logic Corporation.
7 7
8 --------------------------------------- 8 ---------------------------------------
9 Header Set Release Version: 01.05.09 9 Header Set Release Version: 01.05.10
10 Header Set Release Date: 03-11-05 10 Header Set Release Date: 03-11-05
11 --------------------------------------- 11 ---------------------------------------
12 12
13 Filename Current version Prior version 13 Filename Current version Prior version
14 ---------- --------------- ------------- 14 ---------- --------------- -------------
15 mpi.h 01.05.07 01.05.06 15 mpi.h 01.05.08 01.05.07
16 mpi_ioc.h 01.05.08 01.05.07 16 mpi_ioc.h 01.05.09 01.05.08
17 mpi_cnfg.h 01.05.08 01.05.07 17 mpi_cnfg.h 01.05.09 01.05.08
18 mpi_init.h 01.05.04 01.05.03 18 mpi_init.h 01.05.05 01.05.04
19 mpi_targ.h 01.05.04 01.05.03 19 mpi_targ.h 01.05.05 01.05.04
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
@@ -24,7 +24,7 @@
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.01 01.05.01 25 mpi_sas.h 01.05.01 01.05.01
26 mpi_type.h 01.05.01 01.05.01 26 mpi_type.h 01.05.01 01.05.01
27 mpi_history.txt 01.05.09 01.05.08 27 mpi_history.txt 01.05.09 01.05.09
28 28
29 29
30 * Date Version Description 30 * Date Version Description
@@ -88,6 +88,9 @@ mpi.h
88 * 03-11-05 01.05.07 Removed function codes for SCSI IO 32 and 88 * 03-11-05 01.05.07 Removed function codes for SCSI IO 32 and
89 * TargetAssistExtended requests. 89 * TargetAssistExtended requests.
90 * Removed EEDP IOCStatus codes. 90 * Removed EEDP IOCStatus codes.
91 * 06-24-05 01.05.08 Added function codes for SCSI IO 32 and
92 * TargetAssistExtended requests.
93 * Added EEDP IOCStatus codes.
91 * -------------------------------------------------------------------------- 94 * --------------------------------------------------------------------------
92 95
93mpi_ioc.h 96mpi_ioc.h
@@ -159,6 +162,8 @@ mpi_ioc.h
159 * Reply and IOC Init Request. 162 * Reply and IOC Init Request.
160 * 03-11-05 01.05.08 Added family code for 1068E family. 163 * 03-11-05 01.05.08 Added family code for 1068E family.
161 * Removed IOCFacts Reply EEDP Capability bit. 164 * Removed IOCFacts Reply EEDP Capability bit.
165 * 06-24-05 01.05.09 Added 5 new IOCFacts Reply IOCCapabilities bits.
166 * Added Max SATA Targets to SAS Discovery Error event.
162 * -------------------------------------------------------------------------- 167 * --------------------------------------------------------------------------
163 168
164mpi_cnfg.h 169mpi_cnfg.h
@@ -380,6 +385,23 @@ mpi_cnfg.h
380 * New physical mapping mode in SAS IO Unit Page 2. 385 * New physical mapping mode in SAS IO Unit Page 2.
381 * Added CONFIG_PAGE_SAS_ENCLOSURE_0. 386 * Added CONFIG_PAGE_SAS_ENCLOSURE_0.
382 * Added Slot and Enclosure fields to SAS Device Page 0. 387 * Added Slot and Enclosure fields to SAS Device Page 0.
388 * 06-24-05 01.05.09 Added EEDP defines to IOC Page 1.
389 * Added more RAID type defines to IOC Page 2.
390 * Added Port Enable Delay settings to BIOS Page 1.
391 * Added Bad Block Table Full define to RAID Volume Page 0.
392 * Added Previous State defines to RAID Physical Disk
393 * Page 0.
394 * Added Max Sata Targets define for DiscoveryStatus field
395 * of SAS IO Unit Page 0.
396 * Added Device Self Test to Control Flags of SAS IO Unit
397 * Page 1.
398 * Added Direct Attach Starting Slot Number define for SAS
399 * IO Unit Page 2.
400 * Added new fields in SAS Device Page 2 for enclosure
401 * mapping.
402 * Added OwnerDevHandle and Flags field to SAS PHY Page 0.
403 * Added IOC GPIO Flags define to SAS Enclosure Page 0.
404 * Fixed the value for MPI_SAS_IOUNIT1_CONTROL_DEV_SATA_SUPPORT.
383 * -------------------------------------------------------------------------- 405 * --------------------------------------------------------------------------
384 406
385mpi_init.h 407mpi_init.h
@@ -418,6 +440,8 @@ mpi_init.h
418 * Modified SCSI Enclosure Processor Request and Reply to 440 * Modified SCSI Enclosure Processor Request and Reply to
419 * support Enclosure/Slot addressing rather than WWID 441 * support Enclosure/Slot addressing rather than WWID
420 * addressing. 442 * addressing.
443 * 06-24-05 01.05.05 Added SCSI IO 32 structures and defines.
444 * Added four new defines for SEP SlotStatus.
421 * -------------------------------------------------------------------------- 445 * --------------------------------------------------------------------------
422 446
423mpi_targ.h 447mpi_targ.h
@@ -461,6 +485,7 @@ mpi_targ.h
461 * 10-05-04 01.05.02 MSG_TARGET_CMD_BUFFER_POST_BASE_LIST_REPLY added. 485 * 10-05-04 01.05.02 MSG_TARGET_CMD_BUFFER_POST_BASE_LIST_REPLY added.
462 * 02-22-05 01.05.03 Changed a comment. 486 * 02-22-05 01.05.03 Changed a comment.
463 * 03-11-05 01.05.04 Removed TargetAssistExtended Request. 487 * 03-11-05 01.05.04 Removed TargetAssistExtended Request.
488 * 06-24-05 01.05.05 Added TargetAssistExtended structures and defines.
464 * -------------------------------------------------------------------------- 489 * --------------------------------------------------------------------------
465 490
466mpi_fc.h 491mpi_fc.h
@@ -571,20 +596,20 @@ mpi_type.h
571 596
572mpi_history.txt Parts list history 597mpi_history.txt Parts list history
573 598
574Filename 01.05.09 599Filename 01.05.10 01.05.09
575---------- -------- 600---------- -------- --------
576mpi.h 01.05.07 601mpi.h 01.05.08 01.05.07
577mpi_ioc.h 01.05.08 602mpi_ioc.h 01.05.09 01.05.08
578mpi_cnfg.h 01.05.08 603mpi_cnfg.h 01.05.09 01.05.08
579mpi_init.h 01.05.04 604mpi_init.h 01.05.05 01.05.04
580mpi_targ.h 01.05.04 605mpi_targ.h 01.05.05 01.05.04
581mpi_fc.h 01.05.01 606mpi_fc.h 01.05.01 01.05.01
582mpi_lan.h 01.05.01 607mpi_lan.h 01.05.01 01.05.01
583mpi_raid.h 01.05.02 608mpi_raid.h 01.05.02 01.05.02
584mpi_tool.h 01.05.03 609mpi_tool.h 01.05.03 01.05.03
585mpi_inb.h 01.05.01 610mpi_inb.h 01.05.01 01.05.01
586mpi_sas.h 01.05.01 611mpi_sas.h 01.05.01 01.05.01
587mpi_type.h 01.05.01 612mpi_type.h 01.05.01 01.05.01
588 613
589Filename 01.05.08 01.05.07 01.05.06 01.05.05 01.05.04 01.05.03 614Filename 01.05.08 01.05.07 01.05.06 01.05.05 01.05.04 01.05.03
590---------- -------- -------- -------- -------- -------- -------- 615---------- -------- -------- -------- -------- -------- --------
diff --git a/drivers/message/fusion/lsi/mpi_init.h b/drivers/message/fusion/lsi/mpi_init.h
index aca035801a8..d5af75afbd9 100644
--- a/drivers/message/fusion/lsi/mpi_init.h
+++ b/drivers/message/fusion/lsi/mpi_init.h
@@ -6,7 +6,7 @@
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.04 9 * mpi_init.h Version: 01.05.05
10 * 10 *
11 * Version History 11 * Version History
12 * --------------- 12 * ---------------
@@ -48,6 +48,8 @@
48 * Modified SCSI Enclosure Processor Request and Reply to 48 * Modified SCSI Enclosure Processor Request and Reply to
49 * support Enclosure/Slot addressing rather than WWID 49 * support Enclosure/Slot addressing rather than WWID
50 * addressing. 50 * addressing.
51 * 06-24-05 01.05.05 Added SCSI IO 32 structures and defines.
52 * Added four new defines for SEP SlotStatus.
51 * -------------------------------------------------------------------------- 53 * --------------------------------------------------------------------------
52 */ 54 */
53 55
@@ -203,6 +205,197 @@ typedef struct _MSG_SCSI_IO_REPLY
203 205
204 206
205/****************************************************************************/ 207/****************************************************************************/
208/* SCSI IO 32 messages and associated structures */
209/****************************************************************************/
210
211typedef struct
212{
213 U8 CDB[20]; /* 00h */
214 U32 PrimaryReferenceTag; /* 14h */
215 U16 PrimaryApplicationTag; /* 18h */
216 U16 PrimaryApplicationTagMask; /* 1Ah */
217 U32 TransferLength; /* 1Ch */
218} MPI_SCSI_IO32_CDB_EEDP32, MPI_POINTER PTR_MPI_SCSI_IO32_CDB_EEDP32,
219 MpiScsiIo32CdbEedp32_t, MPI_POINTER pMpiScsiIo32CdbEedp32_t;
220
221typedef struct
222{
223 U8 CDB[16]; /* 00h */
224 U32 DataLength; /* 10h */
225 U32 PrimaryReferenceTag; /* 14h */
226 U16 PrimaryApplicationTag; /* 18h */
227 U16 PrimaryApplicationTagMask; /* 1Ah */
228 U32 TransferLength; /* 1Ch */
229} MPI_SCSI_IO32_CDB_EEDP16, MPI_POINTER PTR_MPI_SCSI_IO32_CDB_EEDP16,
230 MpiScsiIo32CdbEedp16_t, MPI_POINTER pMpiScsiIo32CdbEedp16_t;
231
232typedef union
233{
234 U8 CDB32[32];
235 MPI_SCSI_IO32_CDB_EEDP32 EEDP32;
236 MPI_SCSI_IO32_CDB_EEDP16 EEDP16;
237 SGE_SIMPLE_UNION SGE;
238} MPI_SCSI_IO32_CDB_UNION, MPI_POINTER PTR_MPI_SCSI_IO32_CDB_UNION,
239 MpiScsiIo32Cdb_t, MPI_POINTER pMpiScsiIo32Cdb_t;
240
241typedef struct
242{
243 U8 TargetID; /* 00h */
244 U8 Bus; /* 01h */
245 U16 Reserved1; /* 02h */
246 U32 Reserved2; /* 04h */
247} MPI_SCSI_IO32_BUS_TARGET_ID_FORM, MPI_POINTER PTR_MPI_SCSI_IO32_BUS_TARGET_ID_FORM,
248 MpiScsiIo32BusTargetIdForm_t, MPI_POINTER pMpiScsiIo32BusTargetIdForm_t;
249
250typedef union
251{
252 MPI_SCSI_IO32_BUS_TARGET_ID_FORM SCSIID;
253 U64 WWID;
254} MPI_SCSI_IO32_ADDRESS, MPI_POINTER PTR_MPI_SCSI_IO32_ADDRESS,
255 MpiScsiIo32Address_t, MPI_POINTER pMpiScsiIo32Address_t;
256
257typedef struct _MSG_SCSI_IO32_REQUEST
258{
259 U8 Port; /* 00h */
260 U8 Reserved1; /* 01h */
261 U8 ChainOffset; /* 02h */
262 U8 Function; /* 03h */
263 U8 CDBLength; /* 04h */
264 U8 SenseBufferLength; /* 05h */
265 U8 Flags; /* 06h */
266 U8 MsgFlags; /* 07h */
267 U32 MsgContext; /* 08h */
268 U8 LUN[8]; /* 0Ch */
269 U32 Control; /* 14h */
270 MPI_SCSI_IO32_CDB_UNION CDB; /* 18h */
271 U32 DataLength; /* 38h */
272 U32 BidirectionalDataLength; /* 3Ch */
273 U32 SecondaryReferenceTag; /* 40h */
274 U16 SecondaryApplicationTag; /* 44h */
275 U16 Reserved2; /* 46h */
276 U16 EEDPFlags; /* 48h */
277 U16 ApplicationTagTranslationMask; /* 4Ah */
278 U32 EEDPBlockSize; /* 4Ch */
279 MPI_SCSI_IO32_ADDRESS DeviceAddress; /* 50h */
280 U8 SGLOffset0; /* 58h */
281 U8 SGLOffset1; /* 59h */
282 U8 SGLOffset2; /* 5Ah */
283 U8 SGLOffset3; /* 5Bh */
284 U32 Reserved3; /* 5Ch */
285 U32 Reserved4; /* 60h */
286 U32 SenseBufferLowAddr; /* 64h */
287 SGE_IO_UNION SGL; /* 68h */
288} MSG_SCSI_IO32_REQUEST, MPI_POINTER PTR_MSG_SCSI_IO32_REQUEST,
289 SCSIIO32Request_t, MPI_POINTER pSCSIIO32Request_t;
290
291/* SCSI IO 32 MsgFlags bits */
292#define MPI_SCSIIO32_MSGFLGS_SENSE_WIDTH (0x01)
293#define MPI_SCSIIO32_MSGFLGS_SENSE_WIDTH_32 (0x00)
294#define MPI_SCSIIO32_MSGFLGS_SENSE_WIDTH_64 (0x01)
295
296#define MPI_SCSIIO32_MSGFLGS_SENSE_LOCATION (0x02)
297#define MPI_SCSIIO32_MSGFLGS_SENSE_LOC_HOST (0x00)
298#define MPI_SCSIIO32_MSGFLGS_SENSE_LOC_IOC (0x02)
299
300#define MPI_SCSIIO32_MSGFLGS_CMD_DETERMINES_DATA_DIR (0x04)
301#define MPI_SCSIIO32_MSGFLGS_SGL_OFFSETS_CHAINS (0x08)
302#define MPI_SCSIIO32_MSGFLGS_MULTICAST (0x10)
303#define MPI_SCSIIO32_MSGFLGS_BIDIRECTIONAL (0x20)
304#define MPI_SCSIIO32_MSGFLGS_LARGE_CDB (0x40)
305
306/* SCSI IO 32 Flags bits */
307#define MPI_SCSIIO32_FLAGS_FORM_MASK (0x03)
308#define MPI_SCSIIO32_FLAGS_FORM_SCSIID (0x00)
309#define MPI_SCSIIO32_FLAGS_FORM_WWID (0x01)
310
311/* SCSI IO 32 LUN fields */
312#define MPI_SCSIIO32_LUN_FIRST_LEVEL_ADDRESSING (0x0000FFFF)
313#define MPI_SCSIIO32_LUN_SECOND_LEVEL_ADDRESSING (0xFFFF0000)
314#define MPI_SCSIIO32_LUN_THIRD_LEVEL_ADDRESSING (0x0000FFFF)
315#define MPI_SCSIIO32_LUN_FOURTH_LEVEL_ADDRESSING (0xFFFF0000)
316#define MPI_SCSIIO32_LUN_LEVEL_1_WORD (0xFF00)
317#define MPI_SCSIIO32_LUN_LEVEL_1_DWORD (0x0000FF00)
318
319/* SCSI IO 32 Control bits */
320#define MPI_SCSIIO32_CONTROL_DATADIRECTION_MASK (0x03000000)
321#define MPI_SCSIIO32_CONTROL_NODATATRANSFER (0x00000000)
322#define MPI_SCSIIO32_CONTROL_WRITE (0x01000000)
323#define MPI_SCSIIO32_CONTROL_READ (0x02000000)
324#define MPI_SCSIIO32_CONTROL_BIDIRECTIONAL (0x03000000)
325
326#define MPI_SCSIIO32_CONTROL_ADDCDBLEN_MASK (0xFC000000)
327#define MPI_SCSIIO32_CONTROL_ADDCDBLEN_SHIFT (26)
328
329#define MPI_SCSIIO32_CONTROL_TASKATTRIBUTE_MASK (0x00000700)
330#define MPI_SCSIIO32_CONTROL_SIMPLEQ (0x00000000)
331#define MPI_SCSIIO32_CONTROL_HEADOFQ (0x00000100)
332#define MPI_SCSIIO32_CONTROL_ORDEREDQ (0x00000200)
333#define MPI_SCSIIO32_CONTROL_ACAQ (0x00000400)
334#define MPI_SCSIIO32_CONTROL_UNTAGGED (0x00000500)
335#define MPI_SCSIIO32_CONTROL_NO_DISCONNECT (0x00000700)
336
337#define MPI_SCSIIO32_CONTROL_TASKMANAGE_MASK (0x00FF0000)
338#define MPI_SCSIIO32_CONTROL_OBSOLETE (0x00800000)
339#define MPI_SCSIIO32_CONTROL_CLEAR_ACA_RSV (0x00400000)
340#define MPI_SCSIIO32_CONTROL_TARGET_RESET (0x00200000)
341#define MPI_SCSIIO32_CONTROL_LUN_RESET_RSV (0x00100000)
342#define MPI_SCSIIO32_CONTROL_RESERVED (0x00080000)
343#define MPI_SCSIIO32_CONTROL_CLR_TASK_SET_RSV (0x00040000)
344#define MPI_SCSIIO32_CONTROL_ABORT_TASK_SET (0x00020000)
345#define MPI_SCSIIO32_CONTROL_RESERVED2 (0x00010000)
346
347/* SCSI IO 32 EEDPFlags */
348#define MPI_SCSIIO32_EEDPFLAGS_MASK_OP (0x0007)
349#define MPI_SCSIIO32_EEDPFLAGS_NOOP_OP (0x0000)
350#define MPI_SCSIIO32_EEDPFLAGS_CHK_OP (0x0001)
351#define MPI_SCSIIO32_EEDPFLAGS_STRIP_OP (0x0002)
352#define MPI_SCSIIO32_EEDPFLAGS_CHKRM_OP (0x0003)
353#define MPI_SCSIIO32_EEDPFLAGS_INSERT_OP (0x0004)
354#define MPI_SCSIIO32_EEDPFLAGS_REPLACE_OP (0x0006)
355#define MPI_SCSIIO32_EEDPFLAGS_CHKREGEN_OP (0x0007)
356
357#define MPI_SCSIIO32_EEDPFLAGS_PASS_REF_TAG (0x0008)
358#define MPI_SCSIIO32_EEDPFLAGS_8_9THS_MODE (0x0010)
359
360#define MPI_SCSIIO32_EEDPFLAGS_T10_CHK_MASK (0x0700)
361#define MPI_SCSIIO32_EEDPFLAGS_T10_CHK_GUARD (0x0100)
362#define MPI_SCSIIO32_EEDPFLAGS_T10_CHK_REFTAG (0x0200)
363#define MPI_SCSIIO32_EEDPFLAGS_T10_CHK_LBATAG (0x0400)
364#define MPI_SCSIIO32_EEDPFLAGS_T10_CHK_SHIFT (8)
365
366#define MPI_SCSIIO32_EEDPFLAGS_INC_SEC_APPTAG (0x1000)
367#define MPI_SCSIIO32_EEDPFLAGS_INC_PRI_APPTAG (0x2000)
368#define MPI_SCSIIO32_EEDPFLAGS_INC_SEC_REFTAG (0x4000)
369#define MPI_SCSIIO32_EEDPFLAGS_INC_PRI_REFTAG (0x8000)
370
371
372/* SCSIIO32 IO reply structure */
373typedef struct _MSG_SCSIIO32_IO_REPLY
374{
375 U8 Port; /* 00h */
376 U8 Reserved1; /* 01h */
377 U8 MsgLength; /* 02h */
378 U8 Function; /* 03h */
379 U8 CDBLength; /* 04h */
380 U8 SenseBufferLength; /* 05h */
381 U8 Flags; /* 06h */
382 U8 MsgFlags; /* 07h */
383 U32 MsgContext; /* 08h */
384 U8 SCSIStatus; /* 0Ch */
385 U8 SCSIState; /* 0Dh */
386 U16 IOCStatus; /* 0Eh */
387 U32 IOCLogInfo; /* 10h */
388 U32 TransferCount; /* 14h */
389 U32 SenseCount; /* 18h */
390 U32 ResponseInfo; /* 1Ch */
391 U16 TaskTag; /* 20h */
392 U16 Reserved2; /* 22h */
393 U32 BidirectionalTransferCount; /* 24h */
394} MSG_SCSIIO32_IO_REPLY, MPI_POINTER PTR_MSG_SCSIIO32_IO_REPLY,
395 SCSIIO32Reply_t, MPI_POINTER pSCSIIO32Reply_t;
396
397
398/****************************************************************************/
206/* SCSI Task Management messages */ 399/* SCSI Task Management messages */
207/****************************************************************************/ 400/****************************************************************************/
208 401
@@ -310,10 +503,14 @@ typedef struct _MSG_SEP_REQUEST
310#define MPI_SEP_REQ_SLOTSTATUS_UNCONFIGURED (0x00000080) 503#define MPI_SEP_REQ_SLOTSTATUS_UNCONFIGURED (0x00000080)
311#define MPI_SEP_REQ_SLOTSTATUS_HOT_SPARE (0x00000100) 504#define MPI_SEP_REQ_SLOTSTATUS_HOT_SPARE (0x00000100)
312#define MPI_SEP_REQ_SLOTSTATUS_REBUILD_STOPPED (0x00000200) 505#define MPI_SEP_REQ_SLOTSTATUS_REBUILD_STOPPED (0x00000200)
506#define MPI_SEP_REQ_SLOTSTATUS_REQ_CONSISTENCY_CHECK (0x00001000)
507#define MPI_SEP_REQ_SLOTSTATUS_DISABLE (0x00002000)
508#define MPI_SEP_REQ_SLOTSTATUS_REQ_RESERVED_DEVICE (0x00004000)
313#define MPI_SEP_REQ_SLOTSTATUS_IDENTIFY_REQUEST (0x00020000) 509#define MPI_SEP_REQ_SLOTSTATUS_IDENTIFY_REQUEST (0x00020000)
314#define MPI_SEP_REQ_SLOTSTATUS_REQUEST_REMOVE (0x00040000) 510#define MPI_SEP_REQ_SLOTSTATUS_REQUEST_REMOVE (0x00040000)
315#define MPI_SEP_REQ_SLOTSTATUS_REQUEST_INSERT (0x00080000) 511#define MPI_SEP_REQ_SLOTSTATUS_REQUEST_INSERT (0x00080000)
316#define MPI_SEP_REQ_SLOTSTATUS_DO_NOT_MOVE (0x00400000) 512#define MPI_SEP_REQ_SLOTSTATUS_DO_NOT_MOVE (0x00400000)
513#define MPI_SEP_REQ_SLOTSTATUS_ACTIVE (0x00800000)
317#define MPI_SEP_REQ_SLOTSTATUS_B_ENABLE_BYPASS (0x04000000) 514#define MPI_SEP_REQ_SLOTSTATUS_B_ENABLE_BYPASS (0x04000000)
318#define MPI_SEP_REQ_SLOTSTATUS_A_ENABLE_BYPASS (0x08000000) 515#define MPI_SEP_REQ_SLOTSTATUS_A_ENABLE_BYPASS (0x08000000)
319#define MPI_SEP_REQ_SLOTSTATUS_DEV_OFF (0x10000000) 516#define MPI_SEP_REQ_SLOTSTATUS_DEV_OFF (0x10000000)
@@ -352,11 +549,15 @@ typedef struct _MSG_SEP_REPLY
352#define MPI_SEP_REPLY_SLOTSTATUS_UNCONFIGURED (0x00000080) 549#define MPI_SEP_REPLY_SLOTSTATUS_UNCONFIGURED (0x00000080)
353#define MPI_SEP_REPLY_SLOTSTATUS_HOT_SPARE (0x00000100) 550#define MPI_SEP_REPLY_SLOTSTATUS_HOT_SPARE (0x00000100)
354#define MPI_SEP_REPLY_SLOTSTATUS_REBUILD_STOPPED (0x00000200) 551#define MPI_SEP_REPLY_SLOTSTATUS_REBUILD_STOPPED (0x00000200)
552#define MPI_SEP_REPLY_SLOTSTATUS_CONSISTENCY_CHECK (0x00001000)
553#define MPI_SEP_REPLY_SLOTSTATUS_DISABLE (0x00002000)
554#define MPI_SEP_REPLY_SLOTSTATUS_RESERVED_DEVICE (0x00004000)
355#define MPI_SEP_REPLY_SLOTSTATUS_REPORT (0x00010000) 555#define MPI_SEP_REPLY_SLOTSTATUS_REPORT (0x00010000)
356#define MPI_SEP_REPLY_SLOTSTATUS_IDENTIFY_REQUEST (0x00020000) 556#define MPI_SEP_REPLY_SLOTSTATUS_IDENTIFY_REQUEST (0x00020000)
357#define MPI_SEP_REPLY_SLOTSTATUS_REMOVE_READY (0x00040000) 557#define MPI_SEP_REPLY_SLOTSTATUS_REMOVE_READY (0x00040000)
358#define MPI_SEP_REPLY_SLOTSTATUS_INSERT_READY (0x00080000) 558#define MPI_SEP_REPLY_SLOTSTATUS_INSERT_READY (0x00080000)
359#define MPI_SEP_REPLY_SLOTSTATUS_DO_NOT_REMOVE (0x00400000) 559#define MPI_SEP_REPLY_SLOTSTATUS_DO_NOT_REMOVE (0x00400000)
560#define MPI_SEP_REPLY_SLOTSTATUS_ACTIVE (0x00800000)
360#define MPI_SEP_REPLY_SLOTSTATUS_B_BYPASS_ENABLED (0x01000000) 561#define MPI_SEP_REPLY_SLOTSTATUS_B_BYPASS_ENABLED (0x01000000)
361#define MPI_SEP_REPLY_SLOTSTATUS_A_BYPASS_ENABLED (0x02000000) 562#define MPI_SEP_REPLY_SLOTSTATUS_A_BYPASS_ENABLED (0x02000000)
362#define MPI_SEP_REPLY_SLOTSTATUS_B_ENABLE_BYPASS (0x04000000) 563#define MPI_SEP_REPLY_SLOTSTATUS_B_ENABLE_BYPASS (0x04000000)
diff --git a/drivers/message/fusion/lsi/mpi_ioc.h b/drivers/message/fusion/lsi/mpi_ioc.h
index f91eb4efe8c..93b70e2b426 100644
--- a/drivers/message/fusion/lsi/mpi_ioc.h
+++ b/drivers/message/fusion/lsi/mpi_ioc.h
@@ -6,7 +6,7 @@
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.08 9 * mpi_ioc.h Version: 01.05.09
10 * 10 *
11 * Version History 11 * Version History
12 * --------------- 12 * ---------------
@@ -81,6 +81,8 @@
81 * Reply and IOC Init Request. 81 * Reply and IOC Init Request.
82 * 03-11-05 01.05.08 Added family code for 1068E family. 82 * 03-11-05 01.05.08 Added family code for 1068E family.
83 * Removed IOCFacts Reply EEDP Capability bit. 83 * Removed IOCFacts Reply EEDP Capability bit.
84 * 06-24-05 01.05.09 Added 5 new IOCFacts Reply IOCCapabilities bits.
85 * Added Max SATA Targets to SAS Discovery Error event.
84 * -------------------------------------------------------------------------- 86 * --------------------------------------------------------------------------
85 */ 87 */
86 88
@@ -261,7 +263,11 @@ typedef struct _MSG_IOC_FACTS_REPLY
261#define MPI_IOCFACTS_CAPABILITY_DIAG_TRACE_BUFFER (0x00000008) 263#define MPI_IOCFACTS_CAPABILITY_DIAG_TRACE_BUFFER (0x00000008)
262#define MPI_IOCFACTS_CAPABILITY_SNAPSHOT_BUFFER (0x00000010) 264#define MPI_IOCFACTS_CAPABILITY_SNAPSHOT_BUFFER (0x00000010)
263#define MPI_IOCFACTS_CAPABILITY_EXTENDED_BUFFER (0x00000020) 265#define MPI_IOCFACTS_CAPABILITY_EXTENDED_BUFFER (0x00000020)
264 266#define MPI_IOCFACTS_CAPABILITY_EEDP (0x00000040)
267#define MPI_IOCFACTS_CAPABILITY_BIDIRECTIONAL (0x00000080)
268#define MPI_IOCFACTS_CAPABILITY_MULTICAST (0x00000100)
269#define MPI_IOCFACTS_CAPABILITY_SCSIIO32 (0x00000200)
270#define MPI_IOCFACTS_CAPABILITY_NO_SCSIIO16 (0x00000400)
265 271
266 272
267/***************************************************************************** 273/*****************************************************************************
@@ -677,6 +683,7 @@ typedef struct _EVENT_DATA_DISCOVERY_ERROR
677#define MPI_EVENT_DSCVRY_ERR_DS_MULTPL_SUBTRACTIVE (0x00000200) 683#define MPI_EVENT_DSCVRY_ERR_DS_MULTPL_SUBTRACTIVE (0x00000200)
678#define MPI_EVENT_DSCVRY_ERR_DS_TABLE_TO_TABLE (0x00000400) 684#define MPI_EVENT_DSCVRY_ERR_DS_TABLE_TO_TABLE (0x00000400)
679#define MPI_EVENT_DSCVRY_ERR_DS_MULTPL_PATHS (0x00000800) 685#define MPI_EVENT_DSCVRY_ERR_DS_MULTPL_PATHS (0x00000800)
686#define MPI_EVENT_DSCVRY_ERR_DS_MAX_SATA_TARGETS (0x00001000)
680 687
681 688
682/***************************************************************************** 689/*****************************************************************************
diff --git a/drivers/message/fusion/lsi/mpi_targ.h b/drivers/message/fusion/lsi/mpi_targ.h
index 623901fd82b..3f462859cee 100644
--- a/drivers/message/fusion/lsi/mpi_targ.h
+++ b/drivers/message/fusion/lsi/mpi_targ.h
@@ -6,7 +6,7 @@
6 * Title: MPI Target mode messages and structures 6 * Title: MPI Target mode messages and structures
7 * Creation Date: June 22, 2000 7 * Creation Date: June 22, 2000
8 * 8 *
9 * mpi_targ.h Version: 01.05.04 9 * mpi_targ.h Version: 01.05.05
10 * 10 *
11 * Version History 11 * Version History
12 * --------------- 12 * ---------------
@@ -53,6 +53,7 @@
53 * 10-05-04 01.05.02 MSG_TARGET_CMD_BUFFER_POST_BASE_LIST_REPLY added. 53 * 10-05-04 01.05.02 MSG_TARGET_CMD_BUFFER_POST_BASE_LIST_REPLY added.
54 * 02-22-05 01.05.03 Changed a comment. 54 * 02-22-05 01.05.03 Changed a comment.
55 * 03-11-05 01.05.04 Removed TargetAssistExtended Request. 55 * 03-11-05 01.05.04 Removed TargetAssistExtended Request.
56 * 06-24-05 01.05.05 Added TargetAssistExtended structures and defines.
56 * -------------------------------------------------------------------------- 57 * --------------------------------------------------------------------------
57 */ 58 */
58 59
@@ -371,6 +372,77 @@ typedef struct _MSG_TARGET_ERROR_REPLY
371 372
372 373
373/****************************************************************************/ 374/****************************************************************************/
375/* Target Assist Extended Request */
376/****************************************************************************/
377
378typedef struct _MSG_TARGET_ASSIST_EXT_REQUEST
379{
380 U8 StatusCode; /* 00h */
381 U8 TargetAssistFlags; /* 01h */
382 U8 ChainOffset; /* 02h */
383 U8 Function; /* 03h */
384 U16 QueueTag; /* 04h */
385 U8 Reserved1; /* 06h */
386 U8 MsgFlags; /* 07h */
387 U32 MsgContext; /* 08h */
388 U32 ReplyWord; /* 0Ch */
389 U8 LUN[8]; /* 10h */
390 U32 RelativeOffset; /* 18h */
391 U32 Reserved2; /* 1Ch */
392 U32 Reserved3; /* 20h */
393 U32 PrimaryReferenceTag; /* 24h */
394 U16 PrimaryApplicationTag; /* 28h */
395 U16 PrimaryApplicationTagMask; /* 2Ah */
396 U32 Reserved4; /* 2Ch */
397 U32 DataLength; /* 30h */
398 U32 BidirectionalDataLength; /* 34h */
399 U32 SecondaryReferenceTag; /* 38h */
400 U16 SecondaryApplicationTag; /* 3Ch */
401 U16 Reserved5; /* 3Eh */
402 U16 EEDPFlags; /* 40h */
403 U16 ApplicationTagTranslationMask; /* 42h */
404 U32 EEDPBlockSize; /* 44h */
405 U8 SGLOffset0; /* 48h */
406 U8 SGLOffset1; /* 49h */
407 U8 SGLOffset2; /* 4Ah */
408 U8 SGLOffset3; /* 4Bh */
409 U32 Reserved6; /* 4Ch */
410 SGE_IO_UNION SGL[1]; /* 50h */
411} MSG_TARGET_ASSIST_EXT_REQUEST, MPI_POINTER PTR_MSG_TARGET_ASSIST_EXT_REQUEST,
412 TargetAssistExtRequest_t, MPI_POINTER pTargetAssistExtRequest_t;
413
414/* see the defines after MSG_TARGET_ASSIST_REQUEST for TargetAssistFlags */
415
416/* defines for the MsgFlags field */
417#define TARGET_ASSIST_EXT_MSGFLAGS_BIDIRECTIONAL (0x20)
418#define TARGET_ASSIST_EXT_MSGFLAGS_MULTICAST (0x10)
419#define TARGET_ASSIST_EXT_MSGFLAGS_SGL_OFFSET_CHAINS (0x08)
420
421/* defines for the EEDPFlags field */
422#define TARGET_ASSIST_EXT_EEDP_MASK_OP (0x0007)
423#define TARGET_ASSIST_EXT_EEDP_NOOP_OP (0x0000)
424#define TARGET_ASSIST_EXT_EEDP_CHK_OP (0x0001)
425#define TARGET_ASSIST_EXT_EEDP_STRIP_OP (0x0002)
426#define TARGET_ASSIST_EXT_EEDP_CHKRM_OP (0x0003)
427#define TARGET_ASSIST_EXT_EEDP_INSERT_OP (0x0004)
428#define TARGET_ASSIST_EXT_EEDP_REPLACE_OP (0x0006)
429#define TARGET_ASSIST_EXT_EEDP_CHKREGEN_OP (0x0007)
430
431#define TARGET_ASSIST_EXT_EEDP_PASS_REF_TAG (0x0008)
432
433#define TARGET_ASSIST_EXT_EEDP_T10_CHK_MASK (0x0700)
434#define TARGET_ASSIST_EXT_EEDP_T10_CHK_GUARD (0x0100)
435#define TARGET_ASSIST_EXT_EEDP_T10_CHK_APPTAG (0x0200)
436#define TARGET_ASSIST_EXT_EEDP_T10_CHK_REFTAG (0x0400)
437#define TARGET_ASSIST_EXT_EEDP_T10_CHK_SHIFT (8)
438
439#define TARGET_ASSIST_EXT_EEDP_INC_SEC_APPTAG (0x1000)
440#define TARGET_ASSIST_EXT_EEDP_INC_PRI_APPTAG (0x2000)
441#define TARGET_ASSIST_EXT_EEDP_INC_SEC_REFTAG (0x4000)
442#define TARGET_ASSIST_EXT_EEDP_INC_PRI_REFTAG (0x8000)
443
444
445/****************************************************************************/
374/* Target Status Send Request */ 446/* Target Status Send Request */
375/****************************************************************************/ 447/****************************************************************************/
376 448
diff --git a/drivers/message/fusion/mptbase.c b/drivers/message/fusion/mptbase.c
index ffbe6f4720e..f517d0692d5 100644
--- a/drivers/message/fusion/mptbase.c
+++ b/drivers/message/fusion/mptbase.c
@@ -218,8 +218,7 @@ pci_enable_io_access(struct pci_dev *pdev)
218 * (also referred to as a IO Controller or IOC). 218 * (also referred to as a IO Controller or IOC).
219 * This routine must clear the interrupt from the adapter and does 219 * This routine must clear the interrupt from the adapter and does
220 * so by reading the reply FIFO. Multiple replies may be processed 220 * so by reading the reply FIFO. Multiple replies may be processed
221 * per single call to this routine; up to MPT_MAX_REPLIES_PER_ISR 221 * per single call to this routine.
222 * which is currently set to 32 in mptbase.h.
223 * 222 *
224 * This routine handles register-level access of the adapter but 223 * This routine handles register-level access of the adapter but
225 * dispatches (calls) a protocol-specific callback routine to handle 224 * dispatches (calls) a protocol-specific callback routine to handle
@@ -279,11 +278,11 @@ mpt_interrupt(int irq, void *bus_id, struct pt_regs *r)
279 cb_idx = mr->u.frame.hwhdr.msgctxu.fld.cb_idx; 278 cb_idx = mr->u.frame.hwhdr.msgctxu.fld.cb_idx;
280 mf = MPT_INDEX_2_MFPTR(ioc, req_idx); 279 mf = MPT_INDEX_2_MFPTR(ioc, req_idx);
281 280
282 dmfprintk((MYIOC_s_INFO_FMT "Got non-TURBO reply=%p req_idx=%x\n", 281 dmfprintk((MYIOC_s_INFO_FMT "Got non-TURBO reply=%p req_idx=%x cb_idx=%x Function=%x\n",
283 ioc->name, mr, req_idx)); 282 ioc->name, mr, req_idx, cb_idx, mr->u.hdr.Function));
284 DBG_DUMP_REPLY_FRAME(mr) 283 DBG_DUMP_REPLY_FRAME(mr)
285 284
286 /* Check/log IOC log info 285 /* Check/log IOC log info
287 */ 286 */
288 ioc_stat = le16_to_cpu(mr->u.reply.IOCStatus); 287 ioc_stat = le16_to_cpu(mr->u.reply.IOCStatus);
289 if (ioc_stat & MPI_IOCSTATUS_FLAG_LOG_INFO_AVAILABLE) { 288 if (ioc_stat & MPI_IOCSTATUS_FLAG_LOG_INFO_AVAILABLE) {
@@ -345,7 +344,7 @@ mpt_interrupt(int irq, void *bus_id, struct pt_regs *r)
345 if ((mf) && ((mf >= MPT_INDEX_2_MFPTR(ioc, ioc->req_depth)) 344 if ((mf) && ((mf >= MPT_INDEX_2_MFPTR(ioc, ioc->req_depth))
346 || (mf < ioc->req_frames)) ) { 345 || (mf < ioc->req_frames)) ) {
347 printk(MYIOC_s_WARN_FMT 346 printk(MYIOC_s_WARN_FMT
348 "mpt_interrupt: Invalid mf (%p) req_idx (%d)!\n", ioc->name, (void *)mf, req_idx); 347 "mpt_interrupt: Invalid mf (%p)!\n", ioc->name, (void *)mf);
349 cb_idx = 0; 348 cb_idx = 0;
350 pa = 0; 349 pa = 0;
351 freeme = 0; 350 freeme = 0;
@@ -399,7 +398,7 @@ mpt_interrupt(int irq, void *bus_id, struct pt_regs *r)
399 * @mf: Pointer to original MPT request frame 398 * @mf: Pointer to original MPT request frame
400 * @reply: Pointer to MPT reply frame (NULL if TurboReply) 399 * @reply: Pointer to MPT reply frame (NULL if TurboReply)
401 * 400 *
402 * Returns 1 indicating original alloc'd request frame ptr 401 * Returns 1 indicating original alloc'd request frame ptr
403 * should be freed, or 0 if it shouldn't. 402 * should be freed, or 0 if it shouldn't.
404 */ 403 */
405static int 404static int
@@ -408,28 +407,17 @@ mpt_base_reply(MPT_ADAPTER *ioc, MPT_FRAME_HDR *mf, MPT_FRAME_HDR *reply)
408 int freereq = 1; 407 int freereq = 1;
409 u8 func; 408 u8 func;
410 409
411 dprintk((MYIOC_s_INFO_FMT "mpt_base_reply() called\n", ioc->name)); 410 dmfprintk((MYIOC_s_INFO_FMT "mpt_base_reply() called\n", ioc->name));
412
413 if ((mf == NULL) ||
414 (mf >= MPT_INDEX_2_MFPTR(ioc, ioc->req_depth))) {
415 printk(MYIOC_s_ERR_FMT "NULL or BAD request frame ptr! (=%p)\n",
416 ioc->name, (void *)mf);
417 return 1;
418 }
419
420 if (reply == NULL) {
421 dprintk((MYIOC_s_ERR_FMT "Unexpected NULL Event (turbo?) reply!\n",
422 ioc->name));
423 return 1;
424 }
425 411
412#if defined(MPT_DEBUG_MSG_FRAME)
426 if (!(reply->u.hdr.MsgFlags & MPI_MSGFLAGS_CONTINUATION_REPLY)) { 413 if (!(reply->u.hdr.MsgFlags & MPI_MSGFLAGS_CONTINUATION_REPLY)) {
427 dmfprintk((KERN_INFO MYNAM ": Original request frame (@%p) header\n", mf)); 414 dmfprintk((KERN_INFO MYNAM ": Original request frame (@%p) header\n", mf));
428 DBG_DUMP_REQUEST_FRAME_HDR(mf) 415 DBG_DUMP_REQUEST_FRAME_HDR(mf)
429 } 416 }
417#endif
430 418
431 func = reply->u.hdr.Function; 419 func = reply->u.hdr.Function;
432 dprintk((MYIOC_s_INFO_FMT "mpt_base_reply, Function=%02Xh\n", 420 dmfprintk((MYIOC_s_INFO_FMT "mpt_base_reply, Function=%02Xh\n",
433 ioc->name, func)); 421 ioc->name, func));
434 422
435 if (func == MPI_FUNCTION_EVENT_NOTIFICATION) { 423 if (func == MPI_FUNCTION_EVENT_NOTIFICATION) {
@@ -448,8 +436,14 @@ mpt_base_reply(MPT_ADAPTER *ioc, MPT_FRAME_HDR *mf, MPT_FRAME_HDR *reply)
448 * Hmmm... It seems that EventNotificationReply is an exception 436 * Hmmm... It seems that EventNotificationReply is an exception
449 * to the rule of one reply per request. 437 * to the rule of one reply per request.
450 */ 438 */
451 if (pEvReply->MsgFlags & MPI_MSGFLAGS_CONTINUATION_REPLY) 439 if (pEvReply->MsgFlags & MPI_MSGFLAGS_CONTINUATION_REPLY) {
452 freereq = 0; 440 freereq = 0;
441 devtprintk((MYIOC_s_WARN_FMT "EVENT_NOTIFICATION reply %p does not return Request frame\n",
442 ioc->name, pEvReply));
443 } else {
444 devtprintk((MYIOC_s_WARN_FMT "EVENT_NOTIFICATION reply %p returns Request frame\n",
445 ioc->name, pEvReply));
446 }
453 447
454#ifdef CONFIG_PROC_FS 448#ifdef CONFIG_PROC_FS
455// LogEvent(ioc, pEvReply); 449// LogEvent(ioc, pEvReply);
@@ -491,10 +485,21 @@ mpt_base_reply(MPT_ADAPTER *ioc, MPT_FRAME_HDR *mf, MPT_FRAME_HDR *reply)
491 485
492 pCfg->status = status; 486 pCfg->status = status;
493 if (status == MPI_IOCSTATUS_SUCCESS) { 487 if (status == MPI_IOCSTATUS_SUCCESS) {
494 pCfg->hdr->PageVersion = pReply->Header.PageVersion; 488 if ((pReply->Header.PageType &
495 pCfg->hdr->PageLength = pReply->Header.PageLength; 489 MPI_CONFIG_PAGETYPE_MASK) ==
496 pCfg->hdr->PageNumber = pReply->Header.PageNumber; 490 MPI_CONFIG_PAGETYPE_EXTENDED) {
497 pCfg->hdr->PageType = pReply->Header.PageType; 491 pCfg->cfghdr.ehdr->ExtPageLength =
492 le16_to_cpu(pReply->ExtPageLength);
493 pCfg->cfghdr.ehdr->ExtPageType =
494 pReply->ExtPageType;
495 }
496 pCfg->cfghdr.hdr->PageVersion = pReply->Header.PageVersion;
497
498 /* If this is a regular header, save PageLength. */
499 /* LMP Do this better so not using a reserved field! */
500 pCfg->cfghdr.hdr->PageLength = pReply->Header.PageLength;
501 pCfg->cfghdr.hdr->PageNumber = pReply->Header.PageNumber;
502 pCfg->cfghdr.hdr->PageType = pReply->Header.PageType;
498 } 503 }
499 } 504 }
500 505
@@ -705,7 +710,7 @@ mpt_device_driver_deregister(int cb_idx)
705 if (dd_cbfunc->remove) 710 if (dd_cbfunc->remove)
706 dd_cbfunc->remove(ioc->pcidev); 711 dd_cbfunc->remove(ioc->pcidev);
707 } 712 }
708 713
709 MptDeviceDriverHandlers[cb_idx] = NULL; 714 MptDeviceDriverHandlers[cb_idx] = NULL;
710} 715}
711 716
@@ -818,7 +823,7 @@ mpt_put_msg_frame(int handle, MPT_ADAPTER *ioc, MPT_FRAME_HDR *mf)
818 } 823 }
819#endif 824#endif
820 825
821 mf_dma_addr = (ioc->req_frames_low_dma + req_offset) | ioc->RequestNB[req_idx]; 826 mf_dma_addr = (ioc->req_frames_low_dma + req_offset) | ioc->RequestNB[req_idx];
822 dsgprintk((MYIOC_s_INFO_FMT "mf_dma_addr=%x req_idx=%d RequestNB=%x\n", ioc->name, mf_dma_addr, req_idx, ioc->RequestNB[req_idx])); 827 dsgprintk((MYIOC_s_INFO_FMT "mf_dma_addr=%x req_idx=%d RequestNB=%x\n", ioc->name, mf_dma_addr, req_idx, ioc->RequestNB[req_idx]));
823 CHIPREG_WRITE32(&ioc->chip->RequestFifo, mf_dma_addr); 828 CHIPREG_WRITE32(&ioc->chip->RequestFifo, mf_dma_addr);
824} 829}
@@ -920,7 +925,7 @@ mpt_send_handshake_request(int handle, MPT_ADAPTER *ioc, int reqBytes, u32 *req,
920 925
921 /* Make sure there are no doorbells */ 926 /* Make sure there are no doorbells */
922 CHIPREG_WRITE32(&ioc->chip->IntStatus, 0); 927 CHIPREG_WRITE32(&ioc->chip->IntStatus, 0);
923 928
924 CHIPREG_WRITE32(&ioc->chip->Doorbell, 929 CHIPREG_WRITE32(&ioc->chip->Doorbell,
925 ((MPI_FUNCTION_HANDSHAKE<<MPI_DOORBELL_FUNCTION_SHIFT) | 930 ((MPI_FUNCTION_HANDSHAKE<<MPI_DOORBELL_FUNCTION_SHIFT) |
926 ((reqBytes/4)<<MPI_DOORBELL_ADD_DWORDS_SHIFT))); 931 ((reqBytes/4)<<MPI_DOORBELL_ADD_DWORDS_SHIFT)));
@@ -935,14 +940,14 @@ mpt_send_handshake_request(int handle, MPT_ADAPTER *ioc, int reqBytes, u32 *req,
935 return -5; 940 return -5;
936 941
937 dhsprintk((KERN_INFO MYNAM ": %s: mpt_send_handshake_request start, WaitCnt=%d\n", 942 dhsprintk((KERN_INFO MYNAM ": %s: mpt_send_handshake_request start, WaitCnt=%d\n",
938 ioc->name, ii)); 943 ioc->name, ii));
939 944
940 CHIPREG_WRITE32(&ioc->chip->IntStatus, 0); 945 CHIPREG_WRITE32(&ioc->chip->IntStatus, 0);
941 946
942 if ((r = WaitForDoorbellAck(ioc, 5, sleepFlag)) < 0) { 947 if ((r = WaitForDoorbellAck(ioc, 5, sleepFlag)) < 0) {
943 return -2; 948 return -2;
944 } 949 }
945 950
946 /* Send request via doorbell handshake */ 951 /* Send request via doorbell handshake */
947 req_as_bytes = (u8 *) req; 952 req_as_bytes = (u8 *) req;
948 for (ii = 0; ii < reqBytes/4; ii++) { 953 for (ii = 0; ii < reqBytes/4; ii++) {
@@ -988,9 +993,9 @@ mpt_verify_adapter(int iocid, MPT_ADAPTER **iocpp)
988 if (ioc->id == iocid) { 993 if (ioc->id == iocid) {
989 *iocpp =ioc; 994 *iocpp =ioc;
990 return iocid; 995 return iocid;
991 } 996 }
992 } 997 }
993 998
994 *iocpp = NULL; 999 *iocpp = NULL;
995 return -1; 1000 return -1;
996} 1001}
@@ -1032,9 +1037,9 @@ mpt_attach(struct pci_dev *pdev, const struct pci_device_id *id)
1032 1037
1033 if (pci_enable_device(pdev)) 1038 if (pci_enable_device(pdev))
1034 return r; 1039 return r;
1035 1040
1036 dinitprintk((KERN_WARNING MYNAM ": mpt_adapter_install\n")); 1041 dinitprintk((KERN_WARNING MYNAM ": mpt_adapter_install\n"));
1037 1042
1038 if (!pci_set_dma_mask(pdev, DMA_64BIT_MASK)) { 1043 if (!pci_set_dma_mask(pdev, DMA_64BIT_MASK)) {
1039 dprintk((KERN_INFO MYNAM 1044 dprintk((KERN_INFO MYNAM
1040 ": 64 BIT PCI BUS DMA ADDRESSING SUPPORTED\n")); 1045 ": 64 BIT PCI BUS DMA ADDRESSING SUPPORTED\n"));
@@ -1059,7 +1064,7 @@ mpt_attach(struct pci_dev *pdev, const struct pci_device_id *id)
1059 ioc->alloc_total = sizeof(MPT_ADAPTER); 1064 ioc->alloc_total = sizeof(MPT_ADAPTER);
1060 ioc->req_sz = MPT_DEFAULT_FRAME_SIZE; /* avoid div by zero! */ 1065 ioc->req_sz = MPT_DEFAULT_FRAME_SIZE; /* avoid div by zero! */
1061 ioc->reply_sz = MPT_REPLY_FRAME_SIZE; 1066 ioc->reply_sz = MPT_REPLY_FRAME_SIZE;
1062 1067
1063 ioc->pcidev = pdev; 1068 ioc->pcidev = pdev;
1064 ioc->diagPending = 0; 1069 ioc->diagPending = 0;
1065 spin_lock_init(&ioc->diagLock); 1070 spin_lock_init(&ioc->diagLock);
@@ -1088,7 +1093,7 @@ mpt_attach(struct pci_dev *pdev, const struct pci_device_id *id)
1088 /* Find lookup slot. */ 1093 /* Find lookup slot. */
1089 INIT_LIST_HEAD(&ioc->list); 1094 INIT_LIST_HEAD(&ioc->list);
1090 ioc->id = mpt_ids++; 1095 ioc->id = mpt_ids++;
1091 1096
1092 mem_phys = msize = 0; 1097 mem_phys = msize = 0;
1093 port = psize = 0; 1098 port = psize = 0;
1094 for (ii=0; ii < DEVICE_COUNT_RESOURCE; ii++) { 1099 for (ii=0; ii < DEVICE_COUNT_RESOURCE; ii++) {
@@ -1143,7 +1148,7 @@ mpt_attach(struct pci_dev *pdev, const struct pci_device_id *id)
1143 ioc->prod_name = "LSIFC909"; 1148 ioc->prod_name = "LSIFC909";
1144 ioc->bus_type = FC; 1149 ioc->bus_type = FC;
1145 } 1150 }
1146 if (pdev->device == MPI_MANUFACTPAGE_DEVICEID_FC929) { 1151 else if (pdev->device == MPI_MANUFACTPAGE_DEVICEID_FC929) {
1147 ioc->prod_name = "LSIFC929"; 1152 ioc->prod_name = "LSIFC929";
1148 ioc->bus_type = FC; 1153 ioc->bus_type = FC;
1149 } 1154 }
@@ -1322,7 +1327,7 @@ mpt_detach(struct pci_dev *pdev)
1322 remove_proc_entry(pname, NULL); 1327 remove_proc_entry(pname, NULL);
1323 sprintf(pname, MPT_PROCFS_MPTBASEDIR "/%s", ioc->name); 1328 sprintf(pname, MPT_PROCFS_MPTBASEDIR "/%s", ioc->name);
1324 remove_proc_entry(pname, NULL); 1329 remove_proc_entry(pname, NULL);
1325 1330
1326 /* call per device driver remove entry point */ 1331 /* call per device driver remove entry point */
1327 for(ii=0; ii<MPT_MAX_PROTOCOL_DRIVERS; ii++) { 1332 for(ii=0; ii<MPT_MAX_PROTOCOL_DRIVERS; ii++) {
1328 if(MptDeviceDriverHandlers[ii] && 1333 if(MptDeviceDriverHandlers[ii] &&
@@ -1330,7 +1335,7 @@ mpt_detach(struct pci_dev *pdev)
1330 MptDeviceDriverHandlers[ii]->remove(pdev); 1335 MptDeviceDriverHandlers[ii]->remove(pdev);
1331 } 1336 }
1332 } 1337 }
1333 1338
1334 /* Disable interrupts! */ 1339 /* Disable interrupts! */
1335 CHIPREG_WRITE32(&ioc->chip->IntMask, 0xFFFFFFFF); 1340 CHIPREG_WRITE32(&ioc->chip->IntMask, 0xFFFFFFFF);
1336 1341
@@ -1403,7 +1408,7 @@ mpt_resume(struct pci_dev *pdev)
1403 u32 device_state = pdev->current_state; 1408 u32 device_state = pdev->current_state;
1404 int recovery_state; 1409 int recovery_state;
1405 int ii; 1410 int ii;
1406 1411
1407 printk(MYIOC_s_INFO_FMT 1412 printk(MYIOC_s_INFO_FMT
1408 "pci-resume: pdev=0x%p, slot=%s, Previous operating state [D%d]\n", 1413 "pci-resume: pdev=0x%p, slot=%s, Previous operating state [D%d]\n",
1409 ioc->name, pdev, pci_name(pdev), device_state); 1414 ioc->name, pdev, pci_name(pdev), device_state);
@@ -1534,7 +1539,7 @@ mpt_do_ioc_recovery(MPT_ADAPTER *ioc, u32 reason, int sleepFlag)
1534 if ((rc = GetIocFacts(ioc, sleepFlag, reason)) == 0) 1539 if ((rc = GetIocFacts(ioc, sleepFlag, reason)) == 0)
1535 break; 1540 break;
1536 } 1541 }
1537 1542
1538 1543
1539 if (ii == 5) { 1544 if (ii == 5) {
1540 dinitprintk((MYIOC_s_INFO_FMT "Retry IocFacts failed rc=%x\n", ioc->name, rc)); 1545 dinitprintk((MYIOC_s_INFO_FMT "Retry IocFacts failed rc=%x\n", ioc->name, rc));
@@ -1542,7 +1547,7 @@ mpt_do_ioc_recovery(MPT_ADAPTER *ioc, u32 reason, int sleepFlag)
1542 } else if (reason == MPT_HOSTEVENT_IOC_BRINGUP) { 1547 } else if (reason == MPT_HOSTEVENT_IOC_BRINGUP) {
1543 MptDisplayIocCapabilities(ioc); 1548 MptDisplayIocCapabilities(ioc);
1544 } 1549 }
1545 1550
1546 if (alt_ioc_ready) { 1551 if (alt_ioc_ready) {
1547 if ((rc = GetIocFacts(ioc->alt_ioc, sleepFlag, reason)) != 0) { 1552 if ((rc = GetIocFacts(ioc->alt_ioc, sleepFlag, reason)) != 0) {
1548 dinitprintk((MYIOC_s_INFO_FMT "Initial Alt IocFacts failed rc=%x\n", ioc->name, rc)); 1553 dinitprintk((MYIOC_s_INFO_FMT "Initial Alt IocFacts failed rc=%x\n", ioc->name, rc));
@@ -1613,7 +1618,7 @@ mpt_do_ioc_recovery(MPT_ADAPTER *ioc, u32 reason, int sleepFlag)
1613 1618
1614 if (reset_alt_ioc_active && ioc->alt_ioc) { 1619 if (reset_alt_ioc_active && ioc->alt_ioc) {
1615 /* (re)Enable alt-IOC! (reply interrupt) */ 1620 /* (re)Enable alt-IOC! (reply interrupt) */
1616 dprintk((KERN_INFO MYNAM ": alt-%s reply irq re-enabled\n", 1621 dinitprintk((KERN_INFO MYNAM ": alt-%s reply irq re-enabled\n",
1617 ioc->alt_ioc->name)); 1622 ioc->alt_ioc->name));
1618 CHIPREG_WRITE32(&ioc->alt_ioc->chip->IntMask, ~(MPI_HIM_RIM)); 1623 CHIPREG_WRITE32(&ioc->alt_ioc->chip->IntMask, ~(MPI_HIM_RIM));
1619 ioc->alt_ioc->active = 1; 1624 ioc->alt_ioc->active = 1;
@@ -1670,7 +1675,7 @@ mpt_do_ioc_recovery(MPT_ADAPTER *ioc, u32 reason, int sleepFlag)
1670 1675
1671 /* Find IM volumes 1676 /* Find IM volumes
1672 */ 1677 */
1673 if (ioc->facts.MsgVersion >= 0x0102) 1678 if (ioc->facts.MsgVersion >= MPI_VERSION_01_02)
1674 mpt_findImVolumes(ioc); 1679 mpt_findImVolumes(ioc);
1675 1680
1676 /* Check, and possibly reset, the coalescing value 1681 /* Check, and possibly reset, the coalescing value
@@ -1700,7 +1705,7 @@ mpt_do_ioc_recovery(MPT_ADAPTER *ioc, u32 reason, int sleepFlag)
1700 } 1705 }
1701 1706
1702 if (alt_ioc_ready && MptResetHandlers[ii]) { 1707 if (alt_ioc_ready && MptResetHandlers[ii]) {
1703 dprintk((MYIOC_s_INFO_FMT "Calling alt-%s post_reset handler #%d\n", 1708 drsprintk((MYIOC_s_INFO_FMT "Calling alt-%s post_reset handler #%d\n",
1704 ioc->name, ioc->alt_ioc->name, ii)); 1709 ioc->name, ioc->alt_ioc->name, ii));
1705 rc += (*(MptResetHandlers[ii]))(ioc->alt_ioc, MPT_IOC_POST_RESET); 1710 rc += (*(MptResetHandlers[ii]))(ioc->alt_ioc, MPT_IOC_POST_RESET);
1706 handlers++; 1711 handlers++;
@@ -1733,8 +1738,8 @@ mpt_detect_bound_ports(MPT_ADAPTER *ioc, struct pci_dev *pdev)
1733 1738
1734 dprintk((MYIOC_s_INFO_FMT "PCI device %s devfn=%x/%x," 1739 dprintk((MYIOC_s_INFO_FMT "PCI device %s devfn=%x/%x,"
1735 " searching for devfn match on %x or %x\n", 1740 " searching for devfn match on %x or %x\n",
1736 ioc->name, pci_name(pdev), pdev->devfn, 1741 ioc->name, pci_name(pdev), pdev->bus->number,
1737 func-1, func+1)); 1742 pdev->devfn, func-1, func+1));
1738 1743
1739 peer = pci_get_slot(pdev->bus, PCI_DEVFN(slot,func-1)); 1744 peer = pci_get_slot(pdev->bus, PCI_DEVFN(slot,func-1));
1740 if (!peer) { 1745 if (!peer) {
@@ -1861,36 +1866,39 @@ mpt_adapter_disable(MPT_ADAPTER *ioc)
1861static void 1866static void
1862mpt_adapter_dispose(MPT_ADAPTER *ioc) 1867mpt_adapter_dispose(MPT_ADAPTER *ioc)
1863{ 1868{
1864 if (ioc != NULL) { 1869 int sz_first, sz_last;
1865 int sz_first, sz_last;
1866 1870
1867 sz_first = ioc->alloc_total; 1871 if (ioc == NULL)
1872 return;
1868 1873
1869 mpt_adapter_disable(ioc); 1874 sz_first = ioc->alloc_total;
1870 1875
1871 if (ioc->pci_irq != -1) { 1876 mpt_adapter_disable(ioc);
1872 free_irq(ioc->pci_irq, ioc);
1873 ioc->pci_irq = -1;
1874 }
1875 1877
1876 if (ioc->memmap != NULL) 1878 if (ioc->pci_irq != -1) {
1877 iounmap(ioc->memmap); 1879 free_irq(ioc->pci_irq, ioc);
1880 ioc->pci_irq = -1;
1881 }
1882
1883 if (ioc->memmap != NULL) {
1884 iounmap(ioc->memmap);
1885 ioc->memmap = NULL;
1886 }
1878 1887
1879#if defined(CONFIG_MTRR) && 0 1888#if defined(CONFIG_MTRR) && 0
1880 if (ioc->mtrr_reg > 0) { 1889 if (ioc->mtrr_reg > 0) {
1881 mtrr_del(ioc->mtrr_reg, 0, 0); 1890 mtrr_del(ioc->mtrr_reg, 0, 0);
1882 dprintk((KERN_INFO MYNAM ": %s: MTRR region de-registered\n", ioc->name)); 1891 dprintk((KERN_INFO MYNAM ": %s: MTRR region de-registered\n", ioc->name));
1883 } 1892 }
1884#endif 1893#endif
1885 1894
1886 /* Zap the adapter lookup ptr! */ 1895 /* Zap the adapter lookup ptr! */
1887 list_del(&ioc->list); 1896 list_del(&ioc->list);
1888 1897
1889 sz_last = ioc->alloc_total; 1898 sz_last = ioc->alloc_total;
1890 dprintk((KERN_INFO MYNAM ": %s: free'd %d of %d bytes\n", 1899 dprintk((KERN_INFO MYNAM ": %s: free'd %d of %d bytes\n",
1891 ioc->name, sz_first-sz_last+(int)sizeof(*ioc), sz_first)); 1900 ioc->name, sz_first-sz_last+(int)sizeof(*ioc), sz_first));
1892 kfree(ioc); 1901 kfree(ioc);
1893 }
1894} 1902}
1895 1903
1896/*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/ 1904/*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
@@ -1977,7 +1985,7 @@ MakeIocReady(MPT_ADAPTER *ioc, int force, int sleepFlag)
1977 } 1985 }
1978 1986
1979 /* Is it already READY? */ 1987 /* Is it already READY? */
1980 if (!statefault && (ioc_state & MPI_IOC_STATE_MASK) == MPI_IOC_STATE_READY) 1988 if (!statefault && (ioc_state & MPI_IOC_STATE_MASK) == MPI_IOC_STATE_READY)
1981 return 0; 1989 return 0;
1982 1990
1983 /* 1991 /*
@@ -1995,7 +2003,7 @@ MakeIocReady(MPT_ADAPTER *ioc, int force, int sleepFlag)
1995 * Hmmm... Did it get left operational? 2003 * Hmmm... Did it get left operational?
1996 */ 2004 */
1997 if ((ioc_state & MPI_IOC_STATE_MASK) == MPI_IOC_STATE_OPERATIONAL) { 2005 if ((ioc_state & MPI_IOC_STATE_MASK) == MPI_IOC_STATE_OPERATIONAL) {
1998 dinitprintk((MYIOC_s_WARN_FMT "IOC operational unexpected\n", 2006 dinitprintk((MYIOC_s_INFO_FMT "IOC operational unexpected\n",
1999 ioc->name)); 2007 ioc->name));
2000 2008
2001 /* Check WhoInit. 2009 /* Check WhoInit.
@@ -2004,8 +2012,8 @@ MakeIocReady(MPT_ADAPTER *ioc, int force, int sleepFlag)
2004 * Else, fall through to KickStart case 2012 * Else, fall through to KickStart case
2005 */ 2013 */
2006 whoinit = (ioc_state & MPI_DOORBELL_WHO_INIT_MASK) >> MPI_DOORBELL_WHO_INIT_SHIFT; 2014 whoinit = (ioc_state & MPI_DOORBELL_WHO_INIT_MASK) >> MPI_DOORBELL_WHO_INIT_SHIFT;
2007 dprintk((KERN_WARNING MYNAM 2015 dinitprintk((KERN_INFO MYNAM
2008 ": whoinit 0x%x\n statefault %d force %d\n", 2016 ": whoinit 0x%x statefault %d force %d\n",
2009 whoinit, statefault, force)); 2017 whoinit, statefault, force));
2010 if (whoinit == MPI_WHOINIT_PCI_PEER) 2018 if (whoinit == MPI_WHOINIT_PCI_PEER)
2011 return -4; 2019 return -4;
@@ -2140,8 +2148,8 @@ GetIocFacts(MPT_ADAPTER *ioc, int sleepFlag, int reason)
2140 get_facts.Function = MPI_FUNCTION_IOC_FACTS; 2148 get_facts.Function = MPI_FUNCTION_IOC_FACTS;
2141 /* Assert: All other get_facts fields are zero! */ 2149 /* Assert: All other get_facts fields are zero! */
2142 2150
2143 dinitprintk((MYIOC_s_INFO_FMT 2151 dinitprintk((MYIOC_s_INFO_FMT
2144 "Sending get IocFacts request req_sz=%d reply_sz=%d\n", 2152 "Sending get IocFacts request req_sz=%d reply_sz=%d\n",
2145 ioc->name, req_sz, reply_sz)); 2153 ioc->name, req_sz, reply_sz));
2146 2154
2147 /* No non-zero fields in the get_facts request are greater than 2155 /* No non-zero fields in the get_facts request are greater than
@@ -2174,7 +2182,7 @@ GetIocFacts(MPT_ADAPTER *ioc, int sleepFlag, int reason)
2174 facts->IOCExceptions = le16_to_cpu(facts->IOCExceptions); 2182 facts->IOCExceptions = le16_to_cpu(facts->IOCExceptions);
2175 facts->IOCStatus = le16_to_cpu(facts->IOCStatus); 2183 facts->IOCStatus = le16_to_cpu(facts->IOCStatus);
2176 facts->IOCLogInfo = le32_to_cpu(facts->IOCLogInfo); 2184 facts->IOCLogInfo = le32_to_cpu(facts->IOCLogInfo);
2177 status = facts->IOCStatus & MPI_IOCSTATUS_MASK; 2185 status = le16_to_cpu(facts->IOCStatus) & MPI_IOCSTATUS_MASK;
2178 /* CHECKME! IOCStatus, IOCLogInfo */ 2186 /* CHECKME! IOCStatus, IOCLogInfo */
2179 2187
2180 facts->ReplyQueueDepth = le16_to_cpu(facts->ReplyQueueDepth); 2188 facts->ReplyQueueDepth = le16_to_cpu(facts->ReplyQueueDepth);
@@ -2221,7 +2229,7 @@ GetIocFacts(MPT_ADAPTER *ioc, int sleepFlag, int reason)
2221 if ( sz & 0x02 ) 2229 if ( sz & 0x02 )
2222 sz += 2; 2230 sz += 2;
2223 facts->FWImageSize = sz; 2231 facts->FWImageSize = sz;
2224 2232
2225 if (!facts->RequestFrameSize) { 2233 if (!facts->RequestFrameSize) {
2226 /* Something is wrong! */ 2234 /* Something is wrong! */
2227 printk(MYIOC_s_ERR_FMT "IOC reported invalid 0 request size!\n", 2235 printk(MYIOC_s_ERR_FMT "IOC reported invalid 0 request size!\n",
@@ -2240,7 +2248,7 @@ GetIocFacts(MPT_ADAPTER *ioc, int sleepFlag, int reason)
2240 ioc->NBShiftFactor = shiftFactor; 2248 ioc->NBShiftFactor = shiftFactor;
2241 dinitprintk((MYIOC_s_INFO_FMT "NB_for_64_byte_frame=%x NBShiftFactor=%x BlockSize=%x\n", 2249 dinitprintk((MYIOC_s_INFO_FMT "NB_for_64_byte_frame=%x NBShiftFactor=%x BlockSize=%x\n",
2242 ioc->name, vv, shiftFactor, r)); 2250 ioc->name, vv, shiftFactor, r));
2243 2251
2244 if (reason == MPT_HOSTEVENT_IOC_BRINGUP) { 2252 if (reason == MPT_HOSTEVENT_IOC_BRINGUP) {
2245 /* 2253 /*
2246 * Set values for this IOC's request & reply frame sizes, 2254 * Set values for this IOC's request & reply frame sizes,
@@ -2261,7 +2269,7 @@ GetIocFacts(MPT_ADAPTER *ioc, int sleepFlag, int reason)
2261 return r; 2269 return r;
2262 } 2270 }
2263 } else { 2271 } else {
2264 printk(MYIOC_s_ERR_FMT 2272 printk(MYIOC_s_ERR_FMT
2265 "Invalid IOC facts reply, msgLength=%d offsetof=%zd!\n", 2273 "Invalid IOC facts reply, msgLength=%d offsetof=%zd!\n",
2266 ioc->name, facts->MsgLength, (offsetof(IOCFactsReply_t, 2274 ioc->name, facts->MsgLength, (offsetof(IOCFactsReply_t,
2267 RequestFrameSize)/sizeof(u32))); 2275 RequestFrameSize)/sizeof(u32)));
@@ -2413,9 +2421,11 @@ SendIocInit(MPT_ADAPTER *ioc, int sleepFlag)
2413 2421
2414 dhsprintk((MYIOC_s_INFO_FMT "Sending PortEnable (req @ %p)\n", 2422 dhsprintk((MYIOC_s_INFO_FMT "Sending PortEnable (req @ %p)\n",
2415 ioc->name, &ioc_init)); 2423 ioc->name, &ioc_init));
2416 2424
2417 if ((r = SendPortEnable(ioc, 0, sleepFlag)) != 0) 2425 if ((r = SendPortEnable(ioc, 0, sleepFlag)) != 0) {
2426 printk(MYIOC_s_ERR_FMT "Sending PortEnable failed(%d)!\n",ioc->name, r);
2418 return r; 2427 return r;
2428 }
2419 2429
2420 /* YIKES! SUPER IMPORTANT!!! 2430 /* YIKES! SUPER IMPORTANT!!!
2421 * Poll IocState until _OPERATIONAL while IOC is doing 2431 * Poll IocState until _OPERATIONAL while IOC is doing
@@ -2440,7 +2450,7 @@ SendIocInit(MPT_ADAPTER *ioc, int sleepFlag)
2440 state = mpt_GetIocState(ioc, 1); 2450 state = mpt_GetIocState(ioc, 1);
2441 count++; 2451 count++;
2442 } 2452 }
2443 dhsprintk((MYIOC_s_INFO_FMT "INFO - Wait IOC_OPERATIONAL state (cnt=%d)\n", 2453 dinitprintk((MYIOC_s_INFO_FMT "INFO - Wait IOC_OPERATIONAL state (cnt=%d)\n",
2444 ioc->name, count)); 2454 ioc->name, count));
2445 2455
2446 return r; 2456 return r;
@@ -2529,7 +2539,7 @@ mpt_free_fw_memory(MPT_ADAPTER *ioc)
2529 int sz; 2539 int sz;
2530 2540
2531 sz = ioc->facts.FWImageSize; 2541 sz = ioc->facts.FWImageSize;
2532 dinitprintk((KERN_WARNING MYNAM "free_fw_memory: FW Image @ %p[%p], sz=%d[%x] bytes\n", 2542 dinitprintk((KERN_INFO MYNAM "free_fw_memory: FW Image @ %p[%p], sz=%d[%x] bytes\n",
2533 ioc->cached_fw, (void *)(ulong)ioc->cached_fw_dma, sz, sz)); 2543 ioc->cached_fw, (void *)(ulong)ioc->cached_fw_dma, sz, sz));
2534 pci_free_consistent(ioc->pcidev, sz, 2544 pci_free_consistent(ioc->pcidev, sz,
2535 ioc->cached_fw, ioc->cached_fw_dma); 2545 ioc->cached_fw, ioc->cached_fw_dma);
@@ -2573,9 +2583,9 @@ mpt_do_upload(MPT_ADAPTER *ioc, int sleepFlag)
2573 2583
2574 mpt_alloc_fw_memory(ioc, sz); 2584 mpt_alloc_fw_memory(ioc, sz);
2575 2585
2576 dinitprintk((KERN_WARNING MYNAM ": FW Image @ %p[%p], sz=%d[%x] bytes\n", 2586 dinitprintk((KERN_INFO MYNAM ": FW Image @ %p[%p], sz=%d[%x] bytes\n",
2577 ioc->cached_fw, (void *)(ulong)ioc->cached_fw_dma, sz, sz)); 2587 ioc->cached_fw, (void *)(ulong)ioc->cached_fw_dma, sz, sz));
2578 2588
2579 if (ioc->cached_fw == NULL) { 2589 if (ioc->cached_fw == NULL) {
2580 /* Major Failure. 2590 /* Major Failure.
2581 */ 2591 */
@@ -2605,14 +2615,14 @@ mpt_do_upload(MPT_ADAPTER *ioc, int sleepFlag)
2605 mpt_add_sge(&request[sgeoffset], flagsLength, ioc->cached_fw_dma); 2615 mpt_add_sge(&request[sgeoffset], flagsLength, ioc->cached_fw_dma);
2606 2616
2607 sgeoffset += sizeof(u32) + sizeof(dma_addr_t); 2617 sgeoffset += sizeof(u32) + sizeof(dma_addr_t);
2608 dinitprintk((KERN_WARNING MYNAM "Sending FW Upload (req @ %p) sgeoffset=%d \n", 2618 dinitprintk((KERN_INFO MYNAM ": Sending FW Upload (req @ %p) sgeoffset=%d \n",
2609 prequest, sgeoffset)); 2619 prequest, sgeoffset));
2610 DBG_DUMP_FW_REQUEST_FRAME(prequest) 2620 DBG_DUMP_FW_REQUEST_FRAME(prequest)
2611 2621
2612 ii = mpt_handshake_req_reply_wait(ioc, sgeoffset, (u32*)prequest, 2622 ii = mpt_handshake_req_reply_wait(ioc, sgeoffset, (u32*)prequest,
2613 reply_sz, (u16*)preply, 65 /*seconds*/, sleepFlag); 2623 reply_sz, (u16*)preply, 65 /*seconds*/, sleepFlag);
2614 2624
2615 dinitprintk((KERN_WARNING MYNAM "FW Upload completed rc=%x \n", ii)); 2625 dinitprintk((KERN_INFO MYNAM ": FW Upload completed rc=%x \n", ii));
2616 2626
2617 cmdStatus = -EFAULT; 2627 cmdStatus = -EFAULT;
2618 if (ii == 0) { 2628 if (ii == 0) {
@@ -2627,10 +2637,10 @@ mpt_do_upload(MPT_ADAPTER *ioc, int sleepFlag)
2627 cmdStatus = 0; 2637 cmdStatus = 0;
2628 } 2638 }
2629 } 2639 }
2630 dinitprintk((MYIOC_s_INFO_FMT ": do_upload status %d \n", 2640 dinitprintk((MYIOC_s_INFO_FMT ": do_upload cmdStatus=%d \n",
2631 ioc->name, cmdStatus)); 2641 ioc->name, cmdStatus));
2632 2642
2633 2643
2634 if (cmdStatus) { 2644 if (cmdStatus) {
2635 2645
2636 ddlprintk((MYIOC_s_INFO_FMT ": fw upload failed, freeing image \n", 2646 ddlprintk((MYIOC_s_INFO_FMT ": fw upload failed, freeing image \n",
@@ -2761,8 +2771,8 @@ mpt_downloadboot(MPT_ADAPTER *ioc, int sleepFlag)
2761 fwSize = (pExtImage->ImageSize + 3) >> 2; 2771 fwSize = (pExtImage->ImageSize + 3) >> 2;
2762 ptrFw = (u32 *)pExtImage; 2772 ptrFw = (u32 *)pExtImage;
2763 2773
2764 ddlprintk((MYIOC_s_INFO_FMT "Write Ext Image: 0x%x bytes @ %p load_addr=%x\n", 2774 ddlprintk((MYIOC_s_INFO_FMT "Write Ext Image: 0x%x (%d) bytes @ %p load_addr=%x\n",
2765 ioc->name, fwSize*4, ptrFw, load_addr)); 2775 ioc->name, fwSize*4, fwSize*4, ptrFw, load_addr));
2766 CHIPREG_PIO_WRITE32(&ioc->pio_chip->DiagRwAddress, load_addr); 2776 CHIPREG_PIO_WRITE32(&ioc->pio_chip->DiagRwAddress, load_addr);
2767 2777
2768 while (fwSize--) { 2778 while (fwSize--) {
@@ -2845,9 +2855,9 @@ mpt_downloadboot(MPT_ADAPTER *ioc, int sleepFlag)
2845 * 0 else 2855 * 0 else
2846 * 2856 *
2847 * Returns: 2857 * Returns:
2848 * 1 - hard reset, READY 2858 * 1 - hard reset, READY
2849 * 0 - no reset due to History bit, READY 2859 * 0 - no reset due to History bit, READY
2850 * -1 - no reset due to History bit but not READY 2860 * -1 - no reset due to History bit but not READY
2851 * OR reset but failed to come READY 2861 * OR reset but failed to come READY
2852 * -2 - no reset, could not enter DIAG mode 2862 * -2 - no reset, could not enter DIAG mode
2853 * -3 - reset but bad FW bit 2863 * -3 - reset but bad FW bit
@@ -2990,7 +3000,7 @@ mpt_diag_reset(MPT_ADAPTER *ioc, int ignore, int sleepFlag)
2990 * 3000 *
2991 */ 3001 */
2992 CHIPREG_WRITE32(&ioc->chip->Diagnostic, diag0val | MPI_DIAG_DISABLE_ARM); 3002 CHIPREG_WRITE32(&ioc->chip->Diagnostic, diag0val | MPI_DIAG_DISABLE_ARM);
2993 mdelay (1); 3003 mdelay(1);
2994 3004
2995 /* 3005 /*
2996 * Now hit the reset bit in the Diagnostic register 3006 * Now hit the reset bit in the Diagnostic register
@@ -3170,7 +3180,7 @@ SendIocReset(MPT_ADAPTER *ioc, u8 reset_type, int sleepFlag)
3170 u32 state; 3180 u32 state;
3171 int cntdn, count; 3181 int cntdn, count;
3172 3182
3173 drsprintk((KERN_WARNING MYNAM ": %s: Sending IOC reset(0x%02x)!\n", 3183 drsprintk((KERN_INFO MYNAM ": %s: Sending IOC reset(0x%02x)!\n",
3174 ioc->name, reset_type)); 3184 ioc->name, reset_type));
3175 CHIPREG_WRITE32(&ioc->chip->Doorbell, reset_type<<MPI_DOORBELL_FUNCTION_SHIFT); 3185 CHIPREG_WRITE32(&ioc->chip->Doorbell, reset_type<<MPI_DOORBELL_FUNCTION_SHIFT);
3176 if ((r = WaitForDoorbellAck(ioc, 5, sleepFlag)) < 0) 3186 if ((r = WaitForDoorbellAck(ioc, 5, sleepFlag)) < 0)
@@ -3374,6 +3384,9 @@ PrimeIocFifos(MPT_ADAPTER *ioc)
3374 ioc->reply_frames = (MPT_FRAME_HDR *) mem; 3384 ioc->reply_frames = (MPT_FRAME_HDR *) mem;
3375 ioc->reply_frames_low_dma = (u32) (alloc_dma & 0xFFFFFFFF); 3385 ioc->reply_frames_low_dma = (u32) (alloc_dma & 0xFFFFFFFF);
3376 3386
3387 dinitprintk((KERN_INFO MYNAM ": %s ReplyBuffers @ %p[%p]\n",
3388 ioc->name, ioc->reply_frames, (void *)(ulong)alloc_dma));
3389
3377 alloc_dma += reply_sz; 3390 alloc_dma += reply_sz;
3378 mem += reply_sz; 3391 mem += reply_sz;
3379 3392
@@ -3382,7 +3395,7 @@ PrimeIocFifos(MPT_ADAPTER *ioc)
3382 ioc->req_frames = (MPT_FRAME_HDR *) mem; 3395 ioc->req_frames = (MPT_FRAME_HDR *) mem;
3383 ioc->req_frames_dma = alloc_dma; 3396 ioc->req_frames_dma = alloc_dma;
3384 3397
3385 dinitprintk((KERN_INFO MYNAM ": %s.RequestBuffers @ %p[%p]\n", 3398 dinitprintk((KERN_INFO MYNAM ": %s RequestBuffers @ %p[%p]\n",
3386 ioc->name, mem, (void *)(ulong)alloc_dma)); 3399 ioc->name, mem, (void *)(ulong)alloc_dma));
3387 3400
3388 ioc->req_frames_low_dma = (u32) (alloc_dma & 0xFFFFFFFF); 3401 ioc->req_frames_low_dma = (u32) (alloc_dma & 0xFFFFFFFF);
@@ -3408,7 +3421,7 @@ PrimeIocFifos(MPT_ADAPTER *ioc)
3408 ioc->ChainBuffer = mem; 3421 ioc->ChainBuffer = mem;
3409 ioc->ChainBufferDMA = alloc_dma; 3422 ioc->ChainBufferDMA = alloc_dma;
3410 3423
3411 dinitprintk((KERN_INFO MYNAM " :%s.ChainBuffers @ %p(%p)\n", 3424 dinitprintk((KERN_INFO MYNAM " :%s ChainBuffers @ %p(%p)\n",
3412 ioc->name, ioc->ChainBuffer, (void *)(ulong)ioc->ChainBufferDMA)); 3425 ioc->name, ioc->ChainBuffer, (void *)(ulong)ioc->ChainBufferDMA));
3413 3426
3414 /* Initialize the free chain Q. 3427 /* Initialize the free chain Q.
@@ -3513,7 +3526,7 @@ out_fail:
3513 */ 3526 */
3514static int 3527static int
3515mpt_handshake_req_reply_wait(MPT_ADAPTER *ioc, int reqBytes, u32 *req, 3528mpt_handshake_req_reply_wait(MPT_ADAPTER *ioc, int reqBytes, u32 *req,
3516 int replyBytes, u16 *u16reply, int maxwait, int sleepFlag) 3529 int replyBytes, u16 *u16reply, int maxwait, int sleepFlag)
3517{ 3530{
3518 MPIDefaultReply_t *mptReply; 3531 MPIDefaultReply_t *mptReply;
3519 int failcnt = 0; 3532 int failcnt = 0;
@@ -3588,7 +3601,7 @@ mpt_handshake_req_reply_wait(MPT_ADAPTER *ioc, int reqBytes, u32 *req,
3588 */ 3601 */
3589 if (!failcnt && (t = WaitForDoorbellReply(ioc, maxwait, sleepFlag)) < 0) 3602 if (!failcnt && (t = WaitForDoorbellReply(ioc, maxwait, sleepFlag)) < 0)
3590 failcnt++; 3603 failcnt++;
3591 3604
3592 dhsprintk((MYIOC_s_INFO_FMT "HandShake reply count=%d%s\n", 3605 dhsprintk((MYIOC_s_INFO_FMT "HandShake reply count=%d%s\n",
3593 ioc->name, t, failcnt ? " - MISSING DOORBELL REPLY!" : "")); 3606 ioc->name, t, failcnt ? " - MISSING DOORBELL REPLY!" : ""));
3594 3607
@@ -3747,7 +3760,7 @@ WaitForDoorbellReply(MPT_ADAPTER *ioc, int howlong, int sleepFlag)
3747 } 3760 }
3748 3761
3749 dhsprintk((MYIOC_s_INFO_FMT "WaitCnt=%d First handshake reply word=%08x%s\n", 3762 dhsprintk((MYIOC_s_INFO_FMT "WaitCnt=%d First handshake reply word=%08x%s\n",
3750 ioc->name, t, le32_to_cpu(*(u32 *)hs_reply), 3763 ioc->name, t, le32_to_cpu(*(u32 *)hs_reply),
3751 failcnt ? " - MISSING DOORBELL HANDSHAKE!" : "")); 3764 failcnt ? " - MISSING DOORBELL HANDSHAKE!" : ""));
3752 3765
3753 /* 3766 /*
@@ -3819,7 +3832,7 @@ GetLanConfigPages(MPT_ADAPTER *ioc)
3819 hdr.PageLength = 0; 3832 hdr.PageLength = 0;
3820 hdr.PageNumber = 0; 3833 hdr.PageNumber = 0;
3821 hdr.PageType = MPI_CONFIG_PAGETYPE_LAN; 3834 hdr.PageType = MPI_CONFIG_PAGETYPE_LAN;
3822 cfg.hdr = &hdr; 3835 cfg.cfghdr.hdr = &hdr;
3823 cfg.physAddr = -1; 3836 cfg.physAddr = -1;
3824 cfg.action = MPI_CONFIG_ACTION_PAGE_HEADER; 3837 cfg.action = MPI_CONFIG_ACTION_PAGE_HEADER;
3825 cfg.dir = 0; 3838 cfg.dir = 0;
@@ -3863,7 +3876,7 @@ GetLanConfigPages(MPT_ADAPTER *ioc)
3863 hdr.PageLength = 0; 3876 hdr.PageLength = 0;
3864 hdr.PageNumber = 1; 3877 hdr.PageNumber = 1;
3865 hdr.PageType = MPI_CONFIG_PAGETYPE_LAN; 3878 hdr.PageType = MPI_CONFIG_PAGETYPE_LAN;
3866 cfg.hdr = &hdr; 3879 cfg.cfghdr.hdr = &hdr;
3867 cfg.physAddr = -1; 3880 cfg.physAddr = -1;
3868 cfg.action = MPI_CONFIG_ACTION_PAGE_HEADER; 3881 cfg.action = MPI_CONFIG_ACTION_PAGE_HEADER;
3869 cfg.dir = 0; 3882 cfg.dir = 0;
@@ -3930,7 +3943,7 @@ GetFcPortPage0(MPT_ADAPTER *ioc, int portnum)
3930 hdr.PageLength = 0; 3943 hdr.PageLength = 0;
3931 hdr.PageNumber = 0; 3944 hdr.PageNumber = 0;
3932 hdr.PageType = MPI_CONFIG_PAGETYPE_FC_PORT; 3945 hdr.PageType = MPI_CONFIG_PAGETYPE_FC_PORT;
3933 cfg.hdr = &hdr; 3946 cfg.cfghdr.hdr = &hdr;
3934 cfg.physAddr = -1; 3947 cfg.physAddr = -1;
3935 cfg.action = MPI_CONFIG_ACTION_PAGE_HEADER; 3948 cfg.action = MPI_CONFIG_ACTION_PAGE_HEADER;
3936 cfg.dir = 0; 3949 cfg.dir = 0;
@@ -4012,7 +4025,7 @@ GetIoUnitPage2(MPT_ADAPTER *ioc)
4012 hdr.PageLength = 0; 4025 hdr.PageLength = 0;
4013 hdr.PageNumber = 2; 4026 hdr.PageNumber = 2;
4014 hdr.PageType = MPI_CONFIG_PAGETYPE_IO_UNIT; 4027 hdr.PageType = MPI_CONFIG_PAGETYPE_IO_UNIT;
4015 cfg.hdr = &hdr; 4028 cfg.cfghdr.hdr = &hdr;
4016 cfg.physAddr = -1; 4029 cfg.physAddr = -1;
4017 cfg.action = MPI_CONFIG_ACTION_PAGE_HEADER; 4030 cfg.action = MPI_CONFIG_ACTION_PAGE_HEADER;
4018 cfg.dir = 0; 4031 cfg.dir = 0;
@@ -4102,7 +4115,7 @@ mpt_GetScsiPortSettings(MPT_ADAPTER *ioc, int portnum)
4102 header.PageLength = 0; 4115 header.PageLength = 0;
4103 header.PageNumber = 0; 4116 header.PageNumber = 0;
4104 header.PageType = MPI_CONFIG_PAGETYPE_SCSI_PORT; 4117 header.PageType = MPI_CONFIG_PAGETYPE_SCSI_PORT;
4105 cfg.hdr = &header; 4118 cfg.cfghdr.hdr = &header;
4106 cfg.physAddr = -1; 4119 cfg.physAddr = -1;
4107 cfg.pageAddr = portnum; 4120 cfg.pageAddr = portnum;
4108 cfg.action = MPI_CONFIG_ACTION_PAGE_HEADER; 4121 cfg.action = MPI_CONFIG_ACTION_PAGE_HEADER;
@@ -4122,6 +4135,8 @@ mpt_GetScsiPortSettings(MPT_ADAPTER *ioc, int portnum)
4122 ioc->spi_data.minSyncFactor = MPT_ASYNC; 4135 ioc->spi_data.minSyncFactor = MPT_ASYNC;
4123 ioc->spi_data.busType = MPT_HOST_BUS_UNKNOWN; 4136 ioc->spi_data.busType = MPT_HOST_BUS_UNKNOWN;
4124 rc = 1; 4137 rc = 1;
4138 ddvprintk((MYIOC_s_INFO_FMT "Unable to read PortPage0 minSyncFactor=%x\n",
4139 ioc->name, ioc->spi_data.minSyncFactor));
4125 } else { 4140 } else {
4126 /* Save the Port Page 0 data 4141 /* Save the Port Page 0 data
4127 */ 4142 */
@@ -4131,7 +4146,7 @@ mpt_GetScsiPortSettings(MPT_ADAPTER *ioc, int portnum)
4131 4146
4132 if ( (pPP0->Capabilities & MPI_SCSIPORTPAGE0_CAP_QAS) == 0 ) { 4147 if ( (pPP0->Capabilities & MPI_SCSIPORTPAGE0_CAP_QAS) == 0 ) {
4133 ioc->spi_data.noQas |= MPT_TARGET_NO_NEGO_QAS; 4148 ioc->spi_data.noQas |= MPT_TARGET_NO_NEGO_QAS;
4134 dinitprintk((KERN_INFO MYNAM " :%s noQas due to Capabilities=%x\n", 4149 ddvprintk((KERN_INFO MYNAM " :%s noQas due to Capabilities=%x\n",
4135 ioc->name, pPP0->Capabilities)); 4150 ioc->name, pPP0->Capabilities));
4136 } 4151 }
4137 ioc->spi_data.maxBusWidth = pPP0->Capabilities & MPI_SCSIPORTPAGE0_CAP_WIDE ? 1 : 0; 4152 ioc->spi_data.maxBusWidth = pPP0->Capabilities & MPI_SCSIPORTPAGE0_CAP_WIDE ? 1 : 0;
@@ -4140,6 +4155,8 @@ mpt_GetScsiPortSettings(MPT_ADAPTER *ioc, int portnum)
4140 ioc->spi_data.maxSyncOffset = (u8) (data >> 16); 4155 ioc->spi_data.maxSyncOffset = (u8) (data >> 16);
4141 data = pPP0->Capabilities & MPI_SCSIPORTPAGE0_CAP_MIN_SYNC_PERIOD_MASK; 4156 data = pPP0->Capabilities & MPI_SCSIPORTPAGE0_CAP_MIN_SYNC_PERIOD_MASK;
4142 ioc->spi_data.minSyncFactor = (u8) (data >> 8); 4157 ioc->spi_data.minSyncFactor = (u8) (data >> 8);
4158 ddvprintk((MYIOC_s_INFO_FMT "PortPage0 minSyncFactor=%x\n",
4159 ioc->name, ioc->spi_data.minSyncFactor));
4143 } else { 4160 } else {
4144 ioc->spi_data.maxSyncOffset = 0; 4161 ioc->spi_data.maxSyncOffset = 0;
4145 ioc->spi_data.minSyncFactor = MPT_ASYNC; 4162 ioc->spi_data.minSyncFactor = MPT_ASYNC;
@@ -4152,8 +4169,11 @@ mpt_GetScsiPortSettings(MPT_ADAPTER *ioc, int portnum)
4152 if ((ioc->spi_data.busType == MPI_SCSIPORTPAGE0_PHY_SIGNAL_HVD) || 4169 if ((ioc->spi_data.busType == MPI_SCSIPORTPAGE0_PHY_SIGNAL_HVD) ||
4153 (ioc->spi_data.busType == MPI_SCSIPORTPAGE0_PHY_SIGNAL_SE)) { 4170 (ioc->spi_data.busType == MPI_SCSIPORTPAGE0_PHY_SIGNAL_SE)) {
4154 4171
4155 if (ioc->spi_data.minSyncFactor < MPT_ULTRA) 4172 if (ioc->spi_data.minSyncFactor < MPT_ULTRA) {
4156 ioc->spi_data.minSyncFactor = MPT_ULTRA; 4173 ioc->spi_data.minSyncFactor = MPT_ULTRA;
4174 ddvprintk((MYIOC_s_INFO_FMT "HVD or SE detected, minSyncFactor=%x\n",
4175 ioc->name, ioc->spi_data.minSyncFactor));
4176 }
4157 } 4177 }
4158 } 4178 }
4159 if (pbuf) { 4179 if (pbuf) {
@@ -4168,7 +4188,7 @@ mpt_GetScsiPortSettings(MPT_ADAPTER *ioc, int portnum)
4168 header.PageLength = 0; 4188 header.PageLength = 0;
4169 header.PageNumber = 2; 4189 header.PageNumber = 2;
4170 header.PageType = MPI_CONFIG_PAGETYPE_SCSI_PORT; 4190 header.PageType = MPI_CONFIG_PAGETYPE_SCSI_PORT;
4171 cfg.hdr = &header; 4191 cfg.cfghdr.hdr = &header;
4172 cfg.physAddr = -1; 4192 cfg.physAddr = -1;
4173 cfg.pageAddr = portnum; 4193 cfg.pageAddr = portnum;
4174 cfg.action = MPI_CONFIG_ACTION_PAGE_HEADER; 4194 cfg.action = MPI_CONFIG_ACTION_PAGE_HEADER;
@@ -4236,7 +4256,7 @@ mpt_readScsiDevicePageHeaders(MPT_ADAPTER *ioc, int portnum)
4236 header.PageLength = 0; 4256 header.PageLength = 0;
4237 header.PageNumber = 1; 4257 header.PageNumber = 1;
4238 header.PageType = MPI_CONFIG_PAGETYPE_SCSI_DEVICE; 4258 header.PageType = MPI_CONFIG_PAGETYPE_SCSI_DEVICE;
4239 cfg.hdr = &header; 4259 cfg.cfghdr.hdr = &header;
4240 cfg.physAddr = -1; 4260 cfg.physAddr = -1;
4241 cfg.pageAddr = portnum; 4261 cfg.pageAddr = portnum;
4242 cfg.action = MPI_CONFIG_ACTION_PAGE_HEADER; 4262 cfg.action = MPI_CONFIG_ACTION_PAGE_HEADER;
@@ -4245,8 +4265,8 @@ mpt_readScsiDevicePageHeaders(MPT_ADAPTER *ioc, int portnum)
4245 if (mpt_config(ioc, &cfg) != 0) 4265 if (mpt_config(ioc, &cfg) != 0)
4246 return -EFAULT; 4266 return -EFAULT;
4247 4267
4248 ioc->spi_data.sdp1version = cfg.hdr->PageVersion; 4268 ioc->spi_data.sdp1version = cfg.cfghdr.hdr->PageVersion;
4249 ioc->spi_data.sdp1length = cfg.hdr->PageLength; 4269 ioc->spi_data.sdp1length = cfg.cfghdr.hdr->PageLength;
4250 4270
4251 header.PageVersion = 0; 4271 header.PageVersion = 0;
4252 header.PageLength = 0; 4272 header.PageLength = 0;
@@ -4255,8 +4275,8 @@ mpt_readScsiDevicePageHeaders(MPT_ADAPTER *ioc, int portnum)
4255 if (mpt_config(ioc, &cfg) != 0) 4275 if (mpt_config(ioc, &cfg) != 0)
4256 return -EFAULT; 4276 return -EFAULT;
4257 4277
4258 ioc->spi_data.sdp0version = cfg.hdr->PageVersion; 4278 ioc->spi_data.sdp0version = cfg.cfghdr.hdr->PageVersion;
4259 ioc->spi_data.sdp0length = cfg.hdr->PageLength; 4279 ioc->spi_data.sdp0length = cfg.cfghdr.hdr->PageLength;
4260 4280
4261 dcprintk((MYIOC_s_INFO_FMT "Headers: 0: version %d length %d\n", 4281 dcprintk((MYIOC_s_INFO_FMT "Headers: 0: version %d length %d\n",
4262 ioc->name, ioc->spi_data.sdp0version, ioc->spi_data.sdp0length)); 4282 ioc->name, ioc->spi_data.sdp0version, ioc->spi_data.sdp0length));
@@ -4298,7 +4318,7 @@ mpt_findImVolumes(MPT_ADAPTER *ioc)
4298 header.PageLength = 0; 4318 header.PageLength = 0;
4299 header.PageNumber = 2; 4319 header.PageNumber = 2;
4300 header.PageType = MPI_CONFIG_PAGETYPE_IOC; 4320 header.PageType = MPI_CONFIG_PAGETYPE_IOC;
4301 cfg.hdr = &header; 4321 cfg.cfghdr.hdr = &header;
4302 cfg.physAddr = -1; 4322 cfg.physAddr = -1;
4303 cfg.pageAddr = 0; 4323 cfg.pageAddr = 0;
4304 cfg.action = MPI_CONFIG_ACTION_PAGE_HEADER; 4324 cfg.action = MPI_CONFIG_ACTION_PAGE_HEADER;
@@ -4394,7 +4414,7 @@ mpt_read_ioc_pg_3(MPT_ADAPTER *ioc)
4394 header.PageLength = 0; 4414 header.PageLength = 0;
4395 header.PageNumber = 3; 4415 header.PageNumber = 3;
4396 header.PageType = MPI_CONFIG_PAGETYPE_IOC; 4416 header.PageType = MPI_CONFIG_PAGETYPE_IOC;
4397 cfg.hdr = &header; 4417 cfg.cfghdr.hdr = &header;
4398 cfg.physAddr = -1; 4418 cfg.physAddr = -1;
4399 cfg.pageAddr = 0; 4419 cfg.pageAddr = 0;
4400 cfg.action = MPI_CONFIG_ACTION_PAGE_HEADER; 4420 cfg.action = MPI_CONFIG_ACTION_PAGE_HEADER;
@@ -4446,7 +4466,7 @@ mpt_read_ioc_pg_4(MPT_ADAPTER *ioc)
4446 header.PageLength = 0; 4466 header.PageLength = 0;
4447 header.PageNumber = 4; 4467 header.PageNumber = 4;
4448 header.PageType = MPI_CONFIG_PAGETYPE_IOC; 4468 header.PageType = MPI_CONFIG_PAGETYPE_IOC;
4449 cfg.hdr = &header; 4469 cfg.cfghdr.hdr = &header;
4450 cfg.physAddr = -1; 4470 cfg.physAddr = -1;
4451 cfg.pageAddr = 0; 4471 cfg.pageAddr = 0;
4452 cfg.action = MPI_CONFIG_ACTION_PAGE_HEADER; 4472 cfg.action = MPI_CONFIG_ACTION_PAGE_HEADER;
@@ -4498,7 +4518,7 @@ mpt_read_ioc_pg_1(MPT_ADAPTER *ioc)
4498 header.PageLength = 0; 4518 header.PageLength = 0;
4499 header.PageNumber = 1; 4519 header.PageNumber = 1;
4500 header.PageType = MPI_CONFIG_PAGETYPE_IOC; 4520 header.PageType = MPI_CONFIG_PAGETYPE_IOC;
4501 cfg.hdr = &header; 4521 cfg.cfghdr.hdr = &header;
4502 cfg.physAddr = -1; 4522 cfg.physAddr = -1;
4503 cfg.pageAddr = 0; 4523 cfg.pageAddr = 0;
4504 cfg.action = MPI_CONFIG_ACTION_PAGE_HEADER; 4524 cfg.action = MPI_CONFIG_ACTION_PAGE_HEADER;
@@ -4580,13 +4600,13 @@ SendEventNotification(MPT_ADAPTER *ioc, u8 EvSwitch)
4580 4600
4581 evnp = (EventNotification_t *) mpt_get_msg_frame(mpt_base_index, ioc); 4601 evnp = (EventNotification_t *) mpt_get_msg_frame(mpt_base_index, ioc);
4582 if (evnp == NULL) { 4602 if (evnp == NULL) {
4583 dprintk((MYIOC_s_WARN_FMT "Unable to allocate event request frame!\n", 4603 devtprintk((MYIOC_s_WARN_FMT "Unable to allocate event request frame!\n",
4584 ioc->name)); 4604 ioc->name));
4585 return 0; 4605 return 0;
4586 } 4606 }
4587 memset(evnp, 0, sizeof(*evnp)); 4607 memset(evnp, 0, sizeof(*evnp));
4588 4608
4589 dprintk((MYIOC_s_INFO_FMT "Sending EventNotification(%d)\n", ioc->name, EvSwitch)); 4609 devtprintk((MYIOC_s_INFO_FMT "Sending EventNotification (%d) request %p\n", ioc->name, EvSwitch, evnp));
4590 4610
4591 evnp->Function = MPI_FUNCTION_EVENT_NOTIFICATION; 4611 evnp->Function = MPI_FUNCTION_EVENT_NOTIFICATION;
4592 evnp->ChainOffset = 0; 4612 evnp->ChainOffset = 0;
@@ -4610,8 +4630,10 @@ SendEventAck(MPT_ADAPTER *ioc, EventNotificationReply_t *evnp)
4610 EventAck_t *pAck; 4630 EventAck_t *pAck;
4611 4631
4612 if ((pAck = (EventAck_t *) mpt_get_msg_frame(mpt_base_index, ioc)) == NULL) { 4632 if ((pAck = (EventAck_t *) mpt_get_msg_frame(mpt_base_index, ioc)) == NULL) {
4613 printk(MYIOC_s_WARN_FMT "Unable to allocate event ACK request frame!\n", 4633 printk(MYIOC_s_WARN_FMT "Unable to allocate event ACK "
4614 ioc->name); 4634 "request frame for Event=%x EventContext=%x EventData=%x!\n",
4635 ioc->name, evnp->Event, le32_to_cpu(evnp->EventContext),
4636 le32_to_cpu(evnp->Data[0]));
4615 return -1; 4637 return -1;
4616 } 4638 }
4617 memset(pAck, 0, sizeof(*pAck)); 4639 memset(pAck, 0, sizeof(*pAck));
@@ -4647,10 +4669,11 @@ int
4647mpt_config(MPT_ADAPTER *ioc, CONFIGPARMS *pCfg) 4669mpt_config(MPT_ADAPTER *ioc, CONFIGPARMS *pCfg)
4648{ 4670{
4649 Config_t *pReq; 4671 Config_t *pReq;
4672 ConfigExtendedPageHeader_t *pExtHdr = NULL;
4650 MPT_FRAME_HDR *mf; 4673 MPT_FRAME_HDR *mf;
4651 unsigned long flags; 4674 unsigned long flags;
4652 int ii, rc; 4675 int ii, rc;
4653 u32 flagsLength; 4676 int flagsLength;
4654 int in_isr; 4677 int in_isr;
4655 4678
4656 /* Prevent calling wait_event() (below), if caller happens 4679 /* Prevent calling wait_event() (below), if caller happens
@@ -4675,16 +4698,30 @@ mpt_config(MPT_ADAPTER *ioc, CONFIGPARMS *pCfg)
4675 pReq->Reserved = 0; 4698 pReq->Reserved = 0;
4676 pReq->ChainOffset = 0; 4699 pReq->ChainOffset = 0;
4677 pReq->Function = MPI_FUNCTION_CONFIG; 4700 pReq->Function = MPI_FUNCTION_CONFIG;
4701
4702 /* Assume page type is not extended and clear "reserved" fields. */
4678 pReq->ExtPageLength = 0; 4703 pReq->ExtPageLength = 0;
4679 pReq->ExtPageType = 0; 4704 pReq->ExtPageType = 0;
4680 pReq->MsgFlags = 0; 4705 pReq->MsgFlags = 0;
4706
4681 for (ii=0; ii < 8; ii++) 4707 for (ii=0; ii < 8; ii++)
4682 pReq->Reserved2[ii] = 0; 4708 pReq->Reserved2[ii] = 0;
4683 4709
4684 pReq->Header.PageVersion = pCfg->hdr->PageVersion; 4710 pReq->Header.PageVersion = pCfg->cfghdr.hdr->PageVersion;
4685 pReq->Header.PageLength = pCfg->hdr->PageLength; 4711 pReq->Header.PageLength = pCfg->cfghdr.hdr->PageLength;
4686 pReq->Header.PageNumber = pCfg->hdr->PageNumber; 4712 pReq->Header.PageNumber = pCfg->cfghdr.hdr->PageNumber;
4687 pReq->Header.PageType = (pCfg->hdr->PageType & MPI_CONFIG_PAGETYPE_MASK); 4713 pReq->Header.PageType = (pCfg->cfghdr.hdr->PageType & MPI_CONFIG_PAGETYPE_MASK);
4714
4715 if ((pCfg->cfghdr.hdr->PageType & MPI_CONFIG_PAGETYPE_MASK) == MPI_CONFIG_PAGETYPE_EXTENDED) {
4716 pExtHdr = (ConfigExtendedPageHeader_t *)pCfg->cfghdr.ehdr;
4717 pReq->ExtPageLength = cpu_to_le16(pExtHdr->ExtPageLength);
4718 pReq->ExtPageType = pExtHdr->ExtPageType;
4719 pReq->Header.PageType = MPI_CONFIG_PAGETYPE_EXTENDED;
4720
4721 /* Page Length must be treated as a reserved field for the extended header. */
4722 pReq->Header.PageLength = 0;
4723 }
4724
4688 pReq->PageAddress = cpu_to_le32(pCfg->pageAddr); 4725 pReq->PageAddress = cpu_to_le32(pCfg->pageAddr);
4689 4726
4690 /* Add a SGE to the config request. 4727 /* Add a SGE to the config request.
@@ -4694,12 +4731,20 @@ mpt_config(MPT_ADAPTER *ioc, CONFIGPARMS *pCfg)
4694 else 4731 else
4695 flagsLength = MPT_SGE_FLAGS_SSIMPLE_READ; 4732 flagsLength = MPT_SGE_FLAGS_SSIMPLE_READ;
4696 4733
4697 flagsLength |= pCfg->hdr->PageLength * 4; 4734 if ((pCfg->cfghdr.hdr->PageType & MPI_CONFIG_PAGETYPE_MASK) == MPI_CONFIG_PAGETYPE_EXTENDED) {
4735 flagsLength |= pExtHdr->ExtPageLength * 4;
4698 4736
4699 mpt_add_sge((char *)&pReq->PageBufferSGE, flagsLength, pCfg->physAddr); 4737 dcprintk((MYIOC_s_INFO_FMT "Sending Config request type %d, page %d and action %d\n",
4738 ioc->name, pReq->ExtPageType, pReq->Header.PageNumber, pReq->Action));
4739 }
4740 else {
4741 flagsLength |= pCfg->cfghdr.hdr->PageLength * 4;
4742
4743 dcprintk((MYIOC_s_INFO_FMT "Sending Config request type %d, page %d and action %d\n",
4744 ioc->name, pReq->Header.PageType, pReq->Header.PageNumber, pReq->Action));
4745 }
4700 4746
4701 dcprintk((MYIOC_s_INFO_FMT "Sending Config request type %d, page %d and action %d\n", 4747 mpt_add_sge((char *)&pReq->PageBufferSGE, flagsLength, pCfg->physAddr);
4702 ioc->name, pReq->Header.PageType, pReq->Header.PageNumber, pReq->Action));
4703 4748
4704 /* Append pCfg pointer to end of mf 4749 /* Append pCfg pointer to end of mf
4705 */ 4750 */
@@ -4789,8 +4834,8 @@ mpt_toolbox(MPT_ADAPTER *ioc, CONFIGPARMS *pCfg)
4789 pReq->Reserved3 = 0; 4834 pReq->Reserved3 = 0;
4790 pReq->NumAddressBytes = 0x01; 4835 pReq->NumAddressBytes = 0x01;
4791 pReq->Reserved4 = 0; 4836 pReq->Reserved4 = 0;
4792 pReq->DataLength = 0x04; 4837 pReq->DataLength = cpu_to_le16(0x04);
4793 pdev = (struct pci_dev *) ioc->pcidev; 4838 pdev = ioc->pcidev;
4794 if (pdev->devfn & 1) 4839 if (pdev->devfn & 1)
4795 pReq->DeviceAddr = 0xB2; 4840 pReq->DeviceAddr = 0xB2;
4796 else 4841 else
@@ -5504,6 +5549,8 @@ ProcessEventNotification(MPT_ADAPTER *ioc, EventNotificationReply_t *pEventReply
5504 * If needed, send (a single) EventAck. 5549 * If needed, send (a single) EventAck.
5505 */ 5550 */
5506 if (pEventReply->AckRequired == MPI_EVENT_NOTIFICATION_ACK_REQUIRED) { 5551 if (pEventReply->AckRequired == MPI_EVENT_NOTIFICATION_ACK_REQUIRED) {
5552 devtprintk((MYIOC_s_WARN_FMT
5553 "EventAck required\n",ioc->name));
5507 if ((ii = SendEventAck(ioc, pEventReply)) != 0) { 5554 if ((ii = SendEventAck(ioc, pEventReply)) != 0) {
5508 devtprintk((MYIOC_s_WARN_FMT "SendEventAck returned %d\n", 5555 devtprintk((MYIOC_s_WARN_FMT "SendEventAck returned %d\n",
5509 ioc->name, ii)); 5556 ioc->name, ii));
@@ -5584,7 +5631,7 @@ mpt_sp_log_info(MPT_ADAPTER *ioc, u32 log_info)
5584 case 0x00080000: 5631 case 0x00080000:
5585 desc = "Outbound DMA Overrun"; 5632 desc = "Outbound DMA Overrun";
5586 break; 5633 break;
5587 5634
5588 case 0x00090000: 5635 case 0x00090000:
5589 desc = "Task Management"; 5636 desc = "Task Management";
5590 break; 5637 break;
@@ -5600,7 +5647,7 @@ mpt_sp_log_info(MPT_ADAPTER *ioc, u32 log_info)
5600 case 0x000C0000: 5647 case 0x000C0000:
5601 desc = "Untagged Table Size"; 5648 desc = "Untagged Table Size";
5602 break; 5649 break;
5603 5650
5604 } 5651 }
5605 5652
5606 printk(MYIOC_s_INFO_FMT "LogInfo(0x%08x): F/W: %s\n", ioc->name, log_info, desc); 5653 printk(MYIOC_s_INFO_FMT "LogInfo(0x%08x): F/W: %s\n", ioc->name, log_info, desc);
@@ -5692,7 +5739,7 @@ mpt_sp_ioc_info(MPT_ADAPTER *ioc, u32 ioc_status, MPT_FRAME_HDR *mf)
5692 break; 5739 break;
5693 5740
5694 case MPI_IOCSTATUS_SCSI_DATA_UNDERRUN: /* 0x0045 */ 5741 case MPI_IOCSTATUS_SCSI_DATA_UNDERRUN: /* 0x0045 */
5695 /* This error is checked in scsi_io_done(). Skip. 5742 /* This error is checked in scsi_io_done(). Skip.
5696 desc = "SCSI Data Underrun"; 5743 desc = "SCSI Data Underrun";
5697 */ 5744 */
5698 break; 5745 break;
diff --git a/drivers/message/fusion/mptbase.h b/drivers/message/fusion/mptbase.h
index 848fb236b17..f4827d92373 100644
--- a/drivers/message/fusion/mptbase.h
+++ b/drivers/message/fusion/mptbase.h
@@ -915,7 +915,10 @@ struct scsi_cmnd;
915typedef struct _x_config_parms { 915typedef struct _x_config_parms {
916 struct list_head linkage; /* linked list */ 916 struct list_head linkage; /* linked list */
917 struct timer_list timer; /* timer function for this request */ 917 struct timer_list timer; /* timer function for this request */
918 ConfigPageHeader_t *hdr; 918 union {
919 ConfigExtendedPageHeader_t *ehdr;
920 ConfigPageHeader_t *hdr;
921 } cfghdr;
919 dma_addr_t physAddr; 922 dma_addr_t physAddr;
920 int wait_done; /* wait for this request */ 923 int wait_done; /* wait for this request */
921 u32 pageAddr; /* properly formatted */ 924 u32 pageAddr; /* properly formatted */
diff --git a/drivers/message/fusion/mptctl.c b/drivers/message/fusion/mptctl.c
index 05ea5944c48..7577c2417e2 100644
--- a/drivers/message/fusion/mptctl.c
+++ b/drivers/message/fusion/mptctl.c
@@ -242,7 +242,7 @@ mptctl_reply(MPT_ADAPTER *ioc, MPT_FRAME_HDR *req, MPT_FRAME_HDR *reply)
242 /* Set the command status to GOOD if IOC Status is GOOD 242 /* Set the command status to GOOD if IOC Status is GOOD
243 * OR if SCSI I/O cmd and data underrun or recovered error. 243 * OR if SCSI I/O cmd and data underrun or recovered error.
244 */ 244 */
245 iocStatus = reply->u.reply.IOCStatus & MPI_IOCSTATUS_MASK; 245 iocStatus = le16_to_cpu(reply->u.reply.IOCStatus) & MPI_IOCSTATUS_MASK;
246 if (iocStatus == MPI_IOCSTATUS_SUCCESS) 246 if (iocStatus == MPI_IOCSTATUS_SUCCESS)
247 ioc->ioctl->status |= MPT_IOCTL_STATUS_COMMAND_GOOD; 247 ioc->ioctl->status |= MPT_IOCTL_STATUS_COMMAND_GOOD;
248 248
@@ -2324,7 +2324,7 @@ mptctl_hp_hostinfo(unsigned long arg, unsigned int data_size)
2324 hdr.PageLength = 0; 2324 hdr.PageLength = 0;
2325 hdr.PageNumber = 0; 2325 hdr.PageNumber = 0;
2326 hdr.PageType = MPI_CONFIG_PAGETYPE_MANUFACTURING; 2326 hdr.PageType = MPI_CONFIG_PAGETYPE_MANUFACTURING;
2327 cfg.hdr = &hdr; 2327 cfg.cfghdr.hdr = &hdr;
2328 cfg.physAddr = -1; 2328 cfg.physAddr = -1;
2329 cfg.pageAddr = 0; 2329 cfg.pageAddr = 0;
2330 cfg.action = MPI_CONFIG_ACTION_PAGE_HEADER; 2330 cfg.action = MPI_CONFIG_ACTION_PAGE_HEADER;
@@ -2333,7 +2333,7 @@ mptctl_hp_hostinfo(unsigned long arg, unsigned int data_size)
2333 2333
2334 strncpy(karg.serial_number, " ", 24); 2334 strncpy(karg.serial_number, " ", 24);
2335 if (mpt_config(ioc, &cfg) == 0) { 2335 if (mpt_config(ioc, &cfg) == 0) {
2336 if (cfg.hdr->PageLength > 0) { 2336 if (cfg.cfghdr.hdr->PageLength > 0) {
2337 /* Issue the second config page request */ 2337 /* Issue the second config page request */
2338 cfg.action = MPI_CONFIG_ACTION_PAGE_READ_CURRENT; 2338 cfg.action = MPI_CONFIG_ACTION_PAGE_READ_CURRENT;
2339 2339
@@ -2479,7 +2479,7 @@ mptctl_hp_targetinfo(unsigned long arg)
2479 hdr.PageNumber = 0; 2479 hdr.PageNumber = 0;
2480 hdr.PageType = MPI_CONFIG_PAGETYPE_SCSI_DEVICE; 2480 hdr.PageType = MPI_CONFIG_PAGETYPE_SCSI_DEVICE;
2481 2481
2482 cfg.hdr = &hdr; 2482 cfg.cfghdr.hdr = &hdr;
2483 cfg.action = MPI_CONFIG_ACTION_PAGE_READ_CURRENT; 2483 cfg.action = MPI_CONFIG_ACTION_PAGE_READ_CURRENT;
2484 cfg.dir = 0; 2484 cfg.dir = 0;
2485 cfg.timeout = 0; 2485 cfg.timeout = 0;
@@ -2527,15 +2527,15 @@ mptctl_hp_targetinfo(unsigned long arg)
2527 hdr.PageNumber = 3; 2527 hdr.PageNumber = 3;
2528 hdr.PageType = MPI_CONFIG_PAGETYPE_SCSI_DEVICE; 2528 hdr.PageType = MPI_CONFIG_PAGETYPE_SCSI_DEVICE;
2529 2529
2530 cfg.hdr = &hdr; 2530 cfg.cfghdr.hdr = &hdr;
2531 cfg.action = MPI_CONFIG_ACTION_PAGE_HEADER; 2531 cfg.action = MPI_CONFIG_ACTION_PAGE_HEADER;
2532 cfg.dir = 0; 2532 cfg.dir = 0;
2533 cfg.timeout = 0; 2533 cfg.timeout = 0;
2534 cfg.physAddr = -1; 2534 cfg.physAddr = -1;
2535 if ((mpt_config(ioc, &cfg) == 0) && (cfg.hdr->PageLength > 0)) { 2535 if ((mpt_config(ioc, &cfg) == 0) && (cfg.cfghdr.hdr->PageLength > 0)) {
2536 /* Issue the second config page request */ 2536 /* Issue the second config page request */
2537 cfg.action = MPI_CONFIG_ACTION_PAGE_READ_CURRENT; 2537 cfg.action = MPI_CONFIG_ACTION_PAGE_READ_CURRENT;
2538 data_sz = (int) cfg.hdr->PageLength * 4; 2538 data_sz = (int) cfg.cfghdr.hdr->PageLength * 4;
2539 pg3_alloc = (SCSIDevicePage3_t *) pci_alloc_consistent( 2539 pg3_alloc = (SCSIDevicePage3_t *) pci_alloc_consistent(
2540 ioc->pcidev, data_sz, &page_dma); 2540 ioc->pcidev, data_sz, &page_dma);
2541 if (pg3_alloc) { 2541 if (pg3_alloc) {
diff --git a/drivers/message/fusion/mptscsih.c b/drivers/message/fusion/mptscsih.c
index b9d4f78725b..4a003dc5fde 100644
--- a/drivers/message/fusion/mptscsih.c
+++ b/drivers/message/fusion/mptscsih.c
@@ -281,12 +281,12 @@ mptscsih_getFreeChainBuffer(MPT_ADAPTER *ioc, int *retIndex)
281 offset = (u8 *)chainBuf - (u8 *)ioc->ChainBuffer; 281 offset = (u8 *)chainBuf - (u8 *)ioc->ChainBuffer;
282 chain_idx = offset / ioc->req_sz; 282 chain_idx = offset / ioc->req_sz;
283 rc = SUCCESS; 283 rc = SUCCESS;
284 dsgprintk((MYIOC_s_INFO_FMT "getFreeChainBuffer (index %d), got buf=%p\n", 284 dsgprintk((MYIOC_s_ERR_FMT "getFreeChainBuffer chainBuf=%p ChainBuffer=%p offset=%d chain_idx=%d\n",
285 ioc->name, *retIndex, chainBuf)); 285 ioc->name, chainBuf, ioc->ChainBuffer, offset, chain_idx));
286 } else { 286 } else {
287 rc = FAILED; 287 rc = FAILED;
288 chain_idx = MPT_HOST_NO_CHAIN; 288 chain_idx = MPT_HOST_NO_CHAIN;
289 dfailprintk((MYIOC_s_ERR_FMT "getFreeChainBuffer failed\n", 289 dfailprintk((MYIOC_s_INFO_FMT "getFreeChainBuffer failed\n",
290 ioc->name)); 290 ioc->name));
291 } 291 }
292 spin_unlock_irqrestore(&ioc->FreeQlock, flags); 292 spin_unlock_irqrestore(&ioc->FreeQlock, flags);
@@ -432,7 +432,7 @@ nextSGEset:
432 */ 432 */
433 pReq->ChainOffset = 0; 433 pReq->ChainOffset = 0;
434 RequestNB = (((sgeOffset - 1) >> ioc->NBShiftFactor) + 1) & 0x03; 434 RequestNB = (((sgeOffset - 1) >> ioc->NBShiftFactor) + 1) & 0x03;
435 dsgprintk((MYIOC_s_ERR_FMT 435 dsgprintk((MYIOC_s_INFO_FMT
436 "Single Buffer RequestNB=%x, sgeOffset=%d\n", ioc->name, RequestNB, sgeOffset)); 436 "Single Buffer RequestNB=%x, sgeOffset=%d\n", ioc->name, RequestNB, sgeOffset));
437 ioc->RequestNB[req_idx] = RequestNB; 437 ioc->RequestNB[req_idx] = RequestNB;
438 } 438 }
@@ -491,11 +491,12 @@ nextSGEset:
491 /* NOTE: psge points to the beginning of the chain element 491 /* NOTE: psge points to the beginning of the chain element
492 * in current buffer. Get a chain buffer. 492 * in current buffer. Get a chain buffer.
493 */ 493 */
494 dsgprintk((MYIOC_s_INFO_FMT 494 if ((mptscsih_getFreeChainBuffer(ioc, &newIndex)) == FAILED) {
495 "calling getFreeChainBuffer SCSI cmd=%02x (%p)\n", 495 dfailprintk((MYIOC_s_INFO_FMT
496 ioc->name, pReq->CDB[0], SCpnt)); 496 "getFreeChainBuffer FAILED SCSI cmd=%02x (%p)\n",
497 if ((mptscsih_getFreeChainBuffer(ioc, &newIndex)) == FAILED) 497 ioc->name, pReq->CDB[0], SCpnt));
498 return FAILED; 498 return FAILED;
499 }
499 500
500 /* Update the tracking arrays. 501 /* Update the tracking arrays.
501 * If chainSge == NULL, update ReqToChain, else ChainToChain 502 * If chainSge == NULL, update ReqToChain, else ChainToChain
@@ -577,14 +578,20 @@ mptscsih_io_done(MPT_ADAPTER *ioc, MPT_FRAME_HDR *mf, MPT_FRAME_HDR *mr)
577 return 1; 578 return 1;
578 } 579 }
579 580
580 dmfprintk((MYIOC_s_INFO_FMT
581 "ScsiDone (mf=%p,mr=%p,sc=%p,idx=%d)\n",
582 ioc->name, mf, mr, sc, req_idx));
583
584 sc->result = DID_OK << 16; /* Set default reply as OK */ 581 sc->result = DID_OK << 16; /* Set default reply as OK */
585 pScsiReq = (SCSIIORequest_t *) mf; 582 pScsiReq = (SCSIIORequest_t *) mf;
586 pScsiReply = (SCSIIOReply_t *) mr; 583 pScsiReply = (SCSIIOReply_t *) mr;
587 584
585 if((ioc->facts.MsgVersion >= MPI_VERSION_01_05) && pScsiReply){
586 dmfprintk((MYIOC_s_INFO_FMT
587 "ScsiDone (mf=%p,mr=%p,sc=%p,idx=%d,task-tag=%d)\n",
588 ioc->name, mf, mr, sc, req_idx, pScsiReply->TaskTag));
589 }else{
590 dmfprintk((MYIOC_s_INFO_FMT
591 "ScsiDone (mf=%p,mr=%p,sc=%p,idx=%d)\n",
592 ioc->name, mf, mr, sc, req_idx));
593 }
594
588 if (pScsiReply == NULL) { 595 if (pScsiReply == NULL) {
589 /* special context reply handling */ 596 /* special context reply handling */
590 ; 597 ;
@@ -658,8 +665,8 @@ mptscsih_io_done(MPT_ADAPTER *ioc, MPT_FRAME_HDR *mf, MPT_FRAME_HDR *mr)
658 /* Sufficient data transfer occurred */ 665 /* Sufficient data transfer occurred */
659 sc->result = (DID_OK << 16) | scsi_status; 666 sc->result = (DID_OK << 16) | scsi_status;
660 } else if ( xfer_cnt == 0 ) { 667 } else if ( xfer_cnt == 0 ) {
661 /* A CRC Error causes this condition; retry */ 668 /* A CRC Error causes this condition; retry */
662 sc->result = (DRIVER_SENSE << 24) | (DID_OK << 16) | 669 sc->result = (DRIVER_SENSE << 24) | (DID_OK << 16) |
663 (CHECK_CONDITION << 1); 670 (CHECK_CONDITION << 1);
664 sc->sense_buffer[0] = 0x70; 671 sc->sense_buffer[0] = 0x70;
665 sc->sense_buffer[2] = NO_SENSE; 672 sc->sense_buffer[2] = NO_SENSE;
@@ -668,7 +675,9 @@ mptscsih_io_done(MPT_ADAPTER *ioc, MPT_FRAME_HDR *mf, MPT_FRAME_HDR *mr)
668 } else { 675 } else {
669 sc->result = DID_SOFT_ERROR << 16; 676 sc->result = DID_SOFT_ERROR << 16;
670 } 677 }
671 dreplyprintk((KERN_NOTICE "RESIDUAL_MISMATCH: result=%x on id=%d\n", sc->result, sc->target)); 678 dreplyprintk((KERN_NOTICE
679 "RESIDUAL_MISMATCH: result=%x on id=%d\n",
680 sc->result, sc->device->id));
672 break; 681 break;
673 682
674 case MPI_IOCSTATUS_SCSI_DATA_UNDERRUN: /* 0x0045 */ 683 case MPI_IOCSTATUS_SCSI_DATA_UNDERRUN: /* 0x0045 */
@@ -796,7 +805,6 @@ mptscsih_io_done(MPT_ADAPTER *ioc, MPT_FRAME_HDR *mf, MPT_FRAME_HDR *mr)
796 return 1; 805 return 1;
797} 806}
798 807
799
800/* 808/*
801 * mptscsih_flush_running_cmds - For each command found, search 809 * mptscsih_flush_running_cmds - For each command found, search
802 * Scsi_Host instance taskQ and reply to OS. 810 * Scsi_Host instance taskQ and reply to OS.
@@ -1017,7 +1025,7 @@ mptscsih_remove(struct pci_dev *pdev)
1017 scsi_host_put(host); 1025 scsi_host_put(host);
1018 1026
1019 mpt_detach(pdev); 1027 mpt_detach(pdev);
1020 1028
1021} 1029}
1022 1030
1023/*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/ 1031/*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
@@ -1072,7 +1080,7 @@ mptscsih_resume(struct pci_dev *pdev)
1072 MPT_SCSI_HOST *hd; 1080 MPT_SCSI_HOST *hd;
1073 1081
1074 mpt_resume(pdev); 1082 mpt_resume(pdev);
1075 1083
1076 if(!host) 1084 if(!host)
1077 return 0; 1085 return 0;
1078 1086
@@ -1214,8 +1222,8 @@ mptscsih_proc_info(struct Scsi_Host *host, char *buffer, char **start, off_t off
1214 int size = 0; 1222 int size = 0;
1215 1223
1216 if (func) { 1224 if (func) {
1217 /* 1225 /*
1218 * write is not supported 1226 * write is not supported
1219 */ 1227 */
1220 } else { 1228 } else {
1221 if (start) 1229 if (start)
@@ -1535,17 +1543,17 @@ mptscsih_TMHandler(MPT_SCSI_HOST *hd, u8 type, u8 channel, u8 target, u8 lun, in
1535 */ 1543 */
1536 if (mptscsih_tm_pending_wait(hd) == FAILED) { 1544 if (mptscsih_tm_pending_wait(hd) == FAILED) {
1537 if (type == MPI_SCSITASKMGMT_TASKTYPE_ABORT_TASK) { 1545 if (type == MPI_SCSITASKMGMT_TASKTYPE_ABORT_TASK) {
1538 dtmprintk((KERN_WARNING MYNAM ": %s: TMHandler abort: " 1546 dtmprintk((KERN_INFO MYNAM ": %s: TMHandler abort: "
1539 "Timed out waiting for last TM (%d) to complete! \n", 1547 "Timed out waiting for last TM (%d) to complete! \n",
1540 hd->ioc->name, hd->tmPending)); 1548 hd->ioc->name, hd->tmPending));
1541 return FAILED; 1549 return FAILED;
1542 } else if (type == MPI_SCSITASKMGMT_TASKTYPE_TARGET_RESET) { 1550 } else if (type == MPI_SCSITASKMGMT_TASKTYPE_TARGET_RESET) {
1543 dtmprintk((KERN_WARNING MYNAM ": %s: TMHandler target reset: " 1551 dtmprintk((KERN_INFO MYNAM ": %s: TMHandler target reset: "
1544 "Timed out waiting for last TM (%d) to complete! \n", 1552 "Timed out waiting for last TM (%d) to complete! \n",
1545 hd->ioc->name, hd->tmPending)); 1553 hd->ioc->name, hd->tmPending));
1546 return FAILED; 1554 return FAILED;
1547 } else if (type == MPI_SCSITASKMGMT_TASKTYPE_RESET_BUS) { 1555 } else if (type == MPI_SCSITASKMGMT_TASKTYPE_RESET_BUS) {
1548 dtmprintk((KERN_WARNING MYNAM ": %s: TMHandler bus reset: " 1556 dtmprintk((KERN_INFO MYNAM ": %s: TMHandler bus reset: "
1549 "Timed out waiting for last TM (%d) to complete! \n", 1557 "Timed out waiting for last TM (%d) to complete! \n",
1550 hd->ioc->name, hd->tmPending)); 1558 hd->ioc->name, hd->tmPending));
1551 if (hd->tmPending & (1 << MPI_SCSITASKMGMT_TASKTYPE_RESET_BUS)) 1559 if (hd->tmPending & (1 << MPI_SCSITASKMGMT_TASKTYPE_RESET_BUS))
@@ -1631,8 +1639,7 @@ mptscsih_IssueTaskMgmt(MPT_SCSI_HOST *hd, u8 type, u8 channel, u8 target, u8 lun
1631 if ((mf = mpt_get_msg_frame(hd->ioc->TaskCtx, hd->ioc)) == NULL) { 1639 if ((mf = mpt_get_msg_frame(hd->ioc->TaskCtx, hd->ioc)) == NULL) {
1632 dfailprintk((MYIOC_s_ERR_FMT "IssueTaskMgmt, no msg frames!!\n", 1640 dfailprintk((MYIOC_s_ERR_FMT "IssueTaskMgmt, no msg frames!!\n",
1633 hd->ioc->name)); 1641 hd->ioc->name));
1634 //return FAILED; 1642 return FAILED;
1635 return -999;
1636 } 1643 }
1637 dtmprintk((MYIOC_s_INFO_FMT "IssueTaskMgmt request @ %p\n", 1644 dtmprintk((MYIOC_s_INFO_FMT "IssueTaskMgmt request @ %p\n",
1638 hd->ioc->name, mf)); 1645 hd->ioc->name, mf));
@@ -1661,9 +1668,8 @@ mptscsih_IssueTaskMgmt(MPT_SCSI_HOST *hd, u8 type, u8 channel, u8 target, u8 lun
1661 1668
1662 pScsiTm->TaskMsgContext = ctx2abort; 1669 pScsiTm->TaskMsgContext = ctx2abort;
1663 1670
1664 dtmprintk((MYIOC_s_INFO_FMT 1671 dtmprintk((MYIOC_s_INFO_FMT "IssueTaskMgmt: ctx2abort (0x%08x) type=%d\n",
1665 "IssueTaskMgmt: ctx2abort (0x%08x) type=%d\n", 1672 hd->ioc->name, ctx2abort, type));
1666 hd->ioc->name, ctx2abort, type));
1667 1673
1668 DBG_DUMP_TM_REQUEST_FRAME((u32 *)pScsiTm); 1674 DBG_DUMP_TM_REQUEST_FRAME((u32 *)pScsiTm);
1669 1675
@@ -1902,13 +1908,13 @@ mptscsih_host_reset(struct scsi_cmnd *SCpnt)
1902 1908
1903 /* If we can't locate the host to reset, then we failed. */ 1909 /* If we can't locate the host to reset, then we failed. */
1904 if ((hd = (MPT_SCSI_HOST *) SCpnt->device->host->hostdata) == NULL){ 1910 if ((hd = (MPT_SCSI_HOST *) SCpnt->device->host->hostdata) == NULL){
1905 dtmprintk( ( KERN_WARNING MYNAM ": mptscsih_host_reset: " 1911 dtmprintk( ( KERN_INFO MYNAM ": mptscsih_host_reset: "
1906 "Can't locate host! (sc=%p)\n", 1912 "Can't locate host! (sc=%p)\n",
1907 SCpnt ) ); 1913 SCpnt ) );
1908 return FAILED; 1914 return FAILED;
1909 } 1915 }
1910 1916
1911 printk(KERN_WARNING MYNAM ": %s: >> Attempting host reset! (sc=%p)\n", 1917 printk(KERN_WARNING MYNAM ": %s: Attempting host reset! (sc=%p)\n",
1912 hd->ioc->name, SCpnt); 1918 hd->ioc->name, SCpnt);
1913 1919
1914 /* If our attempts to reset the host failed, then return a failed 1920 /* If our attempts to reset the host failed, then return a failed
@@ -1924,7 +1930,7 @@ mptscsih_host_reset(struct scsi_cmnd *SCpnt)
1924 hd->tmState = TM_STATE_NONE; 1930 hd->tmState = TM_STATE_NONE;
1925 } 1931 }
1926 1932
1927 dtmprintk( ( KERN_WARNING MYNAM ": mptscsih_host_reset: " 1933 dtmprintk( ( KERN_INFO MYNAM ": mptscsih_host_reset: "
1928 "Status = %s\n", 1934 "Status = %s\n",
1929 (status == SUCCESS) ? "SUCCESS" : "FAILED" ) ); 1935 (status == SUCCESS) ? "SUCCESS" : "FAILED" ) );
1930 1936
@@ -1951,8 +1957,8 @@ mptscsih_tm_pending_wait(MPT_SCSI_HOST * hd)
1951 if (hd->tmState == TM_STATE_NONE) { 1957 if (hd->tmState == TM_STATE_NONE) {
1952 hd->tmState = TM_STATE_IN_PROGRESS; 1958 hd->tmState = TM_STATE_IN_PROGRESS;
1953 hd->tmPending = 1; 1959 hd->tmPending = 1;
1954 status = SUCCESS;
1955 spin_unlock_irqrestore(&hd->ioc->FreeQlock, flags); 1960 spin_unlock_irqrestore(&hd->ioc->FreeQlock, flags);
1961 status = SUCCESS;
1956 break; 1962 break;
1957 } 1963 }
1958 spin_unlock_irqrestore(&hd->ioc->FreeQlock, flags); 1964 spin_unlock_irqrestore(&hd->ioc->FreeQlock, flags);
@@ -1980,7 +1986,7 @@ mptscsih_tm_wait_for_completion(MPT_SCSI_HOST * hd, ulong timeout )
1980 spin_lock_irqsave(&hd->ioc->FreeQlock, flags); 1986 spin_lock_irqsave(&hd->ioc->FreeQlock, flags);
1981 if(hd->tmPending == 0) { 1987 if(hd->tmPending == 0) {
1982 status = SUCCESS; 1988 status = SUCCESS;
1983 spin_unlock_irqrestore(&hd->ioc->FreeQlock, flags); 1989 spin_unlock_irqrestore(&hd->ioc->FreeQlock, flags);
1984 break; 1990 break;
1985 } 1991 }
1986 spin_unlock_irqrestore(&hd->ioc->FreeQlock, flags); 1992 spin_unlock_irqrestore(&hd->ioc->FreeQlock, flags);
@@ -2318,10 +2324,10 @@ mptscsih_slave_configure(struct scsi_device *device)
2318 if (pTarget == NULL) { 2324 if (pTarget == NULL) {
2319 /* Driver doesn't know about this device. 2325 /* Driver doesn't know about this device.
2320 * Kernel may generate a "Dummy Lun 0" which 2326 * Kernel may generate a "Dummy Lun 0" which
2321 * may become a real Lun if a 2327 * may become a real Lun if a
2322 * "scsi add-single-device" command is executed 2328 * "scsi add-single-device" command is executed
2323 * while the driver is active (hot-plug a 2329 * while the driver is active (hot-plug a
2324 * device). LSI Raid controllers need 2330 * device). LSI Raid controllers need
2325 * queue_depth set to DEV_HIGH for this reason. 2331 * queue_depth set to DEV_HIGH for this reason.
2326 */ 2332 */
2327 scsi_adjust_queue_depth(device, MSG_SIMPLE_TAG, 2333 scsi_adjust_queue_depth(device, MSG_SIMPLE_TAG,
@@ -2691,7 +2697,7 @@ mptscsih_initTarget(MPT_SCSI_HOST *hd, int bus_id, int target_id, u8 lun, char *
2691 * If the peripheral qualifier filter is enabled then if the target reports a 0x1 2697 * If the peripheral qualifier filter is enabled then if the target reports a 0x1
2692 * (i.e. The targer is capable of supporting the specified peripheral device type 2698 * (i.e. The targer is capable of supporting the specified peripheral device type
2693 * on this logical unit; however, the physical device is not currently connected 2699 * on this logical unit; however, the physical device is not currently connected
2694 * to this logical unit) it will be converted to a 0x3 (i.e. The target is not 2700 * to this logical unit) it will be converted to a 0x3 (i.e. The target is not
2695 * capable of supporting a physical device on this logical unit). This is to work 2701 * capable of supporting a physical device on this logical unit). This is to work
2696 * around a bug in th emid-layer in some distributions in which the mid-layer will 2702 * around a bug in th emid-layer in some distributions in which the mid-layer will
2697 * continue to try to communicate to the LUN and evntually create a dummy LUN. 2703 * continue to try to communicate to the LUN and evntually create a dummy LUN.
@@ -3194,8 +3200,8 @@ mptscsih_writeSDP1(MPT_SCSI_HOST *hd, int portnum, int target_id, int flags)
3194 /* Get a MF for this command. 3200 /* Get a MF for this command.
3195 */ 3201 */
3196 if ((mf = mpt_get_msg_frame(ioc->DoneCtx, ioc)) == NULL) { 3202 if ((mf = mpt_get_msg_frame(ioc->DoneCtx, ioc)) == NULL) {
3197 dprintk((MYIOC_s_WARN_FMT "write SDP1: no msg frames!\n", 3203 dfailprintk((MYIOC_s_WARN_FMT "write SDP1: no msg frames!\n",
3198 ioc->name)); 3204 ioc->name));
3199 return -EAGAIN; 3205 return -EAGAIN;
3200 } 3206 }
3201 3207
@@ -3289,7 +3295,7 @@ mptscsih_writeIOCPage4(MPT_SCSI_HOST *hd, int target_id, int bus)
3289 /* Get a MF for this command. 3295 /* Get a MF for this command.
3290 */ 3296 */
3291 if ((mf = mpt_get_msg_frame(ioc->DoneCtx, ioc)) == NULL) { 3297 if ((mf = mpt_get_msg_frame(ioc->DoneCtx, ioc)) == NULL) {
3292 dprintk((MYIOC_s_WARN_FMT "writeIOCPage4 : no msg frames!\n", 3298 dfailprintk((MYIOC_s_WARN_FMT "writeIOCPage4 : no msg frames!\n",
3293 ioc->name)); 3299 ioc->name));
3294 return -EAGAIN; 3300 return -EAGAIN;
3295 } 3301 }
@@ -3447,7 +3453,7 @@ mptscsih_scandv_complete(MPT_ADAPTER *ioc, MPT_FRAME_HDR *mf, MPT_FRAME_HDR *mr)
3447 * some type of error occurred. 3453 * some type of error occurred.
3448 */ 3454 */
3449 MpiRaidActionReply_t *pr = (MpiRaidActionReply_t *)mr; 3455 MpiRaidActionReply_t *pr = (MpiRaidActionReply_t *)mr;
3450 if (pr->ActionStatus == MPI_RAID_ACTION_ASTATUS_SUCCESS) 3456 if (le16_to_cpu(pr->ActionStatus) == MPI_RAID_ACTION_ASTATUS_SUCCESS)
3451 completionCode = MPT_SCANDV_GOOD; 3457 completionCode = MPT_SCANDV_GOOD;
3452 else 3458 else
3453 completionCode = MPT_SCANDV_SOME_ERROR; 3459 completionCode = MPT_SCANDV_SOME_ERROR;
@@ -3955,7 +3961,7 @@ mptscsih_synchronize_cache(MPT_SCSI_HOST *hd, int portnum)
3955 header1.PageLength = ioc->spi_data.sdp1length; 3961 header1.PageLength = ioc->spi_data.sdp1length;
3956 header1.PageNumber = 1; 3962 header1.PageNumber = 1;
3957 header1.PageType = MPI_CONFIG_PAGETYPE_SCSI_DEVICE; 3963 header1.PageType = MPI_CONFIG_PAGETYPE_SCSI_DEVICE;
3958 cfg.hdr = &header1; 3964 cfg.cfghdr.hdr = &header1;
3959 cfg.physAddr = cfg1_dma_addr; 3965 cfg.physAddr = cfg1_dma_addr;
3960 cfg.action = MPI_CONFIG_ACTION_PAGE_WRITE_CURRENT; 3966 cfg.action = MPI_CONFIG_ACTION_PAGE_WRITE_CURRENT;
3961 cfg.dir = 1; 3967 cfg.dir = 1;
@@ -3996,9 +4002,9 @@ mptscsih_synchronize_cache(MPT_SCSI_HOST *hd, int portnum)
3996 dnegoprintk(("syncronize cache: id=%d width=0 factor=MPT_ASYNC " 4002 dnegoprintk(("syncronize cache: id=%d width=0 factor=MPT_ASYNC "
3997 "offset=0 negoFlags=%x request=%x config=%x\n", 4003 "offset=0 negoFlags=%x request=%x config=%x\n",
3998 id, flags, requested, configuration)); 4004 id, flags, requested, configuration));
3999 pcfg1Data->RequestedParameters = le32_to_cpu(requested); 4005 pcfg1Data->RequestedParameters = cpu_to_le32(requested);
4000 pcfg1Data->Reserved = 0; 4006 pcfg1Data->Reserved = 0;
4001 pcfg1Data->Configuration = le32_to_cpu(configuration); 4007 pcfg1Data->Configuration = cpu_to_le32(configuration);
4002 cfg.pageAddr = (bus<<8) | id; 4008 cfg.pageAddr = (bus<<8) | id;
4003 mpt_config(hd->ioc, &cfg); 4009 mpt_config(hd->ioc, &cfg);
4004 } 4010 }
@@ -4353,7 +4359,7 @@ mptscsih_doDv(MPT_SCSI_HOST *hd, int bus_number, int id)
4353 /* Prep cfg structure 4359 /* Prep cfg structure
4354 */ 4360 */
4355 cfg.pageAddr = (bus<<8) | id; 4361 cfg.pageAddr = (bus<<8) | id;
4356 cfg.hdr = NULL; 4362 cfg.cfghdr.hdr = NULL;
4357 4363
4358 /* Prep SDP0 header 4364 /* Prep SDP0 header
4359 */ 4365 */
@@ -4399,7 +4405,7 @@ mptscsih_doDv(MPT_SCSI_HOST *hd, int bus_number, int id)
4399 pcfg1Data = (SCSIDevicePage1_t *) (pDvBuf + sz); 4405 pcfg1Data = (SCSIDevicePage1_t *) (pDvBuf + sz);
4400 cfg1_dma_addr = dvbuf_dma + sz; 4406 cfg1_dma_addr = dvbuf_dma + sz;
4401 4407
4402 /* Skip this ID? Set cfg.hdr to force config page write 4408 /* Skip this ID? Set cfg.cfghdr.hdr to force config page write
4403 */ 4409 */
4404 { 4410 {
4405 ScsiCfgData *pspi_data = &hd->ioc->spi_data; 4411 ScsiCfgData *pspi_data = &hd->ioc->spi_data;
@@ -4417,7 +4423,7 @@ mptscsih_doDv(MPT_SCSI_HOST *hd, int bus_number, int id)
4417 4423
4418 dv.cmd = MPT_SET_MAX; 4424 dv.cmd = MPT_SET_MAX;
4419 mptscsih_dv_parms(hd, &dv, (void *)pcfg1Data); 4425 mptscsih_dv_parms(hd, &dv, (void *)pcfg1Data);
4420 cfg.hdr = &header1; 4426 cfg.cfghdr.hdr = &header1;
4421 4427
4422 /* Save the final negotiated settings to 4428 /* Save the final negotiated settings to
4423 * SCSI device page 1. 4429 * SCSI device page 1.
@@ -4483,7 +4489,7 @@ mptscsih_doDv(MPT_SCSI_HOST *hd, int bus_number, int id)
4483 dv.cmd = MPT_SET_MIN; 4489 dv.cmd = MPT_SET_MIN;
4484 mptscsih_dv_parms(hd, &dv, (void *)pcfg1Data); 4490 mptscsih_dv_parms(hd, &dv, (void *)pcfg1Data);
4485 4491
4486 cfg.hdr = &header1; 4492 cfg.cfghdr.hdr = &header1;
4487 cfg.physAddr = cfg1_dma_addr; 4493 cfg.physAddr = cfg1_dma_addr;
4488 cfg.action = MPI_CONFIG_ACTION_PAGE_WRITE_CURRENT; 4494 cfg.action = MPI_CONFIG_ACTION_PAGE_WRITE_CURRENT;
4489 cfg.dir = 1; 4495 cfg.dir = 1;
@@ -4596,8 +4602,8 @@ mptscsih_doDv(MPT_SCSI_HOST *hd, int bus_number, int id)
4596 if ((pbuf1[56] & 0x02) == 0) { 4602 if ((pbuf1[56] & 0x02) == 0) {
4597 pTarget->negoFlags |= MPT_TARGET_NO_NEGO_QAS; 4603 pTarget->negoFlags |= MPT_TARGET_NO_NEGO_QAS;
4598 hd->ioc->spi_data.noQas = MPT_TARGET_NO_NEGO_QAS; 4604 hd->ioc->spi_data.noQas = MPT_TARGET_NO_NEGO_QAS;
4599 ddvprintk((MYIOC_s_NOTE_FMT 4605 ddvprintk((MYIOC_s_NOTE_FMT
4600 "DV: Start Basic noQas on id=%d due to pbuf1[56]=%x\n", 4606 "DV: Start Basic noQas on id=%d due to pbuf1[56]=%x\n",
4601 ioc->name, id, pbuf1[56])); 4607 ioc->name, id, pbuf1[56]));
4602 } 4608 }
4603 } 4609 }
@@ -4637,7 +4643,7 @@ mptscsih_doDv(MPT_SCSI_HOST *hd, int bus_number, int id)
4637 u32 sdp0_info; 4643 u32 sdp0_info;
4638 u32 sdp0_nego; 4644 u32 sdp0_nego;
4639 4645
4640 cfg.hdr = &header0; 4646 cfg.cfghdr.hdr = &header0;
4641 cfg.physAddr = cfg0_dma_addr; 4647 cfg.physAddr = cfg0_dma_addr;
4642 cfg.action = MPI_CONFIG_ACTION_PAGE_READ_CURRENT; 4648 cfg.action = MPI_CONFIG_ACTION_PAGE_READ_CURRENT;
4643 cfg.dir = 0; 4649 cfg.dir = 0;
@@ -4673,7 +4679,7 @@ mptscsih_doDv(MPT_SCSI_HOST *hd, int bus_number, int id)
4673 if (!firstPass) 4679 if (!firstPass)
4674 doFallback = 1; 4680 doFallback = 1;
4675 } else { 4681 } else {
4676 ddvprintk((MYIOC_s_NOTE_FMT 4682 ddvprintk((MYIOC_s_NOTE_FMT
4677 "DV:Inquiry compared id=%d, calling initTarget\n", ioc->name, id)); 4683 "DV:Inquiry compared id=%d, calling initTarget\n", ioc->name, id));
4678 hd->ioc->spi_data.dvStatus[id] &= ~MPT_SCSICFG_DV_NOT_DONE; 4684 hd->ioc->spi_data.dvStatus[id] &= ~MPT_SCSICFG_DV_NOT_DONE;
4679 mptscsih_initTarget(hd, 4685 mptscsih_initTarget(hd,
@@ -4689,8 +4695,8 @@ mptscsih_doDv(MPT_SCSI_HOST *hd, int bus_number, int id)
4689 4695
4690 } else if (rc == MPT_SCANDV_ISSUE_SENSE) 4696 } else if (rc == MPT_SCANDV_ISSUE_SENSE)
4691 doFallback = 1; /* set fallback flag */ 4697 doFallback = 1; /* set fallback flag */
4692 else if ((rc == MPT_SCANDV_DID_RESET) || 4698 else if ((rc == MPT_SCANDV_DID_RESET) ||
4693 (rc == MPT_SCANDV_SENSE) || 4699 (rc == MPT_SCANDV_SENSE) ||
4694 (rc == MPT_SCANDV_FALLBACK)) 4700 (rc == MPT_SCANDV_FALLBACK))
4695 doFallback = 1; /* set fallback flag */ 4701 doFallback = 1; /* set fallback flag */
4696 else 4702 else
@@ -4722,7 +4728,7 @@ mptscsih_doDv(MPT_SCSI_HOST *hd, int bus_number, int id)
4722 * 4) release 4728 * 4) release
4723 * 5) update nego parms to target struct 4729 * 5) update nego parms to target struct
4724 */ 4730 */
4725 cfg.hdr = &header1; 4731 cfg.cfghdr.hdr = &header1;
4726 cfg.physAddr = cfg1_dma_addr; 4732 cfg.physAddr = cfg1_dma_addr;
4727 cfg.action = MPI_CONFIG_ACTION_PAGE_WRITE_CURRENT; 4733 cfg.action = MPI_CONFIG_ACTION_PAGE_WRITE_CURRENT;
4728 cfg.dir = 1; 4734 cfg.dir = 1;
@@ -5121,12 +5127,12 @@ target_done:
5121 5127
5122 /* Set if cfg1_dma_addr contents is valid 5128 /* Set if cfg1_dma_addr contents is valid
5123 */ 5129 */
5124 if ((cfg.hdr != NULL) && (retcode == 0)){ 5130 if ((cfg.cfghdr.hdr != NULL) && (retcode == 0)){
5125 /* If disk, not U320, disable QAS 5131 /* If disk, not U320, disable QAS
5126 */ 5132 */
5127 if ((inq0 == 0) && (dv.now.factor > MPT_ULTRA320)) { 5133 if ((inq0 == 0) && (dv.now.factor > MPT_ULTRA320)) {
5128 hd->ioc->spi_data.noQas = MPT_TARGET_NO_NEGO_QAS; 5134 hd->ioc->spi_data.noQas = MPT_TARGET_NO_NEGO_QAS;
5129 ddvprintk((MYIOC_s_NOTE_FMT 5135 ddvprintk((MYIOC_s_NOTE_FMT
5130 "noQas set due to id=%d has factor=%x\n", ioc->name, id, dv.now.factor)); 5136 "noQas set due to id=%d has factor=%x\n", ioc->name, id, dv.now.factor));
5131 } 5137 }
5132 5138
@@ -5137,7 +5143,7 @@ target_done:
5137 * skip save of the final negotiated settings to 5143 * skip save of the final negotiated settings to
5138 * SCSI device page 1. 5144 * SCSI device page 1.
5139 * 5145 *
5140 cfg.hdr = &header1; 5146 cfg.cfghdr.hdr = &header1;
5141 cfg.physAddr = cfg1_dma_addr; 5147 cfg.physAddr = cfg1_dma_addr;
5142 cfg.action = MPI_CONFIG_ACTION_PAGE_WRITE_CURRENT; 5148 cfg.action = MPI_CONFIG_ACTION_PAGE_WRITE_CURRENT;
5143 cfg.dir = 1; 5149 cfg.dir = 1;
@@ -5248,7 +5254,7 @@ mptscsih_dv_parms(MPT_SCSI_HOST *hd, DVPARAMETERS *dv,void *pPage)
5248 /* Update tmax values with those from Device Page 0.*/ 5254 /* Update tmax values with those from Device Page 0.*/
5249 pPage0 = (SCSIDevicePage0_t *) pPage; 5255 pPage0 = (SCSIDevicePage0_t *) pPage;
5250 if (pPage0) { 5256 if (pPage0) {
5251 val = cpu_to_le32(pPage0->NegotiatedParameters); 5257 val = le32_to_cpu(pPage0->NegotiatedParameters);
5252 dv->max.width = val & MPI_SCSIDEVPAGE0_NP_WIDE ? 1 : 0; 5258 dv->max.width = val & MPI_SCSIDEVPAGE0_NP_WIDE ? 1 : 0;
5253 dv->max.offset = (val&MPI_SCSIDEVPAGE0_NP_NEG_SYNC_OFFSET_MASK) >> 16; 5259 dv->max.offset = (val&MPI_SCSIDEVPAGE0_NP_NEG_SYNC_OFFSET_MASK) >> 16;
5254 dv->max.factor = (val&MPI_SCSIDEVPAGE0_NP_NEG_SYNC_PERIOD_MASK) >> 8; 5260 dv->max.factor = (val&MPI_SCSIDEVPAGE0_NP_NEG_SYNC_PERIOD_MASK) >> 8;
@@ -5276,12 +5282,12 @@ mptscsih_dv_parms(MPT_SCSI_HOST *hd, DVPARAMETERS *dv,void *pPage)
5276 dv->now.offset, &val, &configuration, dv->now.flags); 5282 dv->now.offset, &val, &configuration, dv->now.flags);
5277 dnegoprintk(("Setting Max: id=%d width=%d factor=%x offset=%x negoFlags=%x request=%x config=%x\n", 5283 dnegoprintk(("Setting Max: id=%d width=%d factor=%x offset=%x negoFlags=%x request=%x config=%x\n",
5278 id, dv->now.width, dv->now.factor, dv->now.offset, dv->now.flags, val, configuration)); 5284 id, dv->now.width, dv->now.factor, dv->now.offset, dv->now.flags, val, configuration));
5279 pPage1->RequestedParameters = le32_to_cpu(val); 5285 pPage1->RequestedParameters = cpu_to_le32(val);
5280 pPage1->Reserved = 0; 5286 pPage1->Reserved = 0;
5281 pPage1->Configuration = le32_to_cpu(configuration); 5287 pPage1->Configuration = cpu_to_le32(configuration);
5282 } 5288 }
5283 5289
5284 ddvprintk(("id=%d width=%d factor=%x offset=%x flags=%x request=%x configuration=%x\n", 5290 ddvprintk(("id=%d width=%d factor=%x offset=%x negoFlags=%x request=%x configuration=%x\n",
5285 id, dv->now.width, dv->now.factor, dv->now.offset, dv->now.flags, val, configuration)); 5291 id, dv->now.width, dv->now.factor, dv->now.offset, dv->now.flags, val, configuration));
5286 break; 5292 break;
5287 5293
@@ -5301,9 +5307,9 @@ mptscsih_dv_parms(MPT_SCSI_HOST *hd, DVPARAMETERS *dv,void *pPage)
5301 offset, &val, &configuration, negoFlags); 5307 offset, &val, &configuration, negoFlags);
5302 dnegoprintk(("Setting Min: id=%d width=%d factor=%x offset=%x negoFlags=%x request=%x config=%x\n", 5308 dnegoprintk(("Setting Min: id=%d width=%d factor=%x offset=%x negoFlags=%x request=%x config=%x\n",
5303 id, width, factor, offset, negoFlags, val, configuration)); 5309 id, width, factor, offset, negoFlags, val, configuration));
5304 pPage1->RequestedParameters = le32_to_cpu(val); 5310 pPage1->RequestedParameters = cpu_to_le32(val);
5305 pPage1->Reserved = 0; 5311 pPage1->Reserved = 0;
5306 pPage1->Configuration = le32_to_cpu(configuration); 5312 pPage1->Configuration = cpu_to_le32(configuration);
5307 } 5313 }
5308 ddvprintk(("id=%d width=%d factor=%x offset=%x request=%x config=%x negoFlags=%x\n", 5314 ddvprintk(("id=%d width=%d factor=%x offset=%x request=%x config=%x negoFlags=%x\n",
5309 id, width, factor, offset, val, configuration, negoFlags)); 5315 id, width, factor, offset, val, configuration, negoFlags));
@@ -5377,12 +5383,12 @@ mptscsih_dv_parms(MPT_SCSI_HOST *hd, DVPARAMETERS *dv,void *pPage)
5377 if (pPage1) { 5383 if (pPage1) {
5378 mptscsih_setDevicePage1Flags (width, factor, offset, &val, 5384 mptscsih_setDevicePage1Flags (width, factor, offset, &val,
5379 &configuration, dv->now.flags); 5385 &configuration, dv->now.flags);
5380 dnegoprintk(("Finish: id=%d width=%d offset=%d factor=%x flags=%x request=%x config=%x\n", 5386 dnegoprintk(("Finish: id=%d width=%d offset=%d factor=%x negoFlags=%x request=%x config=%x\n",
5381 id, width, offset, factor, dv->now.flags, val, configuration)); 5387 id, width, offset, factor, dv->now.flags, val, configuration));
5382 5388
5383 pPage1->RequestedParameters = le32_to_cpu(val); 5389 pPage1->RequestedParameters = cpu_to_le32(val);
5384 pPage1->Reserved = 0; 5390 pPage1->Reserved = 0;
5385 pPage1->Configuration = le32_to_cpu(configuration); 5391 pPage1->Configuration = cpu_to_le32(configuration);
5386 } 5392 }
5387 5393
5388 ddvprintk(("Finish: id=%d offset=%d factor=%x width=%d request=%x config=%x\n", 5394 ddvprintk(("Finish: id=%d offset=%d factor=%x width=%d request=%x config=%x\n",
diff --git a/drivers/message/fusion/mptspi.c b/drivers/message/fusion/mptspi.c
index dfa8806b1e1..587d1274fd7 100644
--- a/drivers/message/fusion/mptspi.c
+++ b/drivers/message/fusion/mptspi.c
@@ -162,15 +162,15 @@ mptspi_probe(struct pci_dev *pdev, const struct pci_device_id *id)
162 u8 *mem; 162 u8 *mem;
163 int error=0; 163 int error=0;
164 int r; 164 int r;
165 165
166 if ((r = mpt_attach(pdev,id)) != 0) 166 if ((r = mpt_attach(pdev,id)) != 0)
167 return r; 167 return r;
168 168
169 ioc = pci_get_drvdata(pdev); 169 ioc = pci_get_drvdata(pdev);
170 ioc->DoneCtx = mptspiDoneCtx; 170 ioc->DoneCtx = mptspiDoneCtx;
171 ioc->TaskCtx = mptspiTaskCtx; 171 ioc->TaskCtx = mptspiTaskCtx;
172 ioc->InternalCtx = mptspiInternalCtx; 172 ioc->InternalCtx = mptspiInternalCtx;
173 173
174 /* Added sanity check on readiness of the MPT adapter. 174 /* Added sanity check on readiness of the MPT adapter.
175 */ 175 */
176 if (ioc->last_state != MPI_IOC_STATE_OPERATIONAL) { 176 if (ioc->last_state != MPI_IOC_STATE_OPERATIONAL) {
diff --git a/drivers/misc/Kconfig b/drivers/misc/Kconfig
index dea6589d153..7fc692a8f5b 100644
--- a/drivers/misc/Kconfig
+++ b/drivers/misc/Kconfig
@@ -6,7 +6,7 @@ menu "Misc devices"
6 6
7config IBM_ASM 7config IBM_ASM
8 tristate "Device driver for IBM RSA service processor" 8 tristate "Device driver for IBM RSA service processor"
9 depends on X86 && PCI && EXPERIMENTAL && BROKEN 9 depends on X86 && PCI && EXPERIMENTAL
10 ---help--- 10 ---help---
11 This option enables device driver support for in-band access to the 11 This option enables device driver support for in-band access to the
12 IBM RSA (Condor) service processor in eServer xSeries systems. 12 IBM RSA (Condor) service processor in eServer xSeries systems.
diff --git a/drivers/misc/ibmasm/uart.c b/drivers/misc/ibmasm/uart.c
index 914804512db..7e98434cfa3 100644
--- a/drivers/misc/ibmasm/uart.c
+++ b/drivers/misc/ibmasm/uart.c
@@ -25,15 +25,15 @@
25#include <linux/termios.h> 25#include <linux/termios.h>
26#include <linux/tty.h> 26#include <linux/tty.h>
27#include <linux/serial_core.h> 27#include <linux/serial_core.h>
28#include <linux/serial.h>
29#include <linux/serial_reg.h> 28#include <linux/serial_reg.h>
29#include <linux/serial_8250.h>
30#include "ibmasm.h" 30#include "ibmasm.h"
31#include "lowlevel.h" 31#include "lowlevel.h"
32 32
33 33
34void ibmasm_register_uart(struct service_processor *sp) 34void ibmasm_register_uart(struct service_processor *sp)
35{ 35{
36 struct serial_struct serial; 36 struct uart_port uport;
37 void __iomem *iomem_base; 37 void __iomem *iomem_base;
38 38
39 iomem_base = sp->base_address + SCOUT_COM_B_BASE; 39 iomem_base = sp->base_address + SCOUT_COM_B_BASE;
@@ -47,14 +47,14 @@ void ibmasm_register_uart(struct service_processor *sp)
47 return; 47 return;
48 } 48 }
49 49
50 memset(&serial, 0, sizeof(serial)); 50 memset(&uport, 0, sizeof(struct uart_port));
51 serial.irq = sp->irq; 51 uport.irq = sp->irq;
52 serial.baud_base = 3686400 / 16; 52 uport.uartclk = 3686400;
53 serial.flags = UPF_AUTOPROBE | UPF_SHARE_IRQ; 53 uport.flags = UPF_AUTOPROBE | UPF_SHARE_IRQ;
54 serial.io_type = UPIO_MEM; 54 uport.iotype = UPIO_MEM;
55 serial.iomem_base = iomem_base; 55 uport.membase = iomem_base;
56 56
57 sp->serial_line = register_serial(&serial); 57 sp->serial_line = serial8250_register_port(&uport);
58 if (sp->serial_line < 0) { 58 if (sp->serial_line < 0) {
59 dev_err(sp->dev, "Failed to register serial port\n"); 59 dev_err(sp->dev, "Failed to register serial port\n");
60 return; 60 return;
@@ -68,5 +68,5 @@ void ibmasm_unregister_uart(struct service_processor *sp)
68 return; 68 return;
69 69
70 disable_uart_interrupts(sp->base_address); 70 disable_uart_interrupts(sp->base_address);
71 unregister_serial(sp->serial_line); 71 serial8250_unregister_port(sp->serial_line);
72} 72}
diff --git a/drivers/mmc/mmc.c b/drivers/mmc/mmc.c
index 3c5904834fe..0a117c61cd1 100644
--- a/drivers/mmc/mmc.c
+++ b/drivers/mmc/mmc.c
@@ -2,6 +2,8 @@
2 * linux/drivers/mmc/mmc.c 2 * linux/drivers/mmc/mmc.c
3 * 3 *
4 * Copyright (C) 2003-2004 Russell King, All Rights Reserved. 4 * Copyright (C) 2003-2004 Russell King, All Rights Reserved.
5 * SD support Copyright (C) 2004 Ian Molton, All Rights Reserved.
6 * SD support Copyright (C) 2005 Pierre Ossman, All Rights Reserved.
5 * 7 *
6 * This program is free software; you can redistribute it and/or modify 8 * 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 9 * it under the terms of the GNU General Public License version 2 as
@@ -16,6 +18,8 @@
16#include <linux/delay.h> 18#include <linux/delay.h>
17#include <linux/pagemap.h> 19#include <linux/pagemap.h>
18#include <linux/err.h> 20#include <linux/err.h>
21#include <asm/scatterlist.h>
22#include <linux/scatterlist.h>
19 23
20#include <linux/mmc/card.h> 24#include <linux/mmc/card.h>
21#include <linux/mmc/host.h> 25#include <linux/mmc/host.h>
@@ -172,7 +176,81 @@ int mmc_wait_for_cmd(struct mmc_host *host, struct mmc_command *cmd, int retries
172 176
173EXPORT_SYMBOL(mmc_wait_for_cmd); 177EXPORT_SYMBOL(mmc_wait_for_cmd);
174 178
179/**
180 * mmc_wait_for_app_cmd - start an application command and wait for
181 completion
182 * @host: MMC host to start command
183 * @rca: RCA to send MMC_APP_CMD to
184 * @cmd: MMC command to start
185 * @retries: maximum number of retries
186 *
187 * Sends a MMC_APP_CMD, checks the card response, sends the command
188 * in the parameter and waits for it to complete. Return any error
189 * that occurred while the command was executing. Do not attempt to
190 * parse the response.
191 */
192int mmc_wait_for_app_cmd(struct mmc_host *host, unsigned int rca,
193 struct mmc_command *cmd, int retries)
194{
195 struct mmc_request mrq;
196 struct mmc_command appcmd;
197
198 int i, err;
199
200 BUG_ON(host->card_busy == NULL);
201 BUG_ON(retries < 0);
202
203 err = MMC_ERR_INVALID;
204
205 /*
206 * We have to resend MMC_APP_CMD for each attempt so
207 * we cannot use the retries field in mmc_command.
208 */
209 for (i = 0;i <= retries;i++) {
210 memset(&mrq, 0, sizeof(struct mmc_request));
211
212 appcmd.opcode = MMC_APP_CMD;
213 appcmd.arg = rca << 16;
214 appcmd.flags = MMC_RSP_R1;
215 appcmd.retries = 0;
216 memset(appcmd.resp, 0, sizeof(appcmd.resp));
217 appcmd.data = NULL;
218
219 mrq.cmd = &appcmd;
220 appcmd.data = NULL;
221
222 mmc_wait_for_req(host, &mrq);
223
224 if (appcmd.error) {
225 err = appcmd.error;
226 continue;
227 }
228
229 /* Check that card supported application commands */
230 if (!(appcmd.resp[0] & R1_APP_CMD))
231 return MMC_ERR_FAILED;
232
233 memset(&mrq, 0, sizeof(struct mmc_request));
234
235 memset(cmd->resp, 0, sizeof(cmd->resp));
236 cmd->retries = 0;
237
238 mrq.cmd = cmd;
239 cmd->data = NULL;
240
241 mmc_wait_for_req(host, &mrq);
175 242
243 err = cmd->error;
244 if (cmd->error == MMC_ERR_NONE)
245 break;
246 }
247
248 return err;
249}
250
251EXPORT_SYMBOL(mmc_wait_for_app_cmd);
252
253static int mmc_select_card(struct mmc_host *host, struct mmc_card *card);
176 254
177/** 255/**
178 * __mmc_claim_host - exclusively claim a host 256 * __mmc_claim_host - exclusively claim a host
@@ -206,16 +284,10 @@ int __mmc_claim_host(struct mmc_host *host, struct mmc_card *card)
206 spin_unlock_irqrestore(&host->lock, flags); 284 spin_unlock_irqrestore(&host->lock, flags);
207 remove_wait_queue(&host->wq, &wait); 285 remove_wait_queue(&host->wq, &wait);
208 286
209 if (card != (void *)-1 && host->card_selected != card) { 287 if (card != (void *)-1) {
210 struct mmc_command cmd; 288 err = mmc_select_card(host, card);
211 289 if (err != MMC_ERR_NONE)
212 host->card_selected = card; 290 return err;
213
214 cmd.opcode = MMC_SELECT_CARD;
215 cmd.arg = card->rca << 16;
216 cmd.flags = MMC_RSP_R1;
217
218 err = mmc_wait_for_cmd(host, &cmd, CMD_RETRIES);
219 } 291 }
220 292
221 return err; 293 return err;
@@ -245,6 +317,63 @@ void mmc_release_host(struct mmc_host *host)
245 317
246EXPORT_SYMBOL(mmc_release_host); 318EXPORT_SYMBOL(mmc_release_host);
247 319
320static int mmc_select_card(struct mmc_host *host, struct mmc_card *card)
321{
322 int err;
323 struct mmc_command cmd;
324
325 BUG_ON(host->card_busy == NULL);
326
327 if (host->card_selected == card)
328 return MMC_ERR_NONE;
329
330 host->card_selected = card;
331
332 cmd.opcode = MMC_SELECT_CARD;
333 cmd.arg = card->rca << 16;
334 cmd.flags = MMC_RSP_R1;
335
336 err = mmc_wait_for_cmd(host, &cmd, CMD_RETRIES);
337 if (err != MMC_ERR_NONE)
338 return err;
339
340 /*
341 * Default bus width is 1 bit.
342 */
343 host->ios.bus_width = MMC_BUS_WIDTH_1;
344
345 /*
346 * We can only change the bus width of the selected
347 * card so therefore we have to put the handling
348 * here.
349 */
350 if (host->caps & MMC_CAP_4_BIT_DATA) {
351 /*
352 * The card is in 1 bit mode by default so
353 * we only need to change if it supports the
354 * wider version.
355 */
356 if (mmc_card_sd(card) &&
357 (card->scr.bus_widths & SD_SCR_BUS_WIDTH_4)) {
358 struct mmc_command cmd;
359 cmd.opcode = SD_APP_SET_BUS_WIDTH;
360 cmd.arg = SD_BUS_WIDTH_4;
361 cmd.flags = MMC_RSP_R1;
362
363 err = mmc_wait_for_app_cmd(host, card->rca, &cmd,
364 CMD_RETRIES);
365 if (err != MMC_ERR_NONE)
366 return err;
367
368 host->ios.bus_width = MMC_BUS_WIDTH_4;
369 }
370 }
371
372 host->ops->set_ios(host, &host->ios);
373
374 return MMC_ERR_NONE;
375}
376
248/* 377/*
249 * Ensure that no card is selected. 378 * Ensure that no card is selected.
250 */ 379 */
@@ -322,48 +451,69 @@ static void mmc_decode_cid(struct mmc_card *card)
322 451
323 memset(&card->cid, 0, sizeof(struct mmc_cid)); 452 memset(&card->cid, 0, sizeof(struct mmc_cid));
324 453
325 /* 454 if (mmc_card_sd(card)) {
326 * The selection of the format here is guesswork based upon 455 /*
327 * information people have sent to date. 456 * SD doesn't currently have a version field so we will
328 */ 457 * have to assume we can parse this.
329 switch (card->csd.mmca_vsn) { 458 */
330 case 0: /* MMC v1.? */ 459 card->cid.manfid = UNSTUFF_BITS(resp, 120, 8);
331 case 1: /* MMC v1.4 */ 460 card->cid.oemid = UNSTUFF_BITS(resp, 104, 16);
332 card->cid.manfid = UNSTUFF_BITS(resp, 104, 24); 461 card->cid.prod_name[0] = UNSTUFF_BITS(resp, 96, 8);
333 card->cid.prod_name[0] = UNSTUFF_BITS(resp, 96, 8); 462 card->cid.prod_name[1] = UNSTUFF_BITS(resp, 88, 8);
334 card->cid.prod_name[1] = UNSTUFF_BITS(resp, 88, 8); 463 card->cid.prod_name[2] = UNSTUFF_BITS(resp, 80, 8);
335 card->cid.prod_name[2] = UNSTUFF_BITS(resp, 80, 8); 464 card->cid.prod_name[3] = UNSTUFF_BITS(resp, 72, 8);
336 card->cid.prod_name[3] = UNSTUFF_BITS(resp, 72, 8); 465 card->cid.prod_name[4] = UNSTUFF_BITS(resp, 64, 8);
337 card->cid.prod_name[4] = UNSTUFF_BITS(resp, 64, 8); 466 card->cid.hwrev = UNSTUFF_BITS(resp, 60, 4);
338 card->cid.prod_name[5] = UNSTUFF_BITS(resp, 56, 8); 467 card->cid.fwrev = UNSTUFF_BITS(resp, 56, 4);
339 card->cid.prod_name[6] = UNSTUFF_BITS(resp, 48, 8); 468 card->cid.serial = UNSTUFF_BITS(resp, 24, 32);
340 card->cid.hwrev = UNSTUFF_BITS(resp, 44, 4); 469 card->cid.year = UNSTUFF_BITS(resp, 12, 8);
341 card->cid.fwrev = UNSTUFF_BITS(resp, 40, 4); 470 card->cid.month = UNSTUFF_BITS(resp, 8, 4);
342 card->cid.serial = UNSTUFF_BITS(resp, 16, 24); 471
343 card->cid.month = UNSTUFF_BITS(resp, 12, 4); 472 card->cid.year += 2000; /* SD cards year offset */
344 card->cid.year = UNSTUFF_BITS(resp, 8, 4) + 1997; 473 } else {
345 break; 474 /*
346 475 * The selection of the format here is based upon published
347 case 2: /* MMC v2.x ? */ 476 * specs from sandisk and from what people have reported.
348 case 3: /* MMC v3.x ? */ 477 */
349 card->cid.manfid = UNSTUFF_BITS(resp, 120, 8); 478 switch (card->csd.mmca_vsn) {
350 card->cid.oemid = UNSTUFF_BITS(resp, 104, 16); 479 case 0: /* MMC v1.0 - v1.2 */
351 card->cid.prod_name[0] = UNSTUFF_BITS(resp, 96, 8); 480 case 1: /* MMC v1.4 */
352 card->cid.prod_name[1] = UNSTUFF_BITS(resp, 88, 8); 481 card->cid.manfid = UNSTUFF_BITS(resp, 104, 24);
353 card->cid.prod_name[2] = UNSTUFF_BITS(resp, 80, 8); 482 card->cid.prod_name[0] = UNSTUFF_BITS(resp, 96, 8);
354 card->cid.prod_name[3] = UNSTUFF_BITS(resp, 72, 8); 483 card->cid.prod_name[1] = UNSTUFF_BITS(resp, 88, 8);
355 card->cid.prod_name[4] = UNSTUFF_BITS(resp, 64, 8); 484 card->cid.prod_name[2] = UNSTUFF_BITS(resp, 80, 8);
356 card->cid.prod_name[5] = UNSTUFF_BITS(resp, 56, 8); 485 card->cid.prod_name[3] = UNSTUFF_BITS(resp, 72, 8);
357 card->cid.serial = UNSTUFF_BITS(resp, 16, 32); 486 card->cid.prod_name[4] = UNSTUFF_BITS(resp, 64, 8);
358 card->cid.month = UNSTUFF_BITS(resp, 12, 4); 487 card->cid.prod_name[5] = UNSTUFF_BITS(resp, 56, 8);
359 card->cid.year = UNSTUFF_BITS(resp, 8, 4) + 1997; 488 card->cid.prod_name[6] = UNSTUFF_BITS(resp, 48, 8);
360 break; 489 card->cid.hwrev = UNSTUFF_BITS(resp, 44, 4);
361 490 card->cid.fwrev = UNSTUFF_BITS(resp, 40, 4);
362 default: 491 card->cid.serial = UNSTUFF_BITS(resp, 16, 24);
363 printk("%s: card has unknown MMCA version %d\n", 492 card->cid.month = UNSTUFF_BITS(resp, 12, 4);
364 mmc_hostname(card->host), card->csd.mmca_vsn); 493 card->cid.year = UNSTUFF_BITS(resp, 8, 4) + 1997;
365 mmc_card_set_bad(card); 494 break;
366 break; 495
496 case 2: /* MMC v2.0 - v2.2 */
497 case 3: /* MMC v3.1 - v3.3 */
498 card->cid.manfid = UNSTUFF_BITS(resp, 120, 8);
499 card->cid.oemid = UNSTUFF_BITS(resp, 104, 16);
500 card->cid.prod_name[0] = UNSTUFF_BITS(resp, 96, 8);
501 card->cid.prod_name[1] = UNSTUFF_BITS(resp, 88, 8);
502 card->cid.prod_name[2] = UNSTUFF_BITS(resp, 80, 8);
503 card->cid.prod_name[3] = UNSTUFF_BITS(resp, 72, 8);
504 card->cid.prod_name[4] = UNSTUFF_BITS(resp, 64, 8);
505 card->cid.prod_name[5] = UNSTUFF_BITS(resp, 56, 8);
506 card->cid.serial = UNSTUFF_BITS(resp, 16, 32);
507 card->cid.month = UNSTUFF_BITS(resp, 12, 4);
508 card->cid.year = UNSTUFF_BITS(resp, 8, 4) + 1997;
509 break;
510
511 default:
512 printk("%s: card has unknown MMCA version %d\n",
513 mmc_hostname(card->host), card->csd.mmca_vsn);
514 mmc_card_set_bad(card);
515 break;
516 }
367 } 517 }
368} 518}
369 519
@@ -376,34 +526,86 @@ static void mmc_decode_csd(struct mmc_card *card)
376 unsigned int e, m, csd_struct; 526 unsigned int e, m, csd_struct;
377 u32 *resp = card->raw_csd; 527 u32 *resp = card->raw_csd;
378 528
379 /* 529 if (mmc_card_sd(card)) {
380 * We only understand CSD structure v1.1 and v2. 530 csd_struct = UNSTUFF_BITS(resp, 126, 2);
381 * v2 has extra information in bits 15, 11 and 10. 531 if (csd_struct != 0) {
382 */ 532 printk("%s: unrecognised CSD structure version %d\n",
383 csd_struct = UNSTUFF_BITS(resp, 126, 2); 533 mmc_hostname(card->host), csd_struct);
384 if (csd_struct != 1 && csd_struct != 2) { 534 mmc_card_set_bad(card);
385 printk("%s: unrecognised CSD structure version %d\n", 535 return;
386 mmc_hostname(card->host), csd_struct); 536 }
387 mmc_card_set_bad(card); 537
388 return; 538 m = UNSTUFF_BITS(resp, 115, 4);
539 e = UNSTUFF_BITS(resp, 112, 3);
540 csd->tacc_ns = (tacc_exp[e] * tacc_mant[m] + 9) / 10;
541 csd->tacc_clks = UNSTUFF_BITS(resp, 104, 8) * 100;
542
543 m = UNSTUFF_BITS(resp, 99, 4);
544 e = UNSTUFF_BITS(resp, 96, 3);
545 csd->max_dtr = tran_exp[e] * tran_mant[m];
546 csd->cmdclass = UNSTUFF_BITS(resp, 84, 12);
547
548 e = UNSTUFF_BITS(resp, 47, 3);
549 m = UNSTUFF_BITS(resp, 62, 12);
550 csd->capacity = (1 + m) << (e + 2);
551
552 csd->read_blkbits = UNSTUFF_BITS(resp, 80, 4);
553 } else {
554 /*
555 * We only understand CSD structure v1.1 and v1.2.
556 * v1.2 has extra information in bits 15, 11 and 10.
557 */
558 csd_struct = UNSTUFF_BITS(resp, 126, 2);
559 if (csd_struct != 1 && csd_struct != 2) {
560 printk("%s: unrecognised CSD structure version %d\n",
561 mmc_hostname(card->host), csd_struct);
562 mmc_card_set_bad(card);
563 return;
564 }
565
566 csd->mmca_vsn = UNSTUFF_BITS(resp, 122, 4);
567 m = UNSTUFF_BITS(resp, 115, 4);
568 e = UNSTUFF_BITS(resp, 112, 3);
569 csd->tacc_ns = (tacc_exp[e] * tacc_mant[m] + 9) / 10;
570 csd->tacc_clks = UNSTUFF_BITS(resp, 104, 8) * 100;
571
572 m = UNSTUFF_BITS(resp, 99, 4);
573 e = UNSTUFF_BITS(resp, 96, 3);
574 csd->max_dtr = tran_exp[e] * tran_mant[m];
575 csd->cmdclass = UNSTUFF_BITS(resp, 84, 12);
576
577 e = UNSTUFF_BITS(resp, 47, 3);
578 m = UNSTUFF_BITS(resp, 62, 12);
579 csd->capacity = (1 + m) << (e + 2);
580
581 csd->read_blkbits = UNSTUFF_BITS(resp, 80, 4);
389 } 582 }
583}
584
585/*
586 * Given a 64-bit response, decode to our card SCR structure.
587 */
588static void mmc_decode_scr(struct mmc_card *card)
589{
590 struct sd_scr *scr = &card->scr;
591 unsigned int scr_struct;
592 u32 resp[4];
390 593
391 csd->mmca_vsn = UNSTUFF_BITS(resp, 122, 4); 594 BUG_ON(!mmc_card_sd(card));
392 m = UNSTUFF_BITS(resp, 115, 4);
393 e = UNSTUFF_BITS(resp, 112, 3);
394 csd->tacc_ns = (tacc_exp[e] * tacc_mant[m] + 9) / 10;
395 csd->tacc_clks = UNSTUFF_BITS(resp, 104, 8) * 100;
396 595
397 m = UNSTUFF_BITS(resp, 99, 4); 596 resp[3] = card->raw_scr[1];
398 e = UNSTUFF_BITS(resp, 96, 3); 597 resp[2] = card->raw_scr[0];
399 csd->max_dtr = tran_exp[e] * tran_mant[m];
400 csd->cmdclass = UNSTUFF_BITS(resp, 84, 12);
401 598
402 e = UNSTUFF_BITS(resp, 47, 3); 599 scr_struct = UNSTUFF_BITS(resp, 60, 4);
403 m = UNSTUFF_BITS(resp, 62, 12); 600 if (scr_struct != 0) {
404 csd->capacity = (1 + m) << (e + 2); 601 printk("%s: unrecognised SCR structure version %d\n",
602 mmc_hostname(card->host), scr_struct);
603 mmc_card_set_bad(card);
604 return;
605 }
405 606
406 csd->read_blkbits = UNSTUFF_BITS(resp, 80, 4); 607 scr->sda_vsn = UNSTUFF_BITS(resp, 56, 4);
608 scr->bus_widths = UNSTUFF_BITS(resp, 48, 4);
407} 609}
408 610
409/* 611/*
@@ -457,6 +659,11 @@ static void mmc_idle_cards(struct mmc_host *host)
457{ 659{
458 struct mmc_command cmd; 660 struct mmc_command cmd;
459 661
662 host->ios.chip_select = MMC_CS_HIGH;
663 host->ops->set_ios(host, &host->ios);
664
665 mmc_delay(1);
666
460 cmd.opcode = MMC_GO_IDLE_STATE; 667 cmd.opcode = MMC_GO_IDLE_STATE;
461 cmd.arg = 0; 668 cmd.arg = 0;
462 cmd.flags = MMC_RSP_NONE; 669 cmd.flags = MMC_RSP_NONE;
@@ -464,6 +671,11 @@ static void mmc_idle_cards(struct mmc_host *host)
464 mmc_wait_for_cmd(host, &cmd, 0); 671 mmc_wait_for_cmd(host, &cmd, 0);
465 672
466 mmc_delay(1); 673 mmc_delay(1);
674
675 host->ios.chip_select = MMC_CS_DONTCARE;
676 host->ops->set_ios(host, &host->ios);
677
678 mmc_delay(1);
467} 679}
468 680
469/* 681/*
@@ -475,7 +687,9 @@ static void mmc_power_up(struct mmc_host *host)
475 687
476 host->ios.vdd = bit; 688 host->ios.vdd = bit;
477 host->ios.bus_mode = MMC_BUSMODE_OPENDRAIN; 689 host->ios.bus_mode = MMC_BUSMODE_OPENDRAIN;
690 host->ios.chip_select = MMC_CS_DONTCARE;
478 host->ios.power_mode = MMC_POWER_UP; 691 host->ios.power_mode = MMC_POWER_UP;
692 host->ios.bus_width = MMC_BUS_WIDTH_1;
479 host->ops->set_ios(host, &host->ios); 693 host->ops->set_ios(host, &host->ios);
480 694
481 mmc_delay(1); 695 mmc_delay(1);
@@ -492,7 +706,9 @@ static void mmc_power_off(struct mmc_host *host)
492 host->ios.clock = 0; 706 host->ios.clock = 0;
493 host->ios.vdd = 0; 707 host->ios.vdd = 0;
494 host->ios.bus_mode = MMC_BUSMODE_OPENDRAIN; 708 host->ios.bus_mode = MMC_BUSMODE_OPENDRAIN;
709 host->ios.chip_select = MMC_CS_DONTCARE;
495 host->ios.power_mode = MMC_POWER_OFF; 710 host->ios.power_mode = MMC_POWER_OFF;
711 host->ios.bus_width = MMC_BUS_WIDTH_1;
496 host->ops->set_ios(host, &host->ios); 712 host->ops->set_ios(host, &host->ios);
497} 713}
498 714
@@ -524,6 +740,34 @@ static int mmc_send_op_cond(struct mmc_host *host, u32 ocr, u32 *rocr)
524 return err; 740 return err;
525} 741}
526 742
743static int mmc_send_app_op_cond(struct mmc_host *host, u32 ocr, u32 *rocr)
744{
745 struct mmc_command cmd;
746 int i, err = 0;
747
748 cmd.opcode = SD_APP_OP_COND;
749 cmd.arg = ocr;
750 cmd.flags = MMC_RSP_R3;
751
752 for (i = 100; i; i--) {
753 err = mmc_wait_for_app_cmd(host, 0, &cmd, CMD_RETRIES);
754 if (err != MMC_ERR_NONE)
755 break;
756
757 if (cmd.resp[0] & MMC_CARD_BUSY || ocr == 0)
758 break;
759
760 err = MMC_ERR_TIMEOUT;
761
762 mmc_delay(10);
763 }
764
765 if (rocr)
766 *rocr = cmd.resp[0];
767
768 return err;
769}
770
527/* 771/*
528 * Discover cards by requesting their CID. If this command 772 * Discover cards by requesting their CID. If this command
529 * times out, it is not an error; there are no further cards 773 * times out, it is not an error; there are no further cards
@@ -567,13 +811,38 @@ static void mmc_discover_cards(struct mmc_host *host)
567 811
568 card->state &= ~MMC_STATE_DEAD; 812 card->state &= ~MMC_STATE_DEAD;
569 813
570 cmd.opcode = MMC_SET_RELATIVE_ADDR; 814 if (host->mode == MMC_MODE_SD) {
571 cmd.arg = card->rca << 16; 815 mmc_card_set_sd(card);
572 cmd.flags = MMC_RSP_R1;
573 816
574 err = mmc_wait_for_cmd(host, &cmd, CMD_RETRIES); 817 cmd.opcode = SD_SEND_RELATIVE_ADDR;
575 if (err != MMC_ERR_NONE) 818 cmd.arg = 0;
576 mmc_card_set_dead(card); 819 cmd.flags = MMC_RSP_R1;
820
821 err = mmc_wait_for_cmd(host, &cmd, CMD_RETRIES);
822 if (err != MMC_ERR_NONE)
823 mmc_card_set_dead(card);
824 else {
825 card->rca = cmd.resp[0] >> 16;
826
827 if (!host->ops->get_ro) {
828 printk(KERN_WARNING "%s: host does not "
829 "support reading read-only "
830 "switch. assuming write-enable.\n",
831 mmc_hostname(host));
832 } else {
833 if (host->ops->get_ro(host))
834 mmc_card_set_readonly(card);
835 }
836 }
837 } else {
838 cmd.opcode = MMC_SET_RELATIVE_ADDR;
839 cmd.arg = card->rca << 16;
840 cmd.flags = MMC_RSP_R1;
841
842 err = mmc_wait_for_cmd(host, &cmd, CMD_RETRIES);
843 if (err != MMC_ERR_NONE)
844 mmc_card_set_dead(card);
845 }
577 } 846 }
578} 847}
579 848
@@ -605,6 +874,79 @@ static void mmc_read_csds(struct mmc_host *host)
605 } 874 }
606} 875}
607 876
877static void mmc_read_scrs(struct mmc_host *host)
878{
879 int err;
880 struct mmc_card *card;
881
882 struct mmc_request mrq;
883 struct mmc_command cmd;
884 struct mmc_data data;
885
886 struct scatterlist sg;
887
888 list_for_each_entry(card, &host->cards, node) {
889 if (card->state & (MMC_STATE_DEAD|MMC_STATE_PRESENT))
890 continue;
891 if (!mmc_card_sd(card))
892 continue;
893
894 err = mmc_select_card(host, card);
895 if (err != MMC_ERR_NONE) {
896 mmc_card_set_dead(card);
897 continue;
898 }
899
900 memset(&cmd, 0, sizeof(struct mmc_command));
901
902 cmd.opcode = MMC_APP_CMD;
903 cmd.arg = card->rca << 16;
904 cmd.flags = MMC_RSP_R1;
905
906 err = mmc_wait_for_cmd(host, &cmd, 0);
907 if ((err != MMC_ERR_NONE) || !(cmd.resp[0] & R1_APP_CMD)) {
908 mmc_card_set_dead(card);
909 continue;
910 }
911
912 memset(&cmd, 0, sizeof(struct mmc_command));
913
914 cmd.opcode = SD_APP_SEND_SCR;
915 cmd.arg = 0;
916 cmd.flags = MMC_RSP_R1;
917
918 memset(&data, 0, sizeof(struct mmc_data));
919
920 data.timeout_ns = card->csd.tacc_ns * 10;
921 data.timeout_clks = card->csd.tacc_clks * 10;
922 data.blksz_bits = 3;
923 data.blocks = 1;
924 data.flags = MMC_DATA_READ;
925 data.sg = &sg;
926 data.sg_len = 1;
927
928 memset(&mrq, 0, sizeof(struct mmc_request));
929
930 mrq.cmd = &cmd;
931 mrq.data = &data;
932
933 sg_init_one(&sg, (u8*)card->raw_scr, 8);
934
935 err = mmc_wait_for_req(host, &mrq);
936 if (err != MMC_ERR_NONE) {
937 mmc_card_set_dead(card);
938 continue;
939 }
940
941 card->raw_scr[0] = ntohl(card->raw_scr[0]);
942 card->raw_scr[1] = ntohl(card->raw_scr[1]);
943
944 mmc_decode_scr(card);
945 }
946
947 mmc_deselect_cards(host);
948}
949
608static unsigned int mmc_calculate_clock(struct mmc_host *host) 950static unsigned int mmc_calculate_clock(struct mmc_host *host)
609{ 951{
610 struct mmc_card *card; 952 struct mmc_card *card;
@@ -657,12 +999,24 @@ static void mmc_setup(struct mmc_host *host)
657 int err; 999 int err;
658 u32 ocr; 1000 u32 ocr;
659 1001
1002 host->mode = MMC_MODE_SD;
1003
660 mmc_power_up(host); 1004 mmc_power_up(host);
661 mmc_idle_cards(host); 1005 mmc_idle_cards(host);
662 1006
663 err = mmc_send_op_cond(host, 0, &ocr); 1007 err = mmc_send_app_op_cond(host, 0, &ocr);
664 if (err != MMC_ERR_NONE) 1008
665 return; 1009 /*
1010 * If we fail to detect any SD cards then try
1011 * searching for MMC cards.
1012 */
1013 if (err != MMC_ERR_NONE) {
1014 host->mode = MMC_MODE_MMC;
1015
1016 err = mmc_send_op_cond(host, 0, &ocr);
1017 if (err != MMC_ERR_NONE)
1018 return;
1019 }
666 1020
667 host->ocr = mmc_select_voltage(host, ocr); 1021 host->ocr = mmc_select_voltage(host, ocr);
668 1022
@@ -702,7 +1056,10 @@ static void mmc_setup(struct mmc_host *host)
702 * all get the idea that they should be ready for CMD2. 1056 * all get the idea that they should be ready for CMD2.
703 * (My SanDisk card seems to need this.) 1057 * (My SanDisk card seems to need this.)
704 */ 1058 */
705 mmc_send_op_cond(host, host->ocr, NULL); 1059 if (host->mode == MMC_MODE_SD)
1060 mmc_send_app_op_cond(host, host->ocr, NULL);
1061 else
1062 mmc_send_op_cond(host, host->ocr, NULL);
706 1063
707 mmc_discover_cards(host); 1064 mmc_discover_cards(host);
708 1065
@@ -713,6 +1070,9 @@ static void mmc_setup(struct mmc_host *host)
713 host->ops->set_ios(host, &host->ios); 1070 host->ops->set_ios(host, &host->ios);
714 1071
715 mmc_read_csds(host); 1072 mmc_read_csds(host);
1073
1074 if (host->mode == MMC_MODE_SD)
1075 mmc_read_scrs(host);
716} 1076}
717 1077
718 1078
diff --git a/drivers/mmc/mmc_block.c b/drivers/mmc/mmc_block.c
index d4eee99c2bf..fa83f15fdf1 100644
--- a/drivers/mmc/mmc_block.c
+++ b/drivers/mmc/mmc_block.c
@@ -95,6 +95,10 @@ static int mmc_blk_open(struct inode *inode, struct file *filp)
95 if (md->usage == 2) 95 if (md->usage == 2)
96 check_disk_change(inode->i_bdev); 96 check_disk_change(inode->i_bdev);
97 ret = 0; 97 ret = 0;
98
99 if ((filp->f_mode & FMODE_WRITE) &&
100 mmc_card_readonly(md->queue.card))
101 ret = -EROFS;
98 } 102 }
99 103
100 return ret; 104 return ret;
@@ -403,9 +407,10 @@ static int mmc_blk_probe(struct mmc_card *card)
403 if (err) 407 if (err)
404 goto out; 408 goto out;
405 409
406 printk(KERN_INFO "%s: %s %s %dKiB\n", 410 printk(KERN_INFO "%s: %s %s %dKiB %s\n",
407 md->disk->disk_name, mmc_card_id(card), mmc_card_name(card), 411 md->disk->disk_name, mmc_card_id(card), mmc_card_name(card),
408 (card->csd.capacity << card->csd.read_blkbits) / 1024); 412 (card->csd.capacity << card->csd.read_blkbits) / 1024,
413 mmc_card_readonly(card)?"(ro)":"");
409 414
410 mmc_set_drvdata(card, md); 415 mmc_set_drvdata(card, md);
411 add_disk(md->disk); 416 add_disk(md->disk);
diff --git a/drivers/mmc/mmc_sysfs.c b/drivers/mmc/mmc_sysfs.c
index ad8949810fc..3f4a66ca955 100644
--- a/drivers/mmc/mmc_sysfs.c
+++ b/drivers/mmc/mmc_sysfs.c
@@ -34,6 +34,7 @@ MMC_ATTR(cid, "%08x%08x%08x%08x\n", card->raw_cid[0], card->raw_cid[1],
34 card->raw_cid[2], card->raw_cid[3]); 34 card->raw_cid[2], card->raw_cid[3]);
35MMC_ATTR(csd, "%08x%08x%08x%08x\n", card->raw_csd[0], card->raw_csd[1], 35MMC_ATTR(csd, "%08x%08x%08x%08x\n", card->raw_csd[0], card->raw_csd[1],
36 card->raw_csd[2], card->raw_csd[3]); 36 card->raw_csd[2], card->raw_csd[3]);
37MMC_ATTR(scr, "%08x%08x\n", card->raw_scr[0], card->raw_scr[1]);
37MMC_ATTR(date, "%02d/%04d\n", card->cid.month, card->cid.year); 38MMC_ATTR(date, "%02d/%04d\n", card->cid.month, card->cid.year);
38MMC_ATTR(fwrev, "0x%x\n", card->cid.fwrev); 39MMC_ATTR(fwrev, "0x%x\n", card->cid.fwrev);
39MMC_ATTR(hwrev, "0x%x\n", card->cid.hwrev); 40MMC_ATTR(hwrev, "0x%x\n", card->cid.hwrev);
@@ -57,6 +58,8 @@ static struct device_attribute mmc_dev_attrs[] = {
57 __ATTR_NULL 58 __ATTR_NULL
58}; 59};
59 60
61static struct device_attribute mmc_dev_attr_scr = MMC_ATTR_RO(scr);
62
60 63
61static void mmc_release_card(struct device *dev) 64static void mmc_release_card(struct device *dev)
62{ 65{
@@ -207,10 +210,20 @@ void mmc_init_card(struct mmc_card *card, struct mmc_host *host)
207 */ 210 */
208int mmc_register_card(struct mmc_card *card) 211int mmc_register_card(struct mmc_card *card)
209{ 212{
213 int ret;
214
210 snprintf(card->dev.bus_id, sizeof(card->dev.bus_id), 215 snprintf(card->dev.bus_id, sizeof(card->dev.bus_id),
211 "%s:%04x", mmc_hostname(card->host), card->rca); 216 "%s:%04x", mmc_hostname(card->host), card->rca);
212 217
213 return device_add(&card->dev); 218 ret = device_add(&card->dev);
219 if (ret == 0) {
220 if (mmc_card_sd(card)) {
221 ret = device_create_file(&card->dev, &mmc_dev_attr_scr);
222 if (ret)
223 device_del(&card->dev);
224 }
225 }
226 return ret;
214} 227}
215 228
216/* 229/*
@@ -219,8 +232,12 @@ int mmc_register_card(struct mmc_card *card)
219 */ 232 */
220void mmc_remove_card(struct mmc_card *card) 233void mmc_remove_card(struct mmc_card *card)
221{ 234{
222 if (mmc_card_present(card)) 235 if (mmc_card_present(card)) {
236 if (mmc_card_sd(card))
237 device_remove_file(&card->dev, &mmc_dev_attr_scr);
238
223 device_del(&card->dev); 239 device_del(&card->dev);
240 }
224 241
225 put_device(&card->dev); 242 put_device(&card->dev);
226} 243}
diff --git a/drivers/mmc/pxamci.c b/drivers/mmc/pxamci.c
index b78beb1b015..e99a53b09e3 100644
--- a/drivers/mmc/pxamci.c
+++ b/drivers/mmc/pxamci.c
@@ -362,6 +362,16 @@ static void pxamci_request(struct mmc_host *mmc, struct mmc_request *mrq)
362 pxamci_start_cmd(host, mrq->cmd, cmdat); 362 pxamci_start_cmd(host, mrq->cmd, cmdat);
363} 363}
364 364
365static int pxamci_get_ro(struct mmc_host *mmc)
366{
367 struct pxamci_host *host = mmc_priv(mmc);
368
369 if (host->pdata && host->pdata->get_ro)
370 return host->pdata->get_ro(mmc->dev);
371 /* Host doesn't support read only detection so assume writeable */
372 return 0;
373}
374
365static void pxamci_set_ios(struct mmc_host *mmc, struct mmc_ios *ios) 375static void pxamci_set_ios(struct mmc_host *mmc, struct mmc_ios *ios)
366{ 376{
367 struct pxamci_host *host = mmc_priv(mmc); 377 struct pxamci_host *host = mmc_priv(mmc);
@@ -401,6 +411,7 @@ static void pxamci_set_ios(struct mmc_host *mmc, struct mmc_ios *ios)
401 411
402static struct mmc_host_ops pxamci_ops = { 412static struct mmc_host_ops pxamci_ops = {
403 .request = pxamci_request, 413 .request = pxamci_request,
414 .get_ro = pxamci_get_ro,
404 .set_ios = pxamci_set_ios, 415 .set_ios = pxamci_set_ios,
405}; 416};
406 417
diff --git a/drivers/mmc/wbsd.c b/drivers/mmc/wbsd.c
index 402c2d661fb..dec01d38c78 100644
--- a/drivers/mmc/wbsd.c
+++ b/drivers/mmc/wbsd.c
@@ -42,7 +42,7 @@
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.3" 45#define DRIVER_VERSION "1.4"
46 46
47#ifdef CONFIG_MMC_DEBUG 47#ifdef CONFIG_MMC_DEBUG
48#define DBG(x...) \ 48#define DBG(x...) \
@@ -720,11 +720,28 @@ static void wbsd_prepare_data(struct wbsd_host* host, struct mmc_data* data)
720 * calculate CRC. 720 * calculate CRC.
721 * 721 *
722 * Space for CRC must be included in the size. 722 * Space for CRC must be included in the size.
723 * Two bytes are needed for each data line.
723 */ 724 */
724 blksize = (1 << data->blksz_bits) + 2; 725 if (host->bus_width == MMC_BUS_WIDTH_1)
726 {
727 blksize = (1 << data->blksz_bits) + 2;
728
729 wbsd_write_index(host, WBSD_IDX_PBSMSB, (blksize >> 4) & 0xF0);
730 wbsd_write_index(host, WBSD_IDX_PBSLSB, blksize & 0xFF);
731 }
732 else if (host->bus_width == MMC_BUS_WIDTH_4)
733 {
734 blksize = (1 << data->blksz_bits) + 2 * 4;
725 735
726 wbsd_write_index(host, WBSD_IDX_PBSMSB, (blksize >> 4) & 0xF0); 736 wbsd_write_index(host, WBSD_IDX_PBSMSB, ((blksize >> 4) & 0xF0)
727 wbsd_write_index(host, WBSD_IDX_PBSLSB, blksize & 0xFF); 737 | WBSD_DATA_WIDTH);
738 wbsd_write_index(host, WBSD_IDX_PBSLSB, blksize & 0xFF);
739 }
740 else
741 {
742 data->error = MMC_ERR_INVALID;
743 return;
744 }
728 745
729 /* 746 /*
730 * Clear the FIFO. This is needed even for DMA 747 * Clear the FIFO. This is needed even for DMA
@@ -960,8 +977,9 @@ static void wbsd_set_ios(struct mmc_host* mmc, struct mmc_ios* ios)
960 struct wbsd_host* host = mmc_priv(mmc); 977 struct wbsd_host* host = mmc_priv(mmc);
961 u8 clk, setup, pwr; 978 u8 clk, setup, pwr;
962 979
963 DBGF("clock %uHz busmode %u powermode %u Vdd %u\n", 980 DBGF("clock %uHz busmode %u powermode %u cs %u Vdd %u width %u\n",
964 ios->clock, ios->bus_mode, ios->power_mode, ios->vdd); 981 ios->clock, ios->bus_mode, ios->power_mode, ios->chip_select,
982 ios->vdd, ios->bus_width);
965 983
966 spin_lock_bh(&host->lock); 984 spin_lock_bh(&host->lock);
967 985
@@ -1003,30 +1021,63 @@ static void wbsd_set_ios(struct mmc_host* mmc, struct mmc_ios* ios)
1003 1021
1004 /* 1022 /*
1005 * MMC cards need to have pin 1 high during init. 1023 * MMC cards need to have pin 1 high during init.
1006 * Init time corresponds rather nicely with the bus mode.
1007 * It wreaks havoc with the card detection though so 1024 * It wreaks havoc with the card detection though so
1008 * that needs to be disabed. 1025 * that needs to be disabled.
1009 */ 1026 */
1010 setup = wbsd_read_index(host, WBSD_IDX_SETUP); 1027 setup = wbsd_read_index(host, WBSD_IDX_SETUP);
1011 if ((ios->power_mode == MMC_POWER_ON) && 1028 if (ios->chip_select == MMC_CS_HIGH)
1012 (ios->bus_mode == MMC_BUSMODE_OPENDRAIN))
1013 { 1029 {
1030 BUG_ON(ios->bus_width != MMC_BUS_WIDTH_1);
1014 setup |= WBSD_DAT3_H; 1031 setup |= WBSD_DAT3_H;
1015 host->flags |= WBSD_FIGNORE_DETECT; 1032 host->flags |= WBSD_FIGNORE_DETECT;
1016 } 1033 }
1017 else 1034 else
1018 { 1035 {
1019 setup &= ~WBSD_DAT3_H; 1036 setup &= ~WBSD_DAT3_H;
1020 host->flags &= ~WBSD_FIGNORE_DETECT; 1037
1038 /*
1039 * We cannot resume card detection immediatly
1040 * because of capacitance and delays in the chip.
1041 */
1042 mod_timer(&host->ignore_timer, jiffies + HZ/100);
1021 } 1043 }
1022 wbsd_write_index(host, WBSD_IDX_SETUP, setup); 1044 wbsd_write_index(host, WBSD_IDX_SETUP, setup);
1023 1045
1046 /*
1047 * Store bus width for later. Will be used when
1048 * setting up the data transfer.
1049 */
1050 host->bus_width = ios->bus_width;
1051
1052 spin_unlock_bh(&host->lock);
1053}
1054
1055static int wbsd_get_ro(struct mmc_host* mmc)
1056{
1057 struct wbsd_host* host = mmc_priv(mmc);
1058 u8 csr;
1059
1060 spin_lock_bh(&host->lock);
1061
1062 csr = inb(host->base + WBSD_CSR);
1063 csr |= WBSD_MSLED;
1064 outb(csr, host->base + WBSD_CSR);
1065
1066 mdelay(1);
1067
1068 csr = inb(host->base + WBSD_CSR);
1069 csr &= ~WBSD_MSLED;
1070 outb(csr, host->base + WBSD_CSR);
1071
1024 spin_unlock_bh(&host->lock); 1072 spin_unlock_bh(&host->lock);
1073
1074 return csr & WBSD_WRPT;
1025} 1075}
1026 1076
1027static struct mmc_host_ops wbsd_ops = { 1077static struct mmc_host_ops wbsd_ops = {
1028 .request = wbsd_request, 1078 .request = wbsd_request,
1029 .set_ios = wbsd_set_ios, 1079 .set_ios = wbsd_set_ios,
1080 .get_ro = wbsd_get_ro,
1030}; 1081};
1031 1082
1032/*****************************************************************************\ 1083/*****************************************************************************\
@@ -1036,6 +1087,31 @@ static struct mmc_host_ops wbsd_ops = {
1036\*****************************************************************************/ 1087\*****************************************************************************/
1037 1088
1038/* 1089/*
1090 * Helper function to reset detection ignore
1091 */
1092
1093static void wbsd_reset_ignore(unsigned long data)
1094{
1095 struct wbsd_host *host = (struct wbsd_host*)data;
1096
1097 BUG_ON(host == NULL);
1098
1099 DBG("Resetting card detection ignore\n");
1100
1101 spin_lock_bh(&host->lock);
1102
1103 host->flags &= ~WBSD_FIGNORE_DETECT;
1104
1105 /*
1106 * Card status might have changed during the
1107 * blackout.
1108 */
1109 tasklet_schedule(&host->card_tasklet);
1110
1111 spin_unlock_bh(&host->lock);
1112}
1113
1114/*
1039 * Helper function for card detection 1115 * Helper function for card detection
1040 */ 1116 */
1041static void wbsd_detect_card(unsigned long data) 1117static void wbsd_detect_card(unsigned long data)
@@ -1097,7 +1173,7 @@ static void wbsd_tasklet_card(unsigned long param)
1097 * Delay card detection to allow electrical connections 1173 * Delay card detection to allow electrical connections
1098 * to stabilise. 1174 * to stabilise.
1099 */ 1175 */
1100 mod_timer(&host->timer, jiffies + HZ/2); 1176 mod_timer(&host->detect_timer, jiffies + HZ/2);
1101 } 1177 }
1102 1178
1103 spin_unlock(&host->lock); 1179 spin_unlock(&host->lock);
@@ -1124,6 +1200,8 @@ static void wbsd_tasklet_card(unsigned long param)
1124 1200
1125 mmc_detect_change(host->mmc); 1201 mmc_detect_change(host->mmc);
1126 } 1202 }
1203 else
1204 spin_unlock(&host->lock);
1127} 1205}
1128 1206
1129static void wbsd_tasklet_fifo(unsigned long param) 1207static void wbsd_tasklet_fifo(unsigned long param)
@@ -1324,15 +1402,20 @@ static int __devinit wbsd_alloc_mmc(struct device* dev)
1324 mmc->f_min = 375000; 1402 mmc->f_min = 375000;
1325 mmc->f_max = 24000000; 1403 mmc->f_max = 24000000;
1326 mmc->ocr_avail = MMC_VDD_32_33|MMC_VDD_33_34; 1404 mmc->ocr_avail = MMC_VDD_32_33|MMC_VDD_33_34;
1405 mmc->caps = MMC_CAP_4_BIT_DATA;
1327 1406
1328 spin_lock_init(&host->lock); 1407 spin_lock_init(&host->lock);
1329 1408
1330 /* 1409 /*
1331 * Set up detection timer 1410 * Set up timers
1332 */ 1411 */
1333 init_timer(&host->timer); 1412 init_timer(&host->detect_timer);
1334 host->timer.data = (unsigned long)host; 1413 host->detect_timer.data = (unsigned long)host;
1335 host->timer.function = wbsd_detect_card; 1414 host->detect_timer.function = wbsd_detect_card;
1415
1416 init_timer(&host->ignore_timer);
1417 host->ignore_timer.data = (unsigned long)host;
1418 host->ignore_timer.function = wbsd_reset_ignore;
1336 1419
1337 /* 1420 /*
1338 * Maximum number of segments. Worst case is one sector per segment 1421 * Maximum number of segments. Worst case is one sector per segment
@@ -1370,7 +1453,8 @@ static void __devexit wbsd_free_mmc(struct device* dev)
1370 host = mmc_priv(mmc); 1453 host = mmc_priv(mmc);
1371 BUG_ON(host == NULL); 1454 BUG_ON(host == NULL);
1372 1455
1373 del_timer_sync(&host->timer); 1456 del_timer_sync(&host->ignore_timer);
1457 del_timer_sync(&host->detect_timer);
1374 1458
1375 mmc_free_host(mmc); 1459 mmc_free_host(mmc);
1376 1460
diff --git a/drivers/mmc/wbsd.h b/drivers/mmc/wbsd.h
index 661a9f6a6e6..9005b5241b3 100644
--- a/drivers/mmc/wbsd.h
+++ b/drivers/mmc/wbsd.h
@@ -106,6 +106,8 @@
106#define WBSD_CLK_16M 0x02 106#define WBSD_CLK_16M 0x02
107#define WBSD_CLK_24M 0x03 107#define WBSD_CLK_24M 0x03
108 108
109#define WBSD_DATA_WIDTH 0x01
110
109#define WBSD_DAT3_H 0x08 111#define WBSD_DAT3_H 0x08
110#define WBSD_FIFO_RESET 0x04 112#define WBSD_FIFO_RESET 0x04
111#define WBSD_SOFT_RESET 0x02 113#define WBSD_SOFT_RESET 0x02
@@ -164,6 +166,7 @@ struct wbsd_host
164 int firsterr; /* See fifo functions */ 166 int firsterr; /* See fifo functions */
165 167
166 u8 clk; /* Current clock speed */ 168 u8 clk; /* Current clock speed */
169 unsigned char bus_width; /* Current bus width */
167 170
168 int config; /* Config port */ 171 int config; /* Config port */
169 u8 unlock_code; /* Code to unlock config */ 172 u8 unlock_code; /* Code to unlock config */
@@ -181,5 +184,6 @@ struct wbsd_host
181 struct tasklet_struct finish_tasklet; 184 struct tasklet_struct finish_tasklet;
182 struct tasklet_struct block_tasklet; 185 struct tasklet_struct block_tasklet;
183 186
184 struct timer_list timer; /* Card detection timer */ 187 struct timer_list detect_timer; /* Card detection timer */
188 struct timer_list ignore_timer; /* Ignore detection timer */
185}; 189};
diff --git a/drivers/mtd/nand/nand_base.c b/drivers/mtd/nand/nand_base.c
index eee5115658c..04e54318bc6 100644
--- a/drivers/mtd/nand/nand_base.c
+++ b/drivers/mtd/nand/nand_base.c
@@ -526,6 +526,7 @@ static void nand_wait_ready(struct mtd_info *mtd)
526 do { 526 do {
527 if (this->dev_ready(mtd)) 527 if (this->dev_ready(mtd))
528 return; 528 return;
529 touch_softlockup_watchdog();
529 } while (time_before(jiffies, timeo)); 530 } while (time_before(jiffies, timeo));
530} 531}
531 532
diff --git a/drivers/net/3c59x.c b/drivers/net/3c59x.c
index 07746b95fd8..455ba915ede 100644
--- a/drivers/net/3c59x.c
+++ b/drivers/net/3c59x.c
@@ -973,6 +973,11 @@ static int vortex_suspend (struct pci_dev *pdev, pm_message_t state)
973 netif_device_detach(dev); 973 netif_device_detach(dev);
974 vortex_down(dev, 1); 974 vortex_down(dev, 1);
975 } 975 }
976 pci_save_state(pdev);
977 pci_enable_wake(pdev, pci_choose_state(pdev, state), 0);
978 free_irq(dev->irq, dev);
979 pci_disable_device(pdev);
980 pci_set_power_state(pdev, pci_choose_state(pdev, state));
976 } 981 }
977 return 0; 982 return 0;
978} 983}
@@ -980,8 +985,19 @@ static int vortex_suspend (struct pci_dev *pdev, pm_message_t state)
980static int vortex_resume (struct pci_dev *pdev) 985static int vortex_resume (struct pci_dev *pdev)
981{ 986{
982 struct net_device *dev = pci_get_drvdata(pdev); 987 struct net_device *dev = pci_get_drvdata(pdev);
988 struct vortex_private *vp = netdev_priv(dev);
983 989
984 if (dev && dev->priv) { 990 if (dev && vp) {
991 pci_set_power_state(pdev, PCI_D0);
992 pci_restore_state(pdev);
993 pci_enable_device(pdev);
994 pci_set_master(pdev);
995 if (request_irq(dev->irq, vp->full_bus_master_rx ?
996 &boomerang_interrupt : &vortex_interrupt, SA_SHIRQ, dev->name, dev)) {
997 printk(KERN_WARNING "%s: Could not reserve IRQ %d\n", dev->name, dev->irq);
998 pci_disable_device(pdev);
999 return -EBUSY;
1000 }
985 if (netif_running(dev)) { 1001 if (netif_running(dev)) {
986 vortex_up(dev); 1002 vortex_up(dev);
987 netif_device_attach(dev); 1003 netif_device_attach(dev);
@@ -1873,6 +1889,7 @@ vortex_timer(unsigned long data)
1873 { 1889 {
1874 spin_lock_bh(&vp->lock); 1890 spin_lock_bh(&vp->lock);
1875 mii_status = mdio_read(dev, vp->phys[0], 1); 1891 mii_status = mdio_read(dev, vp->phys[0], 1);
1892 mii_status = mdio_read(dev, vp->phys[0], 1);
1876 ok = 1; 1893 ok = 1;
1877 if (vortex_debug > 2) 1894 if (vortex_debug > 2)
1878 printk(KERN_DEBUG "%s: MII transceiver has status %4.4x.\n", 1895 printk(KERN_DEBUG "%s: MII transceiver has status %4.4x.\n",
diff --git a/drivers/net/Kconfig b/drivers/net/Kconfig
index 7d8bcb38797..6bb9232514b 100644
--- a/drivers/net/Kconfig
+++ b/drivers/net/Kconfig
@@ -397,7 +397,7 @@ config SUN3LANCE
397 If you're not building a kernel for a Sun 3, say N. 397 If you're not building a kernel for a Sun 3, say N.
398 398
399config SUN3_82586 399config SUN3_82586
400 tristate "Sun3 on-board Intel 82586 support" 400 bool "Sun3 on-board Intel 82586 support"
401 depends on NET_ETHERNET && SUN3 401 depends on NET_ETHERNET && SUN3
402 help 402 help
403 This driver enables support for the on-board Intel 82586 based 403 This driver enables support for the on-board Intel 82586 based
@@ -1924,12 +1924,15 @@ config R8169_VLAN
1924 If in doubt, say Y. 1924 If in doubt, say Y.
1925 1925
1926config SIS190 1926config SIS190
1927 tristate "SiS190 gigabit ethernet support" 1927 tristate "SiS190/SiS191 gigabit ethernet support"
1928 depends on PCI 1928 depends on PCI
1929 select CRC32 1929 select CRC32
1930 select MII 1930 select MII
1931 ---help--- 1931 ---help---
1932 Say Y here if you have a SiS 190 PCI Gigabit Ethernet adapter. 1932 Say Y here if you have a SiS 190 PCI Fast Ethernet adapter or
1933 a SiS 191 PCI Gigabit Ethernet adapter. Both are expected to
1934 appear in lan on motherboard designs which are based on SiS 965
1935 and SiS 966 south bridge.
1933 1936
1934 To compile this driver as a module, choose M here: the module 1937 To compile this driver as a module, choose M here: the module
1935 will be called sis190. This is recommended. 1938 will be called sis190. This is recommended.
@@ -2055,6 +2058,13 @@ config BNX2
2055 To compile this driver as a module, choose M here: the module 2058 To compile this driver as a module, choose M here: the module
2056 will be called bnx2. This is recommended. 2059 will be called bnx2. This is recommended.
2057 2060
2061config SPIDER_NET
2062 tristate "Spider Gigabit Ethernet driver"
2063 depends on PCI && PPC_BPA
2064 help
2065 This driver supports the Gigabit Ethernet chips present on the
2066 Cell Processor-Based Blades from IBM.
2067
2058config GIANFAR 2068config GIANFAR
2059 tristate "Gianfar Ethernet" 2069 tristate "Gianfar Ethernet"
2060 depends on 85xx || 83xx 2070 depends on 85xx || 83xx
diff --git a/drivers/net/Makefile b/drivers/net/Makefile
index 5baafcd5561..8645c843cf4 100644
--- a/drivers/net/Makefile
+++ b/drivers/net/Makefile
@@ -54,6 +54,8 @@ obj-$(CONFIG_STNIC) += stnic.o 8390.o
54obj-$(CONFIG_FEALNX) += fealnx.o 54obj-$(CONFIG_FEALNX) += fealnx.o
55obj-$(CONFIG_TIGON3) += tg3.o 55obj-$(CONFIG_TIGON3) += tg3.o
56obj-$(CONFIG_BNX2) += bnx2.o 56obj-$(CONFIG_BNX2) += bnx2.o
57spidernet-y += spider_net.o spider_net_ethtool.o sungem_phy.o
58obj-$(CONFIG_SPIDER_NET) += spidernet.o
57obj-$(CONFIG_TC35815) += tc35815.o 59obj-$(CONFIG_TC35815) += tc35815.o
58obj-$(CONFIG_SKGE) += skge.o 60obj-$(CONFIG_SKGE) += skge.o
59obj-$(CONFIG_SK98LIN) += sk98lin/ 61obj-$(CONFIG_SK98LIN) += sk98lin/
diff --git a/drivers/net/ac3200.c b/drivers/net/ac3200.c
index 91791ba3776..8a0af5453e2 100644
--- a/drivers/net/ac3200.c
+++ b/drivers/net/ac3200.c
@@ -275,7 +275,7 @@ static int __init ac_probe1(int ioaddr, struct net_device *dev)
275 return 0; 275 return 0;
276out2: 276out2:
277 if (ei_status.reg0) 277 if (ei_status.reg0)
278 iounmap((void *)dev->mem_start); 278 iounmap(ei_status.mem);
279out1: 279out1:
280 free_irq(dev->irq, dev); 280 free_irq(dev->irq, dev);
281out: 281out:
diff --git a/drivers/net/arcnet/arcnet.c b/drivers/net/arcnet/arcnet.c
index 4f9f69e22c1..12ef52c193a 100644
--- a/drivers/net/arcnet/arcnet.c
+++ b/drivers/net/arcnet/arcnet.c
@@ -597,7 +597,7 @@ static int arcnet_send_packet(struct sk_buff *skb, struct net_device *dev)
597 struct ArcProto *proto; 597 struct ArcProto *proto;
598 int txbuf; 598 int txbuf;
599 unsigned long flags; 599 unsigned long flags;
600 int freeskb = 0; 600 int freeskb, retval;
601 601
602 BUGMSG(D_DURING, 602 BUGMSG(D_DURING,
603 "transmit requested (status=%Xh, txbufs=%d/%d, len=%d, protocol %x)\n", 603 "transmit requested (status=%Xh, txbufs=%d/%d, len=%d, protocol %x)\n",
@@ -615,7 +615,7 @@ static int arcnet_send_packet(struct sk_buff *skb, struct net_device *dev)
615 if (skb->len - ARC_HDR_SIZE > XMTU && !proto->continue_tx) { 615 if (skb->len - ARC_HDR_SIZE > XMTU && !proto->continue_tx) {
616 BUGMSG(D_NORMAL, "fixme: packet too large: compensating badly!\n"); 616 BUGMSG(D_NORMAL, "fixme: packet too large: compensating badly!\n");
617 dev_kfree_skb(skb); 617 dev_kfree_skb(skb);
618 return 0; /* don't try again */ 618 return NETDEV_TX_OK; /* don't try again */
619 } 619 }
620 620
621 /* We're busy transmitting a packet... */ 621 /* We're busy transmitting a packet... */
@@ -623,8 +623,11 @@ static int arcnet_send_packet(struct sk_buff *skb, struct net_device *dev)
623 623
624 spin_lock_irqsave(&lp->lock, flags); 624 spin_lock_irqsave(&lp->lock, flags);
625 AINTMASK(0); 625 AINTMASK(0);
626 626 if(lp->next_tx == -1)
627 txbuf = get_arcbuf(dev); 627 txbuf = get_arcbuf(dev);
628 else {
629 txbuf = -1;
630 }
628 if (txbuf != -1) { 631 if (txbuf != -1) {
629 if (proto->prepare_tx(dev, pkt, skb->len, txbuf) && 632 if (proto->prepare_tx(dev, pkt, skb->len, txbuf) &&
630 !proto->ack_tx) { 633 !proto->ack_tx) {
@@ -638,6 +641,8 @@ static int arcnet_send_packet(struct sk_buff *skb, struct net_device *dev)
638 lp->outgoing.skb = skb; 641 lp->outgoing.skb = skb;
639 lp->outgoing.pkt = pkt; 642 lp->outgoing.pkt = pkt;
640 643
644 freeskb = 0;
645
641 if (proto->continue_tx && 646 if (proto->continue_tx &&
642 proto->continue_tx(dev, txbuf)) { 647 proto->continue_tx(dev, txbuf)) {
643 BUGMSG(D_NORMAL, 648 BUGMSG(D_NORMAL,
@@ -645,10 +650,12 @@ static int arcnet_send_packet(struct sk_buff *skb, struct net_device *dev)
645 "(proto='%c')\n", proto->suffix); 650 "(proto='%c')\n", proto->suffix);
646 } 651 }
647 } 652 }
648 653 retval = NETDEV_TX_OK;
654 dev->trans_start = jiffies;
649 lp->next_tx = txbuf; 655 lp->next_tx = txbuf;
650 } else { 656 } else {
651 freeskb = 1; 657 retval = NETDEV_TX_BUSY;
658 freeskb = 0;
652 } 659 }
653 660
654 BUGMSG(D_DEBUG, "%s: %d: %s, status: %x\n",__FILE__,__LINE__,__FUNCTION__,ASTATUS()); 661 BUGMSG(D_DEBUG, "%s: %d: %s, status: %x\n",__FILE__,__LINE__,__FUNCTION__,ASTATUS());
@@ -664,7 +671,7 @@ static int arcnet_send_packet(struct sk_buff *skb, struct net_device *dev)
664 if (freeskb) { 671 if (freeskb) {
665 dev_kfree_skb(skb); 672 dev_kfree_skb(skb);
666 } 673 }
667 return 0; /* no need to try again */ 674 return retval; /* no need to try again */
668} 675}
669 676
670 677
@@ -690,7 +697,6 @@ static int go_tx(struct net_device *dev)
690 /* start sending */ 697 /* start sending */
691 ACOMMAND(TXcmd | (lp->cur_tx << 3)); 698 ACOMMAND(TXcmd | (lp->cur_tx << 3));
692 699
693 dev->trans_start = jiffies;
694 lp->stats.tx_packets++; 700 lp->stats.tx_packets++;
695 lp->lasttrans_dest = lp->lastload_dest; 701 lp->lasttrans_dest = lp->lastload_dest;
696 lp->lastload_dest = 0; 702 lp->lastload_dest = 0;
@@ -917,6 +923,9 @@ irqreturn_t arcnet_interrupt(int irq, void *dev_id, struct pt_regs *regs)
917 923
918 BUGMSG(D_RECON, "Network reconfiguration detected (status=%Xh)\n", 924 BUGMSG(D_RECON, "Network reconfiguration detected (status=%Xh)\n",
919 status); 925 status);
926 /* MYRECON bit is at bit 7 of diagstatus */
927 if(diagstatus & 0x80)
928 BUGMSG(D_RECON,"Put out that recon myself\n");
920 929
921 /* is the RECON info empty or old? */ 930 /* is the RECON info empty or old? */
922 if (!lp->first_recon || !lp->last_recon || 931 if (!lp->first_recon || !lp->last_recon ||
diff --git a/drivers/net/atarilance.c b/drivers/net/atarilance.c
index ad011214c7f..e01b6a78ec6 100644
--- a/drivers/net/atarilance.c
+++ b/drivers/net/atarilance.c
@@ -235,7 +235,7 @@ struct lance_private {
235#define MEM lp->mem 235#define MEM lp->mem
236#define DREG IO->data 236#define DREG IO->data
237#define AREG IO->addr 237#define AREG IO->addr
238#define REGA(a) ( AREG = (a), DREG ) 238#define REGA(a) (*( AREG = (a), &DREG ))
239 239
240/* Definitions for packet buffer access: */ 240/* Definitions for packet buffer access: */
241#define PKT_BUF_SZ 1544 241#define PKT_BUF_SZ 1544
diff --git a/drivers/net/bnx2.c b/drivers/net/bnx2.c
index 7babf6af4e2..55a72c7ad00 100644
--- a/drivers/net/bnx2.c
+++ b/drivers/net/bnx2.c
@@ -2004,14 +2004,14 @@ bnx2_init_cpus(struct bnx2 *bp)
2004} 2004}
2005 2005
2006static int 2006static int
2007bnx2_set_power_state(struct bnx2 *bp, int state) 2007bnx2_set_power_state(struct bnx2 *bp, pci_power_t state)
2008{ 2008{
2009 u16 pmcsr; 2009 u16 pmcsr;
2010 2010
2011 pci_read_config_word(bp->pdev, bp->pm_cap + PCI_PM_CTRL, &pmcsr); 2011 pci_read_config_word(bp->pdev, bp->pm_cap + PCI_PM_CTRL, &pmcsr);
2012 2012
2013 switch (state) { 2013 switch (state) {
2014 case 0: { 2014 case PCI_D0: {
2015 u32 val; 2015 u32 val;
2016 2016
2017 pci_write_config_word(bp->pdev, bp->pm_cap + PCI_PM_CTRL, 2017 pci_write_config_word(bp->pdev, bp->pm_cap + PCI_PM_CTRL,
@@ -2032,7 +2032,7 @@ bnx2_set_power_state(struct bnx2 *bp, int state)
2032 REG_WR(bp, BNX2_RPM_CONFIG, val); 2032 REG_WR(bp, BNX2_RPM_CONFIG, val);
2033 break; 2033 break;
2034 } 2034 }
2035 case 3: { 2035 case PCI_D3hot: {
2036 int i; 2036 int i;
2037 u32 val, wol_msg; 2037 u32 val, wol_msg;
2038 2038
@@ -3886,7 +3886,7 @@ bnx2_open(struct net_device *dev)
3886 struct bnx2 *bp = dev->priv; 3886 struct bnx2 *bp = dev->priv;
3887 int rc; 3887 int rc;
3888 3888
3889 bnx2_set_power_state(bp, 0); 3889 bnx2_set_power_state(bp, PCI_D0);
3890 bnx2_disable_int(bp); 3890 bnx2_disable_int(bp);
3891 3891
3892 rc = bnx2_alloc_mem(bp); 3892 rc = bnx2_alloc_mem(bp);
@@ -4197,7 +4197,7 @@ bnx2_close(struct net_device *dev)
4197 bnx2_free_mem(bp); 4197 bnx2_free_mem(bp);
4198 bp->link_up = 0; 4198 bp->link_up = 0;
4199 netif_carrier_off(bp->dev); 4199 netif_carrier_off(bp->dev);
4200 bnx2_set_power_state(bp, 3); 4200 bnx2_set_power_state(bp, PCI_D3hot);
4201 return 0; 4201 return 0;
4202} 4202}
4203 4203
@@ -5203,7 +5203,7 @@ bnx2_init_board(struct pci_dev *pdev, struct net_device *dev)
5203 BNX2_PCICFG_MISC_CONFIG_REG_WINDOW_ENA | 5203 BNX2_PCICFG_MISC_CONFIG_REG_WINDOW_ENA |
5204 BNX2_PCICFG_MISC_CONFIG_TARGET_MB_WORD_SWAP); 5204 BNX2_PCICFG_MISC_CONFIG_TARGET_MB_WORD_SWAP);
5205 5205
5206 bnx2_set_power_state(bp, 0); 5206 bnx2_set_power_state(bp, PCI_D0);
5207 5207
5208 bp->chip_id = REG_RD(bp, BNX2_MISC_ID); 5208 bp->chip_id = REG_RD(bp, BNX2_MISC_ID);
5209 5209
@@ -5495,7 +5495,7 @@ bnx2_remove_one(struct pci_dev *pdev)
5495} 5495}
5496 5496
5497static int 5497static int
5498bnx2_suspend(struct pci_dev *pdev, u32 state) 5498bnx2_suspend(struct pci_dev *pdev, pm_message_t state)
5499{ 5499{
5500 struct net_device *dev = pci_get_drvdata(pdev); 5500 struct net_device *dev = pci_get_drvdata(pdev);
5501 struct bnx2 *bp = dev->priv; 5501 struct bnx2 *bp = dev->priv;
@@ -5513,7 +5513,7 @@ bnx2_suspend(struct pci_dev *pdev, u32 state)
5513 reset_code = BNX2_DRV_MSG_CODE_SUSPEND_NO_WOL; 5513 reset_code = BNX2_DRV_MSG_CODE_SUSPEND_NO_WOL;
5514 bnx2_reset_chip(bp, reset_code); 5514 bnx2_reset_chip(bp, reset_code);
5515 bnx2_free_skbs(bp); 5515 bnx2_free_skbs(bp);
5516 bnx2_set_power_state(bp, state); 5516 bnx2_set_power_state(bp, pci_choose_state(pdev, state));
5517 return 0; 5517 return 0;
5518} 5518}
5519 5519
@@ -5526,7 +5526,7 @@ bnx2_resume(struct pci_dev *pdev)
5526 if (!netif_running(dev)) 5526 if (!netif_running(dev))
5527 return 0; 5527 return 0;
5528 5528
5529 bnx2_set_power_state(bp, 0); 5529 bnx2_set_power_state(bp, PCI_D0);
5530 netif_device_attach(dev); 5530 netif_device_attach(dev);
5531 bnx2_init_nic(bp); 5531 bnx2_init_nic(bp);
5532 bnx2_netif_start(bp); 5532 bnx2_netif_start(bp);
diff --git a/drivers/net/chelsio/common.h b/drivers/net/chelsio/common.h
index f09348802b4..bf3e7b6a7a1 100644
--- a/drivers/net/chelsio/common.h
+++ b/drivers/net/chelsio/common.h
@@ -88,7 +88,7 @@ struct t1_rx_mode {
88 88
89static inline u8 *t1_get_next_mcaddr(struct t1_rx_mode *rm) 89static inline u8 *t1_get_next_mcaddr(struct t1_rx_mode *rm)
90{ 90{
91 u8 *addr = 0; 91 u8 *addr = NULL;
92 92
93 if (rm->idx++ < rm->dev->mc_count) { 93 if (rm->idx++ < rm->dev->mc_count) {
94 addr = rm->list->dmi_addr; 94 addr = rm->list->dmi_addr;
@@ -190,7 +190,7 @@ struct sge;
190struct peespi; 190struct peespi;
191 191
192struct adapter { 192struct adapter {
193 u8 *regs; 193 u8 __iomem *regs;
194 struct pci_dev *pdev; 194 struct pci_dev *pdev;
195 unsigned long registered_device_map; 195 unsigned long registered_device_map;
196 unsigned long open_device_map; 196 unsigned long open_device_map;
diff --git a/drivers/net/chelsio/cxgb2.c b/drivers/net/chelsio/cxgb2.c
index 28ae478b386..349ebe783ed 100644
--- a/drivers/net/chelsio/cxgb2.c
+++ b/drivers/net/chelsio/cxgb2.c
@@ -824,7 +824,7 @@ static void cxgb_proc_cleanup(struct adapter *adapter,
824static int t1_ioctl(struct net_device *dev, struct ifreq *req, int cmd) 824static int t1_ioctl(struct net_device *dev, struct ifreq *req, int cmd)
825{ 825{
826 struct adapter *adapter = dev->priv; 826 struct adapter *adapter = dev->priv;
827 struct mii_ioctl_data *data = (struct mii_ioctl_data *)&req->ifr_data; 827 struct mii_ioctl_data *data = if_mii(req);
828 828
829 switch (cmd) { 829 switch (cmd) {
830 case SIOCGMIIPHY: 830 case SIOCGMIIPHY:
diff --git a/drivers/net/dm9000.c b/drivers/net/dm9000.c
index 6440a892bb8..e54fc10f684 100644
--- a/drivers/net/dm9000.c
+++ b/drivers/net/dm9000.c
@@ -1140,7 +1140,7 @@ dm9000_phy_write(struct net_device *dev, int phyaddr_unused, int reg, int value)
1140} 1140}
1141 1141
1142static int 1142static int
1143dm9000_drv_suspend(struct device *dev, u32 state, u32 level) 1143dm9000_drv_suspend(struct device *dev, pm_message_t state, u32 level)
1144{ 1144{
1145 struct net_device *ndev = dev_get_drvdata(dev); 1145 struct net_device *ndev = dev_get_drvdata(dev);
1146 1146
diff --git a/drivers/net/e1000/e1000_hw.h b/drivers/net/e1000/e1000_hw.h
index 93e9f878875..51c2b3a18b6 100644
--- a/drivers/net/e1000/e1000_hw.h
+++ b/drivers/net/e1000/e1000_hw.h
@@ -1270,7 +1270,7 @@ struct e1000_hw_stats {
1270 1270
1271/* Structure containing variables used by the shared code (e1000_hw.c) */ 1271/* Structure containing variables used by the shared code (e1000_hw.c) */
1272struct e1000_hw { 1272struct e1000_hw {
1273 uint8_t *hw_addr; 1273 uint8_t __iomem *hw_addr;
1274 uint8_t *flash_address; 1274 uint8_t *flash_address;
1275 e1000_mac_type mac_type; 1275 e1000_mac_type mac_type;
1276 e1000_phy_type phy_type; 1276 e1000_phy_type phy_type;
diff --git a/drivers/net/e1000/e1000_main.c b/drivers/net/e1000/e1000_main.c
index 9b596e0bbf9..7c8a0a22dcd 100644
--- a/drivers/net/e1000/e1000_main.c
+++ b/drivers/net/e1000/e1000_main.c
@@ -162,7 +162,7 @@ static void e1000_vlan_rx_add_vid(struct net_device *netdev, uint16_t vid);
162static void e1000_vlan_rx_kill_vid(struct net_device *netdev, uint16_t vid); 162static void e1000_vlan_rx_kill_vid(struct net_device *netdev, uint16_t vid);
163static void e1000_restore_vlan(struct e1000_adapter *adapter); 163static void e1000_restore_vlan(struct e1000_adapter *adapter);
164 164
165static int e1000_suspend(struct pci_dev *pdev, uint32_t state); 165static int e1000_suspend(struct pci_dev *pdev, pm_message_t state);
166#ifdef CONFIG_PM 166#ifdef CONFIG_PM
167static int e1000_resume(struct pci_dev *pdev); 167static int e1000_resume(struct pci_dev *pdev);
168#endif 168#endif
@@ -3642,7 +3642,7 @@ e1000_set_spd_dplx(struct e1000_adapter *adapter, uint16_t spddplx)
3642} 3642}
3643 3643
3644static int 3644static int
3645e1000_suspend(struct pci_dev *pdev, uint32_t state) 3645e1000_suspend(struct pci_dev *pdev, pm_message_t state)
3646{ 3646{
3647 struct net_device *netdev = pci_get_drvdata(pdev); 3647 struct net_device *netdev = pci_get_drvdata(pdev);
3648 struct e1000_adapter *adapter = netdev_priv(netdev); 3648 struct e1000_adapter *adapter = netdev_priv(netdev);
@@ -3726,9 +3726,7 @@ e1000_suspend(struct pci_dev *pdev, uint32_t state)
3726 } 3726 }
3727 3727
3728 pci_disable_device(pdev); 3728 pci_disable_device(pdev);
3729 3729 pci_set_power_state(pdev, pci_choose_state(pdev, state));
3730 state = (state > 0) ? 3 : 0;
3731 pci_set_power_state(pdev, state);
3732 3730
3733 return 0; 3731 return 0;
3734} 3732}
@@ -3741,13 +3739,13 @@ e1000_resume(struct pci_dev *pdev)
3741 struct e1000_adapter *adapter = netdev_priv(netdev); 3739 struct e1000_adapter *adapter = netdev_priv(netdev);
3742 uint32_t manc, ret_val, swsm; 3740 uint32_t manc, ret_val, swsm;
3743 3741
3744 pci_set_power_state(pdev, 0); 3742 pci_set_power_state(pdev, PCI_D0);
3745 pci_restore_state(pdev); 3743 pci_restore_state(pdev);
3746 ret_val = pci_enable_device(pdev); 3744 ret_val = pci_enable_device(pdev);
3747 pci_set_master(pdev); 3745 pci_set_master(pdev);
3748 3746
3749 pci_enable_wake(pdev, 3, 0); 3747 pci_enable_wake(pdev, PCI_D3hot, 0);
3750 pci_enable_wake(pdev, 4, 0); /* 4 == D3 cold */ 3748 pci_enable_wake(pdev, PCI_D3cold, 0);
3751 3749
3752 e1000_reset(adapter); 3750 e1000_reset(adapter);
3753 E1000_WRITE_REG(&adapter->hw, WUS, ~0); 3751 E1000_WRITE_REG(&adapter->hw, WUS, ~0);
diff --git a/drivers/net/forcedeth.c b/drivers/net/forcedeth.c
index 7d93948aec8..d6eefdb71c1 100644
--- a/drivers/net/forcedeth.c
+++ b/drivers/net/forcedeth.c
@@ -1372,7 +1372,7 @@ static int nv_change_mtu(struct net_device *dev, int new_mtu)
1372 1372
1373 /* synchronized against open : rtnl_lock() held by caller */ 1373 /* synchronized against open : rtnl_lock() held by caller */
1374 if (netif_running(dev)) { 1374 if (netif_running(dev)) {
1375 u8 *base = get_hwbase(dev); 1375 u8 __iomem *base = get_hwbase(dev);
1376 /* 1376 /*
1377 * It seems that the nic preloads valid ring entries into an 1377 * It seems that the nic preloads valid ring entries into an
1378 * internal buffer. The procedure for flushing everything is 1378 * internal buffer. The procedure for flushing everything is
@@ -1423,7 +1423,7 @@ static int nv_change_mtu(struct net_device *dev, int new_mtu)
1423 1423
1424static void nv_copy_mac_to_hw(struct net_device *dev) 1424static void nv_copy_mac_to_hw(struct net_device *dev)
1425{ 1425{
1426 u8 *base = get_hwbase(dev); 1426 u8 __iomem *base = get_hwbase(dev);
1427 u32 mac[2]; 1427 u32 mac[2];
1428 1428
1429 mac[0] = (dev->dev_addr[0] << 0) + (dev->dev_addr[1] << 8) + 1429 mac[0] = (dev->dev_addr[0] << 0) + (dev->dev_addr[1] << 8) +
diff --git a/drivers/net/hamachi.c b/drivers/net/hamachi.c
index d9df1d9a573..bc9a3bf8d56 100644
--- a/drivers/net/hamachi.c
+++ b/drivers/net/hamachi.c
@@ -204,6 +204,10 @@ KERN_INFO " Further modifications by Keith Underwood <keithu@parl.clemson.edu>
204 204
205#define RUN_AT(x) (jiffies + (x)) 205#define RUN_AT(x) (jiffies + (x))
206 206
207#ifndef ADDRLEN
208#define ADDRLEN 32
209#endif
210
207/* Condensed bus+endian portability operations. */ 211/* Condensed bus+endian portability operations. */
208#if ADDRLEN == 64 212#if ADDRLEN == 64
209#define cpu_to_leXX(addr) cpu_to_le64(addr) 213#define cpu_to_leXX(addr) cpu_to_le64(addr)
diff --git a/drivers/net/irda/smsc-ircc2.c b/drivers/net/irda/smsc-ircc2.c
index 10125a1dba2..dd89bda1f13 100644
--- a/drivers/net/irda/smsc-ircc2.c
+++ b/drivers/net/irda/smsc-ircc2.c
@@ -4,10 +4,10 @@
4 * Description: Driver for the SMC Infrared Communications Controller 4 * Description: Driver for the SMC Infrared Communications Controller
5 * Status: Experimental. 5 * Status: Experimental.
6 * Author: Daniele Peri (peri@csai.unipa.it) 6 * Author: Daniele Peri (peri@csai.unipa.it)
7 * Created at: 7 * Created at:
8 * Modified at: 8 * Modified at:
9 * Modified by: 9 * Modified by:
10 * 10 *
11 * Copyright (c) 2002 Daniele Peri 11 * Copyright (c) 2002 Daniele Peri
12 * All Rights Reserved. 12 * All Rights Reserved.
13 * Copyright (c) 2002 Jean Tourrilhes 13 * Copyright (c) 2002 Jean Tourrilhes
@@ -17,26 +17,26 @@
17 * 17 *
18 * Copyright (c) 2001 Stefani Seibold 18 * Copyright (c) 2001 Stefani Seibold
19 * Copyright (c) 1999-2001 Dag Brattli 19 * Copyright (c) 1999-2001 Dag Brattli
20 * Copyright (c) 1998-1999 Thomas Davis, 20 * Copyright (c) 1998-1999 Thomas Davis,
21 * 21 *
22 * and irport.c: 22 * and irport.c:
23 * 23 *
24 * Copyright (c) 1997, 1998, 1999-2000 Dag Brattli, All Rights Reserved. 24 * Copyright (c) 1997, 1998, 1999-2000 Dag Brattli, All Rights Reserved.
25 * 25 *
26 * 26 *
27 * This program is free software; you can redistribute it and/or 27 * This program is free software; you can redistribute it and/or
28 * modify it under the terms of the GNU General Public License as 28 * modify it under the terms of the GNU General Public License as
29 * published by the Free Software Foundation; either version 2 of 29 * published by the Free Software Foundation; either version 2 of
30 * the License, or (at your option) any later version. 30 * the License, or (at your option) any later version.
31 * 31 *
32 * This program is distributed in the hope that it will be useful, 32 * This program is distributed in the hope that it will be useful,
33 * but WITHOUT ANY WARRANTY; without even the implied warranty of 33 * but WITHOUT ANY WARRANTY; without even the implied warranty of
34 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 34 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
35 * GNU General Public License for more details. 35 * GNU General Public License for more details.
36 * 36 *
37 * You should have received a copy of the GNU General Public License 37 * You should have received a copy of the GNU General Public License
38 * along with this program; if not, write to the Free Software 38 * along with this program; if not, write to the Free Software
39 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, 39 * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
40 * MA 02111-1307 USA 40 * MA 02111-1307 USA
41 * 41 *
42 ********************************************************************/ 42 ********************************************************************/
@@ -68,24 +68,42 @@
68#include "smsc-ircc2.h" 68#include "smsc-ircc2.h"
69#include "smsc-sio.h" 69#include "smsc-sio.h"
70 70
71
72MODULE_AUTHOR("Daniele Peri <peri@csai.unipa.it>");
73MODULE_DESCRIPTION("SMC IrCC SIR/FIR controller driver");
74MODULE_LICENSE("GPL");
75
76static int ircc_dma = 255;
77module_param(ircc_dma, int, 0);
78MODULE_PARM_DESC(ircc_dma, "DMA channel");
79
80static int ircc_irq = 255;
81module_param(ircc_irq, int, 0);
82MODULE_PARM_DESC(ircc_irq, "IRQ line");
83
84static int ircc_fir;
85module_param(ircc_fir, int, 0);
86MODULE_PARM_DESC(ircc_fir, "FIR Base Address");
87
88static int ircc_sir;
89module_param(ircc_sir, int, 0);
90MODULE_PARM_DESC(ircc_sir, "SIR Base Address");
91
92static int ircc_cfg;
93module_param(ircc_cfg, int, 0);
94MODULE_PARM_DESC(ircc_cfg, "Configuration register base address");
95
96static int ircc_transceiver;
97module_param(ircc_transceiver, int, 0);
98MODULE_PARM_DESC(ircc_transceiver, "Transceiver type");
99
71/* Types */ 100/* Types */
72 101
73struct smsc_transceiver { 102struct smsc_transceiver {
74 char *name; 103 char *name;
75 void (*set_for_speed)(int fir_base, u32 speed); 104 void (*set_for_speed)(int fir_base, u32 speed);
76 int (*probe)(int fir_base); 105 int (*probe)(int fir_base);
77}; 106};
78typedef struct smsc_transceiver smsc_transceiver_t;
79
80#if 0
81struct smc_chip {
82 char *name;
83 u16 flags;
84 u8 devid;
85 u8 rev;
86};
87typedef struct smc_chip smc_chip_t;
88#endif
89 107
90struct smsc_chip { 108struct smsc_chip {
91 char *name; 109 char *name;
@@ -96,20 +114,18 @@ struct smsc_chip {
96 u8 devid; 114 u8 devid;
97 u8 rev; 115 u8 rev;
98}; 116};
99typedef struct smsc_chip smsc_chip_t;
100 117
101struct smsc_chip_address { 118struct smsc_chip_address {
102 unsigned int cfg_base; 119 unsigned int cfg_base;
103 unsigned int type; 120 unsigned int type;
104}; 121};
105typedef struct smsc_chip_address smsc_chip_address_t;
106 122
107/* Private data for each instance */ 123/* Private data for each instance */
108struct smsc_ircc_cb { 124struct smsc_ircc_cb {
109 struct net_device *netdev; /* Yes! we are some kind of netdevice */ 125 struct net_device *netdev; /* Yes! we are some kind of netdevice */
110 struct net_device_stats stats; 126 struct net_device_stats stats;
111 struct irlap_cb *irlap; /* The link layer we are binded to */ 127 struct irlap_cb *irlap; /* The link layer we are binded to */
112 128
113 chipio_t io; /* IrDA controller information */ 129 chipio_t io; /* IrDA controller information */
114 iobuff_t tx_buff; /* Transmit buffer */ 130 iobuff_t tx_buff; /* Transmit buffer */
115 iobuff_t rx_buff; /* Receive buffer */ 131 iobuff_t rx_buff; /* Receive buffer */
@@ -119,7 +135,7 @@ struct smsc_ircc_cb {
119 struct qos_info qos; /* QoS capabilities for this device */ 135 struct qos_info qos; /* QoS capabilities for this device */
120 136
121 spinlock_t lock; /* For serializing operations */ 137 spinlock_t lock; /* For serializing operations */
122 138
123 __u32 new_speed; 139 __u32 new_speed;
124 __u32 flags; /* Interface flags */ 140 __u32 flags; /* Interface flags */
125 141
@@ -127,18 +143,20 @@ struct smsc_ircc_cb {
127 int tx_len; /* Number of frames in tx_buff */ 143 int tx_len; /* Number of frames in tx_buff */
128 144
129 int transceiver; 145 int transceiver;
130 struct pm_dev *pmdev; 146 struct platform_device *pldev;
131}; 147};
132 148
133/* Constants */ 149/* Constants */
134 150
135static const char *driver_name = "smsc-ircc2"; 151#define SMSC_IRCC2_DRIVER_NAME "smsc-ircc2"
136#define DIM(x) (sizeof(x)/(sizeof(*(x)))) 152
137#define SMSC_IRCC2_C_IRDA_FALLBACK_SPEED 9600 153#define SMSC_IRCC2_C_IRDA_FALLBACK_SPEED 9600
138#define SMSC_IRCC2_C_DEFAULT_TRANSCEIVER 1 154#define SMSC_IRCC2_C_DEFAULT_TRANSCEIVER 1
139#define SMSC_IRCC2_C_NET_TIMEOUT 0 155#define SMSC_IRCC2_C_NET_TIMEOUT 0
140#define SMSC_IRCC2_C_SIR_STOP 0 156#define SMSC_IRCC2_C_SIR_STOP 0
141 157
158static const char *driver_name = SMSC_IRCC2_DRIVER_NAME;
159
142/* Prototypes */ 160/* Prototypes */
143 161
144static int smsc_ircc_open(unsigned int firbase, unsigned int sirbase, u8 dma, u8 irq); 162static int smsc_ircc_open(unsigned int firbase, unsigned int sirbase, u8 dma, u8 irq);
@@ -147,15 +165,15 @@ static void smsc_ircc_setup_io(struct smsc_ircc_cb *self, unsigned int fir_base,
147static void smsc_ircc_setup_qos(struct smsc_ircc_cb *self); 165static void smsc_ircc_setup_qos(struct smsc_ircc_cb *self);
148static void smsc_ircc_init_chip(struct smsc_ircc_cb *self); 166static void smsc_ircc_init_chip(struct smsc_ircc_cb *self);
149static int __exit smsc_ircc_close(struct smsc_ircc_cb *self); 167static int __exit smsc_ircc_close(struct smsc_ircc_cb *self);
150static int smsc_ircc_dma_receive(struct smsc_ircc_cb *self, int iobase); 168static int smsc_ircc_dma_receive(struct smsc_ircc_cb *self);
151static void smsc_ircc_dma_receive_complete(struct smsc_ircc_cb *self, int iobase); 169static void smsc_ircc_dma_receive_complete(struct smsc_ircc_cb *self);
152static void smsc_ircc_sir_receive(struct smsc_ircc_cb *self); 170static void smsc_ircc_sir_receive(struct smsc_ircc_cb *self);
153static int smsc_ircc_hard_xmit_sir(struct sk_buff *skb, struct net_device *dev); 171static int smsc_ircc_hard_xmit_sir(struct sk_buff *skb, struct net_device *dev);
154static int smsc_ircc_hard_xmit_fir(struct sk_buff *skb, struct net_device *dev); 172static int smsc_ircc_hard_xmit_fir(struct sk_buff *skb, struct net_device *dev);
155static void smsc_ircc_dma_xmit(struct smsc_ircc_cb *self, int iobase, int bofs); 173static void smsc_ircc_dma_xmit(struct smsc_ircc_cb *self, int bofs);
156static void smsc_ircc_dma_xmit_complete(struct smsc_ircc_cb *self, int iobase); 174static void smsc_ircc_dma_xmit_complete(struct smsc_ircc_cb *self);
157static void smsc_ircc_change_speed(void *priv, u32 speed); 175static void smsc_ircc_change_speed(struct smsc_ircc_cb *self, u32 speed);
158static void smsc_ircc_set_sir_speed(void *priv, u32 speed); 176static void smsc_ircc_set_sir_speed(struct smsc_ircc_cb *self, u32 speed);
159static irqreturn_t smsc_ircc_interrupt(int irq, void *dev_id, struct pt_regs *regs); 177static irqreturn_t smsc_ircc_interrupt(int irq, void *dev_id, struct pt_regs *regs);
160static irqreturn_t smsc_ircc_interrupt_sir(struct net_device *dev); 178static irqreturn_t smsc_ircc_interrupt_sir(struct net_device *dev);
161static void smsc_ircc_sir_start(struct smsc_ircc_cb *self); 179static void smsc_ircc_sir_start(struct smsc_ircc_cb *self);
@@ -171,7 +189,6 @@ static int smsc_ircc_net_ioctl(struct net_device *dev, struct ifreq *rq, int cm
171static void smsc_ircc_timeout(struct net_device *dev); 189static void smsc_ircc_timeout(struct net_device *dev);
172#endif 190#endif
173static struct net_device_stats *smsc_ircc_net_get_stats(struct net_device *dev); 191static struct net_device_stats *smsc_ircc_net_get_stats(struct net_device *dev);
174static int smsc_ircc_pmproc(struct pm_dev *dev, pm_request_t rqst, void *data);
175static int smsc_ircc_is_receiving(struct smsc_ircc_cb *self); 192static int smsc_ircc_is_receiving(struct smsc_ircc_cb *self);
176static void smsc_ircc_probe_transceiver(struct smsc_ircc_cb *self); 193static void smsc_ircc_probe_transceiver(struct smsc_ircc_cb *self);
177static void smsc_ircc_set_transceiver_for_speed(struct smsc_ircc_cb *self, u32 speed); 194static void smsc_ircc_set_transceiver_for_speed(struct smsc_ircc_cb *self, u32 speed);
@@ -179,9 +196,9 @@ static void smsc_ircc_sir_wait_hw_transmitter_finish(struct smsc_ircc_cb *self);
179 196
180/* Probing */ 197/* Probing */
181static int __init smsc_ircc_look_for_chips(void); 198static int __init smsc_ircc_look_for_chips(void);
182static const smsc_chip_t * __init smsc_ircc_probe(unsigned short cfg_base,u8 reg,const smsc_chip_t *chip,char *type); 199static const struct smsc_chip * __init smsc_ircc_probe(unsigned short cfg_base, u8 reg, const struct smsc_chip *chip, char *type);
183static int __init smsc_superio_flat(const smsc_chip_t *chips, unsigned short cfg_base, char *type); 200static int __init smsc_superio_flat(const struct smsc_chip *chips, unsigned short cfg_base, char *type);
184static int __init smsc_superio_paged(const smsc_chip_t *chips, unsigned short cfg_base, char *type); 201static int __init smsc_superio_paged(const struct smsc_chip *chips, unsigned short cfg_base, char *type);
185static int __init smsc_superio_fdc(unsigned short cfg_base); 202static int __init smsc_superio_fdc(unsigned short cfg_base);
186static int __init smsc_superio_lpc(unsigned short cfg_base); 203static int __init smsc_superio_lpc(unsigned short cfg_base);
187 204
@@ -196,21 +213,26 @@ static int smsc_ircc_probe_transceiver_smsc_ircc_atc(int fir_base);
196 213
197/* Power Management */ 214/* Power Management */
198 215
199static void smsc_ircc_suspend(struct smsc_ircc_cb *self); 216static int smsc_ircc_suspend(struct device *dev, pm_message_t state, u32 level);
200static void smsc_ircc_wakeup(struct smsc_ircc_cb *self); 217static int smsc_ircc_resume(struct device *dev, u32 level);
201static int smsc_ircc_pmproc(struct pm_dev *dev, pm_request_t rqst, void *data);
202 218
219static struct device_driver smsc_ircc_driver = {
220 .name = SMSC_IRCC2_DRIVER_NAME,
221 .bus = &platform_bus_type,
222 .suspend = smsc_ircc_suspend,
223 .resume = smsc_ircc_resume,
224};
203 225
204/* Transceivers for SMSC-ircc */ 226/* Transceivers for SMSC-ircc */
205 227
206static smsc_transceiver_t smsc_transceivers[]= 228static struct smsc_transceiver smsc_transceivers[] =
207{ 229{
208 { "Toshiba Satellite 1800 (GP data pin select)", smsc_ircc_set_transceiver_toshiba_sat1800, smsc_ircc_probe_transceiver_toshiba_sat1800}, 230 { "Toshiba Satellite 1800 (GP data pin select)", smsc_ircc_set_transceiver_toshiba_sat1800, smsc_ircc_probe_transceiver_toshiba_sat1800 },
209 { "Fast pin select", smsc_ircc_set_transceiver_smsc_ircc_fast_pin_select, smsc_ircc_probe_transceiver_smsc_ircc_fast_pin_select}, 231 { "Fast pin select", smsc_ircc_set_transceiver_smsc_ircc_fast_pin_select, smsc_ircc_probe_transceiver_smsc_ircc_fast_pin_select },
210 { "ATC IRMode", smsc_ircc_set_transceiver_smsc_ircc_atc, smsc_ircc_probe_transceiver_smsc_ircc_atc}, 232 { "ATC IRMode", smsc_ircc_set_transceiver_smsc_ircc_atc, smsc_ircc_probe_transceiver_smsc_ircc_atc },
211 { NULL, NULL} 233 { NULL, NULL }
212}; 234};
213#define SMSC_IRCC2_C_NUMBER_OF_TRANSCEIVERS (DIM(smsc_transceivers)-1) 235#define SMSC_IRCC2_C_NUMBER_OF_TRANSCEIVERS (ARRAY_SIZE(smsc_transceivers) - 1)
214 236
215/* SMC SuperIO chipsets definitions */ 237/* SMC SuperIO chipsets definitions */
216 238
@@ -221,7 +243,7 @@ static smsc_transceiver_t smsc_transceivers[]=
221#define FIR 4 /* SuperIO Chip has fast IRDA */ 243#define FIR 4 /* SuperIO Chip has fast IRDA */
222#define SERx4 8 /* SuperIO Chip supports 115,2 KBaud * 4=460,8 KBaud */ 244#define SERx4 8 /* SuperIO Chip supports 115,2 KBaud * 4=460,8 KBaud */
223 245
224static smsc_chip_t __initdata fdc_chips_flat[]= 246static struct smsc_chip __initdata fdc_chips_flat[] =
225{ 247{
226 /* Base address 0x3f0 or 0x370 */ 248 /* Base address 0x3f0 or 0x370 */
227 { "37C44", KEY55_1|NoIRDA, 0x00, 0x00 }, /* This chip cannot be detected */ 249 { "37C44", KEY55_1|NoIRDA, 0x00, 0x00 }, /* This chip cannot be detected */
@@ -235,7 +257,7 @@ static smsc_chip_t __initdata fdc_chips_flat[]=
235 { NULL } 257 { NULL }
236}; 258};
237 259
238static smsc_chip_t __initdata fdc_chips_paged[]= 260static struct smsc_chip __initdata fdc_chips_paged[] =
239{ 261{
240 /* Base address 0x3f0 or 0x370 */ 262 /* Base address 0x3f0 or 0x370 */
241 { "37B72X", KEY55_1|SIR|SERx4, 0x4c, 0x00 }, 263 { "37B72X", KEY55_1|SIR|SERx4, 0x4c, 0x00 },
@@ -254,7 +276,7 @@ static smsc_chip_t __initdata fdc_chips_paged[]=
254 { NULL } 276 { NULL }
255}; 277};
256 278
257static smsc_chip_t __initdata lpc_chips_flat[]= 279static struct smsc_chip __initdata lpc_chips_flat[] =
258{ 280{
259 /* Base address 0x2E or 0x4E */ 281 /* Base address 0x2E or 0x4E */
260 { "47N227", KEY55_1|FIR|SERx4, 0x5a, 0x00 }, 282 { "47N227", KEY55_1|FIR|SERx4, 0x5a, 0x00 },
@@ -262,7 +284,7 @@ static smsc_chip_t __initdata lpc_chips_flat[]=
262 { NULL } 284 { NULL }
263}; 285};
264 286
265static smsc_chip_t __initdata lpc_chips_paged[]= 287static struct smsc_chip __initdata lpc_chips_paged[] =
266{ 288{
267 /* Base address 0x2E or 0x4E */ 289 /* Base address 0x2E or 0x4E */
268 { "47B27X", KEY55_1|SIR|SERx4, 0x51, 0x00 }, 290 { "47B27X", KEY55_1|SIR|SERx4, 0x51, 0x00 },
@@ -281,33 +303,25 @@ static smsc_chip_t __initdata lpc_chips_paged[]=
281#define SMSCSIO_TYPE_FLAT 4 303#define SMSCSIO_TYPE_FLAT 4
282#define SMSCSIO_TYPE_PAGED 8 304#define SMSCSIO_TYPE_PAGED 8
283 305
284static smsc_chip_address_t __initdata possible_addresses[]= 306static struct smsc_chip_address __initdata possible_addresses[] =
285{ 307{
286 {0x3f0, SMSCSIO_TYPE_FDC|SMSCSIO_TYPE_FLAT|SMSCSIO_TYPE_PAGED}, 308 { 0x3f0, SMSCSIO_TYPE_FDC|SMSCSIO_TYPE_FLAT|SMSCSIO_TYPE_PAGED },
287 {0x370, SMSCSIO_TYPE_FDC|SMSCSIO_TYPE_FLAT|SMSCSIO_TYPE_PAGED}, 309 { 0x370, SMSCSIO_TYPE_FDC|SMSCSIO_TYPE_FLAT|SMSCSIO_TYPE_PAGED },
288 {0xe0, SMSCSIO_TYPE_FDC|SMSCSIO_TYPE_FLAT|SMSCSIO_TYPE_PAGED}, 310 { 0xe0, SMSCSIO_TYPE_FDC|SMSCSIO_TYPE_FLAT|SMSCSIO_TYPE_PAGED },
289 {0x2e, SMSCSIO_TYPE_LPC|SMSCSIO_TYPE_FLAT|SMSCSIO_TYPE_PAGED}, 311 { 0x2e, SMSCSIO_TYPE_LPC|SMSCSIO_TYPE_FLAT|SMSCSIO_TYPE_PAGED },
290 {0x4e, SMSCSIO_TYPE_LPC|SMSCSIO_TYPE_FLAT|SMSCSIO_TYPE_PAGED}, 312 { 0x4e, SMSCSIO_TYPE_LPC|SMSCSIO_TYPE_FLAT|SMSCSIO_TYPE_PAGED },
291 {0,0} 313 { 0, 0 }
292}; 314};
293 315
294/* Globals */ 316/* Globals */
295 317
296static struct smsc_ircc_cb *dev_self[] = { NULL, NULL}; 318static struct smsc_ircc_cb *dev_self[] = { NULL, NULL };
297 319static unsigned short dev_count;
298static int ircc_irq=255;
299static int ircc_dma=255;
300static int ircc_fir=0;
301static int ircc_sir=0;
302static int ircc_cfg=0;
303static int ircc_transceiver=0;
304
305static unsigned short dev_count=0;
306 320
307static inline void register_bank(int iobase, int bank) 321static inline void register_bank(int iobase, int bank)
308{ 322{
309 outb(((inb(iobase+IRCC_MASTER) & 0xf0) | (bank & 0x07)), 323 outb(((inb(iobase + IRCC_MASTER) & 0xf0) | (bank & 0x07)),
310 iobase+IRCC_MASTER); 324 iobase + IRCC_MASTER);
311} 325}
312 326
313 327
@@ -327,34 +341,44 @@ static inline void register_bank(int iobase, int bank)
327 */ 341 */
328static int __init smsc_ircc_init(void) 342static int __init smsc_ircc_init(void)
329{ 343{
330 int ret=-ENODEV; 344 int ret;
331 345
332 IRDA_DEBUG(1, "%s\n", __FUNCTION__); 346 IRDA_DEBUG(1, "%s\n", __FUNCTION__);
333 347
334 dev_count=0; 348 ret = driver_register(&smsc_ircc_driver);
335 349 if (ret) {
336 if ((ircc_fir>0)&&(ircc_sir>0)) { 350 IRDA_ERROR("%s, Can't register driver!\n", driver_name);
351 return ret;
352 }
353
354 dev_count = 0;
355
356 if (ircc_fir > 0 && ircc_sir > 0) {
337 IRDA_MESSAGE(" Overriding FIR address 0x%04x\n", ircc_fir); 357 IRDA_MESSAGE(" Overriding FIR address 0x%04x\n", ircc_fir);
338 IRDA_MESSAGE(" Overriding SIR address 0x%04x\n", ircc_sir); 358 IRDA_MESSAGE(" Overriding SIR address 0x%04x\n", ircc_sir);
339 359
340 if (smsc_ircc_open(ircc_fir, ircc_sir, ircc_dma, ircc_irq) == 0) 360 if (smsc_ircc_open(ircc_fir, ircc_sir, ircc_dma, ircc_irq))
341 return 0; 361 ret = -ENODEV;
342 362 } else {
343 return -ENODEV; 363 ret = -ENODEV;
344 } 364
365 /* try user provided configuration register base address */
366 if (ircc_cfg > 0) {
367 IRDA_MESSAGE(" Overriding configuration address "
368 "0x%04x\n", ircc_cfg);
369 if (!smsc_superio_fdc(ircc_cfg))
370 ret = 0;
371 if (!smsc_superio_lpc(ircc_cfg))
372 ret = 0;
373 }
345 374
346 /* try user provided configuration register base address */ 375 if (smsc_ircc_look_for_chips() > 0)
347 if (ircc_cfg>0) {
348 IRDA_MESSAGE(" Overriding configuration address 0x%04x\n",
349 ircc_cfg);
350 if (!smsc_superio_fdc(ircc_cfg))
351 ret = 0;
352 if (!smsc_superio_lpc(ircc_cfg))
353 ret = 0; 376 ret = 0;
354 } 377 }
355 378
356 if(smsc_ircc_look_for_chips()>0) ret = 0; 379 if (ret)
357 380 driver_unregister(&smsc_ircc_driver);
381
358 return ret; 382 return ret;
359} 383}
360 384
@@ -369,15 +393,15 @@ static int __init smsc_ircc_open(unsigned int fir_base, unsigned int sir_base, u
369 struct smsc_ircc_cb *self; 393 struct smsc_ircc_cb *self;
370 struct net_device *dev; 394 struct net_device *dev;
371 int err; 395 int err;
372 396
373 IRDA_DEBUG(1, "%s\n", __FUNCTION__); 397 IRDA_DEBUG(1, "%s\n", __FUNCTION__);
374 398
375 err = smsc_ircc_present(fir_base, sir_base); 399 err = smsc_ircc_present(fir_base, sir_base);
376 if(err) 400 if (err)
377 goto err_out; 401 goto err_out;
378 402
379 err = -ENOMEM; 403 err = -ENOMEM;
380 if (dev_count > DIM(dev_self)) { 404 if (dev_count >= ARRAY_SIZE(dev_self)) {
381 IRDA_WARNING("%s(), too many devices!\n", __FUNCTION__); 405 IRDA_WARNING("%s(), too many devices!\n", __FUNCTION__);
382 goto err_out1; 406 goto err_out1;
383 } 407 }
@@ -396,14 +420,14 @@ static int __init smsc_ircc_open(unsigned int fir_base, unsigned int sir_base, u
396 dev->hard_start_xmit = smsc_ircc_hard_xmit_sir; 420 dev->hard_start_xmit = smsc_ircc_hard_xmit_sir;
397#if SMSC_IRCC2_C_NET_TIMEOUT 421#if SMSC_IRCC2_C_NET_TIMEOUT
398 dev->tx_timeout = smsc_ircc_timeout; 422 dev->tx_timeout = smsc_ircc_timeout;
399 dev->watchdog_timeo = HZ*2; /* Allow enough time for speed change */ 423 dev->watchdog_timeo = HZ * 2; /* Allow enough time for speed change */
400#endif 424#endif
401 dev->open = smsc_ircc_net_open; 425 dev->open = smsc_ircc_net_open;
402 dev->stop = smsc_ircc_net_close; 426 dev->stop = smsc_ircc_net_close;
403 dev->do_ioctl = smsc_ircc_net_ioctl; 427 dev->do_ioctl = smsc_ircc_net_ioctl;
404 dev->get_stats = smsc_ircc_net_get_stats; 428 dev->get_stats = smsc_ircc_net_get_stats;
405 429
406 self = dev->priv; 430 self = netdev_priv(dev);
407 self->netdev = dev; 431 self->netdev = dev;
408 432
409 /* Make ifconfig display some details */ 433 /* Make ifconfig display some details */
@@ -411,10 +435,10 @@ static int __init smsc_ircc_open(unsigned int fir_base, unsigned int sir_base, u
411 dev->irq = self->io.irq = irq; 435 dev->irq = self->io.irq = irq;
412 436
413 /* Need to store self somewhere */ 437 /* Need to store self somewhere */
414 dev_self[dev_count++] = self; 438 dev_self[dev_count] = self;
415 spin_lock_init(&self->lock); 439 spin_lock_init(&self->lock);
416 440
417 self->rx_buff.truesize = SMSC_IRCC2_RX_BUFF_TRUESIZE; 441 self->rx_buff.truesize = SMSC_IRCC2_RX_BUFF_TRUESIZE;
418 self->tx_buff.truesize = SMSC_IRCC2_TX_BUFF_TRUESIZE; 442 self->tx_buff.truesize = SMSC_IRCC2_TX_BUFF_TRUESIZE;
419 443
420 self->rx_buff.head = 444 self->rx_buff.head =
@@ -442,33 +466,40 @@ static int __init smsc_ircc_open(unsigned int fir_base, unsigned int sir_base, u
442 self->rx_buff.state = OUTSIDE_FRAME; 466 self->rx_buff.state = OUTSIDE_FRAME;
443 self->tx_buff.data = self->tx_buff.head; 467 self->tx_buff.data = self->tx_buff.head;
444 self->rx_buff.data = self->rx_buff.head; 468 self->rx_buff.data = self->rx_buff.head;
445
446 smsc_ircc_setup_io(self, fir_base, sir_base, dma, irq);
447 469
470 smsc_ircc_setup_io(self, fir_base, sir_base, dma, irq);
448 smsc_ircc_setup_qos(self); 471 smsc_ircc_setup_qos(self);
449
450 smsc_ircc_init_chip(self); 472 smsc_ircc_init_chip(self);
451 473
452 if(ircc_transceiver > 0 && 474 if (ircc_transceiver > 0 &&
453 ircc_transceiver < SMSC_IRCC2_C_NUMBER_OF_TRANSCEIVERS) 475 ircc_transceiver < SMSC_IRCC2_C_NUMBER_OF_TRANSCEIVERS)
454 self->transceiver = ircc_transceiver; 476 self->transceiver = ircc_transceiver;
455 else 477 else
456 smsc_ircc_probe_transceiver(self); 478 smsc_ircc_probe_transceiver(self);
457 479
458 err = register_netdev(self->netdev); 480 err = register_netdev(self->netdev);
459 if(err) { 481 if (err) {
460 IRDA_ERROR("%s, Network device registration failed!\n", 482 IRDA_ERROR("%s, Network device registration failed!\n",
461 driver_name); 483 driver_name);
462 goto err_out4; 484 goto err_out4;
463 } 485 }
464 486
465 self->pmdev = pm_register(PM_SYS_DEV, PM_SYS_IRDA, smsc_ircc_pmproc); 487 self->pldev = platform_device_register_simple(SMSC_IRCC2_DRIVER_NAME,
466 if (self->pmdev) 488 dev_count, NULL, 0);
467 self->pmdev->data = self; 489 if (IS_ERR(self->pldev)) {
490 err = PTR_ERR(self->pldev);
491 goto err_out5;
492 }
493 dev_set_drvdata(&self->pldev->dev, self);
468 494
469 IRDA_MESSAGE("IrDA: Registered device %s\n", dev->name); 495 IRDA_MESSAGE("IrDA: Registered device %s\n", dev->name);
496 dev_count++;
470 497
471 return 0; 498 return 0;
499
500 err_out5:
501 unregister_netdev(self->netdev);
502
472 err_out4: 503 err_out4:
473 dma_free_coherent(NULL, self->tx_buff.truesize, 504 dma_free_coherent(NULL, self->tx_buff.truesize,
474 self->tx_buff.head, self->tx_buff_dma); 505 self->tx_buff.head, self->tx_buff_dma);
@@ -477,7 +508,7 @@ static int __init smsc_ircc_open(unsigned int fir_base, unsigned int sir_base, u
477 self->rx_buff.head, self->rx_buff_dma); 508 self->rx_buff.head, self->rx_buff_dma);
478 err_out2: 509 err_out2:
479 free_netdev(self->netdev); 510 free_netdev(self->netdev);
480 dev_self[--dev_count] = NULL; 511 dev_self[dev_count] = NULL;
481 err_out1: 512 err_out1:
482 release_region(fir_base, SMSC_IRCC2_FIR_CHIP_IO_EXTENT); 513 release_region(fir_base, SMSC_IRCC2_FIR_CHIP_IO_EXTENT);
483 release_region(sir_base, SMSC_IRCC2_SIR_CHIP_IO_EXTENT); 514 release_region(sir_base, SMSC_IRCC2_SIR_CHIP_IO_EXTENT);
@@ -511,16 +542,16 @@ static int smsc_ircc_present(unsigned int fir_base, unsigned int sir_base)
511 542
512 register_bank(fir_base, 3); 543 register_bank(fir_base, 3);
513 544
514 high = inb(fir_base+IRCC_ID_HIGH); 545 high = inb(fir_base + IRCC_ID_HIGH);
515 low = inb(fir_base+IRCC_ID_LOW); 546 low = inb(fir_base + IRCC_ID_LOW);
516 chip = inb(fir_base+IRCC_CHIP_ID); 547 chip = inb(fir_base + IRCC_CHIP_ID);
517 version = inb(fir_base+IRCC_VERSION); 548 version = inb(fir_base + IRCC_VERSION);
518 config = inb(fir_base+IRCC_INTERFACE); 549 config = inb(fir_base + IRCC_INTERFACE);
519 dma = config & IRCC_INTERFACE_DMA_MASK; 550 dma = config & IRCC_INTERFACE_DMA_MASK;
520 irq = (config & IRCC_INTERFACE_IRQ_MASK) >> 4; 551 irq = (config & IRCC_INTERFACE_IRQ_MASK) >> 4;
521 552
522 if (high != 0x10 || low != 0xb8 || (chip != 0xf1 && chip != 0xf2)) { 553 if (high != 0x10 || low != 0xb8 || (chip != 0xf1 && chip != 0xf2)) {
523 IRDA_WARNING("%s(), addr 0x%04x - no device found!\n", 554 IRDA_WARNING("%s(), addr 0x%04x - no device found!\n",
524 __FUNCTION__, fir_base); 555 __FUNCTION__, fir_base);
525 goto out3; 556 goto out3;
526 } 557 }
@@ -529,6 +560,7 @@ static int smsc_ircc_present(unsigned int fir_base, unsigned int sir_base)
529 chip & 0x0f, version, fir_base, sir_base, dma, irq); 560 chip & 0x0f, version, fir_base, sir_base, dma, irq);
530 561
531 return 0; 562 return 0;
563
532 out3: 564 out3:
533 release_region(sir_base, SMSC_IRCC2_SIR_CHIP_IO_EXTENT); 565 release_region(sir_base, SMSC_IRCC2_SIR_CHIP_IO_EXTENT);
534 out2: 566 out2:
@@ -543,16 +575,16 @@ static int smsc_ircc_present(unsigned int fir_base, unsigned int sir_base)
543 * Setup I/O 575 * Setup I/O
544 * 576 *
545 */ 577 */
546static void smsc_ircc_setup_io(struct smsc_ircc_cb *self, 578static void smsc_ircc_setup_io(struct smsc_ircc_cb *self,
547 unsigned int fir_base, unsigned int sir_base, 579 unsigned int fir_base, unsigned int sir_base,
548 u8 dma, u8 irq) 580 u8 dma, u8 irq)
549{ 581{
550 unsigned char config, chip_dma, chip_irq; 582 unsigned char config, chip_dma, chip_irq;
551 583
552 register_bank(fir_base, 3); 584 register_bank(fir_base, 3);
553 config = inb(fir_base+IRCC_INTERFACE); 585 config = inb(fir_base + IRCC_INTERFACE);
554 chip_dma = config & IRCC_INTERFACE_DMA_MASK; 586 chip_dma = config & IRCC_INTERFACE_DMA_MASK;
555 chip_irq = (config & IRCC_INTERFACE_IRQ_MASK) >> 4; 587 chip_irq = (config & IRCC_INTERFACE_IRQ_MASK) >> 4;
556 588
557 self->io.fir_base = fir_base; 589 self->io.fir_base = fir_base;
558 self->io.sir_base = sir_base; 590 self->io.sir_base = sir_base;
@@ -566,17 +598,15 @@ static void smsc_ircc_setup_io(struct smsc_ircc_cb *self,
566 IRDA_MESSAGE("%s, Overriding IRQ - chip says %d, using %d\n", 598 IRDA_MESSAGE("%s, Overriding IRQ - chip says %d, using %d\n",
567 driver_name, chip_irq, irq); 599 driver_name, chip_irq, irq);
568 self->io.irq = irq; 600 self->io.irq = irq;
569 } 601 } else
570 else
571 self->io.irq = chip_irq; 602 self->io.irq = chip_irq;
572 603
573 if (dma < 255) { 604 if (dma < 255) {
574 if (dma != chip_dma) 605 if (dma != chip_dma)
575 IRDA_MESSAGE("%s, Overriding DMA - chip says %d, using %d\n", 606 IRDA_MESSAGE("%s, Overriding DMA - chip says %d, using %d\n",
576 driver_name, chip_dma, dma); 607 driver_name, chip_dma, dma);
577 self->io.dma = dma; 608 self->io.dma = dma;
578 } 609 } else
579 else
580 self->io.dma = chip_dma; 610 self->io.dma = chip_dma;
581 611
582} 612}
@@ -591,7 +621,7 @@ static void smsc_ircc_setup_qos(struct smsc_ircc_cb *self)
591{ 621{
592 /* Initialize QoS for this device */ 622 /* Initialize QoS for this device */
593 irda_init_max_qos_capabilies(&self->qos); 623 irda_init_max_qos_capabilies(&self->qos);
594 624
595 self->qos.baud_rate.bits = IR_9600|IR_19200|IR_38400|IR_57600| 625 self->qos.baud_rate.bits = IR_9600|IR_19200|IR_38400|IR_57600|
596 IR_115200|IR_576000|IR_1152000|(IR_4000000 << 8); 626 IR_115200|IR_576000|IR_1152000|(IR_4000000 << 8);
597 627
@@ -608,43 +638,43 @@ static void smsc_ircc_setup_qos(struct smsc_ircc_cb *self)
608 */ 638 */
609static void smsc_ircc_init_chip(struct smsc_ircc_cb *self) 639static void smsc_ircc_init_chip(struct smsc_ircc_cb *self)
610{ 640{
611 int iobase, ir_mode, ctrl, fast; 641 int iobase, ir_mode, ctrl, fast;
612 642
613 IRDA_ASSERT( self != NULL, return; ); 643 IRDA_ASSERT(self != NULL, return;);
614 iobase = self->io.fir_base;
615 644
645 iobase = self->io.fir_base;
616 ir_mode = IRCC_CFGA_IRDA_SIR_A; 646 ir_mode = IRCC_CFGA_IRDA_SIR_A;
617 ctrl = 0; 647 ctrl = 0;
618 fast = 0; 648 fast = 0;
619 649
620 register_bank(iobase, 0); 650 register_bank(iobase, 0);
621 outb(IRCC_MASTER_RESET, iobase+IRCC_MASTER); 651 outb(IRCC_MASTER_RESET, iobase + IRCC_MASTER);
622 outb(0x00, iobase+IRCC_MASTER); 652 outb(0x00, iobase + IRCC_MASTER);
623 653
624 register_bank(iobase, 1); 654 register_bank(iobase, 1);
625 outb(((inb(iobase+IRCC_SCE_CFGA) & 0x87) | ir_mode), 655 outb(((inb(iobase + IRCC_SCE_CFGA) & 0x87) | ir_mode),
626 iobase+IRCC_SCE_CFGA); 656 iobase + IRCC_SCE_CFGA);
627 657
628#ifdef smsc_669 /* Uses pin 88/89 for Rx/Tx */ 658#ifdef smsc_669 /* Uses pin 88/89 for Rx/Tx */
629 outb(((inb(iobase+IRCC_SCE_CFGB) & 0x3f) | IRCC_CFGB_MUX_COM), 659 outb(((inb(iobase + IRCC_SCE_CFGB) & 0x3f) | IRCC_CFGB_MUX_COM),
630 iobase+IRCC_SCE_CFGB); 660 iobase + IRCC_SCE_CFGB);
631#else 661#else
632 outb(((inb(iobase+IRCC_SCE_CFGB) & 0x3f) | IRCC_CFGB_MUX_IR), 662 outb(((inb(iobase + IRCC_SCE_CFGB) & 0x3f) | IRCC_CFGB_MUX_IR),
633 iobase+IRCC_SCE_CFGB); 663 iobase + IRCC_SCE_CFGB);
634#endif 664#endif
635 (void) inb(iobase+IRCC_FIFO_THRESHOLD); 665 (void) inb(iobase + IRCC_FIFO_THRESHOLD);
636 outb(SMSC_IRCC2_FIFO_THRESHOLD, iobase+IRCC_FIFO_THRESHOLD); 666 outb(SMSC_IRCC2_FIFO_THRESHOLD, iobase + IRCC_FIFO_THRESHOLD);
637 667
638 register_bank(iobase, 4); 668 register_bank(iobase, 4);
639 outb((inb(iobase+IRCC_CONTROL) & 0x30) | ctrl, iobase+IRCC_CONTROL); 669 outb((inb(iobase + IRCC_CONTROL) & 0x30) | ctrl, iobase + IRCC_CONTROL);
640 670
641 register_bank(iobase, 0); 671 register_bank(iobase, 0);
642 outb(fast, iobase+IRCC_LCR_A); 672 outb(fast, iobase + IRCC_LCR_A);
643 673
644 smsc_ircc_set_sir_speed(self, SMSC_IRCC2_C_IRDA_FALLBACK_SPEED); 674 smsc_ircc_set_sir_speed(self, SMSC_IRCC2_C_IRDA_FALLBACK_SPEED);
645 675
646 /* Power on device */ 676 /* Power on device */
647 outb(0x00, iobase+IRCC_MASTER); 677 outb(0x00, iobase + IRCC_MASTER);
648} 678}
649 679
650/* 680/*
@@ -662,12 +692,12 @@ static int smsc_ircc_net_ioctl(struct net_device *dev, struct ifreq *rq, int cmd
662 692
663 IRDA_ASSERT(dev != NULL, return -1;); 693 IRDA_ASSERT(dev != NULL, return -1;);
664 694
665 self = dev->priv; 695 self = netdev_priv(dev);
666 696
667 IRDA_ASSERT(self != NULL, return -1;); 697 IRDA_ASSERT(self != NULL, return -1;);
668 698
669 IRDA_DEBUG(2, "%s(), %s, (cmd=0x%X)\n", __FUNCTION__, dev->name, cmd); 699 IRDA_DEBUG(2, "%s(), %s, (cmd=0x%X)\n", __FUNCTION__, dev->name, cmd);
670 700
671 switch (cmd) { 701 switch (cmd) {
672 case SIOCSBANDWIDTH: /* Set bandwidth */ 702 case SIOCSBANDWIDTH: /* Set bandwidth */
673 if (!capable(CAP_NET_ADMIN)) 703 if (!capable(CAP_NET_ADMIN))
@@ -703,14 +733,14 @@ static int smsc_ircc_net_ioctl(struct net_device *dev, struct ifreq *rq, int cmd
703 default: 733 default:
704 ret = -EOPNOTSUPP; 734 ret = -EOPNOTSUPP;
705 } 735 }
706 736
707 return ret; 737 return ret;
708} 738}
709 739
710static struct net_device_stats *smsc_ircc_net_get_stats(struct net_device *dev) 740static struct net_device_stats *smsc_ircc_net_get_stats(struct net_device *dev)
711{ 741{
712 struct smsc_ircc_cb *self = (struct smsc_ircc_cb *) dev->priv; 742 struct smsc_ircc_cb *self = netdev_priv(dev);
713 743
714 return &self->stats; 744 return &self->stats;
715} 745}
716 746
@@ -724,11 +754,9 @@ static struct net_device_stats *smsc_ircc_net_get_stats(struct net_device *dev)
724 754
725static void smsc_ircc_timeout(struct net_device *dev) 755static void smsc_ircc_timeout(struct net_device *dev)
726{ 756{
727 struct smsc_ircc_cb *self; 757 struct smsc_ircc_cb *self = netdev_priv(dev);
728 unsigned long flags; 758 unsigned long flags;
729 759
730 self = (struct smsc_ircc_cb *) dev->priv;
731
732 IRDA_WARNING("%s: transmit timed out, changing speed to: %d\n", 760 IRDA_WARNING("%s: transmit timed out, changing speed to: %d\n",
733 dev->name, self->io.speed); 761 dev->name, self->io.speed);
734 spin_lock_irqsave(&self->lock, flags); 762 spin_lock_irqsave(&self->lock, flags);
@@ -751,26 +779,23 @@ int smsc_ircc_hard_xmit_sir(struct sk_buff *skb, struct net_device *dev)
751{ 779{
752 struct smsc_ircc_cb *self; 780 struct smsc_ircc_cb *self;
753 unsigned long flags; 781 unsigned long flags;
754 int iobase;
755 s32 speed; 782 s32 speed;
756 783
757 IRDA_DEBUG(1, "%s\n", __FUNCTION__); 784 IRDA_DEBUG(1, "%s\n", __FUNCTION__);
758 785
759 IRDA_ASSERT(dev != NULL, return 0;); 786 IRDA_ASSERT(dev != NULL, return 0;);
760
761 self = (struct smsc_ircc_cb *) dev->priv;
762 IRDA_ASSERT(self != NULL, return 0;);
763 787
764 iobase = self->io.sir_base; 788 self = netdev_priv(dev);
789 IRDA_ASSERT(self != NULL, return 0;);
765 790
766 netif_stop_queue(dev); 791 netif_stop_queue(dev);
767 792
768 /* Make sure test of self->io.speed & speed change are atomic */ 793 /* Make sure test of self->io.speed & speed change are atomic */
769 spin_lock_irqsave(&self->lock, flags); 794 spin_lock_irqsave(&self->lock, flags);
770 795
771 /* Check if we need to change the speed */ 796 /* Check if we need to change the speed */
772 speed = irda_get_next_speed(skb); 797 speed = irda_get_next_speed(skb);
773 if ((speed != self->io.speed) && (speed != -1)) { 798 if (speed != self->io.speed && speed != -1) {
774 /* Check for empty frame */ 799 /* Check for empty frame */
775 if (!skb->len) { 800 if (!skb->len) {
776 /* 801 /*
@@ -787,27 +812,26 @@ int smsc_ircc_hard_xmit_sir(struct sk_buff *skb, struct net_device *dev)
787 spin_unlock_irqrestore(&self->lock, flags); 812 spin_unlock_irqrestore(&self->lock, flags);
788 dev_kfree_skb(skb); 813 dev_kfree_skb(skb);
789 return 0; 814 return 0;
790 } else {
791 self->new_speed = speed;
792 } 815 }
816 self->new_speed = speed;
793 } 817 }
794 818
795 /* Init tx buffer */ 819 /* Init tx buffer */
796 self->tx_buff.data = self->tx_buff.head; 820 self->tx_buff.data = self->tx_buff.head;
797 821
798 /* Copy skb to tx_buff while wrapping, stuffing and making CRC */ 822 /* Copy skb to tx_buff while wrapping, stuffing and making CRC */
799 self->tx_buff.len = async_wrap_skb(skb, self->tx_buff.data, 823 self->tx_buff.len = async_wrap_skb(skb, self->tx_buff.data,
800 self->tx_buff.truesize); 824 self->tx_buff.truesize);
801 825
802 self->stats.tx_bytes += self->tx_buff.len; 826 self->stats.tx_bytes += self->tx_buff.len;
803 827
804 /* Turn on transmit finished interrupt. Will fire immediately! */ 828 /* Turn on transmit finished interrupt. Will fire immediately! */
805 outb(UART_IER_THRI, iobase+UART_IER); 829 outb(UART_IER_THRI, self->io.sir_base + UART_IER);
806 830
807 spin_unlock_irqrestore(&self->lock, flags); 831 spin_unlock_irqrestore(&self->lock, flags);
808 832
809 dev_kfree_skb(skb); 833 dev_kfree_skb(skb);
810 834
811 return 0; 835 return 0;
812} 836}
813 837
@@ -826,9 +850,9 @@ static void smsc_ircc_set_fir_speed(struct smsc_ircc_cb *self, u32 speed)
826 850
827 self->io.speed = speed; 851 self->io.speed = speed;
828 852
829 switch(speed) { 853 switch (speed) {
830 default: 854 default:
831 case 576000: 855 case 576000:
832 ir_mode = IRCC_CFGA_IRDA_HDLC; 856 ir_mode = IRCC_CFGA_IRDA_HDLC;
833 ctrl = IRCC_CRC; 857 ctrl = IRCC_CRC;
834 fast = 0; 858 fast = 0;
@@ -853,14 +877,14 @@ static void smsc_ircc_set_fir_speed(struct smsc_ircc_cb *self, u32 speed)
853 Now in tranceiver! 877 Now in tranceiver!
854 /* This causes an interrupt */ 878 /* This causes an interrupt */
855 register_bank(fir_base, 0); 879 register_bank(fir_base, 0);
856 outb((inb(fir_base+IRCC_LCR_A) & 0xbf) | fast, fir_base+IRCC_LCR_A); 880 outb((inb(fir_base + IRCC_LCR_A) & 0xbf) | fast, fir_base + IRCC_LCR_A);
857 #endif 881 #endif
858 882
859 register_bank(fir_base, 1); 883 register_bank(fir_base, 1);
860 outb(((inb(fir_base+IRCC_SCE_CFGA) & IRCC_SCE_CFGA_BLOCK_CTRL_BITS_MASK) | ir_mode), fir_base+IRCC_SCE_CFGA); 884 outb(((inb(fir_base + IRCC_SCE_CFGA) & IRCC_SCE_CFGA_BLOCK_CTRL_BITS_MASK) | ir_mode), fir_base + IRCC_SCE_CFGA);
861 885
862 register_bank(fir_base, 4); 886 register_bank(fir_base, 4);
863 outb((inb(fir_base+IRCC_CONTROL) & 0x30) | ctrl, fir_base+IRCC_CONTROL); 887 outb((inb(fir_base + IRCC_CONTROL) & 0x30) | ctrl, fir_base + IRCC_CONTROL);
864} 888}
865 889
866/* 890/*
@@ -885,31 +909,31 @@ static void smsc_ircc_fir_start(struct smsc_ircc_cb *self)
885 /* Reset everything */ 909 /* Reset everything */
886 910
887 /* Install FIR transmit handler */ 911 /* Install FIR transmit handler */
888 dev->hard_start_xmit = smsc_ircc_hard_xmit_fir; 912 dev->hard_start_xmit = smsc_ircc_hard_xmit_fir;
889 913
890 /* Clear FIFO */ 914 /* Clear FIFO */
891 outb(inb(fir_base+IRCC_LCR_A)|IRCC_LCR_A_FIFO_RESET, fir_base+IRCC_LCR_A); 915 outb(inb(fir_base + IRCC_LCR_A) | IRCC_LCR_A_FIFO_RESET, fir_base + IRCC_LCR_A);
892 916
893 /* Enable interrupt */ 917 /* Enable interrupt */
894 /*outb(IRCC_IER_ACTIVE_FRAME|IRCC_IER_EOM, fir_base+IRCC_IER);*/ 918 /*outb(IRCC_IER_ACTIVE_FRAME|IRCC_IER_EOM, fir_base + IRCC_IER);*/
895 919
896 register_bank(fir_base, 1); 920 register_bank(fir_base, 1);
897 921
898 /* Select the TX/RX interface */ 922 /* Select the TX/RX interface */
899#ifdef SMSC_669 /* Uses pin 88/89 for Rx/Tx */ 923#ifdef SMSC_669 /* Uses pin 88/89 for Rx/Tx */
900 outb(((inb(fir_base+IRCC_SCE_CFGB) & 0x3f) | IRCC_CFGB_MUX_COM), 924 outb(((inb(fir_base + IRCC_SCE_CFGB) & 0x3f) | IRCC_CFGB_MUX_COM),
901 fir_base+IRCC_SCE_CFGB); 925 fir_base + IRCC_SCE_CFGB);
902#else 926#else
903 outb(((inb(fir_base+IRCC_SCE_CFGB) & 0x3f) | IRCC_CFGB_MUX_IR), 927 outb(((inb(fir_base + IRCC_SCE_CFGB) & 0x3f) | IRCC_CFGB_MUX_IR),
904 fir_base+IRCC_SCE_CFGB); 928 fir_base + IRCC_SCE_CFGB);
905#endif 929#endif
906 (void) inb(fir_base+IRCC_FIFO_THRESHOLD); 930 (void) inb(fir_base + IRCC_FIFO_THRESHOLD);
907 931
908 /* Enable SCE interrupts */ 932 /* Enable SCE interrupts */
909 outb(0, fir_base+IRCC_MASTER); 933 outb(0, fir_base + IRCC_MASTER);
910 register_bank(fir_base, 0); 934 register_bank(fir_base, 0);
911 outb(IRCC_IER_ACTIVE_FRAME|IRCC_IER_EOM, fir_base+IRCC_IER); 935 outb(IRCC_IER_ACTIVE_FRAME | IRCC_IER_EOM, fir_base + IRCC_IER);
912 outb(IRCC_MASTER_INT_EN, fir_base+IRCC_MASTER); 936 outb(IRCC_MASTER_INT_EN, fir_base + IRCC_MASTER);
913} 937}
914 938
915/* 939/*
@@ -923,13 +947,13 @@ static void smsc_ircc_fir_stop(struct smsc_ircc_cb *self)
923 int fir_base; 947 int fir_base;
924 948
925 IRDA_DEBUG(1, "%s\n", __FUNCTION__); 949 IRDA_DEBUG(1, "%s\n", __FUNCTION__);
926 950
927 IRDA_ASSERT(self != NULL, return;); 951 IRDA_ASSERT(self != NULL, return;);
928 952
929 fir_base = self->io.fir_base; 953 fir_base = self->io.fir_base;
930 register_bank(fir_base, 0); 954 register_bank(fir_base, 0);
931 /*outb(IRCC_MASTER_RESET, fir_base+IRCC_MASTER);*/ 955 /*outb(IRCC_MASTER_RESET, fir_base + IRCC_MASTER);*/
932 outb(inb(fir_base+IRCC_LCR_B) & IRCC_LCR_B_SIP_ENABLE, fir_base+IRCC_LCR_B); 956 outb(inb(fir_base + IRCC_LCR_B) & IRCC_LCR_B_SIP_ENABLE, fir_base + IRCC_LCR_B);
933} 957}
934 958
935 959
@@ -941,18 +965,15 @@ static void smsc_ircc_fir_stop(struct smsc_ircc_cb *self)
941 * This function *must* be called with spinlock held, because it may 965 * This function *must* be called with spinlock held, because it may
942 * be called from the irq handler. - Jean II 966 * be called from the irq handler. - Jean II
943 */ 967 */
944static void smsc_ircc_change_speed(void *priv, u32 speed) 968static void smsc_ircc_change_speed(struct smsc_ircc_cb *self, u32 speed)
945{ 969{
946 struct smsc_ircc_cb *self = (struct smsc_ircc_cb *) priv;
947 struct net_device *dev; 970 struct net_device *dev;
948 int iobase;
949 int last_speed_was_sir; 971 int last_speed_was_sir;
950 972
951 IRDA_DEBUG(0, "%s() changing speed to: %d\n", __FUNCTION__, speed); 973 IRDA_DEBUG(0, "%s() changing speed to: %d\n", __FUNCTION__, speed);
952 974
953 IRDA_ASSERT(self != NULL, return;); 975 IRDA_ASSERT(self != NULL, return;);
954 dev = self->netdev; 976 dev = self->netdev;
955 iobase = self->io.fir_base;
956 977
957 last_speed_was_sir = self->io.speed <= SMSC_IRCC2_MAX_SIR_SPEED; 978 last_speed_was_sir = self->io.speed <= SMSC_IRCC2_MAX_SIR_SPEED;
958 979
@@ -961,30 +982,30 @@ static void smsc_ircc_change_speed(void *priv, u32 speed)
961 speed= 1152000; 982 speed= 1152000;
962 self->io.speed = speed; 983 self->io.speed = speed;
963 last_speed_was_sir = 0; 984 last_speed_was_sir = 0;
964 smsc_ircc_fir_start(self); 985 smsc_ircc_fir_start(self);
965 #endif 986 #endif
966 987
967 if(self->io.speed == 0) 988 if (self->io.speed == 0)
968 smsc_ircc_sir_start(self); 989 smsc_ircc_sir_start(self);
969 990
970 #if 0 991 #if 0
971 if(!last_speed_was_sir) speed = self->io.speed; 992 if (!last_speed_was_sir) speed = self->io.speed;
972 #endif 993 #endif
973 994
974 if(self->io.speed != speed) smsc_ircc_set_transceiver_for_speed(self, speed); 995 if (self->io.speed != speed)
996 smsc_ircc_set_transceiver_for_speed(self, speed);
975 997
976 self->io.speed = speed; 998 self->io.speed = speed;
977 999
978 if(speed <= SMSC_IRCC2_MAX_SIR_SPEED) { 1000 if (speed <= SMSC_IRCC2_MAX_SIR_SPEED) {
979 if(!last_speed_was_sir) { 1001 if (!last_speed_was_sir) {
980 smsc_ircc_fir_stop(self); 1002 smsc_ircc_fir_stop(self);
981 smsc_ircc_sir_start(self); 1003 smsc_ircc_sir_start(self);
982 } 1004 }
983 smsc_ircc_set_sir_speed(self, speed); 1005 smsc_ircc_set_sir_speed(self, speed);
984 } 1006 } else {
985 else { 1007 if (last_speed_was_sir) {
986 if(last_speed_was_sir) { 1008 #if SMSC_IRCC2_C_SIR_STOP
987 #if SMSC_IRCC2_C_SIR_STOP
988 smsc_ircc_sir_stop(self); 1009 smsc_ircc_sir_stop(self);
989 #endif 1010 #endif
990 smsc_ircc_fir_start(self); 1011 smsc_ircc_fir_start(self);
@@ -994,13 +1015,13 @@ static void smsc_ircc_change_speed(void *priv, u32 speed)
994 #if 0 1015 #if 0
995 self->tx_buff.len = 10; 1016 self->tx_buff.len = 10;
996 self->tx_buff.data = self->tx_buff.head; 1017 self->tx_buff.data = self->tx_buff.head;
997 1018
998 smsc_ircc_dma_xmit(self, iobase, 4000); 1019 smsc_ircc_dma_xmit(self, 4000);
999 #endif 1020 #endif
1000 /* Be ready for incoming frames */ 1021 /* Be ready for incoming frames */
1001 smsc_ircc_dma_receive(self, iobase); 1022 smsc_ircc_dma_receive(self);
1002 } 1023 }
1003 1024
1004 netif_wake_queue(dev); 1025 netif_wake_queue(dev);
1005} 1026}
1006 1027
@@ -1010,10 +1031,9 @@ static void smsc_ircc_change_speed(void *priv, u32 speed)
1010 * Set speed of IrDA port to specified baudrate 1031 * Set speed of IrDA port to specified baudrate
1011 * 1032 *
1012 */ 1033 */
1013void smsc_ircc_set_sir_speed(void *priv, __u32 speed) 1034void smsc_ircc_set_sir_speed(struct smsc_ircc_cb *self, __u32 speed)
1014{ 1035{
1015 struct smsc_ircc_cb *self = (struct smsc_ircc_cb *) priv; 1036 int iobase;
1016 int iobase;
1017 int fcr; /* FIFO control reg */ 1037 int fcr; /* FIFO control reg */
1018 int lcr; /* Line control reg */ 1038 int lcr; /* Line control reg */
1019 int divisor; 1039 int divisor;
@@ -1022,38 +1042,36 @@ void smsc_ircc_set_sir_speed(void *priv, __u32 speed)
1022 1042
1023 IRDA_ASSERT(self != NULL, return;); 1043 IRDA_ASSERT(self != NULL, return;);
1024 iobase = self->io.sir_base; 1044 iobase = self->io.sir_base;
1025 1045
1026 /* Update accounting for new speed */ 1046 /* Update accounting for new speed */
1027 self->io.speed = speed; 1047 self->io.speed = speed;
1028 1048
1029 /* Turn off interrupts */ 1049 /* Turn off interrupts */
1030 outb(0, iobase+UART_IER); 1050 outb(0, iobase + UART_IER);
1051
1052 divisor = SMSC_IRCC2_MAX_SIR_SPEED / speed;
1031 1053
1032 divisor = SMSC_IRCC2_MAX_SIR_SPEED/speed;
1033
1034 fcr = UART_FCR_ENABLE_FIFO; 1054 fcr = UART_FCR_ENABLE_FIFO;
1035 1055
1036 /* 1056 /*
1037 * Use trigger level 1 to avoid 3 ms. timeout delay at 9600 bps, and 1057 * Use trigger level 1 to avoid 3 ms. timeout delay at 9600 bps, and
1038 * almost 1,7 ms at 19200 bps. At speeds above that we can just forget 1058 * almost 1,7 ms at 19200 bps. At speeds above that we can just forget
1039 * about this timeout since it will always be fast enough. 1059 * about this timeout since it will always be fast enough.
1040 */ 1060 */
1041 if (self->io.speed < 38400) 1061 fcr |= self->io.speed < 38400 ?
1042 fcr |= UART_FCR_TRIGGER_1; 1062 UART_FCR_TRIGGER_1 : UART_FCR_TRIGGER_14;
1043 else 1063
1044 fcr |= UART_FCR_TRIGGER_14;
1045
1046 /* IrDA ports use 8N1 */ 1064 /* IrDA ports use 8N1 */
1047 lcr = UART_LCR_WLEN8; 1065 lcr = UART_LCR_WLEN8;
1048 1066
1049 outb(UART_LCR_DLAB | lcr, iobase+UART_LCR); /* Set DLAB */ 1067 outb(UART_LCR_DLAB | lcr, iobase + UART_LCR); /* Set DLAB */
1050 outb(divisor & 0xff, iobase+UART_DLL); /* Set speed */ 1068 outb(divisor & 0xff, iobase + UART_DLL); /* Set speed */
1051 outb(divisor >> 8, iobase+UART_DLM); 1069 outb(divisor >> 8, iobase + UART_DLM);
1052 outb(lcr, iobase+UART_LCR); /* Set 8N1 */ 1070 outb(lcr, iobase + UART_LCR); /* Set 8N1 */
1053 outb(fcr, iobase+UART_FCR); /* Enable FIFO's */ 1071 outb(fcr, iobase + UART_FCR); /* Enable FIFO's */
1054 1072
1055 /* Turn on interrups */ 1073 /* Turn on interrups */
1056 outb(UART_IER_RLSI|UART_IER_RDI|UART_IER_THRI, iobase+UART_IER); 1074 outb(UART_IER_RLSI | UART_IER_RDI | UART_IER_THRI, iobase + UART_IER);
1057 1075
1058 IRDA_DEBUG(2, "%s() speed changed to: %d\n", __FUNCTION__, speed); 1076 IRDA_DEBUG(2, "%s() speed changed to: %d\n", __FUNCTION__, speed);
1059} 1077}
@@ -1070,15 +1088,12 @@ static int smsc_ircc_hard_xmit_fir(struct sk_buff *skb, struct net_device *dev)
1070 struct smsc_ircc_cb *self; 1088 struct smsc_ircc_cb *self;
1071 unsigned long flags; 1089 unsigned long flags;
1072 s32 speed; 1090 s32 speed;
1073 int iobase;
1074 int mtt; 1091 int mtt;
1075 1092
1076 IRDA_ASSERT(dev != NULL, return 0;); 1093 IRDA_ASSERT(dev != NULL, return 0;);
1077 self = (struct smsc_ircc_cb *) dev->priv; 1094 self = netdev_priv(dev);
1078 IRDA_ASSERT(self != NULL, return 0;); 1095 IRDA_ASSERT(self != NULL, return 0;);
1079 1096
1080 iobase = self->io.fir_base;
1081
1082 netif_stop_queue(dev); 1097 netif_stop_queue(dev);
1083 1098
1084 /* Make sure test of self->io.speed & speed change are atomic */ 1099 /* Make sure test of self->io.speed & speed change are atomic */
@@ -1086,30 +1101,31 @@ static int smsc_ircc_hard_xmit_fir(struct sk_buff *skb, struct net_device *dev)
1086 1101
1087 /* Check if we need to change the speed after this frame */ 1102 /* Check if we need to change the speed after this frame */
1088 speed = irda_get_next_speed(skb); 1103 speed = irda_get_next_speed(skb);
1089 if ((speed != self->io.speed) && (speed != -1)) { 1104 if (speed != self->io.speed && speed != -1) {
1090 /* Check for empty frame */ 1105 /* Check for empty frame */
1091 if (!skb->len) { 1106 if (!skb->len) {
1092 /* Note : you should make sure that speed changes 1107 /* Note : you should make sure that speed changes
1093 * are not going to corrupt any outgoing frame. 1108 * are not going to corrupt any outgoing frame.
1094 * Look at nsc-ircc for the gory details - Jean II */ 1109 * Look at nsc-ircc for the gory details - Jean II */
1095 smsc_ircc_change_speed(self, speed); 1110 smsc_ircc_change_speed(self, speed);
1096 spin_unlock_irqrestore(&self->lock, flags); 1111 spin_unlock_irqrestore(&self->lock, flags);
1097 dev_kfree_skb(skb); 1112 dev_kfree_skb(skb);
1098 return 0; 1113 return 0;
1099 } else 1114 }
1100 self->new_speed = speed; 1115
1116 self->new_speed = speed;
1101 } 1117 }
1102 1118
1103 memcpy(self->tx_buff.head, skb->data, skb->len); 1119 memcpy(self->tx_buff.head, skb->data, skb->len);
1104 1120
1105 self->tx_buff.len = skb->len; 1121 self->tx_buff.len = skb->len;
1106 self->tx_buff.data = self->tx_buff.head; 1122 self->tx_buff.data = self->tx_buff.head;
1107 1123
1108 mtt = irda_get_mtt(skb); 1124 mtt = irda_get_mtt(skb);
1109 if (mtt) { 1125 if (mtt) {
1110 int bofs; 1126 int bofs;
1111 1127
1112 /* 1128 /*
1113 * Compute how many BOFs (STA or PA's) we need to waste the 1129 * Compute how many BOFs (STA or PA's) we need to waste the
1114 * min turn time given the speed of the link. 1130 * min turn time given the speed of the link.
1115 */ 1131 */
@@ -1117,11 +1133,12 @@ static int smsc_ircc_hard_xmit_fir(struct sk_buff *skb, struct net_device *dev)
1117 if (bofs > 4095) 1133 if (bofs > 4095)
1118 bofs = 4095; 1134 bofs = 4095;
1119 1135
1120 smsc_ircc_dma_xmit(self, iobase, bofs); 1136 smsc_ircc_dma_xmit(self, bofs);
1121 } else { 1137 } else {
1122 /* Transmit frame */ 1138 /* Transmit frame */
1123 smsc_ircc_dma_xmit(self, iobase, 0); 1139 smsc_ircc_dma_xmit(self, 0);
1124 } 1140 }
1141
1125 spin_unlock_irqrestore(&self->lock, flags); 1142 spin_unlock_irqrestore(&self->lock, flags);
1126 dev_kfree_skb(skb); 1143 dev_kfree_skb(skb);
1127 1144
@@ -1129,43 +1146,44 @@ static int smsc_ircc_hard_xmit_fir(struct sk_buff *skb, struct net_device *dev)
1129} 1146}
1130 1147
1131/* 1148/*
1132 * Function smsc_ircc_dma_xmit (self, iobase) 1149 * Function smsc_ircc_dma_xmit (self, bofs)
1133 * 1150 *
1134 * Transmit data using DMA 1151 * Transmit data using DMA
1135 * 1152 *
1136 */ 1153 */
1137static void smsc_ircc_dma_xmit(struct smsc_ircc_cb *self, int iobase, int bofs) 1154static void smsc_ircc_dma_xmit(struct smsc_ircc_cb *self, int bofs)
1138{ 1155{
1156 int iobase = self->io.fir_base;
1139 u8 ctrl; 1157 u8 ctrl;
1140 1158
1141 IRDA_DEBUG(3, "%s\n", __FUNCTION__); 1159 IRDA_DEBUG(3, "%s\n", __FUNCTION__);
1142#if 1 1160#if 1
1143 /* Disable Rx */ 1161 /* Disable Rx */
1144 register_bank(iobase, 0); 1162 register_bank(iobase, 0);
1145 outb(0x00, iobase+IRCC_LCR_B); 1163 outb(0x00, iobase + IRCC_LCR_B);
1146#endif 1164#endif
1147 register_bank(iobase, 1); 1165 register_bank(iobase, 1);
1148 outb(inb(iobase+IRCC_SCE_CFGB) & ~IRCC_CFGB_DMA_ENABLE, 1166 outb(inb(iobase + IRCC_SCE_CFGB) & ~IRCC_CFGB_DMA_ENABLE,
1149 iobase+IRCC_SCE_CFGB); 1167 iobase + IRCC_SCE_CFGB);
1150 1168
1151 self->io.direction = IO_XMIT; 1169 self->io.direction = IO_XMIT;
1152 1170
1153 /* Set BOF additional count for generating the min turn time */ 1171 /* Set BOF additional count for generating the min turn time */
1154 register_bank(iobase, 4); 1172 register_bank(iobase, 4);
1155 outb(bofs & 0xff, iobase+IRCC_BOF_COUNT_LO); 1173 outb(bofs & 0xff, iobase + IRCC_BOF_COUNT_LO);
1156 ctrl = inb(iobase+IRCC_CONTROL) & 0xf0; 1174 ctrl = inb(iobase + IRCC_CONTROL) & 0xf0;
1157 outb(ctrl | ((bofs >> 8) & 0x0f), iobase+IRCC_BOF_COUNT_HI); 1175 outb(ctrl | ((bofs >> 8) & 0x0f), iobase + IRCC_BOF_COUNT_HI);
1158 1176
1159 /* Set max Tx frame size */ 1177 /* Set max Tx frame size */
1160 outb(self->tx_buff.len >> 8, iobase+IRCC_TX_SIZE_HI); 1178 outb(self->tx_buff.len >> 8, iobase + IRCC_TX_SIZE_HI);
1161 outb(self->tx_buff.len & 0xff, iobase+IRCC_TX_SIZE_LO); 1179 outb(self->tx_buff.len & 0xff, iobase + IRCC_TX_SIZE_LO);
1162 1180
1163 /*outb(UART_MCR_OUT2, self->io.sir_base + UART_MCR);*/ 1181 /*outb(UART_MCR_OUT2, self->io.sir_base + UART_MCR);*/
1164 1182
1165 /* Enable burst mode chip Tx DMA */ 1183 /* Enable burst mode chip Tx DMA */
1166 register_bank(iobase, 1); 1184 register_bank(iobase, 1);
1167 outb(inb(iobase+IRCC_SCE_CFGB) | IRCC_CFGB_DMA_ENABLE | 1185 outb(inb(iobase + IRCC_SCE_CFGB) | IRCC_CFGB_DMA_ENABLE |
1168 IRCC_CFGB_DMA_BURST, iobase+IRCC_SCE_CFGB); 1186 IRCC_CFGB_DMA_BURST, iobase + IRCC_SCE_CFGB);
1169 1187
1170 /* Setup DMA controller (must be done after enabling chip DMA) */ 1188 /* Setup DMA controller (must be done after enabling chip DMA) */
1171 irda_setup_dma(self->io.dma, self->tx_buff_dma, self->tx_buff.len, 1189 irda_setup_dma(self->io.dma, self->tx_buff_dma, self->tx_buff.len,
@@ -1174,50 +1192,52 @@ static void smsc_ircc_dma_xmit(struct smsc_ircc_cb *self, int iobase, int bofs)
1174 /* Enable interrupt */ 1192 /* Enable interrupt */
1175 1193
1176 register_bank(iobase, 0); 1194 register_bank(iobase, 0);
1177 outb(IRCC_IER_ACTIVE_FRAME | IRCC_IER_EOM, iobase+IRCC_IER); 1195 outb(IRCC_IER_ACTIVE_FRAME | IRCC_IER_EOM, iobase + IRCC_IER);
1178 outb(IRCC_MASTER_INT_EN, iobase+IRCC_MASTER); 1196 outb(IRCC_MASTER_INT_EN, iobase + IRCC_MASTER);
1179 1197
1180 /* Enable transmit */ 1198 /* Enable transmit */
1181 outb(IRCC_LCR_B_SCE_TRANSMIT | IRCC_LCR_B_SIP_ENABLE, iobase+IRCC_LCR_B); 1199 outb(IRCC_LCR_B_SCE_TRANSMIT | IRCC_LCR_B_SIP_ENABLE, iobase + IRCC_LCR_B);
1182} 1200}
1183 1201
1184/* 1202/*
1185 * Function smsc_ircc_dma_xmit_complete (self) 1203 * Function smsc_ircc_dma_xmit_complete (self)
1186 * 1204 *
1187 * The transfer of a frame in finished. This function will only be called 1205 * The transfer of a frame in finished. This function will only be called
1188 * by the interrupt handler 1206 * by the interrupt handler
1189 * 1207 *
1190 */ 1208 */
1191static void smsc_ircc_dma_xmit_complete(struct smsc_ircc_cb *self, int iobase) 1209static void smsc_ircc_dma_xmit_complete(struct smsc_ircc_cb *self)
1192{ 1210{
1211 int iobase = self->io.fir_base;
1212
1193 IRDA_DEBUG(3, "%s\n", __FUNCTION__); 1213 IRDA_DEBUG(3, "%s\n", __FUNCTION__);
1194#if 0 1214#if 0
1195 /* Disable Tx */ 1215 /* Disable Tx */
1196 register_bank(iobase, 0); 1216 register_bank(iobase, 0);
1197 outb(0x00, iobase+IRCC_LCR_B); 1217 outb(0x00, iobase + IRCC_LCR_B);
1198#endif 1218#endif
1199 register_bank(self->io.fir_base, 1); 1219 register_bank(iobase, 1);
1200 outb(inb(self->io.fir_base+IRCC_SCE_CFGB) & ~IRCC_CFGB_DMA_ENABLE, 1220 outb(inb(iobase + IRCC_SCE_CFGB) & ~IRCC_CFGB_DMA_ENABLE,
1201 self->io.fir_base+IRCC_SCE_CFGB); 1221 iobase + IRCC_SCE_CFGB);
1202 1222
1203 /* Check for underrun! */ 1223 /* Check for underrun! */
1204 register_bank(iobase, 0); 1224 register_bank(iobase, 0);
1205 if (inb(iobase+IRCC_LSR) & IRCC_LSR_UNDERRUN) { 1225 if (inb(iobase + IRCC_LSR) & IRCC_LSR_UNDERRUN) {
1206 self->stats.tx_errors++; 1226 self->stats.tx_errors++;
1207 self->stats.tx_fifo_errors++; 1227 self->stats.tx_fifo_errors++;
1208 1228
1209 /* Reset error condition */ 1229 /* Reset error condition */
1210 register_bank(iobase, 0); 1230 register_bank(iobase, 0);
1211 outb(IRCC_MASTER_ERROR_RESET, iobase+IRCC_MASTER); 1231 outb(IRCC_MASTER_ERROR_RESET, iobase + IRCC_MASTER);
1212 outb(0x00, iobase+IRCC_MASTER); 1232 outb(0x00, iobase + IRCC_MASTER);
1213 } else { 1233 } else {
1214 self->stats.tx_packets++; 1234 self->stats.tx_packets++;
1215 self->stats.tx_bytes += self->tx_buff.len; 1235 self->stats.tx_bytes += self->tx_buff.len;
1216 } 1236 }
1217 1237
1218 /* Check if it's time to change the speed */ 1238 /* Check if it's time to change the speed */
1219 if (self->new_speed) { 1239 if (self->new_speed) {
1220 smsc_ircc_change_speed(self, self->new_speed); 1240 smsc_ircc_change_speed(self, self->new_speed);
1221 self->new_speed = 0; 1241 self->new_speed = 0;
1222 } 1242 }
1223 1243
@@ -1231,31 +1251,32 @@ static void smsc_ircc_dma_xmit_complete(struct smsc_ircc_cb *self, int iobase)
1231 * if it starts to receive a frame. 1251 * if it starts to receive a frame.
1232 * 1252 *
1233 */ 1253 */
1234static int smsc_ircc_dma_receive(struct smsc_ircc_cb *self, int iobase) 1254static int smsc_ircc_dma_receive(struct smsc_ircc_cb *self)
1235{ 1255{
1256 int iobase = self->io.fir_base;
1236#if 0 1257#if 0
1237 /* Turn off chip DMA */ 1258 /* Turn off chip DMA */
1238 register_bank(iobase, 1); 1259 register_bank(iobase, 1);
1239 outb(inb(iobase+IRCC_SCE_CFGB) & ~IRCC_CFGB_DMA_ENABLE, 1260 outb(inb(iobase + IRCC_SCE_CFGB) & ~IRCC_CFGB_DMA_ENABLE,
1240 iobase+IRCC_SCE_CFGB); 1261 iobase + IRCC_SCE_CFGB);
1241#endif 1262#endif
1242 1263
1243 /* Disable Tx */ 1264 /* Disable Tx */
1244 register_bank(iobase, 0); 1265 register_bank(iobase, 0);
1245 outb(0x00, iobase+IRCC_LCR_B); 1266 outb(0x00, iobase + IRCC_LCR_B);
1246 1267
1247 /* Turn off chip DMA */ 1268 /* Turn off chip DMA */
1248 register_bank(iobase, 1); 1269 register_bank(iobase, 1);
1249 outb(inb(iobase+IRCC_SCE_CFGB) & ~IRCC_CFGB_DMA_ENABLE, 1270 outb(inb(iobase + IRCC_SCE_CFGB) & ~IRCC_CFGB_DMA_ENABLE,
1250 iobase+IRCC_SCE_CFGB); 1271 iobase + IRCC_SCE_CFGB);
1251 1272
1252 self->io.direction = IO_RECV; 1273 self->io.direction = IO_RECV;
1253 self->rx_buff.data = self->rx_buff.head; 1274 self->rx_buff.data = self->rx_buff.head;
1254 1275
1255 /* Set max Rx frame size */ 1276 /* Set max Rx frame size */
1256 register_bank(iobase, 4); 1277 register_bank(iobase, 4);
1257 outb((2050 >> 8) & 0x0f, iobase+IRCC_RX_SIZE_HI); 1278 outb((2050 >> 8) & 0x0f, iobase + IRCC_RX_SIZE_HI);
1258 outb(2050 & 0xff, iobase+IRCC_RX_SIZE_LO); 1279 outb(2050 & 0xff, iobase + IRCC_RX_SIZE_LO);
1259 1280
1260 /* Setup DMA controller */ 1281 /* Setup DMA controller */
1261 irda_setup_dma(self->io.dma, self->rx_buff_dma, self->rx_buff.truesize, 1282 irda_setup_dma(self->io.dma, self->rx_buff_dma, self->rx_buff.truesize,
@@ -1263,83 +1284,83 @@ static int smsc_ircc_dma_receive(struct smsc_ircc_cb *self, int iobase)
1263 1284
1264 /* Enable burst mode chip Rx DMA */ 1285 /* Enable burst mode chip Rx DMA */
1265 register_bank(iobase, 1); 1286 register_bank(iobase, 1);
1266 outb(inb(iobase+IRCC_SCE_CFGB) | IRCC_CFGB_DMA_ENABLE | 1287 outb(inb(iobase + IRCC_SCE_CFGB) | IRCC_CFGB_DMA_ENABLE |
1267 IRCC_CFGB_DMA_BURST, iobase+IRCC_SCE_CFGB); 1288 IRCC_CFGB_DMA_BURST, iobase + IRCC_SCE_CFGB);
1268 1289
1269 /* Enable interrupt */ 1290 /* Enable interrupt */
1270 register_bank(iobase, 0); 1291 register_bank(iobase, 0);
1271 outb(IRCC_IER_ACTIVE_FRAME | IRCC_IER_EOM, iobase+IRCC_IER); 1292 outb(IRCC_IER_ACTIVE_FRAME | IRCC_IER_EOM, iobase + IRCC_IER);
1272 outb(IRCC_MASTER_INT_EN, iobase+IRCC_MASTER); 1293 outb(IRCC_MASTER_INT_EN, iobase + IRCC_MASTER);
1273
1274 1294
1275 /* Enable receiver */ 1295 /* Enable receiver */
1276 register_bank(iobase, 0); 1296 register_bank(iobase, 0);
1277 outb(IRCC_LCR_B_SCE_RECEIVE | IRCC_LCR_B_SIP_ENABLE, 1297 outb(IRCC_LCR_B_SCE_RECEIVE | IRCC_LCR_B_SIP_ENABLE,
1278 iobase+IRCC_LCR_B); 1298 iobase + IRCC_LCR_B);
1279 1299
1280 return 0; 1300 return 0;
1281} 1301}
1282 1302
1283/* 1303/*
1284 * Function smsc_ircc_dma_receive_complete(self, iobase) 1304 * Function smsc_ircc_dma_receive_complete(self)
1285 * 1305 *
1286 * Finished with receiving frames 1306 * Finished with receiving frames
1287 * 1307 *
1288 */ 1308 */
1289static void smsc_ircc_dma_receive_complete(struct smsc_ircc_cb *self, int iobase) 1309static void smsc_ircc_dma_receive_complete(struct smsc_ircc_cb *self)
1290{ 1310{
1291 struct sk_buff *skb; 1311 struct sk_buff *skb;
1292 int len, msgcnt, lsr; 1312 int len, msgcnt, lsr;
1293 1313 int iobase = self->io.fir_base;
1314
1294 register_bank(iobase, 0); 1315 register_bank(iobase, 0);
1295 1316
1296 IRDA_DEBUG(3, "%s\n", __FUNCTION__); 1317 IRDA_DEBUG(3, "%s\n", __FUNCTION__);
1297#if 0 1318#if 0
1298 /* Disable Rx */ 1319 /* Disable Rx */
1299 register_bank(iobase, 0); 1320 register_bank(iobase, 0);
1300 outb(0x00, iobase+IRCC_LCR_B); 1321 outb(0x00, iobase + IRCC_LCR_B);
1301#endif 1322#endif
1302 register_bank(iobase, 0); 1323 register_bank(iobase, 0);
1303 outb(inb(iobase+IRCC_LSAR) & ~IRCC_LSAR_ADDRESS_MASK, iobase+IRCC_LSAR); 1324 outb(inb(iobase + IRCC_LSAR) & ~IRCC_LSAR_ADDRESS_MASK, iobase + IRCC_LSAR);
1304 lsr= inb(iobase+IRCC_LSR); 1325 lsr= inb(iobase + IRCC_LSR);
1305 msgcnt = inb(iobase+IRCC_LCR_B) & 0x08; 1326 msgcnt = inb(iobase + IRCC_LCR_B) & 0x08;
1306 1327
1307 IRDA_DEBUG(2, "%s: dma count = %d\n", __FUNCTION__, 1328 IRDA_DEBUG(2, "%s: dma count = %d\n", __FUNCTION__,
1308 get_dma_residue(self->io.dma)); 1329 get_dma_residue(self->io.dma));
1309 1330
1310 len = self->rx_buff.truesize - get_dma_residue(self->io.dma); 1331 len = self->rx_buff.truesize - get_dma_residue(self->io.dma);
1311 1332
1312 /* Look for errors 1333 /* Look for errors */
1313 */ 1334 if (lsr & (IRCC_LSR_FRAME_ERROR | IRCC_LSR_CRC_ERROR | IRCC_LSR_SIZE_ERROR)) {
1314
1315 if(lsr & (IRCC_LSR_FRAME_ERROR | IRCC_LSR_CRC_ERROR | IRCC_LSR_SIZE_ERROR)) {
1316 self->stats.rx_errors++; 1335 self->stats.rx_errors++;
1317 if(lsr & IRCC_LSR_FRAME_ERROR) self->stats.rx_frame_errors++; 1336 if (lsr & IRCC_LSR_FRAME_ERROR)
1318 if(lsr & IRCC_LSR_CRC_ERROR) self->stats.rx_crc_errors++; 1337 self->stats.rx_frame_errors++;
1319 if(lsr & IRCC_LSR_SIZE_ERROR) self->stats.rx_length_errors++; 1338 if (lsr & IRCC_LSR_CRC_ERROR)
1320 if(lsr & (IRCC_LSR_UNDERRUN | IRCC_LSR_OVERRUN)) self->stats.rx_length_errors++; 1339 self->stats.rx_crc_errors++;
1340 if (lsr & IRCC_LSR_SIZE_ERROR)
1341 self->stats.rx_length_errors++;
1342 if (lsr & (IRCC_LSR_UNDERRUN | IRCC_LSR_OVERRUN))
1343 self->stats.rx_length_errors++;
1321 return; 1344 return;
1322 } 1345 }
1346
1323 /* Remove CRC */ 1347 /* Remove CRC */
1324 if (self->io.speed < 4000000) 1348 len -= self->io.speed < 4000000 ? 2 : 4;
1325 len -= 2;
1326 else
1327 len -= 4;
1328 1349
1329 if ((len < 2) || (len > 2050)) { 1350 if (len < 2 || len > 2050) {
1330 IRDA_WARNING("%s(), bogus len=%d\n", __FUNCTION__, len); 1351 IRDA_WARNING("%s(), bogus len=%d\n", __FUNCTION__, len);
1331 return; 1352 return;
1332 } 1353 }
1333 IRDA_DEBUG(2, "%s: msgcnt = %d, len=%d\n", __FUNCTION__, msgcnt, len); 1354 IRDA_DEBUG(2, "%s: msgcnt = %d, len=%d\n", __FUNCTION__, msgcnt, len);
1334 1355
1335 skb = dev_alloc_skb(len+1); 1356 skb = dev_alloc_skb(len + 1);
1336 if (!skb) { 1357 if (!skb) {
1337 IRDA_WARNING("%s(), memory squeeze, dropping frame.\n", 1358 IRDA_WARNING("%s(), memory squeeze, dropping frame.\n",
1338 __FUNCTION__); 1359 __FUNCTION__);
1339 return; 1360 return;
1340 } 1361 }
1341 /* Make sure IP header gets aligned */ 1362 /* Make sure IP header gets aligned */
1342 skb_reserve(skb, 1); 1363 skb_reserve(skb, 1);
1343 1364
1344 memcpy(skb_put(skb, len), self->rx_buff.data, len); 1365 memcpy(skb_put(skb, len), self->rx_buff.data, len);
1345 self->stats.rx_packets++; 1366 self->stats.rx_packets++;
@@ -1357,7 +1378,7 @@ static void smsc_ircc_dma_receive_complete(struct smsc_ircc_cb *self, int iobase
1357 * Receive one frame from the infrared port 1378 * Receive one frame from the infrared port
1358 * 1379 *
1359 */ 1380 */
1360static void smsc_ircc_sir_receive(struct smsc_ircc_cb *self) 1381static void smsc_ircc_sir_receive(struct smsc_ircc_cb *self)
1361{ 1382{
1362 int boguscount = 0; 1383 int boguscount = 0;
1363 int iobase; 1384 int iobase;
@@ -1366,20 +1387,20 @@ static void smsc_ircc_sir_receive(struct smsc_ircc_cb *self)
1366 1387
1367 iobase = self->io.sir_base; 1388 iobase = self->io.sir_base;
1368 1389
1369 /* 1390 /*
1370 * Receive all characters in Rx FIFO, unwrap and unstuff them. 1391 * Receive all characters in Rx FIFO, unwrap and unstuff them.
1371 * async_unwrap_char will deliver all found frames 1392 * async_unwrap_char will deliver all found frames
1372 */ 1393 */
1373 do { 1394 do {
1374 async_unwrap_char(self->netdev, &self->stats, &self->rx_buff, 1395 async_unwrap_char(self->netdev, &self->stats, &self->rx_buff,
1375 inb(iobase+UART_RX)); 1396 inb(iobase + UART_RX));
1376 1397
1377 /* Make sure we don't stay here to long */ 1398 /* Make sure we don't stay here to long */
1378 if (boguscount++ > 32) { 1399 if (boguscount++ > 32) {
1379 IRDA_DEBUG(2, "%s(), breaking!\n", __FUNCTION__); 1400 IRDA_DEBUG(2, "%s(), breaking!\n", __FUNCTION__);
1380 break; 1401 break;
1381 } 1402 }
1382 } while (inb(iobase+UART_LSR) & UART_LSR_DR); 1403 } while (inb(iobase + UART_LSR) & UART_LSR_DR);
1383} 1404}
1384 1405
1385 1406
@@ -1397,18 +1418,19 @@ static irqreturn_t smsc_ircc_interrupt(int irq, void *dev_id, struct pt_regs *re
1397 irqreturn_t ret = IRQ_NONE; 1418 irqreturn_t ret = IRQ_NONE;
1398 1419
1399 if (dev == NULL) { 1420 if (dev == NULL) {
1400 printk(KERN_WARNING "%s: irq %d for unknown device.\n", 1421 printk(KERN_WARNING "%s: irq %d for unknown device.\n",
1401 driver_name, irq); 1422 driver_name, irq);
1402 goto irq_ret; 1423 goto irq_ret;
1403 } 1424 }
1404 self = (struct smsc_ircc_cb *) dev->priv; 1425
1426 self = netdev_priv(dev);
1405 IRDA_ASSERT(self != NULL, return IRQ_NONE;); 1427 IRDA_ASSERT(self != NULL, return IRQ_NONE;);
1406 1428
1407 /* Serialise the interrupt handler in various CPUs, stop Tx path */ 1429 /* Serialise the interrupt handler in various CPUs, stop Tx path */
1408 spin_lock(&self->lock); 1430 spin_lock(&self->lock);
1409 1431
1410 /* Check if we should use the SIR interrupt handler */ 1432 /* Check if we should use the SIR interrupt handler */
1411 if (self->io.speed <= SMSC_IRCC2_MAX_SIR_SPEED) { 1433 if (self->io.speed <= SMSC_IRCC2_MAX_SIR_SPEED) {
1412 ret = smsc_ircc_interrupt_sir(dev); 1434 ret = smsc_ircc_interrupt_sir(dev);
1413 goto irq_ret_unlock; 1435 goto irq_ret_unlock;
1414 } 1436 }
@@ -1416,25 +1438,25 @@ static irqreturn_t smsc_ircc_interrupt(int irq, void *dev_id, struct pt_regs *re
1416 iobase = self->io.fir_base; 1438 iobase = self->io.fir_base;
1417 1439
1418 register_bank(iobase, 0); 1440 register_bank(iobase, 0);
1419 iir = inb(iobase+IRCC_IIR); 1441 iir = inb(iobase + IRCC_IIR);
1420 if (iir == 0) 1442 if (iir == 0)
1421 goto irq_ret_unlock; 1443 goto irq_ret_unlock;
1422 ret = IRQ_HANDLED; 1444 ret = IRQ_HANDLED;
1423 1445
1424 /* Disable interrupts */ 1446 /* Disable interrupts */
1425 outb(0, iobase+IRCC_IER); 1447 outb(0, iobase + IRCC_IER);
1426 lcra = inb(iobase+IRCC_LCR_A); 1448 lcra = inb(iobase + IRCC_LCR_A);
1427 lsr = inb(iobase+IRCC_LSR); 1449 lsr = inb(iobase + IRCC_LSR);
1428 1450
1429 IRDA_DEBUG(2, "%s(), iir = 0x%02x\n", __FUNCTION__, iir); 1451 IRDA_DEBUG(2, "%s(), iir = 0x%02x\n", __FUNCTION__, iir);
1430 1452
1431 if (iir & IRCC_IIR_EOM) { 1453 if (iir & IRCC_IIR_EOM) {
1432 if (self->io.direction == IO_RECV) 1454 if (self->io.direction == IO_RECV)
1433 smsc_ircc_dma_receive_complete(self, iobase); 1455 smsc_ircc_dma_receive_complete(self);
1434 else 1456 else
1435 smsc_ircc_dma_xmit_complete(self, iobase); 1457 smsc_ircc_dma_xmit_complete(self);
1436 1458
1437 smsc_ircc_dma_receive(self, iobase); 1459 smsc_ircc_dma_receive(self);
1438 } 1460 }
1439 1461
1440 if (iir & IRCC_IIR_ACTIVE_FRAME) { 1462 if (iir & IRCC_IIR_ACTIVE_FRAME) {
@@ -1444,7 +1466,7 @@ static irqreturn_t smsc_ircc_interrupt(int irq, void *dev_id, struct pt_regs *re
1444 /* Enable interrupts again */ 1466 /* Enable interrupts again */
1445 1467
1446 register_bank(iobase, 0); 1468 register_bank(iobase, 0);
1447 outb(IRCC_IER_ACTIVE_FRAME|IRCC_IER_EOM, iobase+IRCC_IER); 1469 outb(IRCC_IER_ACTIVE_FRAME | IRCC_IER_EOM, iobase + IRCC_IER);
1448 1470
1449 irq_ret_unlock: 1471 irq_ret_unlock:
1450 spin_unlock(&self->lock); 1472 spin_unlock(&self->lock);
@@ -1459,7 +1481,7 @@ static irqreturn_t smsc_ircc_interrupt(int irq, void *dev_id, struct pt_regs *re
1459 */ 1481 */
1460static irqreturn_t smsc_ircc_interrupt_sir(struct net_device *dev) 1482static irqreturn_t smsc_ircc_interrupt_sir(struct net_device *dev)
1461{ 1483{
1462 struct smsc_ircc_cb *self = dev->priv; 1484 struct smsc_ircc_cb *self = netdev_priv(dev);
1463 int boguscount = 0; 1485 int boguscount = 0;
1464 int iobase; 1486 int iobase;
1465 int iir, lsr; 1487 int iir, lsr;
@@ -1469,14 +1491,14 @@ static irqreturn_t smsc_ircc_interrupt_sir(struct net_device *dev)
1469 1491
1470 iobase = self->io.sir_base; 1492 iobase = self->io.sir_base;
1471 1493
1472 iir = inb(iobase+UART_IIR) & UART_IIR_ID; 1494 iir = inb(iobase + UART_IIR) & UART_IIR_ID;
1473 if (iir == 0) 1495 if (iir == 0)
1474 return IRQ_NONE; 1496 return IRQ_NONE;
1475 while (iir) { 1497 while (iir) {
1476 /* Clear interrupt */ 1498 /* Clear interrupt */
1477 lsr = inb(iobase+UART_LSR); 1499 lsr = inb(iobase + UART_LSR);
1478 1500
1479 IRDA_DEBUG(4, "%s(), iir=%02x, lsr=%02x, iobase=%#x\n", 1501 IRDA_DEBUG(4, "%s(), iir=%02x, lsr=%02x, iobase=%#x\n",
1480 __FUNCTION__, iir, lsr, iobase); 1502 __FUNCTION__, iir, lsr, iobase);
1481 1503
1482 switch (iir) { 1504 switch (iir) {
@@ -1496,13 +1518,13 @@ static irqreturn_t smsc_ircc_interrupt_sir(struct net_device *dev)
1496 IRDA_DEBUG(0, "%s(), unhandled IIR=%#x\n", 1518 IRDA_DEBUG(0, "%s(), unhandled IIR=%#x\n",
1497 __FUNCTION__, iir); 1519 __FUNCTION__, iir);
1498 break; 1520 break;
1499 } 1521 }
1500 1522
1501 /* Make sure we don't stay here to long */ 1523 /* Make sure we don't stay here to long */
1502 if (boguscount++ > 100) 1524 if (boguscount++ > 100)
1503 break; 1525 break;
1504 1526
1505 iir = inb(iobase + UART_IIR) & UART_IIR_ID; 1527 iir = inb(iobase + UART_IIR) & UART_IIR_ID;
1506 } 1528 }
1507 /*spin_unlock(&self->lock);*/ 1529 /*spin_unlock(&self->lock);*/
1508 return IRQ_HANDLED; 1530 return IRQ_HANDLED;
@@ -1529,7 +1551,7 @@ static int ircc_is_receiving(struct smsc_ircc_cb *self)
1529 get_dma_residue(self->io.dma)); 1551 get_dma_residue(self->io.dma));
1530 1552
1531 status = (self->rx_buff.state != OUTSIDE_FRAME); 1553 status = (self->rx_buff.state != OUTSIDE_FRAME);
1532 1554
1533 return status; 1555 return status;
1534} 1556}
1535#endif /* unused */ 1557#endif /* unused */
@@ -1544,19 +1566,16 @@ static int ircc_is_receiving(struct smsc_ircc_cb *self)
1544static int smsc_ircc_net_open(struct net_device *dev) 1566static int smsc_ircc_net_open(struct net_device *dev)
1545{ 1567{
1546 struct smsc_ircc_cb *self; 1568 struct smsc_ircc_cb *self;
1547 int iobase;
1548 char hwname[16]; 1569 char hwname[16];
1549 unsigned long flags; 1570 unsigned long flags;
1550 1571
1551 IRDA_DEBUG(1, "%s\n", __FUNCTION__); 1572 IRDA_DEBUG(1, "%s\n", __FUNCTION__);
1552 1573
1553 IRDA_ASSERT(dev != NULL, return -1;); 1574 IRDA_ASSERT(dev != NULL, return -1;);
1554 self = (struct smsc_ircc_cb *) dev->priv; 1575 self = netdev_priv(dev);
1555 IRDA_ASSERT(self != NULL, return 0;); 1576 IRDA_ASSERT(self != NULL, return 0;);
1556
1557 iobase = self->io.fir_base;
1558 1577
1559 if (request_irq(self->io.irq, smsc_ircc_interrupt, 0, dev->name, 1578 if (request_irq(self->io.irq, smsc_ircc_interrupt, 0, dev->name,
1560 (void *) dev)) { 1579 (void *) dev)) {
1561 IRDA_DEBUG(0, "%s(), unable to allocate irq=%d\n", 1580 IRDA_DEBUG(0, "%s(), unable to allocate irq=%d\n",
1562 __FUNCTION__, self->io.irq); 1581 __FUNCTION__, self->io.irq);
@@ -1568,14 +1587,14 @@ static int smsc_ircc_net_open(struct net_device *dev)
1568 self->io.speed = 0; 1587 self->io.speed = 0;
1569 smsc_ircc_change_speed(self, SMSC_IRCC2_C_IRDA_FALLBACK_SPEED); 1588 smsc_ircc_change_speed(self, SMSC_IRCC2_C_IRDA_FALLBACK_SPEED);
1570 spin_unlock_irqrestore(&self->lock, flags); 1589 spin_unlock_irqrestore(&self->lock, flags);
1571 1590
1572 /* Give self a hardware name */ 1591 /* Give self a hardware name */
1573 /* It would be cool to offer the chip revision here - Jean II */ 1592 /* It would be cool to offer the chip revision here - Jean II */
1574 sprintf(hwname, "SMSC @ 0x%03x", self->io.fir_base); 1593 sprintf(hwname, "SMSC @ 0x%03x", self->io.fir_base);
1575 1594
1576 /* 1595 /*
1577 * Open new IrLAP layer instance, now that everything should be 1596 * Open new IrLAP layer instance, now that everything should be
1578 * initialized properly 1597 * initialized properly
1579 */ 1598 */
1580 self->irlap = irlap_open(dev, &self->qos, hwname); 1599 self->irlap = irlap_open(dev, &self->qos, hwname);
1581 1600
@@ -1590,7 +1609,7 @@ static int smsc_ircc_net_open(struct net_device *dev)
1590 __FUNCTION__, self->io.dma); 1609 __FUNCTION__, self->io.dma);
1591 return -EAGAIN; 1610 return -EAGAIN;
1592 } 1611 }
1593 1612
1594 netif_start_queue(dev); 1613 netif_start_queue(dev);
1595 1614
1596 return 0; 1615 return 0;
@@ -1605,73 +1624,53 @@ static int smsc_ircc_net_open(struct net_device *dev)
1605static int smsc_ircc_net_close(struct net_device *dev) 1624static int smsc_ircc_net_close(struct net_device *dev)
1606{ 1625{
1607 struct smsc_ircc_cb *self; 1626 struct smsc_ircc_cb *self;
1608 int iobase;
1609 1627
1610 IRDA_DEBUG(1, "%s\n", __FUNCTION__); 1628 IRDA_DEBUG(1, "%s\n", __FUNCTION__);
1611 1629
1612 IRDA_ASSERT(dev != NULL, return -1;); 1630 IRDA_ASSERT(dev != NULL, return -1;);
1613 self = (struct smsc_ircc_cb *) dev->priv; 1631 self = netdev_priv(dev);
1614 IRDA_ASSERT(self != NULL, return 0;); 1632 IRDA_ASSERT(self != NULL, return 0;);
1615
1616 iobase = self->io.fir_base;
1617 1633
1618 /* Stop device */ 1634 /* Stop device */
1619 netif_stop_queue(dev); 1635 netif_stop_queue(dev);
1620 1636
1621 /* Stop and remove instance of IrLAP */ 1637 /* Stop and remove instance of IrLAP */
1622 if (self->irlap) 1638 if (self->irlap)
1623 irlap_close(self->irlap); 1639 irlap_close(self->irlap);
1624 self->irlap = NULL; 1640 self->irlap = NULL;
1625 1641
1626 free_irq(self->io.irq, dev); 1642 free_irq(self->io.irq, dev);
1627
1628 disable_dma(self->io.dma); 1643 disable_dma(self->io.dma);
1629
1630 free_dma(self->io.dma); 1644 free_dma(self->io.dma);
1631 1645
1632 return 0; 1646 return 0;
1633} 1647}
1634 1648
1635 1649static int smsc_ircc_suspend(struct device *dev, pm_message_t state, u32 level)
1636static void smsc_ircc_suspend(struct smsc_ircc_cb *self)
1637{ 1650{
1638 IRDA_MESSAGE("%s, Suspending\n", driver_name); 1651 struct smsc_ircc_cb *self = dev_get_drvdata(dev);
1639 1652
1640 if (self->io.suspended) 1653 IRDA_MESSAGE("%s, Suspending\n", driver_name);
1641 return;
1642 1654
1643 smsc_ircc_net_close(self->netdev); 1655 if (level == SUSPEND_DISABLE && !self->io.suspended) {
1656 smsc_ircc_net_close(self->netdev);
1657 self->io.suspended = 1;
1658 }
1644 1659
1645 self->io.suspended = 1; 1660 return 0;
1646} 1661}
1647 1662
1648static void smsc_ircc_wakeup(struct smsc_ircc_cb *self) 1663static int smsc_ircc_resume(struct device *dev, u32 level)
1649{ 1664{
1650 if (!self->io.suspended) 1665 struct smsc_ircc_cb *self = dev_get_drvdata(dev);
1651 return;
1652 1666
1653 /* The code was doing a "cli()" here, but this can't be right. 1667 if (level == RESUME_ENABLE && self->io.suspended) {
1654 * If you need protection, do it in net_open with a spinlock
1655 * or give a good reason. - Jean II */
1656 1668
1657 smsc_ircc_net_open(self->netdev); 1669 smsc_ircc_net_open(self->netdev);
1658 1670 self->io.suspended = 0;
1659 IRDA_MESSAGE("%s, Waking up\n", driver_name);
1660}
1661 1671
1662static int smsc_ircc_pmproc(struct pm_dev *dev, pm_request_t rqst, void *data) 1672 IRDA_MESSAGE("%s, Waking up\n", driver_name);
1663{ 1673 }
1664 struct smsc_ircc_cb *self = (struct smsc_ircc_cb*) dev->data;
1665 if (self) {
1666 switch (rqst) {
1667 case PM_SUSPEND:
1668 smsc_ircc_suspend(self);
1669 break;
1670 case PM_RESUME:
1671 smsc_ircc_wakeup(self);
1672 break;
1673 }
1674 }
1675 return 0; 1674 return 0;
1676} 1675}
1677 1676
@@ -1690,10 +1689,7 @@ static int __exit smsc_ircc_close(struct smsc_ircc_cb *self)
1690 1689
1691 IRDA_ASSERT(self != NULL, return -1;); 1690 IRDA_ASSERT(self != NULL, return -1;);
1692 1691
1693 iobase = self->io.fir_base; 1692 platform_device_unregister(self->pldev);
1694
1695 if (self->pmdev)
1696 pm_unregister(self->pmdev);
1697 1693
1698 /* Remove netdevice */ 1694 /* Remove netdevice */
1699 unregister_netdev(self->netdev); 1695 unregister_netdev(self->netdev);
@@ -1702,15 +1698,16 @@ static int __exit smsc_ircc_close(struct smsc_ircc_cb *self)
1702 spin_lock_irqsave(&self->lock, flags); 1698 spin_lock_irqsave(&self->lock, flags);
1703 1699
1704 /* Stop interrupts */ 1700 /* Stop interrupts */
1701 iobase = self->io.fir_base;
1705 register_bank(iobase, 0); 1702 register_bank(iobase, 0);
1706 outb(0, iobase+IRCC_IER); 1703 outb(0, iobase + IRCC_IER);
1707 outb(IRCC_MASTER_RESET, iobase+IRCC_MASTER); 1704 outb(IRCC_MASTER_RESET, iobase + IRCC_MASTER);
1708 outb(0x00, iobase+IRCC_MASTER); 1705 outb(0x00, iobase + IRCC_MASTER);
1709#if 0 1706#if 0
1710 /* Reset to SIR mode */ 1707 /* Reset to SIR mode */
1711 register_bank(iobase, 1); 1708 register_bank(iobase, 1);
1712 outb(IRCC_CFGA_IRDA_SIR_A|IRCC_CFGA_TX_POLARITY, iobase+IRCC_SCE_CFGA); 1709 outb(IRCC_CFGA_IRDA_SIR_A|IRCC_CFGA_TX_POLARITY, iobase + IRCC_SCE_CFGA);
1713 outb(IRCC_CFGB_IR, iobase+IRCC_SCE_CFGB); 1710 outb(IRCC_CFGB_IR, iobase + IRCC_SCE_CFGB);
1714#endif 1711#endif
1715 spin_unlock_irqrestore(&self->lock, flags); 1712 spin_unlock_irqrestore(&self->lock, flags);
1716 1713
@@ -1720,7 +1717,7 @@ static int __exit smsc_ircc_close(struct smsc_ircc_cb *self)
1720 1717
1721 release_region(self->io.fir_base, self->io.fir_ext); 1718 release_region(self->io.fir_base, self->io.fir_ext);
1722 1719
1723 IRDA_DEBUG(0, "%s(), releasing 0x%03x\n", __FUNCTION__, 1720 IRDA_DEBUG(0, "%s(), releasing 0x%03x\n", __FUNCTION__,
1724 self->io.sir_base); 1721 self->io.sir_base);
1725 1722
1726 release_region(self->io.sir_base, self->io.sir_ext); 1723 release_region(self->io.sir_base, self->io.sir_ext);
@@ -1728,7 +1725,7 @@ static int __exit smsc_ircc_close(struct smsc_ircc_cb *self)
1728 if (self->tx_buff.head) 1725 if (self->tx_buff.head)
1729 dma_free_coherent(NULL, self->tx_buff.truesize, 1726 dma_free_coherent(NULL, self->tx_buff.truesize,
1730 self->tx_buff.head, self->tx_buff_dma); 1727 self->tx_buff.head, self->tx_buff_dma);
1731 1728
1732 if (self->rx_buff.head) 1729 if (self->rx_buff.head)
1733 dma_free_coherent(NULL, self->rx_buff.truesize, 1730 dma_free_coherent(NULL, self->rx_buff.truesize,
1734 self->rx_buff.head, self->rx_buff_dma); 1731 self->rx_buff.head, self->rx_buff_dma);
@@ -1744,10 +1741,12 @@ static void __exit smsc_ircc_cleanup(void)
1744 1741
1745 IRDA_DEBUG(1, "%s\n", __FUNCTION__); 1742 IRDA_DEBUG(1, "%s\n", __FUNCTION__);
1746 1743
1747 for (i=0; i < 2; i++) { 1744 for (i = 0; i < 2; i++) {
1748 if (dev_self[i]) 1745 if (dev_self[i])
1749 smsc_ircc_close(dev_self[i]); 1746 smsc_ircc_close(dev_self[i]);
1750 } 1747 }
1748
1749 driver_unregister(&smsc_ircc_driver);
1751} 1750}
1752 1751
1753/* 1752/*
@@ -1763,34 +1762,34 @@ void smsc_ircc_sir_start(struct smsc_ircc_cb *self)
1763 1762
1764 IRDA_DEBUG(3, "%s\n", __FUNCTION__); 1763 IRDA_DEBUG(3, "%s\n", __FUNCTION__);
1765 1764
1766 IRDA_ASSERT(self != NULL, return;); 1765 IRDA_ASSERT(self != NULL, return;);
1767 dev= self->netdev; 1766 dev = self->netdev;
1768 IRDA_ASSERT(dev != NULL, return;); 1767 IRDA_ASSERT(dev != NULL, return;);
1769 dev->hard_start_xmit = &smsc_ircc_hard_xmit_sir; 1768 dev->hard_start_xmit = &smsc_ircc_hard_xmit_sir;
1770 1769
1771 fir_base = self->io.fir_base; 1770 fir_base = self->io.fir_base;
1772 sir_base = self->io.sir_base; 1771 sir_base = self->io.sir_base;
1773 1772
1774 /* Reset everything */ 1773 /* Reset everything */
1775 outb(IRCC_MASTER_RESET, fir_base+IRCC_MASTER); 1774 outb(IRCC_MASTER_RESET, fir_base + IRCC_MASTER);
1776 1775
1777 #if SMSC_IRCC2_C_SIR_STOP 1776 #if SMSC_IRCC2_C_SIR_STOP
1778 /*smsc_ircc_sir_stop(self);*/ 1777 /*smsc_ircc_sir_stop(self);*/
1779 #endif 1778 #endif
1780 1779
1781 register_bank(fir_base, 1); 1780 register_bank(fir_base, 1);
1782 outb(((inb(fir_base+IRCC_SCE_CFGA) & IRCC_SCE_CFGA_BLOCK_CTRL_BITS_MASK) | IRCC_CFGA_IRDA_SIR_A), fir_base+IRCC_SCE_CFGA); 1781 outb(((inb(fir_base + IRCC_SCE_CFGA) & IRCC_SCE_CFGA_BLOCK_CTRL_BITS_MASK) | IRCC_CFGA_IRDA_SIR_A), fir_base + IRCC_SCE_CFGA);
1783 1782
1784 /* Initialize UART */ 1783 /* Initialize UART */
1785 outb(UART_LCR_WLEN8, sir_base+UART_LCR); /* Reset DLAB */ 1784 outb(UART_LCR_WLEN8, sir_base + UART_LCR); /* Reset DLAB */
1786 outb((UART_MCR_DTR | UART_MCR_RTS | UART_MCR_OUT2), sir_base+UART_MCR); 1785 outb((UART_MCR_DTR | UART_MCR_RTS | UART_MCR_OUT2), sir_base + UART_MCR);
1787 1786
1788 /* Turn on interrups */ 1787 /* Turn on interrups */
1789 outb(UART_IER_RLSI | UART_IER_RDI |UART_IER_THRI, sir_base+UART_IER); 1788 outb(UART_IER_RLSI | UART_IER_RDI |UART_IER_THRI, sir_base + UART_IER);
1790 1789
1791 IRDA_DEBUG(3, "%s() - exit\n", __FUNCTION__); 1790 IRDA_DEBUG(3, "%s() - exit\n", __FUNCTION__);
1792 1791
1793 outb(0x00, fir_base+IRCC_MASTER); 1792 outb(0x00, fir_base + IRCC_MASTER);
1794} 1793}
1795 1794
1796#if SMSC_IRCC2_C_SIR_STOP 1795#if SMSC_IRCC2_C_SIR_STOP
@@ -1802,10 +1801,10 @@ void smsc_ircc_sir_stop(struct smsc_ircc_cb *self)
1802 iobase = self->io.sir_base; 1801 iobase = self->io.sir_base;
1803 1802
1804 /* Reset UART */ 1803 /* Reset UART */
1805 outb(0, iobase+UART_MCR); 1804 outb(0, iobase + UART_MCR);
1806 1805
1807 /* Turn off interrupts */ 1806 /* Turn off interrupts */
1808 outb(0, iobase+UART_IER); 1807 outb(0, iobase + UART_IER);
1809} 1808}
1810#endif 1809#endif
1811 1810
@@ -1831,16 +1830,16 @@ static void smsc_ircc_sir_write_wakeup(struct smsc_ircc_cb *self)
1831 /* Finished with frame? */ 1830 /* Finished with frame? */
1832 if (self->tx_buff.len > 0) { 1831 if (self->tx_buff.len > 0) {
1833 /* Write data left in transmit buffer */ 1832 /* Write data left in transmit buffer */
1834 actual = smsc_ircc_sir_write(iobase, self->io.fifo_size, 1833 actual = smsc_ircc_sir_write(iobase, self->io.fifo_size,
1835 self->tx_buff.data, self->tx_buff.len); 1834 self->tx_buff.data, self->tx_buff.len);
1836 self->tx_buff.data += actual; 1835 self->tx_buff.data += actual;
1837 self->tx_buff.len -= actual; 1836 self->tx_buff.len -= actual;
1838 } else { 1837 } else {
1839 1838
1840 /*if (self->tx_buff.len ==0) {*/ 1839 /*if (self->tx_buff.len ==0) {*/
1841 1840
1842 /* 1841 /*
1843 * Now serial buffer is almost free & we can start 1842 * Now serial buffer is almost free & we can start
1844 * transmission of another packet. But first we must check 1843 * transmission of another packet. But first we must check
1845 * if we need to change the speed of the hardware 1844 * if we need to change the speed of the hardware
1846 */ 1845 */
@@ -1856,21 +1855,19 @@ static void smsc_ircc_sir_write_wakeup(struct smsc_ircc_cb *self)
1856 } 1855 }
1857 self->stats.tx_packets++; 1856 self->stats.tx_packets++;
1858 1857
1859 if(self->io.speed <= 115200) { 1858 if (self->io.speed <= 115200) {
1860 /* 1859 /*
1861 * Reset Rx FIFO to make sure that all reflected transmit data 1860 * Reset Rx FIFO to make sure that all reflected transmit data
1862 * is discarded. This is needed for half duplex operation 1861 * is discarded. This is needed for half duplex operation
1863 */ 1862 */
1864 fcr = UART_FCR_ENABLE_FIFO | UART_FCR_CLEAR_RCVR; 1863 fcr = UART_FCR_ENABLE_FIFO | UART_FCR_CLEAR_RCVR;
1865 if (self->io.speed < 38400) 1864 fcr |= self->io.speed < 38400 ?
1866 fcr |= UART_FCR_TRIGGER_1; 1865 UART_FCR_TRIGGER_1 : UART_FCR_TRIGGER_14;
1867 else
1868 fcr |= UART_FCR_TRIGGER_14;
1869 1866
1870 outb(fcr, iobase+UART_FCR); 1867 outb(fcr, iobase + UART_FCR);
1871 1868
1872 /* Turn on receive interrupts */ 1869 /* Turn on receive interrupts */
1873 outb(UART_IER_RDI, iobase+UART_IER); 1870 outb(UART_IER_RDI, iobase + UART_IER);
1874 } 1871 }
1875 } 1872 }
1876} 1873}
@@ -1884,17 +1881,17 @@ static void smsc_ircc_sir_write_wakeup(struct smsc_ircc_cb *self)
1884static int smsc_ircc_sir_write(int iobase, int fifo_size, __u8 *buf, int len) 1881static int smsc_ircc_sir_write(int iobase, int fifo_size, __u8 *buf, int len)
1885{ 1882{
1886 int actual = 0; 1883 int actual = 0;
1887 1884
1888 /* Tx FIFO should be empty! */ 1885 /* Tx FIFO should be empty! */
1889 if (!(inb(iobase+UART_LSR) & UART_LSR_THRE)) { 1886 if (!(inb(iobase + UART_LSR) & UART_LSR_THRE)) {
1890 IRDA_WARNING("%s(), failed, fifo not empty!\n", __FUNCTION__); 1887 IRDA_WARNING("%s(), failed, fifo not empty!\n", __FUNCTION__);
1891 return 0; 1888 return 0;
1892 } 1889 }
1893 1890
1894 /* Fill FIFO with current frame */ 1891 /* Fill FIFO with current frame */
1895 while ((fifo_size-- > 0) && (actual < len)) { 1892 while (fifo_size-- > 0 && actual < len) {
1896 /* Transmit next byte */ 1893 /* Transmit next byte */
1897 outb(buf[actual], iobase+UART_TX); 1894 outb(buf[actual], iobase + UART_TX);
1898 actual++; 1895 actual++;
1899 } 1896 }
1900 return actual; 1897 return actual;
@@ -1921,20 +1918,21 @@ static int smsc_ircc_is_receiving(struct smsc_ircc_cb *self)
1921static void smsc_ircc_probe_transceiver(struct smsc_ircc_cb *self) 1918static void smsc_ircc_probe_transceiver(struct smsc_ircc_cb *self)
1922{ 1919{
1923 unsigned int i; 1920 unsigned int i;
1924 1921
1925 IRDA_ASSERT(self != NULL, return;); 1922 IRDA_ASSERT(self != NULL, return;);
1926 1923
1927 for(i=0; smsc_transceivers[i].name!=NULL; i++) 1924 for (i = 0; smsc_transceivers[i].name != NULL; i++)
1928 if((*smsc_transceivers[i].probe)(self->io.fir_base)) { 1925 if (smsc_transceivers[i].probe(self->io.fir_base)) {
1929 IRDA_MESSAGE(" %s transceiver found\n", 1926 IRDA_MESSAGE(" %s transceiver found\n",
1930 smsc_transceivers[i].name); 1927 smsc_transceivers[i].name);
1931 self->transceiver= i+1; 1928 self->transceiver= i + 1;
1932 return; 1929 return;
1933 } 1930 }
1931
1934 IRDA_MESSAGE("No transceiver found. Defaulting to %s\n", 1932 IRDA_MESSAGE("No transceiver found. Defaulting to %s\n",
1935 smsc_transceivers[SMSC_IRCC2_C_DEFAULT_TRANSCEIVER].name); 1933 smsc_transceivers[SMSC_IRCC2_C_DEFAULT_TRANSCEIVER].name);
1936 1934
1937 self->transceiver= SMSC_IRCC2_C_DEFAULT_TRANSCEIVER; 1935 self->transceiver = SMSC_IRCC2_C_DEFAULT_TRANSCEIVER;
1938} 1936}
1939 1937
1940 1938
@@ -1947,9 +1945,10 @@ static void smsc_ircc_probe_transceiver(struct smsc_ircc_cb *self)
1947static void smsc_ircc_set_transceiver_for_speed(struct smsc_ircc_cb *self, u32 speed) 1945static void smsc_ircc_set_transceiver_for_speed(struct smsc_ircc_cb *self, u32 speed)
1948{ 1946{
1949 unsigned int trx; 1947 unsigned int trx;
1950 1948
1951 trx = self->transceiver; 1949 trx = self->transceiver;
1952 if(trx>0) (*smsc_transceivers[trx-1].set_for_speed)(self->io.fir_base, speed); 1950 if (trx > 0)
1951 smsc_transceivers[trx - 1].set_for_speed(self->io.fir_base, speed);
1953} 1952}
1954 1953
1955/* 1954/*
@@ -1977,16 +1976,14 @@ static void smsc_ircc_set_transceiver_for_speed(struct smsc_ircc_cb *self, u32 s
1977 1976
1978static void smsc_ircc_sir_wait_hw_transmitter_finish(struct smsc_ircc_cb *self) 1977static void smsc_ircc_sir_wait_hw_transmitter_finish(struct smsc_ircc_cb *self)
1979{ 1978{
1980 int iobase; 1979 int iobase = self->io.sir_base;
1981 int count = SMSC_IRCC2_HW_TRANSMITTER_TIMEOUT_US; 1980 int count = SMSC_IRCC2_HW_TRANSMITTER_TIMEOUT_US;
1982 1981
1983 iobase = self->io.sir_base;
1984
1985 /* Calibrated busy loop */ 1982 /* Calibrated busy loop */
1986 while((count-- > 0) && !(inb(iobase+UART_LSR) & UART_LSR_TEMT)) 1983 while (count-- > 0 && !(inb(iobase + UART_LSR) & UART_LSR_TEMT))
1987 udelay(1); 1984 udelay(1);
1988 1985
1989 if(count == 0) 1986 if (count == 0)
1990 IRDA_DEBUG(0, "%s(): stuck transmitter\n", __FUNCTION__); 1987 IRDA_DEBUG(0, "%s(): stuck transmitter\n", __FUNCTION__);
1991} 1988}
1992 1989
@@ -1998,40 +1995,42 @@ static void smsc_ircc_sir_wait_hw_transmitter_finish(struct smsc_ircc_cb *self)
1998 1995
1999static int __init smsc_ircc_look_for_chips(void) 1996static int __init smsc_ircc_look_for_chips(void)
2000{ 1997{
2001 smsc_chip_address_t *address; 1998 struct smsc_chip_address *address;
2002 char *type; 1999 char *type;
2003 unsigned int cfg_base, found; 2000 unsigned int cfg_base, found;
2004 2001
2005 found = 0; 2002 found = 0;
2006 address = possible_addresses; 2003 address = possible_addresses;
2007 2004
2008 while(address->cfg_base){ 2005 while (address->cfg_base) {
2009 cfg_base = address->cfg_base; 2006 cfg_base = address->cfg_base;
2010 2007
2011 /*printk(KERN_WARNING "%s(): probing: 0x%02x for: 0x%02x\n", __FUNCTION__, cfg_base, address->type);*/ 2008 /*printk(KERN_WARNING "%s(): probing: 0x%02x for: 0x%02x\n", __FUNCTION__, cfg_base, address->type);*/
2012 2009
2013 if( address->type & SMSCSIO_TYPE_FDC){ 2010 if (address->type & SMSCSIO_TYPE_FDC) {
2014 type = "FDC"; 2011 type = "FDC";
2015 if((address->type) & SMSCSIO_TYPE_FLAT) { 2012 if (address->type & SMSCSIO_TYPE_FLAT)
2016 if(!smsc_superio_flat(fdc_chips_flat,cfg_base, type)) found++; 2013 if (!smsc_superio_flat(fdc_chips_flat, cfg_base, type))
2017 } 2014 found++;
2018 if((address->type) & SMSCSIO_TYPE_PAGED) { 2015
2019 if(!smsc_superio_paged(fdc_chips_paged,cfg_base, type)) found++; 2016 if (address->type & SMSCSIO_TYPE_PAGED)
2020 } 2017 if (!smsc_superio_paged(fdc_chips_paged, cfg_base, type))
2018 found++;
2021 } 2019 }
2022 if( address->type & SMSCSIO_TYPE_LPC){ 2020 if (address->type & SMSCSIO_TYPE_LPC) {
2023 type = "LPC"; 2021 type = "LPC";
2024 if((address->type) & SMSCSIO_TYPE_FLAT) { 2022 if (address->type & SMSCSIO_TYPE_FLAT)
2025 if(!smsc_superio_flat(lpc_chips_flat,cfg_base,type)) found++; 2023 if (!smsc_superio_flat(lpc_chips_flat, cfg_base, type))
2026 } 2024 found++;
2027 if((address->type) & SMSCSIO_TYPE_PAGED) { 2025
2028 if(!smsc_superio_paged(lpc_chips_paged,cfg_base,"LPC")) found++; 2026 if (address->type & SMSCSIO_TYPE_PAGED)
2029 } 2027 if (!smsc_superio_paged(lpc_chips_paged, cfg_base, type))
2028 found++;
2030 } 2029 }
2031 address++; 2030 address++;
2032 } 2031 }
2033 return found; 2032 return found;
2034} 2033}
2035 2034
2036/* 2035/*
2037 * Function smsc_superio_flat (chip, base, type) 2036 * Function smsc_superio_flat (chip, base, type)
@@ -2039,7 +2038,7 @@ static int __init smsc_ircc_look_for_chips(void)
2039 * Try to get configuration of a smc SuperIO chip with flat register model 2038 * Try to get configuration of a smc SuperIO chip with flat register model
2040 * 2039 *
2041 */ 2040 */
2042static int __init smsc_superio_flat(const smsc_chip_t *chips, unsigned short cfgbase, char *type) 2041static int __init smsc_superio_flat(const struct smsc_chip *chips, unsigned short cfgbase, char *type)
2043{ 2042{
2044 unsigned short firbase, sirbase; 2043 unsigned short firbase, sirbase;
2045 u8 mode, dma, irq; 2044 u8 mode, dma, irq;
@@ -2047,39 +2046,37 @@ static int __init smsc_superio_flat(const smsc_chip_t *chips, unsigned short cfg
2047 2046
2048 IRDA_DEBUG(1, "%s\n", __FUNCTION__); 2047 IRDA_DEBUG(1, "%s\n", __FUNCTION__);
2049 2048
2050 if (smsc_ircc_probe(cfgbase, SMSCSIOFLAT_DEVICEID_REG, chips, type)==NULL) 2049 if (smsc_ircc_probe(cfgbase, SMSCSIOFLAT_DEVICEID_REG, chips, type) == NULL)
2051 return ret; 2050 return ret;
2052 2051
2053 outb(SMSCSIOFLAT_UARTMODE0C_REG, cfgbase); 2052 outb(SMSCSIOFLAT_UARTMODE0C_REG, cfgbase);
2054 mode = inb(cfgbase+1); 2053 mode = inb(cfgbase + 1);
2055 2054
2056 /*printk(KERN_WARNING "%s(): mode: 0x%02x\n", __FUNCTION__, mode);*/ 2055 /*printk(KERN_WARNING "%s(): mode: 0x%02x\n", __FUNCTION__, mode);*/
2057 2056
2058 if(!(mode & SMSCSIOFLAT_UART2MODE_VAL_IRDA)) 2057 if (!(mode & SMSCSIOFLAT_UART2MODE_VAL_IRDA))
2059 IRDA_WARNING("%s(): IrDA not enabled\n", __FUNCTION__); 2058 IRDA_WARNING("%s(): IrDA not enabled\n", __FUNCTION__);
2060 2059
2061 outb(SMSCSIOFLAT_UART2BASEADDR_REG, cfgbase); 2060 outb(SMSCSIOFLAT_UART2BASEADDR_REG, cfgbase);
2062 sirbase = inb(cfgbase+1) << 2; 2061 sirbase = inb(cfgbase + 1) << 2;
2063 2062
2064 /* FIR iobase */ 2063 /* FIR iobase */
2065 outb(SMSCSIOFLAT_FIRBASEADDR_REG, cfgbase); 2064 outb(SMSCSIOFLAT_FIRBASEADDR_REG, cfgbase);
2066 firbase = inb(cfgbase+1) << 3; 2065 firbase = inb(cfgbase + 1) << 3;
2067 2066
2068 /* DMA */ 2067 /* DMA */
2069 outb(SMSCSIOFLAT_FIRDMASELECT_REG, cfgbase); 2068 outb(SMSCSIOFLAT_FIRDMASELECT_REG, cfgbase);
2070 dma = inb(cfgbase+1) & SMSCSIOFLAT_FIRDMASELECT_MASK; 2069 dma = inb(cfgbase + 1) & SMSCSIOFLAT_FIRDMASELECT_MASK;
2071 2070
2072 /* IRQ */ 2071 /* IRQ */
2073 outb(SMSCSIOFLAT_UARTIRQSELECT_REG, cfgbase); 2072 outb(SMSCSIOFLAT_UARTIRQSELECT_REG, cfgbase);
2074 irq = inb(cfgbase+1) & SMSCSIOFLAT_UART2IRQSELECT_MASK; 2073 irq = inb(cfgbase + 1) & SMSCSIOFLAT_UART2IRQSELECT_MASK;
2075 2074
2076 IRDA_MESSAGE("%s(): fir: 0x%02x, sir: 0x%02x, dma: %02d, irq: %d, mode: 0x%02x\n", __FUNCTION__, firbase, sirbase, dma, irq, mode); 2075 IRDA_MESSAGE("%s(): fir: 0x%02x, sir: 0x%02x, dma: %02d, irq: %d, mode: 0x%02x\n", __FUNCTION__, firbase, sirbase, dma, irq, mode);
2077 2076
2078 if (firbase) { 2077 if (firbase && smsc_ircc_open(firbase, sirbase, dma, irq) == 0)
2079 if (smsc_ircc_open(firbase, sirbase, dma, irq) == 0) 2078 ret = 0;
2080 ret=0; 2079
2081 }
2082
2083 /* Exit configuration */ 2080 /* Exit configuration */
2084 outb(SMSCSIO_CFGEXITKEY, cfgbase); 2081 outb(SMSCSIO_CFGEXITKEY, cfgbase);
2085 2082
@@ -2092,26 +2089,26 @@ static int __init smsc_superio_flat(const smsc_chip_t *chips, unsigned short cfg
2092 * Try to get configuration of a smc SuperIO chip with paged register model 2089 * Try to get configuration of a smc SuperIO chip with paged register model
2093 * 2090 *
2094 */ 2091 */
2095static int __init smsc_superio_paged(const smsc_chip_t *chips, unsigned short cfg_base, char *type) 2092static int __init smsc_superio_paged(const struct smsc_chip *chips, unsigned short cfg_base, char *type)
2096{ 2093{
2097 unsigned short fir_io, sir_io; 2094 unsigned short fir_io, sir_io;
2098 int ret = -ENODEV; 2095 int ret = -ENODEV;
2099 2096
2100 IRDA_DEBUG(1, "%s\n", __FUNCTION__); 2097 IRDA_DEBUG(1, "%s\n", __FUNCTION__);
2101 2098
2102 if (smsc_ircc_probe(cfg_base,0x20,chips,type)==NULL) 2099 if (smsc_ircc_probe(cfg_base, 0x20, chips, type) == NULL)
2103 return ret; 2100 return ret;
2104 2101
2105 /* Select logical device (UART2) */ 2102 /* Select logical device (UART2) */
2106 outb(0x07, cfg_base); 2103 outb(0x07, cfg_base);
2107 outb(0x05, cfg_base + 1); 2104 outb(0x05, cfg_base + 1);
2108 2105
2109 /* SIR iobase */ 2106 /* SIR iobase */
2110 outb(0x60, cfg_base); 2107 outb(0x60, cfg_base);
2111 sir_io = inb(cfg_base + 1) << 8; 2108 sir_io = inb(cfg_base + 1) << 8;
2112 outb(0x61, cfg_base); 2109 outb(0x61, cfg_base);
2113 sir_io |= inb(cfg_base + 1); 2110 sir_io |= inb(cfg_base + 1);
2114 2111
2115 /* Read FIR base */ 2112 /* Read FIR base */
2116 outb(0x62, cfg_base); 2113 outb(0x62, cfg_base);
2117 fir_io = inb(cfg_base + 1) << 8; 2114 fir_io = inb(cfg_base + 1) << 8;
@@ -2119,11 +2116,9 @@ static int __init smsc_superio_paged(const smsc_chip_t *chips, unsigned short cf
2119 fir_io |= inb(cfg_base + 1); 2116 fir_io |= inb(cfg_base + 1);
2120 outb(0x2b, cfg_base); /* ??? */ 2117 outb(0x2b, cfg_base); /* ??? */
2121 2118
2122 if (fir_io) { 2119 if (fir_io && smsc_ircc_open(fir_io, sir_io, ircc_dma, ircc_irq) == 0)
2123 if (smsc_ircc_open(fir_io, sir_io, ircc_dma, ircc_irq) == 0) 2120 ret = 0;
2124 ret=0; 2121
2125 }
2126
2127 /* Exit configuration */ 2122 /* Exit configuration */
2128 outb(SMSCSIO_CFGEXITKEY, cfg_base); 2123 outb(SMSCSIO_CFGEXITKEY, cfg_base);
2129 2124
@@ -2131,21 +2126,17 @@ static int __init smsc_superio_paged(const smsc_chip_t *chips, unsigned short cf
2131} 2126}
2132 2127
2133 2128
2134static int __init smsc_access(unsigned short cfg_base,unsigned char reg) 2129static int __init smsc_access(unsigned short cfg_base, unsigned char reg)
2135{ 2130{
2136 IRDA_DEBUG(1, "%s\n", __FUNCTION__); 2131 IRDA_DEBUG(1, "%s\n", __FUNCTION__);
2137 2132
2138 outb(reg, cfg_base); 2133 outb(reg, cfg_base);
2139 2134 return inb(cfg_base) != reg ? -1 : 0;
2140 if (inb(cfg_base)!=reg)
2141 return -1;
2142
2143 return 0;
2144} 2135}
2145 2136
2146static const smsc_chip_t * __init smsc_ircc_probe(unsigned short cfg_base,u8 reg,const smsc_chip_t *chip,char *type) 2137static const struct smsc_chip * __init smsc_ircc_probe(unsigned short cfg_base, u8 reg, const struct smsc_chip *chip, char *type)
2147{ 2138{
2148 u8 devid,xdevid,rev; 2139 u8 devid, xdevid, rev;
2149 2140
2150 IRDA_DEBUG(1, "%s\n", __FUNCTION__); 2141 IRDA_DEBUG(1, "%s\n", __FUNCTION__);
2151 2142
@@ -2158,7 +2149,7 @@ static const smsc_chip_t * __init smsc_ircc_probe(unsigned short cfg_base,u8 reg
2158 2149
2159 outb(reg, cfg_base); 2150 outb(reg, cfg_base);
2160 2151
2161 xdevid=inb(cfg_base+1); 2152 xdevid = inb(cfg_base + 1);
2162 2153
2163 /* Enter configuration */ 2154 /* Enter configuration */
2164 2155
@@ -2168,51 +2159,49 @@ static const smsc_chip_t * __init smsc_ircc_probe(unsigned short cfg_base,u8 reg
2168 if (smsc_access(cfg_base,0x55)) /* send second key and check */ 2159 if (smsc_access(cfg_base,0x55)) /* send second key and check */
2169 return NULL; 2160 return NULL;
2170 #endif 2161 #endif
2171 2162
2172 /* probe device ID */ 2163 /* probe device ID */
2173 2164
2174 if (smsc_access(cfg_base,reg)) 2165 if (smsc_access(cfg_base, reg))
2175 return NULL; 2166 return NULL;
2176 2167
2177 devid=inb(cfg_base+1); 2168 devid = inb(cfg_base + 1);
2178
2179 if (devid==0) /* typical value for unused port */
2180 return NULL;
2181 2169
2182 if (devid==0xff) /* typical value for unused port */ 2170 if (devid == 0 || devid == 0xff) /* typical values for unused port */
2183 return NULL; 2171 return NULL;
2184 2172
2185 /* probe revision ID */ 2173 /* probe revision ID */
2186 2174
2187 if (smsc_access(cfg_base,reg+1)) 2175 if (smsc_access(cfg_base, reg + 1))
2188 return NULL; 2176 return NULL;
2189 2177
2190 rev=inb(cfg_base+1); 2178 rev = inb(cfg_base + 1);
2191 2179
2192 if (rev>=128) /* i think this will make no sense */ 2180 if (rev >= 128) /* i think this will make no sense */
2193 return NULL; 2181 return NULL;
2194 2182
2195 if (devid==xdevid) /* protection against false positives */ 2183 if (devid == xdevid) /* protection against false positives */
2196 return NULL; 2184 return NULL;
2197 2185
2198 /* Check for expected device ID; are there others? */ 2186 /* Check for expected device ID; are there others? */
2199 2187
2200 while(chip->devid!=devid) { 2188 while (chip->devid != devid) {
2201 2189
2202 chip++; 2190 chip++;
2203 2191
2204 if (chip->name==NULL) 2192 if (chip->name == NULL)
2205 return NULL; 2193 return NULL;
2206 } 2194 }
2207 2195
2208 IRDA_MESSAGE("found SMC SuperIO Chip (devid=0x%02x rev=%02X base=0x%04x): %s%s\n",devid,rev,cfg_base,type,chip->name); 2196 IRDA_MESSAGE("found SMC SuperIO Chip (devid=0x%02x rev=%02X base=0x%04x): %s%s\n",
2197 devid, rev, cfg_base, type, chip->name);
2209 2198
2210 if (chip->rev>rev){ 2199 if (chip->rev > rev) {
2211 IRDA_MESSAGE("Revision higher than expected\n"); 2200 IRDA_MESSAGE("Revision higher than expected\n");
2212 return NULL; 2201 return NULL;
2213 } 2202 }
2214 2203
2215 if (chip->flags&NoIRDA) 2204 if (chip->flags & NoIRDA)
2216 IRDA_MESSAGE("chipset does not support IRDA\n"); 2205 IRDA_MESSAGE("chipset does not support IRDA\n");
2217 2206
2218 return chip; 2207 return chip;
@@ -2226,8 +2215,8 @@ static int __init smsc_superio_fdc(unsigned short cfg_base)
2226 IRDA_WARNING("%s: can't get cfg_base of 0x%03x\n", 2215 IRDA_WARNING("%s: can't get cfg_base of 0x%03x\n",
2227 __FUNCTION__, cfg_base); 2216 __FUNCTION__, cfg_base);
2228 } else { 2217 } else {
2229 if (!smsc_superio_flat(fdc_chips_flat,cfg_base,"FDC") 2218 if (!smsc_superio_flat(fdc_chips_flat, cfg_base, "FDC") ||
2230 ||!smsc_superio_paged(fdc_chips_paged,cfg_base,"FDC")) 2219 !smsc_superio_paged(fdc_chips_paged, cfg_base, "FDC"))
2231 ret = 0; 2220 ret = 0;
2232 2221
2233 release_region(cfg_base, 2); 2222 release_region(cfg_base, 2);
@@ -2244,9 +2233,10 @@ static int __init smsc_superio_lpc(unsigned short cfg_base)
2244 IRDA_WARNING("%s: can't get cfg_base of 0x%03x\n", 2233 IRDA_WARNING("%s: can't get cfg_base of 0x%03x\n",
2245 __FUNCTION__, cfg_base); 2234 __FUNCTION__, cfg_base);
2246 } else { 2235 } else {
2247 if (!smsc_superio_flat(lpc_chips_flat,cfg_base,"LPC") 2236 if (!smsc_superio_flat(lpc_chips_flat, cfg_base, "LPC") ||
2248 ||!smsc_superio_paged(lpc_chips_paged,cfg_base,"LPC")) 2237 !smsc_superio_paged(lpc_chips_paged, cfg_base, "LPC"))
2249 ret = 0; 2238 ret = 0;
2239
2250 release_region(cfg_base, 2); 2240 release_region(cfg_base, 2);
2251 } 2241 }
2252 return ret; 2242 return ret;
@@ -2269,18 +2259,23 @@ static int __init smsc_superio_lpc(unsigned short cfg_base)
2269static void smsc_ircc_set_transceiver_smsc_ircc_atc(int fir_base, u32 speed) 2259static void smsc_ircc_set_transceiver_smsc_ircc_atc(int fir_base, u32 speed)
2270{ 2260{
2271 unsigned long jiffies_now, jiffies_timeout; 2261 unsigned long jiffies_now, jiffies_timeout;
2272 u8 val; 2262 u8 val;
2273 2263
2274 jiffies_now= jiffies; 2264 jiffies_now = jiffies;
2275 jiffies_timeout= jiffies+SMSC_IRCC2_ATC_PROGRAMMING_TIMEOUT_JIFFIES; 2265 jiffies_timeout = jiffies + SMSC_IRCC2_ATC_PROGRAMMING_TIMEOUT_JIFFIES;
2276 2266
2277 /* ATC */ 2267 /* ATC */
2278 register_bank(fir_base, 4); 2268 register_bank(fir_base, 4);
2279 outb((inb(fir_base+IRCC_ATC) & IRCC_ATC_MASK) |IRCC_ATC_nPROGREADY|IRCC_ATC_ENABLE, fir_base+IRCC_ATC); 2269 outb((inb(fir_base + IRCC_ATC) & IRCC_ATC_MASK) | IRCC_ATC_nPROGREADY|IRCC_ATC_ENABLE,
2280 while((val=(inb(fir_base+IRCC_ATC) & IRCC_ATC_nPROGREADY)) && !time_after(jiffies, jiffies_timeout)); 2270 fir_base + IRCC_ATC);
2281 if(val) 2271
2272 while ((val = (inb(fir_base + IRCC_ATC) & IRCC_ATC_nPROGREADY)) &&
2273 !time_after(jiffies, jiffies_timeout))
2274 /* empty */;
2275
2276 if (val)
2282 IRDA_WARNING("%s(): ATC: 0x%02x\n", __FUNCTION__, 2277 IRDA_WARNING("%s(): ATC: 0x%02x\n", __FUNCTION__,
2283 inb(fir_base+IRCC_ATC)); 2278 inb(fir_base + IRCC_ATC));
2284} 2279}
2285 2280
2286/* 2281/*
@@ -2298,34 +2293,32 @@ static int smsc_ircc_probe_transceiver_smsc_ircc_atc(int fir_base)
2298/* 2293/*
2299 * Function smsc_ircc_set_transceiver_smsc_ircc_fast_pin_select(self, speed) 2294 * Function smsc_ircc_set_transceiver_smsc_ircc_fast_pin_select(self, speed)
2300 * 2295 *
2301 * Set transceiver 2296 * Set transceiver
2302 * 2297 *
2303 */ 2298 */
2304 2299
2305static void smsc_ircc_set_transceiver_smsc_ircc_fast_pin_select(int fir_base, u32 speed) 2300static void smsc_ircc_set_transceiver_smsc_ircc_fast_pin_select(int fir_base, u32 speed)
2306{ 2301{
2307 u8 fast_mode; 2302 u8 fast_mode;
2308 2303
2309 switch(speed) 2304 switch (speed) {
2310 { 2305 default:
2311 default: 2306 case 576000 :
2312 case 576000 : 2307 fast_mode = 0;
2313 fast_mode = 0;
2314 break; 2308 break;
2315 case 1152000 : 2309 case 1152000 :
2316 case 4000000 : 2310 case 4000000 :
2317 fast_mode = IRCC_LCR_A_FAST; 2311 fast_mode = IRCC_LCR_A_FAST;
2318 break; 2312 break;
2319
2320 } 2313 }
2321 register_bank(fir_base, 0); 2314 register_bank(fir_base, 0);
2322 outb((inb(fir_base+IRCC_LCR_A) & 0xbf) | fast_mode, fir_base+IRCC_LCR_A); 2315 outb((inb(fir_base + IRCC_LCR_A) & 0xbf) | fast_mode, fir_base + IRCC_LCR_A);
2323} 2316}
2324 2317
2325/* 2318/*
2326 * Function smsc_ircc_probe_transceiver_smsc_ircc_fast_pin_select(fir_base) 2319 * Function smsc_ircc_probe_transceiver_smsc_ircc_fast_pin_select(fir_base)
2327 * 2320 *
2328 * Probe transceiver 2321 * Probe transceiver
2329 * 2322 *
2330 */ 2323 */
2331 2324
@@ -2337,35 +2330,34 @@ static int smsc_ircc_probe_transceiver_smsc_ircc_fast_pin_select(int fir_base)
2337/* 2330/*
2338 * Function smsc_ircc_set_transceiver_toshiba_sat1800(fir_base, speed) 2331 * Function smsc_ircc_set_transceiver_toshiba_sat1800(fir_base, speed)
2339 * 2332 *
2340 * Set transceiver 2333 * Set transceiver
2341 * 2334 *
2342 */ 2335 */
2343 2336
2344static void smsc_ircc_set_transceiver_toshiba_sat1800(int fir_base, u32 speed) 2337static void smsc_ircc_set_transceiver_toshiba_sat1800(int fir_base, u32 speed)
2345{ 2338{
2346 u8 fast_mode; 2339 u8 fast_mode;
2347 2340
2348 switch(speed) 2341 switch (speed) {
2349 { 2342 default:
2350 default: 2343 case 576000 :
2351 case 576000 : 2344 fast_mode = 0;
2352 fast_mode = 0;
2353 break; 2345 break;
2354 case 1152000 : 2346 case 1152000 :
2355 case 4000000 : 2347 case 4000000 :
2356 fast_mode = /*IRCC_LCR_A_FAST |*/ IRCC_LCR_A_GP_DATA; 2348 fast_mode = /*IRCC_LCR_A_FAST |*/ IRCC_LCR_A_GP_DATA;
2357 break; 2349 break;
2358 2350
2359 } 2351 }
2360 /* This causes an interrupt */ 2352 /* This causes an interrupt */
2361 register_bank(fir_base, 0); 2353 register_bank(fir_base, 0);
2362 outb((inb(fir_base+IRCC_LCR_A) & 0xbf) | fast_mode, fir_base+IRCC_LCR_A); 2354 outb((inb(fir_base + IRCC_LCR_A) & 0xbf) | fast_mode, fir_base + IRCC_LCR_A);
2363} 2355}
2364 2356
2365/* 2357/*
2366 * Function smsc_ircc_probe_transceiver_toshiba_sat1800(fir_base) 2358 * Function smsc_ircc_probe_transceiver_toshiba_sat1800(fir_base)
2367 * 2359 *
2368 * Probe transceiver 2360 * Probe transceiver
2369 * 2361 *
2370 */ 2362 */
2371 2363
@@ -2377,20 +2369,3 @@ static int smsc_ircc_probe_transceiver_toshiba_sat1800(int fir_base)
2377 2369
2378module_init(smsc_ircc_init); 2370module_init(smsc_ircc_init);
2379module_exit(smsc_ircc_cleanup); 2371module_exit(smsc_ircc_cleanup);
2380
2381MODULE_AUTHOR("Daniele Peri <peri@csai.unipa.it>");
2382MODULE_DESCRIPTION("SMC IrCC SIR/FIR controller driver");
2383MODULE_LICENSE("GPL");
2384
2385module_param(ircc_dma, int, 0);
2386MODULE_PARM_DESC(ircc_dma, "DMA channel");
2387module_param(ircc_irq, int, 0);
2388MODULE_PARM_DESC(ircc_irq, "IRQ line");
2389module_param(ircc_fir, int, 0);
2390MODULE_PARM_DESC(ircc_fir, "FIR Base Address");
2391module_param(ircc_sir, int, 0);
2392MODULE_PARM_DESC(ircc_sir, "SIR Base Address");
2393module_param(ircc_cfg, int, 0);
2394MODULE_PARM_DESC(ircc_cfg, "Configuration register base address");
2395module_param(ircc_transceiver, int, 0);
2396MODULE_PARM_DESC(ircc_transceiver, "Transceiver type");
diff --git a/drivers/net/irda/smsc-ircc2.h b/drivers/net/irda/smsc-ircc2.h
index 458611cc0d4..0c36286d87f 100644
--- a/drivers/net/irda/smsc-ircc2.h
+++ b/drivers/net/irda/smsc-ircc2.h
@@ -1,5 +1,5 @@
1/********************************************************************* 1/*********************************************************************
2 * $Id: smsc-ircc2.h,v 1.12.2.1 2002/10/27 10:52:37 dip Exp $ 2 * $Id: smsc-ircc2.h,v 1.12.2.1 2002/10/27 10:52:37 dip Exp $
3 * 3 *
4 * Description: Definitions for the SMC IrCC chipset 4 * Description: Definitions for the SMC IrCC chipset
5 * Status: Experimental. 5 * Status: Experimental.
@@ -9,25 +9,25 @@
9 * All Rights Reserved. 9 * All Rights Reserved.
10 * 10 *
11 * Based on smc-ircc.h: 11 * Based on smc-ircc.h:
12 * 12 *
13 * Copyright (c) 1999-2000, Dag Brattli <dagb@cs.uit.no> 13 * Copyright (c) 1999-2000, Dag Brattli <dagb@cs.uit.no>
14 * Copyright (c) 1998-1999, Thomas Davis (tadavis@jps.net> 14 * Copyright (c) 1998-1999, Thomas Davis (tadavis@jps.net>
15 * All Rights Reserved 15 * All Rights Reserved
16 * 16 *
17 * 17 *
18 * This program is free software; you can redistribute it and/or 18 * This program is free software; you can redistribute it and/or
19 * modify it under the terms of the GNU General Public License as 19 * modify it under the terms of the GNU General Public License as
20 * published by the Free Software Foundation; either version 2 of 20 * published by the Free Software Foundation; either version 2 of
21 * the License, or (at your option) any later version. 21 * the License, or (at your option) any later version.
22 * 22 *
23 * This program is distributed in the hope that it will be useful, 23 * This program is distributed in the hope that it will be useful,
24 * but WITHOUT ANY WARRANTY; without even the implied warranty of 24 * but WITHOUT ANY WARRANTY; without even the implied warranty of
25 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 25 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
26 * GNU General Public License for more details. 26 * GNU General Public License for more details.
27 * 27 *
28 * You should have received a copy of the GNU General Public License 28 * You should have received a copy of the GNU General Public License
29 * along with this program; if not, write to the Free Software 29 * along with this program; if not, write to the Free Software
30 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, 30 * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
31 * MA 02111-1307 USA 31 * MA 02111-1307 USA
32 * 32 *
33 ********************************************************************/ 33 ********************************************************************/
@@ -112,10 +112,10 @@
112 112
113#define IRCC_CFGA_COM 0x00 113#define IRCC_CFGA_COM 0x00
114#define IRCC_SCE_CFGA_BLOCK_CTRL_BITS_MASK 0x87 114#define IRCC_SCE_CFGA_BLOCK_CTRL_BITS_MASK 0x87
115#define IRCC_CFGA_IRDA_SIR_A 0x08 115#define IRCC_CFGA_IRDA_SIR_A 0x08
116#define IRCC_CFGA_ASK_SIR 0x10 116#define IRCC_CFGA_ASK_SIR 0x10
117#define IRCC_CFGA_IRDA_SIR_B 0x18 117#define IRCC_CFGA_IRDA_SIR_B 0x18
118#define IRCC_CFGA_IRDA_HDLC 0x20 118#define IRCC_CFGA_IRDA_HDLC 0x20
119#define IRCC_CFGA_IRDA_4PPM 0x28 119#define IRCC_CFGA_IRDA_4PPM 0x28
120#define IRCC_CFGA_CONSUMER 0x30 120#define IRCC_CFGA_CONSUMER 0x30
121#define IRCC_CFGA_RAW_IR 0x38 121#define IRCC_CFGA_RAW_IR 0x38
@@ -130,7 +130,7 @@
130#define IRCC_CFGB_LPBCK_TX_CRC 0x10 130#define IRCC_CFGB_LPBCK_TX_CRC 0x10
131#define IRCC_CFGB_NOWAIT 0x08 131#define IRCC_CFGB_NOWAIT 0x08
132#define IRCC_CFGB_STRING_MOVE 0x04 132#define IRCC_CFGB_STRING_MOVE 0x04
133#define IRCC_CFGB_DMA_BURST 0x02 133#define IRCC_CFGB_DMA_BURST 0x02
134#define IRCC_CFGB_DMA_ENABLE 0x01 134#define IRCC_CFGB_DMA_ENABLE 0x01
135 135
136#define IRCC_CFGB_MUX_COM 0x00 136#define IRCC_CFGB_MUX_COM 0x00
@@ -141,11 +141,11 @@
141/* Register block 3 - Identification Registers! */ 141/* Register block 3 - Identification Registers! */
142#define IRCC_ID_HIGH 0x00 /* 0x10 */ 142#define IRCC_ID_HIGH 0x00 /* 0x10 */
143#define IRCC_ID_LOW 0x01 /* 0xB8 */ 143#define IRCC_ID_LOW 0x01 /* 0xB8 */
144#define IRCC_CHIP_ID 0x02 /* 0xF1 */ 144#define IRCC_CHIP_ID 0x02 /* 0xF1 */
145#define IRCC_VERSION 0x03 /* 0x01 */ 145#define IRCC_VERSION 0x03 /* 0x01 */
146#define IRCC_INTERFACE 0x04 /* low 4 = DMA, high 4 = IRQ */ 146#define IRCC_INTERFACE 0x04 /* low 4 = DMA, high 4 = IRQ */
147#define IRCC_INTERFACE_DMA_MASK 0x0F /* low 4 = DMA, high 4 = IRQ */ 147#define IRCC_INTERFACE_DMA_MASK 0x0F /* low 4 = DMA, high 4 = IRQ */
148#define IRCC_INTERFACE_IRQ_MASK 0xF0 /* low 4 = DMA, high 4 = IRQ */ 148#define IRCC_INTERFACE_IRQ_MASK 0xF0 /* low 4 = DMA, high 4 = IRQ */
149 149
150/* Register block 4 - IrDA */ 150/* Register block 4 - IrDA */
151#define IRCC_CONTROL 0x00 151#define IRCC_CONTROL 0x00
@@ -163,10 +163,10 @@
163 163
164/* Register block 5 - IrDA */ 164/* Register block 5 - IrDA */
165#define IRCC_ATC 0x00 165#define IRCC_ATC 0x00
166#define IRCC_ATC_nPROGREADY 0x80 166#define IRCC_ATC_nPROGREADY 0x80
167#define IRCC_ATC_SPEED 0x40 167#define IRCC_ATC_SPEED 0x40
168#define IRCC_ATC_ENABLE 0x20 168#define IRCC_ATC_ENABLE 0x20
169#define IRCC_ATC_MASK 0xE0 169#define IRCC_ATC_MASK 0xE0
170 170
171 171
172#define IRCC_IRHALFDUPLEX_TIMEOUT 0x01 172#define IRCC_IRHALFDUPLEX_TIMEOUT 0x01
@@ -178,8 +178,8 @@
178 */ 178 */
179 179
180#define SMSC_IRCC2_MAX_SIR_SPEED 115200 180#define SMSC_IRCC2_MAX_SIR_SPEED 115200
181#define SMSC_IRCC2_FIR_CHIP_IO_EXTENT 8 181#define SMSC_IRCC2_FIR_CHIP_IO_EXTENT 8
182#define SMSC_IRCC2_SIR_CHIP_IO_EXTENT 8 182#define SMSC_IRCC2_SIR_CHIP_IO_EXTENT 8
183#define SMSC_IRCC2_FIFO_SIZE 16 183#define SMSC_IRCC2_FIFO_SIZE 16
184#define SMSC_IRCC2_FIFO_THRESHOLD 64 184#define SMSC_IRCC2_FIFO_THRESHOLD 64
185/* Max DMA buffer size needed = (data_size + 6) * (window_size) + 6; */ 185/* Max DMA buffer size needed = (data_size + 6) * (window_size) + 6; */
diff --git a/drivers/net/irda/vlsi_ir.c b/drivers/net/irda/vlsi_ir.c
index 006e4f57560..6d9de626c96 100644
--- a/drivers/net/irda/vlsi_ir.c
+++ b/drivers/net/irda/vlsi_ir.c
@@ -1749,11 +1749,6 @@ static int vlsi_irda_suspend(struct pci_dev *pdev, pm_message_t state)
1749 struct net_device *ndev = pci_get_drvdata(pdev); 1749 struct net_device *ndev = pci_get_drvdata(pdev);
1750 vlsi_irda_dev_t *idev; 1750 vlsi_irda_dev_t *idev;
1751 1751
1752 if (state < 1 || state > 3 ) {
1753 IRDA_ERROR("%s - %s: invalid pm state request: %u\n",
1754 __FUNCTION__, PCIDEV_NAME(pdev), state);
1755 return 0;
1756 }
1757 if (!ndev) { 1752 if (!ndev) {
1758 IRDA_ERROR("%s - %s: no netdevice \n", 1753 IRDA_ERROR("%s - %s: no netdevice \n",
1759 __FUNCTION__, PCIDEV_NAME(pdev)); 1754 __FUNCTION__, PCIDEV_NAME(pdev));
@@ -1762,12 +1757,12 @@ static int vlsi_irda_suspend(struct pci_dev *pdev, pm_message_t state)
1762 idev = ndev->priv; 1757 idev = ndev->priv;
1763 down(&idev->sem); 1758 down(&idev->sem);
1764 if (pdev->current_state != 0) { /* already suspended */ 1759 if (pdev->current_state != 0) { /* already suspended */
1765 if (state > pdev->current_state) { /* simply go deeper */ 1760 if (state.event > pdev->current_state) { /* simply go deeper */
1766 pci_set_power_state(pdev,state); 1761 pci_set_power_state(pdev, pci_choose_state(pdev, state));
1767 pdev->current_state = state; 1762 pdev->current_state = state.event;
1768 } 1763 }
1769 else 1764 else
1770 IRDA_ERROR("%s - %s: invalid suspend request %u -> %u\n", __FUNCTION__, PCIDEV_NAME(pdev), pdev->current_state, state); 1765 IRDA_ERROR("%s - %s: invalid suspend request %u -> %u\n", __FUNCTION__, PCIDEV_NAME(pdev), pdev->current_state, state.event);
1771 up(&idev->sem); 1766 up(&idev->sem);
1772 return 0; 1767 return 0;
1773 } 1768 }
@@ -1781,8 +1776,8 @@ static int vlsi_irda_suspend(struct pci_dev *pdev, pm_message_t state)
1781 idev->new_baud = idev->baud; 1776 idev->new_baud = idev->baud;
1782 } 1777 }
1783 1778
1784 pci_set_power_state(pdev,state); 1779 pci_set_power_state(pdev, pci_choose_state(pdev, state));
1785 pdev->current_state = state; 1780 pdev->current_state = state.event;
1786 idev->resume_ok = 1; 1781 idev->resume_ok = 1;
1787 up(&idev->sem); 1782 up(&idev->sem);
1788 return 0; 1783 return 0;
@@ -1807,8 +1802,8 @@ static int vlsi_irda_resume(struct pci_dev *pdev)
1807 return 0; 1802 return 0;
1808 } 1803 }
1809 1804
1810 pci_set_power_state(pdev, 0); 1805 pci_set_power_state(pdev, PCI_D0);
1811 pdev->current_state = 0; 1806 pdev->current_state = PM_EVENT_ON;
1812 1807
1813 if (!idev->resume_ok) { 1808 if (!idev->resume_ok) {
1814 /* should be obsolete now - but used to happen due to: 1809 /* should be obsolete now - but used to happen due to:
diff --git a/drivers/net/iseries_veth.c b/drivers/net/iseries_veth.c
index dc5d089bf18..3d56cf5a4e2 100644
--- a/drivers/net/iseries_veth.c
+++ b/drivers/net/iseries_veth.c
@@ -4,6 +4,7 @@
4 * Copyright (C) 2001 Kyle A. Lucke (klucke@us.ibm.com), IBM Corp. 4 * Copyright (C) 2001 Kyle A. Lucke (klucke@us.ibm.com), IBM Corp.
5 * Substantially cleaned up by: 5 * Substantially cleaned up by:
6 * Copyright (C) 2003 David Gibson <dwg@au1.ibm.com>, IBM Corporation. 6 * Copyright (C) 2003 David Gibson <dwg@au1.ibm.com>, IBM Corporation.
7 * Copyright (C) 2004-2005 Michael Ellerman, IBM Corporation.
7 * 8 *
8 * This program is free software; you can redistribute it and/or 9 * This program is free software; you can redistribute it and/or
9 * modify it under the terms of the GNU General Public License as 10 * modify it under the terms of the GNU General Public License as
diff --git a/drivers/net/mv643xx_eth.c b/drivers/net/mv643xx_eth.c
index fb6b232069d..7c9dbc8c942 100644
--- a/drivers/net/mv643xx_eth.c
+++ b/drivers/net/mv643xx_eth.c
@@ -58,11 +58,10 @@
58 58
59#define INT_CAUSE_UNMASK_ALL 0x0007ffff 59#define INT_CAUSE_UNMASK_ALL 0x0007ffff
60#define INT_CAUSE_UNMASK_ALL_EXT 0x0011ffff 60#define INT_CAUSE_UNMASK_ALL_EXT 0x0011ffff
61#ifdef MV643XX_RX_QUEUE_FILL_ON_TASK
62#define INT_CAUSE_MASK_ALL 0x00000000 61#define INT_CAUSE_MASK_ALL 0x00000000
62#define INT_CAUSE_MASK_ALL_EXT 0x00000000
63#define INT_CAUSE_CHECK_BITS INT_CAUSE_UNMASK_ALL 63#define INT_CAUSE_CHECK_BITS INT_CAUSE_UNMASK_ALL
64#define INT_CAUSE_CHECK_BITS_EXT INT_CAUSE_UNMASK_ALL_EXT 64#define INT_CAUSE_CHECK_BITS_EXT INT_CAUSE_UNMASK_ALL_EXT
65#endif
66 65
67#ifdef MV643XX_CHECKSUM_OFFLOAD_TX 66#ifdef MV643XX_CHECKSUM_OFFLOAD_TX
68#define MAX_DESCS_PER_SKB (MAX_SKB_FRAGS + 1) 67#define MAX_DESCS_PER_SKB (MAX_SKB_FRAGS + 1)
@@ -259,14 +258,13 @@ static void mv643xx_eth_update_mac_address(struct net_device *dev)
259static void mv643xx_eth_set_rx_mode(struct net_device *dev) 258static void mv643xx_eth_set_rx_mode(struct net_device *dev)
260{ 259{
261 struct mv643xx_private *mp = netdev_priv(dev); 260 struct mv643xx_private *mp = netdev_priv(dev);
262 u32 config_reg;
263 261
264 config_reg = ethernet_get_config_reg(mp->port_num);
265 if (dev->flags & IFF_PROMISC) 262 if (dev->flags & IFF_PROMISC)
266 config_reg |= (u32) MV643XX_ETH_UNICAST_PROMISCUOUS_MODE; 263 mp->port_config |= (u32) MV643XX_ETH_UNICAST_PROMISCUOUS_MODE;
267 else 264 else
268 config_reg &= ~(u32) MV643XX_ETH_UNICAST_PROMISCUOUS_MODE; 265 mp->port_config &= ~(u32) MV643XX_ETH_UNICAST_PROMISCUOUS_MODE;
269 ethernet_set_config_reg(mp->port_num, config_reg); 266
267 mv_write(MV643XX_ETH_PORT_CONFIG_REG(mp->port_num), mp->port_config);
270} 268}
271 269
272/* 270/*
@@ -369,15 +367,6 @@ static int mv643xx_eth_free_tx_queue(struct net_device *dev,
369 367
370 dev_kfree_skb_irq(pkt_info.return_info); 368 dev_kfree_skb_irq(pkt_info.return_info);
371 released = 0; 369 released = 0;
372
373 /*
374 * Decrement the number of outstanding skbs counter on
375 * the TX queue.
376 */
377 if (mp->tx_ring_skbs == 0)
378 panic("ERROR - TX outstanding SKBs"
379 " counter is corrupted");
380 mp->tx_ring_skbs--;
381 } else 370 } else
382 dma_unmap_page(NULL, pkt_info.buf_ptr, 371 dma_unmap_page(NULL, pkt_info.buf_ptr,
383 pkt_info.byte_cnt, DMA_TO_DEVICE); 372 pkt_info.byte_cnt, DMA_TO_DEVICE);
@@ -412,15 +401,13 @@ static int mv643xx_eth_receive_queue(struct net_device *dev)
412 struct pkt_info pkt_info; 401 struct pkt_info pkt_info;
413 402
414#ifdef MV643XX_NAPI 403#ifdef MV643XX_NAPI
415 while (eth_port_receive(mp, &pkt_info) == ETH_OK && budget > 0) { 404 while (budget-- > 0 && eth_port_receive(mp, &pkt_info) == ETH_OK) {
416#else 405#else
417 while (eth_port_receive(mp, &pkt_info) == ETH_OK) { 406 while (eth_port_receive(mp, &pkt_info) == ETH_OK) {
418#endif 407#endif
419 mp->rx_ring_skbs--; 408 mp->rx_ring_skbs--;
420 received_packets++; 409 received_packets++;
421#ifdef MV643XX_NAPI 410
422 budget--;
423#endif
424 /* Update statistics. Note byte count includes 4 byte CRC count */ 411 /* Update statistics. Note byte count includes 4 byte CRC count */
425 stats->rx_packets++; 412 stats->rx_packets++;
426 stats->rx_bytes += pkt_info.byte_cnt; 413 stats->rx_bytes += pkt_info.byte_cnt;
@@ -1044,9 +1031,6 @@ static void mv643xx_tx(struct net_device *dev)
1044 DMA_TO_DEVICE); 1031 DMA_TO_DEVICE);
1045 1032
1046 dev_kfree_skb_irq(pkt_info.return_info); 1033 dev_kfree_skb_irq(pkt_info.return_info);
1047
1048 if (mp->tx_ring_skbs)
1049 mp->tx_ring_skbs--;
1050 } else 1034 } else
1051 dma_unmap_page(NULL, pkt_info.buf_ptr, 1035 dma_unmap_page(NULL, pkt_info.buf_ptr,
1052 pkt_info.byte_cnt, DMA_TO_DEVICE); 1036 pkt_info.byte_cnt, DMA_TO_DEVICE);
@@ -1189,7 +1173,6 @@ linear:
1189 pkt_info.buf_ptr = dma_map_single(NULL, skb->data, skb->len, 1173 pkt_info.buf_ptr = dma_map_single(NULL, skb->data, skb->len,
1190 DMA_TO_DEVICE); 1174 DMA_TO_DEVICE);
1191 pkt_info.return_info = skb; 1175 pkt_info.return_info = skb;
1192 mp->tx_ring_skbs++;
1193 status = eth_port_send(mp, &pkt_info); 1176 status = eth_port_send(mp, &pkt_info);
1194 if ((status == ETH_ERROR) || (status == ETH_QUEUE_FULL)) 1177 if ((status == ETH_ERROR) || (status == ETH_QUEUE_FULL))
1195 printk(KERN_ERR "%s: Error on transmitting packet\n", 1178 printk(KERN_ERR "%s: Error on transmitting packet\n",
@@ -1274,7 +1257,6 @@ linear:
1274 pkt_info.cmd_sts |= ETH_TX_ENABLE_INTERRUPT | 1257 pkt_info.cmd_sts |= ETH_TX_ENABLE_INTERRUPT |
1275 ETH_TX_LAST_DESC; 1258 ETH_TX_LAST_DESC;
1276 pkt_info.return_info = skb; 1259 pkt_info.return_info = skb;
1277 mp->tx_ring_skbs++;
1278 } else { 1260 } else {
1279 pkt_info.return_info = 0; 1261 pkt_info.return_info = 0;
1280 } 1262 }
@@ -1311,7 +1293,6 @@ linear:
1311 pkt_info.buf_ptr = dma_map_single(NULL, skb->data, skb->len, 1293 pkt_info.buf_ptr = dma_map_single(NULL, skb->data, skb->len,
1312 DMA_TO_DEVICE); 1294 DMA_TO_DEVICE);
1313 pkt_info.return_info = skb; 1295 pkt_info.return_info = skb;
1314 mp->tx_ring_skbs++;
1315 status = eth_port_send(mp, &pkt_info); 1296 status = eth_port_send(mp, &pkt_info);
1316 if ((status == ETH_ERROR) || (status == ETH_QUEUE_FULL)) 1297 if ((status == ETH_ERROR) || (status == ETH_QUEUE_FULL))
1317 printk(KERN_ERR "%s: Error on transmitting packet\n", 1298 printk(KERN_ERR "%s: Error on transmitting packet\n",
@@ -1356,6 +1337,43 @@ static struct net_device_stats *mv643xx_eth_get_stats(struct net_device *dev)
1356 return &mp->stats; 1337 return &mp->stats;
1357} 1338}
1358 1339
1340#ifdef CONFIG_NET_POLL_CONTROLLER
1341static inline void mv643xx_enable_irq(struct mv643xx_private *mp)
1342{
1343 int port_num = mp->port_num;
1344 unsigned long flags;
1345
1346 spin_lock_irqsave(&mp->lock, flags);
1347 mv_write(MV643XX_ETH_INTERRUPT_MASK_REG(port_num),
1348 INT_CAUSE_UNMASK_ALL);
1349 mv_write(MV643XX_ETH_INTERRUPT_EXTEND_MASK_REG(port_num),
1350 INT_CAUSE_UNMASK_ALL_EXT);
1351 spin_unlock_irqrestore(&mp->lock, flags);
1352}
1353
1354static inline void mv643xx_disable_irq(struct mv643xx_private *mp)
1355{
1356 int port_num = mp->port_num;
1357 unsigned long flags;
1358
1359 spin_lock_irqsave(&mp->lock, flags);
1360 mv_write(MV643XX_ETH_INTERRUPT_MASK_REG(port_num),
1361 INT_CAUSE_MASK_ALL);
1362 mv_write(MV643XX_ETH_INTERRUPT_EXTEND_MASK_REG(port_num),
1363 INT_CAUSE_MASK_ALL_EXT);
1364 spin_unlock_irqrestore(&mp->lock, flags);
1365}
1366
1367static void mv643xx_netpoll(struct net_device *netdev)
1368{
1369 struct mv643xx_private *mp = netdev_priv(netdev);
1370
1371 mv643xx_disable_irq(mp);
1372 mv643xx_eth_int_handler(netdev->irq, netdev, NULL);
1373 mv643xx_enable_irq(mp);
1374}
1375#endif
1376
1359/*/ 1377/*/
1360 * mv643xx_eth_probe 1378 * mv643xx_eth_probe
1361 * 1379 *
@@ -1406,6 +1424,10 @@ static int mv643xx_eth_probe(struct device *ddev)
1406 dev->weight = 64; 1424 dev->weight = 64;
1407#endif 1425#endif
1408 1426
1427#ifdef CONFIG_NET_POLL_CONTROLLER
1428 dev->poll_controller = mv643xx_netpoll;
1429#endif
1430
1409 dev->watchdog_timeo = 2 * HZ; 1431 dev->watchdog_timeo = 2 * HZ;
1410 dev->tx_queue_len = mp->tx_ring_size; 1432 dev->tx_queue_len = mp->tx_ring_size;
1411 dev->base_addr = 0; 1433 dev->base_addr = 0;
@@ -1883,6 +1905,9 @@ static void eth_port_start(struct mv643xx_private *mp)
1883 /* Enable port Rx. */ 1905 /* Enable port Rx. */
1884 mv_write(MV643XX_ETH_RECEIVE_QUEUE_COMMAND_REG(port_num), 1906 mv_write(MV643XX_ETH_RECEIVE_QUEUE_COMMAND_REG(port_num),
1885 mp->port_rx_queue_command); 1907 mp->port_rx_queue_command);
1908
1909 /* Disable port bandwidth limits by clearing MTU register */
1910 mv_write(MV643XX_ETH_MAXIMUM_TRANSMIT_UNIT(port_num), 0);
1886} 1911}
1887 1912
1888/* 1913/*
@@ -2292,34 +2317,6 @@ static void eth_port_reset(unsigned int port_num)
2292 mv_write(MV643XX_ETH_PORT_SERIAL_CONTROL_REG(port_num), reg_data); 2317 mv_write(MV643XX_ETH_PORT_SERIAL_CONTROL_REG(port_num), reg_data);
2293} 2318}
2294 2319
2295/*
2296 * ethernet_set_config_reg - Set specified bits in configuration register.
2297 *
2298 * DESCRIPTION:
2299 * This function sets specified bits in the given ethernet
2300 * configuration register.
2301 *
2302 * INPUT:
2303 * unsigned int eth_port_num Ethernet Port number.
2304 * unsigned int value 32 bit value.
2305 *
2306 * OUTPUT:
2307 * The set bits in the value parameter are set in the configuration
2308 * register.
2309 *
2310 * RETURN:
2311 * None.
2312 *
2313 */
2314static void ethernet_set_config_reg(unsigned int eth_port_num,
2315 unsigned int value)
2316{
2317 unsigned int eth_config_reg;
2318
2319 eth_config_reg = mv_read(MV643XX_ETH_PORT_CONFIG_REG(eth_port_num));
2320 eth_config_reg |= value;
2321 mv_write(MV643XX_ETH_PORT_CONFIG_REG(eth_port_num), eth_config_reg);
2322}
2323 2320
2324static int eth_port_autoneg_supported(unsigned int eth_port_num) 2321static int eth_port_autoneg_supported(unsigned int eth_port_num)
2325{ 2322{
@@ -2346,31 +2343,6 @@ static int eth_port_link_is_up(unsigned int eth_port_num)
2346} 2343}
2347 2344
2348/* 2345/*
2349 * ethernet_get_config_reg - Get the port configuration register
2350 *
2351 * DESCRIPTION:
2352 * This function returns the configuration register value of the given
2353 * ethernet port.
2354 *
2355 * INPUT:
2356 * unsigned int eth_port_num Ethernet Port number.
2357 *
2358 * OUTPUT:
2359 * None.
2360 *
2361 * RETURN:
2362 * Port configuration register value.
2363 */
2364static unsigned int ethernet_get_config_reg(unsigned int eth_port_num)
2365{
2366 unsigned int eth_config_reg;
2367
2368 eth_config_reg = mv_read(MV643XX_ETH_PORT_CONFIG_EXTEND_REG
2369 (eth_port_num));
2370 return eth_config_reg;
2371}
2372
2373/*
2374 * eth_port_read_smi_reg - Read PHY registers 2346 * eth_port_read_smi_reg - Read PHY registers
2375 * 2347 *
2376 * DESCRIPTION: 2348 * DESCRIPTION:
@@ -2528,6 +2500,9 @@ static ETH_FUNC_RET_STATUS eth_port_send(struct mv643xx_private *mp,
2528 return ETH_ERROR; 2500 return ETH_ERROR;
2529 } 2501 }
2530 2502
2503 mp->tx_ring_skbs++;
2504 BUG_ON(mp->tx_ring_skbs > mp->tx_ring_size);
2505
2531 /* Get the Tx Desc ring indexes */ 2506 /* Get the Tx Desc ring indexes */
2532 tx_desc_curr = mp->tx_curr_desc_q; 2507 tx_desc_curr = mp->tx_curr_desc_q;
2533 tx_desc_used = mp->tx_used_desc_q; 2508 tx_desc_used = mp->tx_used_desc_q;
@@ -2594,6 +2569,9 @@ static ETH_FUNC_RET_STATUS eth_port_send(struct mv643xx_private *mp,
2594 if (mp->tx_resource_err) 2569 if (mp->tx_resource_err)
2595 return ETH_QUEUE_FULL; 2570 return ETH_QUEUE_FULL;
2596 2571
2572 mp->tx_ring_skbs++;
2573 BUG_ON(mp->tx_ring_skbs > mp->tx_ring_size);
2574
2597 /* Get the Tx Desc ring indexes */ 2575 /* Get the Tx Desc ring indexes */
2598 tx_desc_curr = mp->tx_curr_desc_q; 2576 tx_desc_curr = mp->tx_curr_desc_q;
2599 tx_desc_used = mp->tx_used_desc_q; 2577 tx_desc_used = mp->tx_used_desc_q;
@@ -2694,6 +2672,9 @@ static ETH_FUNC_RET_STATUS eth_tx_return_desc(struct mv643xx_private *mp,
2694 /* Any Tx return cancels the Tx resource error status */ 2672 /* Any Tx return cancels the Tx resource error status */
2695 mp->tx_resource_err = 0; 2673 mp->tx_resource_err = 0;
2696 2674
2675 BUG_ON(mp->tx_ring_skbs == 0);
2676 mp->tx_ring_skbs--;
2677
2697 return ETH_OK; 2678 return ETH_OK;
2698} 2679}
2699 2680
diff --git a/drivers/net/mv643xx_eth.h b/drivers/net/mv643xx_eth.h
index 7678b59c295..bcfda5192da 100644
--- a/drivers/net/mv643xx_eth.h
+++ b/drivers/net/mv643xx_eth.h
@@ -408,10 +408,6 @@ static void eth_port_init(struct mv643xx_private *mp);
408static void eth_port_reset(unsigned int eth_port_num); 408static void eth_port_reset(unsigned int eth_port_num);
409static void eth_port_start(struct mv643xx_private *mp); 409static void eth_port_start(struct mv643xx_private *mp);
410 410
411static void ethernet_set_config_reg(unsigned int eth_port_num,
412 unsigned int value);
413static unsigned int ethernet_get_config_reg(unsigned int eth_port_num);
414
415/* Port MAC address routines */ 411/* Port MAC address routines */
416static void eth_port_uc_addr_set(unsigned int eth_port_num, 412static void eth_port_uc_addr_set(unsigned int eth_port_num,
417 unsigned char *p_addr); 413 unsigned char *p_addr);
diff --git a/drivers/net/ne3210.c b/drivers/net/ne3210.c
index 6c92f096901..73501d84658 100644
--- a/drivers/net/ne3210.c
+++ b/drivers/net/ne3210.c
@@ -26,9 +26,6 @@
26 Updated to EISA probing API 5/2003 by Marc Zyngier. 26 Updated to EISA probing API 5/2003 by Marc Zyngier.
27*/ 27*/
28 28
29static const char *version =
30 "ne3210.c: Driver revision v0.03, 30/09/98\n";
31
32#include <linux/module.h> 29#include <linux/module.h>
33#include <linux/eisa.h> 30#include <linux/eisa.h>
34#include <linux/kernel.h> 31#include <linux/kernel.h>
@@ -197,7 +194,7 @@ static int __init ne3210_eisa_probe (struct device *device)
197 ei_status.priv = phys_mem; 194 ei_status.priv = phys_mem;
198 195
199 if (ei_debug > 0) 196 if (ei_debug > 0)
200 printk(version); 197 printk("ne3210 loaded.\n");
201 198
202 ei_status.reset_8390 = &ne3210_reset_8390; 199 ei_status.reset_8390 = &ne3210_reset_8390;
203 ei_status.block_input = &ne3210_block_input; 200 ei_status.block_input = &ne3210_block_input;
@@ -360,12 +357,12 @@ MODULE_DESCRIPTION("NE3210 EISA Ethernet driver");
360MODULE_LICENSE("GPL"); 357MODULE_LICENSE("GPL");
361MODULE_DEVICE_TABLE(eisa, ne3210_ids); 358MODULE_DEVICE_TABLE(eisa, ne3210_ids);
362 359
363int ne3210_init(void) 360static int ne3210_init(void)
364{ 361{
365 return eisa_driver_register (&ne3210_eisa_driver); 362 return eisa_driver_register (&ne3210_eisa_driver);
366} 363}
367 364
368void ne3210_cleanup(void) 365static void ne3210_cleanup(void)
369{ 366{
370 eisa_driver_unregister (&ne3210_eisa_driver); 367 eisa_driver_unregister (&ne3210_eisa_driver);
371} 368}
diff --git a/drivers/net/phy/Kconfig b/drivers/net/phy/Kconfig
index 6a2fe358347..14f4de1a818 100644
--- a/drivers/net/phy/Kconfig
+++ b/drivers/net/phy/Kconfig
@@ -6,7 +6,7 @@ menu "PHY device support"
6 6
7config PHYLIB 7config PHYLIB
8 tristate "PHY Device support and infrastructure" 8 tristate "PHY Device support and infrastructure"
9 depends on NET_ETHERNET 9 depends on NET_ETHERNET && (BROKEN || !ARCH_S390)
10 help 10 help
11 Ethernet controllers are usually attached to PHY 11 Ethernet controllers are usually attached to PHY
12 devices. This option provides infrastructure for 12 devices. This option provides infrastructure for
diff --git a/drivers/net/phy/mdio_bus.c b/drivers/net/phy/mdio_bus.c
index 41f62c0c5fc..90630672703 100644
--- a/drivers/net/phy/mdio_bus.c
+++ b/drivers/net/phy/mdio_bus.c
@@ -128,7 +128,7 @@ static int mdio_bus_match(struct device *dev, struct device_driver *drv)
128/* Suspend and resume. Copied from platform_suspend and 128/* Suspend and resume. Copied from platform_suspend and
129 * platform_resume 129 * platform_resume
130 */ 130 */
131static int mdio_bus_suspend(struct device * dev, u32 state) 131static int mdio_bus_suspend(struct device * dev, pm_message_t state)
132{ 132{
133 int ret = 0; 133 int ret = 0;
134 struct device_driver *drv = dev->driver; 134 struct device_driver *drv = dev->driver;
@@ -170,7 +170,7 @@ int __init mdio_bus_init(void)
170 return bus_register(&mdio_bus_type); 170 return bus_register(&mdio_bus_type);
171} 171}
172 172
173void __exit mdio_bus_exit(void) 173void mdio_bus_exit(void)
174{ 174{
175 bus_unregister(&mdio_bus_type); 175 bus_unregister(&mdio_bus_type);
176} 176}
diff --git a/drivers/net/s2io-regs.h b/drivers/net/s2io-regs.h
index 2234a8f05eb..7cefe5507b9 100644
--- a/drivers/net/s2io-regs.h
+++ b/drivers/net/s2io-regs.h
@@ -1,5 +1,5 @@
1/************************************************************************ 1/************************************************************************
2 * regs.h: A Linux PCI-X Ethernet driver for S2IO 10GbE Server NIC 2 * regs.h: A Linux PCI-X Ethernet driver for Neterion 10GbE Server NIC
3 * Copyright(c) 2002-2005 Neterion Inc. 3 * Copyright(c) 2002-2005 Neterion Inc.
4 4
5 * This software may be used and distributed according to the terms of 5 * This software may be used and distributed according to the terms of
@@ -713,13 +713,16 @@ typedef struct _XENA_dev_config {
713 u64 mc_err_reg; 713 u64 mc_err_reg;
714#define MC_ERR_REG_ECC_DB_ERR_L BIT(14) 714#define MC_ERR_REG_ECC_DB_ERR_L BIT(14)
715#define MC_ERR_REG_ECC_DB_ERR_U BIT(15) 715#define MC_ERR_REG_ECC_DB_ERR_U BIT(15)
716#define MC_ERR_REG_MIRI_ECC_DB_ERR_0 BIT(18)
717#define MC_ERR_REG_MIRI_ECC_DB_ERR_1 BIT(20)
716#define MC_ERR_REG_MIRI_CRI_ERR_0 BIT(22) 718#define MC_ERR_REG_MIRI_CRI_ERR_0 BIT(22)
717#define MC_ERR_REG_MIRI_CRI_ERR_1 BIT(23) 719#define MC_ERR_REG_MIRI_CRI_ERR_1 BIT(23)
718#define MC_ERR_REG_SM_ERR BIT(31) 720#define MC_ERR_REG_SM_ERR BIT(31)
719#define MC_ERR_REG_ECC_ALL_SNG (BIT(6) | \ 721#define MC_ERR_REG_ECC_ALL_SNG (BIT(2) | BIT(3) | BIT(4) | BIT(5) |\
720 BIT(7) | BIT(17) | BIT(19)) 722 BIT(6) | BIT(7) | BIT(17) | BIT(19))
721#define MC_ERR_REG_ECC_ALL_DBL (BIT(14) | \ 723#define MC_ERR_REG_ECC_ALL_DBL (BIT(10) | BIT(11) | BIT(12) |\
722 BIT(15) | BIT(18) | BIT(20)) 724 BIT(13) | BIT(14) | BIT(15) |\
725 BIT(18) | BIT(20))
723 u64 mc_err_mask; 726 u64 mc_err_mask;
724 u64 mc_err_alarm; 727 u64 mc_err_alarm;
725 728
diff --git a/drivers/net/s2io.c b/drivers/net/s2io.c
index 7ca78228b10..c829e6a2e8a 100644
--- a/drivers/net/s2io.c
+++ b/drivers/net/s2io.c
@@ -1,5 +1,5 @@
1/************************************************************************ 1/************************************************************************
2 * s2io.c: A Linux PCI-X Ethernet driver for S2IO 10GbE Server NIC 2 * s2io.c: A Linux PCI-X Ethernet driver for Neterion 10GbE Server NIC
3 * Copyright(c) 2002-2005 Neterion Inc. 3 * Copyright(c) 2002-2005 Neterion Inc.
4 4
5 * This software may be used and distributed according to the terms of 5 * This software may be used and distributed according to the terms of
@@ -28,7 +28,7 @@
28 * explaination of all the variables. 28 * explaination of all the variables.
29 * rx_ring_num : This can be used to program the number of receive rings used 29 * rx_ring_num : This can be used to program the number of receive rings used
30 * in the driver. 30 * in the driver.
31 * rx_ring_len: This defines the number of descriptors each ring can have. This 31 * rx_ring_sz: This defines the number of descriptors each ring can have. This
32 * is also an array of size 8. 32 * is also an array of size 8.
33 * tx_fifo_num: This defines the number of Tx FIFOs thats used int the driver. 33 * tx_fifo_num: This defines the number of Tx FIFOs thats used int the driver.
34 * tx_fifo_len: This too is an array of 8. Each element defines the number of 34 * tx_fifo_len: This too is an array of 8. Each element defines the number of
@@ -67,7 +67,7 @@
67 67
68/* S2io Driver name & version. */ 68/* S2io Driver name & version. */
69static char s2io_driver_name[] = "Neterion"; 69static char s2io_driver_name[] = "Neterion";
70static char s2io_driver_version[] = "Version 2.0.3.1"; 70static char s2io_driver_version[] = "Version 2.0.8.1";
71 71
72static inline int RXD_IS_UP2DT(RxD_t *rxdp) 72static inline int RXD_IS_UP2DT(RxD_t *rxdp)
73{ 73{
@@ -354,7 +354,7 @@ static int init_shared_mem(struct s2io_nic *nic)
354 int lst_size, lst_per_page; 354 int lst_size, lst_per_page;
355 struct net_device *dev = nic->dev; 355 struct net_device *dev = nic->dev;
356#ifdef CONFIG_2BUFF_MODE 356#ifdef CONFIG_2BUFF_MODE
357 u64 tmp; 357 unsigned long tmp;
358 buffAdd_t *ba; 358 buffAdd_t *ba;
359#endif 359#endif
360 360
@@ -404,7 +404,7 @@ static int init_shared_mem(struct s2io_nic *nic)
404 config->tx_cfg[i].fifo_len - 1; 404 config->tx_cfg[i].fifo_len - 1;
405 mac_control->fifos[i].fifo_no = i; 405 mac_control->fifos[i].fifo_no = i;
406 mac_control->fifos[i].nic = nic; 406 mac_control->fifos[i].nic = nic;
407 mac_control->fifos[i].max_txds = MAX_SKB_FRAGS; 407 mac_control->fifos[i].max_txds = MAX_SKB_FRAGS + 1;
408 408
409 for (j = 0; j < page_num; j++) { 409 for (j = 0; j < page_num; j++) {
410 int k = 0; 410 int k = 0;
@@ -418,6 +418,26 @@ static int init_shared_mem(struct s2io_nic *nic)
418 DBG_PRINT(ERR_DBG, "failed for TxDL\n"); 418 DBG_PRINT(ERR_DBG, "failed for TxDL\n");
419 return -ENOMEM; 419 return -ENOMEM;
420 } 420 }
421 /* If we got a zero DMA address(can happen on
422 * certain platforms like PPC), reallocate.
423 * Store virtual address of page we don't want,
424 * to be freed later.
425 */
426 if (!tmp_p) {
427 mac_control->zerodma_virt_addr = tmp_v;
428 DBG_PRINT(INIT_DBG,
429 "%s: Zero DMA address for TxDL. ", dev->name);
430 DBG_PRINT(INIT_DBG,
431 "Virtual address %llx\n", (u64)tmp_v);
432 tmp_v = pci_alloc_consistent(nic->pdev,
433 PAGE_SIZE, &tmp_p);
434 if (!tmp_v) {
435 DBG_PRINT(ERR_DBG,
436 "pci_alloc_consistent ");
437 DBG_PRINT(ERR_DBG, "failed for TxDL\n");
438 return -ENOMEM;
439 }
440 }
421 while (k < lst_per_page) { 441 while (k < lst_per_page) {
422 int l = (j * lst_per_page) + k; 442 int l = (j * lst_per_page) + k;
423 if (l == config->tx_cfg[i].fifo_len) 443 if (l == config->tx_cfg[i].fifo_len)
@@ -542,18 +562,18 @@ static int init_shared_mem(struct s2io_nic *nic)
542 (BUF0_LEN + ALIGN_SIZE, GFP_KERNEL); 562 (BUF0_LEN + ALIGN_SIZE, GFP_KERNEL);
543 if (!ba->ba_0_org) 563 if (!ba->ba_0_org)
544 return -ENOMEM; 564 return -ENOMEM;
545 tmp = (u64) ba->ba_0_org; 565 tmp = (unsigned long) ba->ba_0_org;
546 tmp += ALIGN_SIZE; 566 tmp += ALIGN_SIZE;
547 tmp &= ~((u64) ALIGN_SIZE); 567 tmp &= ~((unsigned long) ALIGN_SIZE);
548 ba->ba_0 = (void *) tmp; 568 ba->ba_0 = (void *) tmp;
549 569
550 ba->ba_1_org = (void *) kmalloc 570 ba->ba_1_org = (void *) kmalloc
551 (BUF1_LEN + ALIGN_SIZE, GFP_KERNEL); 571 (BUF1_LEN + ALIGN_SIZE, GFP_KERNEL);
552 if (!ba->ba_1_org) 572 if (!ba->ba_1_org)
553 return -ENOMEM; 573 return -ENOMEM;
554 tmp = (u64) ba->ba_1_org; 574 tmp = (unsigned long) ba->ba_1_org;
555 tmp += ALIGN_SIZE; 575 tmp += ALIGN_SIZE;
556 tmp &= ~((u64) ALIGN_SIZE); 576 tmp &= ~((unsigned long) ALIGN_SIZE);
557 ba->ba_1 = (void *) tmp; 577 ba->ba_1 = (void *) tmp;
558 k++; 578 k++;
559 } 579 }
@@ -600,7 +620,7 @@ static void free_shared_mem(struct s2io_nic *nic)
600 mac_info_t *mac_control; 620 mac_info_t *mac_control;
601 struct config_param *config; 621 struct config_param *config;
602 int lst_size, lst_per_page; 622 int lst_size, lst_per_page;
603 623 struct net_device *dev = nic->dev;
604 624
605 if (!nic) 625 if (!nic)
606 return; 626 return;
@@ -616,9 +636,10 @@ static void free_shared_mem(struct s2io_nic *nic)
616 lst_per_page); 636 lst_per_page);
617 for (j = 0; j < page_num; j++) { 637 for (j = 0; j < page_num; j++) {
618 int mem_blks = (j * lst_per_page); 638 int mem_blks = (j * lst_per_page);
619 if ((!mac_control->fifos[i].list_info) || 639 if (!mac_control->fifos[i].list_info)
620 (!mac_control->fifos[i].list_info[mem_blks]. 640 return;
621 list_virt_addr)) 641 if (!mac_control->fifos[i].list_info[mem_blks].
642 list_virt_addr)
622 break; 643 break;
623 pci_free_consistent(nic->pdev, PAGE_SIZE, 644 pci_free_consistent(nic->pdev, PAGE_SIZE,
624 mac_control->fifos[i]. 645 mac_control->fifos[i].
@@ -628,6 +649,18 @@ static void free_shared_mem(struct s2io_nic *nic)
628 list_info[mem_blks]. 649 list_info[mem_blks].
629 list_phy_addr); 650 list_phy_addr);
630 } 651 }
652 /* If we got a zero DMA address during allocation,
653 * free the page now
654 */
655 if (mac_control->zerodma_virt_addr) {
656 pci_free_consistent(nic->pdev, PAGE_SIZE,
657 mac_control->zerodma_virt_addr,
658 (dma_addr_t)0);
659 DBG_PRINT(INIT_DBG,
660 "%s: Freeing TxDL with zero DMA addr. ", dev->name);
661 DBG_PRINT(INIT_DBG, "Virtual address %llx\n",
662 (u64)(mac_control->zerodma_virt_addr));
663 }
631 kfree(mac_control->fifos[i].list_info); 664 kfree(mac_control->fifos[i].list_info);
632 } 665 }
633 666
@@ -686,7 +719,7 @@ static void free_shared_mem(struct s2io_nic *nic)
686 719
687static int s2io_verify_pci_mode(nic_t *nic) 720static int s2io_verify_pci_mode(nic_t *nic)
688{ 721{
689 XENA_dev_config_t *bar0 = (XENA_dev_config_t *) nic->bar0; 722 XENA_dev_config_t __iomem *bar0 = nic->bar0;
690 register u64 val64 = 0; 723 register u64 val64 = 0;
691 int mode; 724 int mode;
692 725
@@ -704,7 +737,7 @@ static int s2io_verify_pci_mode(nic_t *nic)
704 */ 737 */
705static int s2io_print_pci_mode(nic_t *nic) 738static int s2io_print_pci_mode(nic_t *nic)
706{ 739{
707 XENA_dev_config_t *bar0 = (XENA_dev_config_t *) nic->bar0; 740 XENA_dev_config_t __iomem *bar0 = nic->bar0;
708 register u64 val64 = 0; 741 register u64 val64 = 0;
709 int mode; 742 int mode;
710 struct config_param *config = &nic->config; 743 struct config_param *config = &nic->config;
@@ -1403,7 +1436,7 @@ static int init_nic(struct s2io_nic *nic)
1403 writeq(0xffbbffbbffbbffbbULL, &bar0->mc_pause_thresh_q4q7); 1436 writeq(0xffbbffbbffbbffbbULL, &bar0->mc_pause_thresh_q4q7);
1404 1437
1405 /* Disable RMAC PAD STRIPPING */ 1438 /* Disable RMAC PAD STRIPPING */
1406 add = (void *) &bar0->mac_cfg; 1439 add = &bar0->mac_cfg;
1407 val64 = readq(&bar0->mac_cfg); 1440 val64 = readq(&bar0->mac_cfg);
1408 val64 &= ~(MAC_CFG_RMAC_STRIP_PAD); 1441 val64 &= ~(MAC_CFG_RMAC_STRIP_PAD);
1409 writeq(RMAC_CFG_KEY(0x4C0D), &bar0->rmac_cfg_key); 1442 writeq(RMAC_CFG_KEY(0x4C0D), &bar0->rmac_cfg_key);
@@ -1934,7 +1967,7 @@ static int start_nic(struct s2io_nic *nic)
1934 val64 |= 0x0000800000000000ULL; 1967 val64 |= 0x0000800000000000ULL;
1935 writeq(val64, &bar0->gpio_control); 1968 writeq(val64, &bar0->gpio_control);
1936 val64 = 0x0411040400000000ULL; 1969 val64 = 0x0411040400000000ULL;
1937 writeq(val64, (void __iomem *) ((u8 *) bar0 + 0x2700)); 1970 writeq(val64, (void __iomem *)bar0 + 0x2700);
1938 } 1971 }
1939 1972
1940 /* 1973 /*
@@ -2395,7 +2428,7 @@ static int s2io_poll(struct net_device *dev, int *budget)
2395 int pkt_cnt = 0, org_pkts_to_process; 2428 int pkt_cnt = 0, org_pkts_to_process;
2396 mac_info_t *mac_control; 2429 mac_info_t *mac_control;
2397 struct config_param *config; 2430 struct config_param *config;
2398 XENA_dev_config_t *bar0 = (XENA_dev_config_t *) nic->bar0; 2431 XENA_dev_config_t __iomem *bar0 = nic->bar0;
2399 u64 val64; 2432 u64 val64;
2400 int i; 2433 int i;
2401 2434
@@ -2479,9 +2512,10 @@ static void rx_intr_handler(ring_info_t *ring_data)
2479#endif 2512#endif
2480 spin_lock(&nic->rx_lock); 2513 spin_lock(&nic->rx_lock);
2481 if (atomic_read(&nic->card_state) == CARD_DOWN) { 2514 if (atomic_read(&nic->card_state) == CARD_DOWN) {
2482 DBG_PRINT(ERR_DBG, "%s: %s going down for reset\n", 2515 DBG_PRINT(INTR_DBG, "%s: %s going down for reset\n",
2483 __FUNCTION__, dev->name); 2516 __FUNCTION__, dev->name);
2484 spin_unlock(&nic->rx_lock); 2517 spin_unlock(&nic->rx_lock);
2518 return;
2485 } 2519 }
2486 2520
2487 get_info = ring_data->rx_curr_get_info; 2521 get_info = ring_data->rx_curr_get_info;
@@ -2596,8 +2630,14 @@ static void tx_intr_handler(fifo_info_t *fifo_data)
2596 if (txdlp->Control_1 & TXD_T_CODE) { 2630 if (txdlp->Control_1 & TXD_T_CODE) {
2597 unsigned long long err; 2631 unsigned long long err;
2598 err = txdlp->Control_1 & TXD_T_CODE; 2632 err = txdlp->Control_1 & TXD_T_CODE;
2599 DBG_PRINT(ERR_DBG, "***TxD error %llx\n", 2633 if ((err >> 48) == 0xA) {
2600 err); 2634 DBG_PRINT(TX_DBG, "TxD returned due \
2635 to loss of link\n");
2636 }
2637 else {
2638 DBG_PRINT(ERR_DBG, "***TxD error \
2639 %llx\n", err);
2640 }
2601 } 2641 }
2602 2642
2603 skb = (struct sk_buff *) ((unsigned long) 2643 skb = (struct sk_buff *) ((unsigned long)
@@ -2689,12 +2729,16 @@ static void alarm_intr_handler(struct s2io_nic *nic)
2689 if (val64 & MC_ERR_REG_ECC_ALL_DBL) { 2729 if (val64 & MC_ERR_REG_ECC_ALL_DBL) {
2690 nic->mac_control.stats_info->sw_stat. 2730 nic->mac_control.stats_info->sw_stat.
2691 double_ecc_errs++; 2731 double_ecc_errs++;
2692 DBG_PRINT(ERR_DBG, "%s: Device indicates ", 2732 DBG_PRINT(INIT_DBG, "%s: Device indicates ",
2693 dev->name); 2733 dev->name);
2694 DBG_PRINT(ERR_DBG, "double ECC error!!\n"); 2734 DBG_PRINT(INIT_DBG, "double ECC error!!\n");
2695 if (nic->device_type != XFRAME_II_DEVICE) { 2735 if (nic->device_type != XFRAME_II_DEVICE) {
2696 netif_stop_queue(dev); 2736 /* Reset XframeI only if critical error */
2697 schedule_work(&nic->rst_timer_task); 2737 if (val64 & (MC_ERR_REG_MIRI_ECC_DB_ERR_0 |
2738 MC_ERR_REG_MIRI_ECC_DB_ERR_1)) {
2739 netif_stop_queue(dev);
2740 schedule_work(&nic->rst_timer_task);
2741 }
2698 } 2742 }
2699 } else { 2743 } else {
2700 nic->mac_control.stats_info->sw_stat. 2744 nic->mac_control.stats_info->sw_stat.
@@ -2706,7 +2750,8 @@ static void alarm_intr_handler(struct s2io_nic *nic)
2706 val64 = readq(&bar0->serr_source); 2750 val64 = readq(&bar0->serr_source);
2707 if (val64 & SERR_SOURCE_ANY) { 2751 if (val64 & SERR_SOURCE_ANY) {
2708 DBG_PRINT(ERR_DBG, "%s: Device indicates ", dev->name); 2752 DBG_PRINT(ERR_DBG, "%s: Device indicates ", dev->name);
2709 DBG_PRINT(ERR_DBG, "serious error!!\n"); 2753 DBG_PRINT(ERR_DBG, "serious error %llx!!\n",
2754 (unsigned long long)val64);
2710 netif_stop_queue(dev); 2755 netif_stop_queue(dev);
2711 schedule_work(&nic->rst_timer_task); 2756 schedule_work(&nic->rst_timer_task);
2712 } 2757 }
@@ -2831,7 +2876,7 @@ void s2io_reset(nic_t * sp)
2831 val64 |= 0x0000800000000000ULL; 2876 val64 |= 0x0000800000000000ULL;
2832 writeq(val64, &bar0->gpio_control); 2877 writeq(val64, &bar0->gpio_control);
2833 val64 = 0x0411040400000000ULL; 2878 val64 = 0x0411040400000000ULL;
2834 writeq(val64, (void __iomem *) ((u8 *) bar0 + 0x2700)); 2879 writeq(val64, (void __iomem *)bar0 + 0x2700);
2835 } 2880 }
2836 2881
2837 /* 2882 /*
@@ -3130,7 +3175,7 @@ int s2io_xmit(struct sk_buff *skb, struct net_device *dev)
3130 queue_len = mac_control->fifos[queue].tx_curr_put_info.fifo_len + 1; 3175 queue_len = mac_control->fifos[queue].tx_curr_put_info.fifo_len + 1;
3131 /* Avoid "put" pointer going beyond "get" pointer */ 3176 /* Avoid "put" pointer going beyond "get" pointer */
3132 if (txdp->Host_Control || (((put_off + 1) % queue_len) == get_off)) { 3177 if (txdp->Host_Control || (((put_off + 1) % queue_len) == get_off)) {
3133 DBG_PRINT(ERR_DBG, "Error in xmit, No free TXDs.\n"); 3178 DBG_PRINT(TX_DBG, "Error in xmit, No free TXDs.\n");
3134 netif_stop_queue(dev); 3179 netif_stop_queue(dev);
3135 dev_kfree_skb(skb); 3180 dev_kfree_skb(skb);
3136 spin_unlock_irqrestore(&sp->tx_lock, flags); 3181 spin_unlock_irqrestore(&sp->tx_lock, flags);
@@ -3234,7 +3279,7 @@ s2io_alarm_handle(unsigned long data)
3234 3279
3235static void s2io_txpic_intr_handle(nic_t *sp) 3280static void s2io_txpic_intr_handle(nic_t *sp)
3236{ 3281{
3237 XENA_dev_config_t *bar0 = (XENA_dev_config_t *) sp->bar0; 3282 XENA_dev_config_t __iomem *bar0 = sp->bar0;
3238 u64 val64; 3283 u64 val64;
3239 3284
3240 val64 = readq(&bar0->pic_int_status); 3285 val64 = readq(&bar0->pic_int_status);
@@ -3528,7 +3573,7 @@ static void s2io_set_multicast(struct net_device *dev)
3528 3573
3529 val64 = readq(&bar0->mac_cfg); 3574 val64 = readq(&bar0->mac_cfg);
3530 sp->promisc_flg = 1; 3575 sp->promisc_flg = 1;
3531 DBG_PRINT(ERR_DBG, "%s: entered promiscuous mode\n", 3576 DBG_PRINT(INFO_DBG, "%s: entered promiscuous mode\n",
3532 dev->name); 3577 dev->name);
3533 } else if (!(dev->flags & IFF_PROMISC) && (sp->promisc_flg)) { 3578 } else if (!(dev->flags & IFF_PROMISC) && (sp->promisc_flg)) {
3534 /* Remove the NIC from promiscuous mode */ 3579 /* Remove the NIC from promiscuous mode */
@@ -3543,7 +3588,7 @@ static void s2io_set_multicast(struct net_device *dev)
3543 3588
3544 val64 = readq(&bar0->mac_cfg); 3589 val64 = readq(&bar0->mac_cfg);
3545 sp->promisc_flg = 0; 3590 sp->promisc_flg = 0;
3546 DBG_PRINT(ERR_DBG, "%s: left promiscuous mode\n", 3591 DBG_PRINT(INFO_DBG, "%s: left promiscuous mode\n",
3547 dev->name); 3592 dev->name);
3548 } 3593 }
3549 3594
@@ -5325,7 +5370,7 @@ s2io_init_nic(struct pci_dev *pdev, const struct pci_device_id *pre)
5325 break; 5370 break;
5326 } 5371 }
5327 } 5372 }
5328 config->max_txds = MAX_SKB_FRAGS; 5373 config->max_txds = MAX_SKB_FRAGS + 1;
5329 5374
5330 /* Rx side parameters. */ 5375 /* Rx side parameters. */
5331 if (rx_ring_sz[0] == 0) 5376 if (rx_ring_sz[0] == 0)
@@ -5525,9 +5570,14 @@ s2io_init_nic(struct pci_dev *pdev, const struct pci_device_id *pre)
5525 if (sp->device_type & XFRAME_II_DEVICE) { 5570 if (sp->device_type & XFRAME_II_DEVICE) {
5526 DBG_PRINT(ERR_DBG, "%s: Neterion Xframe II 10GbE adapter ", 5571 DBG_PRINT(ERR_DBG, "%s: Neterion Xframe II 10GbE adapter ",
5527 dev->name); 5572 dev->name);
5528 DBG_PRINT(ERR_DBG, "(rev %d), Driver %s\n", 5573 DBG_PRINT(ERR_DBG, "(rev %d), %s",
5529 get_xena_rev_id(sp->pdev), 5574 get_xena_rev_id(sp->pdev),
5530 s2io_driver_version); 5575 s2io_driver_version);
5576#ifdef CONFIG_2BUFF_MODE
5577 DBG_PRINT(ERR_DBG, ", Buffer mode %d",2);
5578#endif
5579
5580 DBG_PRINT(ERR_DBG, "\nCopyright(c) 2002-2005 Neterion Inc.\n");
5531 DBG_PRINT(ERR_DBG, "MAC ADDR: %02x:%02x:%02x:%02x:%02x:%02x\n", 5581 DBG_PRINT(ERR_DBG, "MAC ADDR: %02x:%02x:%02x:%02x:%02x:%02x\n",
5532 sp->def_mac_addr[0].mac_addr[0], 5582 sp->def_mac_addr[0].mac_addr[0],
5533 sp->def_mac_addr[0].mac_addr[1], 5583 sp->def_mac_addr[0].mac_addr[1],
@@ -5544,9 +5594,13 @@ s2io_init_nic(struct pci_dev *pdev, const struct pci_device_id *pre)
5544 } else { 5594 } else {
5545 DBG_PRINT(ERR_DBG, "%s: Neterion Xframe I 10GbE adapter ", 5595 DBG_PRINT(ERR_DBG, "%s: Neterion Xframe I 10GbE adapter ",
5546 dev->name); 5596 dev->name);
5547 DBG_PRINT(ERR_DBG, "(rev %d), Driver %s\n", 5597 DBG_PRINT(ERR_DBG, "(rev %d), %s",
5548 get_xena_rev_id(sp->pdev), 5598 get_xena_rev_id(sp->pdev),
5549 s2io_driver_version); 5599 s2io_driver_version);
5600#ifdef CONFIG_2BUFF_MODE
5601 DBG_PRINT(ERR_DBG, ", Buffer mode %d",2);
5602#endif
5603 DBG_PRINT(ERR_DBG, "\nCopyright(c) 2002-2005 Neterion Inc.\n");
5550 DBG_PRINT(ERR_DBG, "MAC ADDR: %02x:%02x:%02x:%02x:%02x:%02x\n", 5604 DBG_PRINT(ERR_DBG, "MAC ADDR: %02x:%02x:%02x:%02x:%02x:%02x\n",
5551 sp->def_mac_addr[0].mac_addr[0], 5605 sp->def_mac_addr[0].mac_addr[0],
5552 sp->def_mac_addr[0].mac_addr[1], 5606 sp->def_mac_addr[0].mac_addr[1],
diff --git a/drivers/net/s2io.h b/drivers/net/s2io.h
index bc64d967f08..89151cb5218 100644
--- a/drivers/net/s2io.h
+++ b/drivers/net/s2io.h
@@ -1,5 +1,5 @@
1/************************************************************************ 1/************************************************************************
2 * s2io.h: A Linux PCI-X Ethernet driver for S2IO 10GbE Server NIC 2 * s2io.h: A Linux PCI-X Ethernet driver for Neterion 10GbE Server NIC
3 * Copyright(c) 2002-2005 Neterion Inc. 3 * Copyright(c) 2002-2005 Neterion Inc.
4 4
5 * This software may be used and distributed according to the terms of 5 * This software may be used and distributed according to the terms of
@@ -622,6 +622,9 @@ typedef struct mac_info {
622 /* Fifo specific structure */ 622 /* Fifo specific structure */
623 fifo_info_t fifos[MAX_TX_FIFOS]; 623 fifo_info_t fifos[MAX_TX_FIFOS];
624 624
625 /* Save virtual address of TxD page with zero DMA addr(if any) */
626 void *zerodma_virt_addr;
627
625/* rx side stuff */ 628/* rx side stuff */
626 /* Ring specific structure */ 629 /* Ring specific structure */
627 ring_info_t rings[MAX_RX_RINGS]; 630 ring_info_t rings[MAX_RX_RINGS];
diff --git a/drivers/net/sis190.c b/drivers/net/sis190.c
index bf3440aa6c2..92f75529eff 100644
--- a/drivers/net/sis190.c
+++ b/drivers/net/sis190.c
@@ -179,14 +179,6 @@ enum sis190_register_content {
179 TxInterFrameGapShift = 24, 179 TxInterFrameGapShift = 24,
180 TxDMAShift = 8, /* DMA burst value (0-7) is shift this many bits */ 180 TxDMAShift = 8, /* DMA burst value (0-7) is shift this many bits */
181 181
182 /* StationControl */
183 _1000bpsF = 0x1c00,
184 _1000bpsH = 0x0c00,
185 _100bpsF = 0x1800,
186 _100bpsH = 0x0800,
187 _10bpsF = 0x1400,
188 _10bpsH = 0x0400,
189
190 LinkStatus = 0x02, // unused 182 LinkStatus = 0x02, // unused
191 FullDup = 0x01, // unused 183 FullDup = 0x01, // unused
192 184
@@ -279,6 +271,12 @@ enum sis190_eeprom_address {
279 EEPROMMACAddr = 0x03 271 EEPROMMACAddr = 0x03
280}; 272};
281 273
274enum sis190_feature {
275 F_HAS_RGMII = 1,
276 F_PHY_88E1111 = 2,
277 F_PHY_BCM5461 = 4
278};
279
282struct sis190_private { 280struct sis190_private {
283 void __iomem *mmio_addr; 281 void __iomem *mmio_addr;
284 struct pci_dev *pci_dev; 282 struct pci_dev *pci_dev;
@@ -300,6 +298,7 @@ struct sis190_private {
300 u32 msg_enable; 298 u32 msg_enable;
301 struct mii_if_info mii_if; 299 struct mii_if_info mii_if;
302 struct list_head first_phy; 300 struct list_head first_phy;
301 u32 features;
303}; 302};
304 303
305struct sis190_phy { 304struct sis190_phy {
@@ -321,24 +320,25 @@ static struct mii_chip_info {
321 const char *name; 320 const char *name;
322 u16 id[2]; 321 u16 id[2];
323 unsigned int type; 322 unsigned int type;
323 u32 feature;
324} mii_chip_table[] = { 324} mii_chip_table[] = {
325 { "Broadcom PHY BCM5461", { 0x0020, 0x60c0 }, LAN }, 325 { "Broadcom PHY BCM5461", { 0x0020, 0x60c0 }, LAN, F_PHY_BCM5461 },
326 { "Agere PHY ET1101B", { 0x0282, 0xf010 }, LAN }, 326 { "Agere PHY ET1101B", { 0x0282, 0xf010 }, LAN, 0 },
327 { "Marvell PHY 88E1111", { 0x0141, 0x0cc0 }, LAN }, 327 { "Marvell PHY 88E1111", { 0x0141, 0x0cc0 }, LAN, F_PHY_88E1111 },
328 { "Realtek PHY RTL8201", { 0x0000, 0x8200 }, LAN }, 328 { "Realtek PHY RTL8201", { 0x0000, 0x8200 }, LAN, 0 },
329 { NULL, } 329 { NULL, }
330}; 330};
331 331
332const static struct { 332const static struct {
333 const char *name; 333 const char *name;
334 u8 version; /* depend on docs */
335 u32 RxConfigMask; /* clear the bits supported by this chip */
336} sis_chip_info[] = { 334} sis_chip_info[] = {
337 { DRV_NAME, 0x00, 0xff7e1880, }, 335 { "SiS 190 PCI Fast Ethernet adapter" },
336 { "SiS 191 PCI Gigabit Ethernet adapter" },
338}; 337};
339 338
340static struct pci_device_id sis190_pci_tbl[] __devinitdata = { 339static struct pci_device_id sis190_pci_tbl[] __devinitdata = {
341 { PCI_DEVICE(PCI_VENDOR_ID_SI, 0x0190), 0, 0, 0 }, 340 { PCI_DEVICE(PCI_VENDOR_ID_SI, 0x0190), 0, 0, 0 },
341 { PCI_DEVICE(PCI_VENDOR_ID_SI, 0x0191), 0, 0, 1 },
342 { 0, }, 342 { 0, },
343}; 343};
344 344
@@ -360,7 +360,7 @@ MODULE_VERSION(DRV_VERSION);
360MODULE_LICENSE("GPL"); 360MODULE_LICENSE("GPL");
361 361
362static const u32 sis190_intr_mask = 362static const u32 sis190_intr_mask =
363 RxQEmpty | RxQInt | TxQ1Int | TxQ0Int | RxHalt | TxHalt; 363 RxQEmpty | RxQInt | TxQ1Int | TxQ0Int | RxHalt | TxHalt | LinkChange;
364 364
365/* 365/*
366 * Maximum number of multicast addresses to filter (vs. Rx-all-multicast). 366 * Maximum number of multicast addresses to filter (vs. Rx-all-multicast).
@@ -879,11 +879,6 @@ static void sis190_hw_start(struct net_device *dev)
879 879
880 SIS_W32(IntrStatus, 0xffffffff); 880 SIS_W32(IntrStatus, 0xffffffff);
881 SIS_W32(IntrMask, 0x0); 881 SIS_W32(IntrMask, 0x0);
882 /*
883 * Default is 100Mbps.
884 * A bit strange: 100Mbps is 0x1801 elsewhere -- FR 2005/06/09
885 */
886 SIS_W16(StationControl, 0x1901);
887 SIS_W32(GMIIControl, 0x0); 882 SIS_W32(GMIIControl, 0x0);
888 SIS_W32(TxMacControl, 0x60); 883 SIS_W32(TxMacControl, 0x60);
889 SIS_W16(RxMacControl, 0x02); 884 SIS_W16(RxMacControl, 0x02);
@@ -923,35 +918,30 @@ static void sis190_phy_task(void * data)
923 BMSR_ANEGCOMPLETE)) { 918 BMSR_ANEGCOMPLETE)) {
924 net_link(tp, KERN_WARNING "%s: PHY reset until link up.\n", 919 net_link(tp, KERN_WARNING "%s: PHY reset until link up.\n",
925 dev->name); 920 dev->name);
921 netif_carrier_off(dev);
926 mdio_write(ioaddr, phy_id, MII_BMCR, val | BMCR_RESET); 922 mdio_write(ioaddr, phy_id, MII_BMCR, val | BMCR_RESET);
927 mod_timer(&tp->timer, jiffies + SIS190_PHY_TIMEOUT); 923 mod_timer(&tp->timer, jiffies + SIS190_PHY_TIMEOUT);
928 } else { 924 } else {
929 /* Rejoice ! */ 925 /* Rejoice ! */
930 struct { 926 struct {
931 int val; 927 int val;
928 u32 ctl;
932 const char *msg; 929 const char *msg;
933 u16 ctl;
934 } reg31[] = { 930 } reg31[] = {
935 { LPA_1000XFULL | LPA_SLCT, 931 { LPA_1000XFULL | LPA_SLCT, 0x07000c00 | 0x00001000,
936 "1000 Mbps Full Duplex", 932 "1000 Mbps Full Duplex" },
937 0x01 | _1000bpsF }, 933 { LPA_1000XHALF | LPA_SLCT, 0x07000c00,
938 { LPA_1000XHALF | LPA_SLCT, 934 "1000 Mbps Half Duplex" },
939 "1000 Mbps Half Duplex", 935 { LPA_100FULL, 0x04000800 | 0x00001000,
940 0x01 | _1000bpsH }, 936 "100 Mbps Full Duplex" },
941 { LPA_100FULL, 937 { LPA_100HALF, 0x04000800,
942 "100 Mbps Full Duplex", 938 "100 Mbps Half Duplex" },
943 0x01 | _100bpsF }, 939 { LPA_10FULL, 0x04000400 | 0x00001000,
944 { LPA_100HALF, 940 "10 Mbps Full Duplex" },
945 "100 Mbps Half Duplex", 941 { LPA_10HALF, 0x04000400,
946 0x01 | _100bpsH }, 942 "10 Mbps Half Duplex" },
947 { LPA_10FULL, 943 { 0, 0x04000400, "unknown" }
948 "10 Mbps Full Duplex", 944 }, *p;
949 0x01 | _10bpsF },
950 { LPA_10HALF,
951 "10 Mbps Half Duplex",
952 0x01 | _10bpsH },
953 { 0, "unknown", 0x0000 }
954 }, *p;
955 u16 adv; 945 u16 adv;
956 946
957 val = mdio_read(ioaddr, phy_id, 0x1f); 947 val = mdio_read(ioaddr, phy_id, 0x1f);
@@ -964,12 +954,29 @@ static void sis190_phy_task(void * data)
964 954
965 val &= adv; 955 val &= adv;
966 956
967 for (p = reg31; p->ctl; p++) { 957 for (p = reg31; p->val; p++) {
968 if ((val & p->val) == p->val) 958 if ((val & p->val) == p->val)
969 break; 959 break;
970 } 960 }
971 if (p->ctl) 961
972 SIS_W16(StationControl, p->ctl); 962 p->ctl |= SIS_R32(StationControl) & ~0x0f001c00;
963
964 if ((tp->features & F_HAS_RGMII) &&
965 (tp->features & F_PHY_BCM5461)) {
966 // Set Tx Delay in RGMII mode.
967 mdio_write(ioaddr, phy_id, 0x18, 0xf1c7);
968 udelay(200);
969 mdio_write(ioaddr, phy_id, 0x1c, 0x8c00);
970 p->ctl |= 0x03000000;
971 }
972
973 SIS_W32(StationControl, p->ctl);
974
975 if (tp->features & F_HAS_RGMII) {
976 SIS_W32(RGDelay, 0x0441);
977 SIS_W32(RGDelay, 0x0440);
978 }
979
973 net_link(tp, KERN_INFO "%s: link on %s mode.\n", dev->name, 980 net_link(tp, KERN_INFO "%s: link on %s mode.\n", dev->name,
974 p->msg); 981 p->msg);
975 netif_carrier_on(dev); 982 netif_carrier_on(dev);
@@ -1308,6 +1315,7 @@ static void sis190_init_phy(struct net_device *dev, struct sis190_private *tp,
1308 phy->type = (p->type == MIX) ? 1315 phy->type = (p->type == MIX) ?
1309 ((mii_status & (BMSR_100FULL | BMSR_100HALF)) ? 1316 ((mii_status & (BMSR_100FULL | BMSR_100HALF)) ?
1310 LAN : HOME) : p->type; 1317 LAN : HOME) : p->type;
1318 tp->features |= p->feature;
1311 } else 1319 } else
1312 phy->type = UNKNOWN; 1320 phy->type = UNKNOWN;
1313 1321
@@ -1316,6 +1324,25 @@ static void sis190_init_phy(struct net_device *dev, struct sis190_private *tp,
1316 (phy->type == UNKNOWN) ? "Unknown PHY" : p->name, phy_id); 1324 (phy->type == UNKNOWN) ? "Unknown PHY" : p->name, phy_id);
1317} 1325}
1318 1326
1327static void sis190_mii_probe_88e1111_fixup(struct sis190_private *tp)
1328{
1329 if (tp->features & F_PHY_88E1111) {
1330 void __iomem *ioaddr = tp->mmio_addr;
1331 int phy_id = tp->mii_if.phy_id;
1332 u16 reg[2][2] = {
1333 { 0x808b, 0x0ce1 },
1334 { 0x808f, 0x0c60 }
1335 }, *p;
1336
1337 p = (tp->features & F_HAS_RGMII) ? reg[0] : reg[1];
1338
1339 mdio_write(ioaddr, phy_id, 0x1b, p[0]);
1340 udelay(200);
1341 mdio_write(ioaddr, phy_id, 0x14, p[1]);
1342 udelay(200);
1343 }
1344}
1345
1319/** 1346/**
1320 * sis190_mii_probe - Probe MII PHY for sis190 1347 * sis190_mii_probe - Probe MII PHY for sis190
1321 * @dev: the net device to probe for 1348 * @dev: the net device to probe for
@@ -1366,6 +1393,8 @@ static int __devinit sis190_mii_probe(struct net_device *dev)
1366 /* Select default PHY for mac */ 1393 /* Select default PHY for mac */
1367 sis190_default_phy(dev); 1394 sis190_default_phy(dev);
1368 1395
1396 sis190_mii_probe_88e1111_fixup(tp);
1397
1369 mii_if->dev = dev; 1398 mii_if->dev = dev;
1370 mii_if->mdio_read = __mdio_read; 1399 mii_if->mdio_read = __mdio_read;
1371 mii_if->mdio_write = __mdio_write; 1400 mii_if->mdio_write = __mdio_write;
@@ -1505,6 +1534,11 @@ static void sis190_tx_timeout(struct net_device *dev)
1505 netif_wake_queue(dev); 1534 netif_wake_queue(dev);
1506} 1535}
1507 1536
1537static void sis190_set_rgmii(struct sis190_private *tp, u8 reg)
1538{
1539 tp->features |= (reg & 0x80) ? F_HAS_RGMII : 0;
1540}
1541
1508static int __devinit sis190_get_mac_addr_from_eeprom(struct pci_dev *pdev, 1542static int __devinit sis190_get_mac_addr_from_eeprom(struct pci_dev *pdev,
1509 struct net_device *dev) 1543 struct net_device *dev)
1510{ 1544{
@@ -1532,6 +1566,8 @@ static int __devinit sis190_get_mac_addr_from_eeprom(struct pci_dev *pdev,
1532 ((u16 *)dev->dev_addr)[0] = le16_to_cpu(w); 1566 ((u16 *)dev->dev_addr)[0] = le16_to_cpu(w);
1533 } 1567 }
1534 1568
1569 sis190_set_rgmii(tp, sis190_read_eeprom(ioaddr, EEPROMInfo));
1570
1535 return 0; 1571 return 0;
1536} 1572}
1537 1573
@@ -1577,6 +1613,8 @@ static int __devinit sis190_get_mac_addr_from_apc(struct pci_dev *pdev,
1577 outb(0x12, 0x78); 1613 outb(0x12, 0x78);
1578 reg = inb(0x79); 1614 reg = inb(0x79);
1579 1615
1616 sis190_set_rgmii(tp, reg);
1617
1580 /* Restore the value to ISA Bridge */ 1618 /* Restore the value to ISA Bridge */
1581 pci_write_config_byte(isa_bridge, 0x48, tmp8); 1619 pci_write_config_byte(isa_bridge, 0x48, tmp8);
1582 pci_dev_put(isa_bridge); 1620 pci_dev_put(isa_bridge);
@@ -1799,6 +1837,9 @@ static int __devinit sis190_init_one(struct pci_dev *pdev,
1799 dev->dev_addr[2], dev->dev_addr[3], 1837 dev->dev_addr[2], dev->dev_addr[3],
1800 dev->dev_addr[4], dev->dev_addr[5]); 1838 dev->dev_addr[4], dev->dev_addr[5]);
1801 1839
1840 net_probe(tp, KERN_INFO "%s: %s mode.\n", dev->name,
1841 (tp->features & F_HAS_RGMII) ? "RGMII" : "GMII");
1842
1802 netif_carrier_off(dev); 1843 netif_carrier_off(dev);
1803 1844
1804 sis190_set_speed_auto(dev); 1845 sis190_set_speed_auto(dev);
diff --git a/drivers/net/smc91x.h b/drivers/net/smc91x.h
index a9b06b8d8e3..ac9ce6509ee 100644
--- a/drivers/net/smc91x.h
+++ b/drivers/net/smc91x.h
@@ -986,7 +986,7 @@ static const char * chip_ids[ 16 ] = {
986 }) 986 })
987#endif 987#endif
988 988
989#if SMC_CAN_USE_DATACS 989#ifdef SMC_CAN_USE_DATACS
990#define SMC_PUSH_DATA(p, l) \ 990#define SMC_PUSH_DATA(p, l) \
991 if ( lp->datacs ) { \ 991 if ( lp->datacs ) { \
992 unsigned char *__ptr = (p); \ 992 unsigned char *__ptr = (p); \
diff --git a/drivers/net/spider_net.c b/drivers/net/spider_net.c
new file mode 100644
index 00000000000..4e19220473d
--- /dev/null
+++ b/drivers/net/spider_net.c
@@ -0,0 +1,2334 @@
1/*
2 * Network device driver for Cell Processor-Based Blade
3 *
4 * (C) Copyright IBM Corp. 2005
5 *
6 * Authors : Utz Bacher <utz.bacher@de.ibm.com>
7 * Jens Osterkamp <Jens.Osterkamp@de.ibm.com>
8 *
9 * This program is free software; you can redistribute it and/or modify
10 * it under the terms of the GNU General Public License as published by
11 * the Free Software Foundation; either version 2, or (at your option)
12 * any later version.
13 *
14 * This program is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 * GNU General Public License for more details.
18 *
19 * You should have received a copy of the GNU General Public License
20 * along with this program; if not, write to the Free Software
21 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
22 */
23
24#include <linux/config.h>
25
26#include <linux/compiler.h>
27#include <linux/crc32.h>
28#include <linux/delay.h>
29#include <linux/etherdevice.h>
30#include <linux/ethtool.h>
31#include <linux/firmware.h>
32#include <linux/if_vlan.h>
33#include <linux/init.h>
34#include <linux/ioport.h>
35#include <linux/ip.h>
36#include <linux/kernel.h>
37#include <linux/mii.h>
38#include <linux/module.h>
39#include <linux/netdevice.h>
40#include <linux/device.h>
41#include <linux/pci.h>
42#include <linux/skbuff.h>
43#include <linux/slab.h>
44#include <linux/tcp.h>
45#include <linux/types.h>
46#include <linux/wait.h>
47#include <linux/workqueue.h>
48#include <asm/bitops.h>
49#include <asm/pci-bridge.h>
50#include <net/checksum.h>
51
52#include "spider_net.h"
53
54MODULE_AUTHOR("Utz Bacher <utz.bacher@de.ibm.com> and Jens Osterkamp " \
55 "<Jens.Osterkamp@de.ibm.com>");
56MODULE_DESCRIPTION("Spider Southbridge Gigabit Ethernet driver");
57MODULE_LICENSE("GPL");
58
59static int rx_descriptors = SPIDER_NET_RX_DESCRIPTORS_DEFAULT;
60static int tx_descriptors = SPIDER_NET_TX_DESCRIPTORS_DEFAULT;
61
62module_param(rx_descriptors, int, 0644);
63module_param(tx_descriptors, int, 0644);
64
65MODULE_PARM_DESC(rx_descriptors, "number of descriptors used " \
66 "in rx chains");
67MODULE_PARM_DESC(tx_descriptors, "number of descriptors used " \
68 "in tx chain");
69
70char spider_net_driver_name[] = "spidernet";
71
72static struct pci_device_id spider_net_pci_tbl[] = {
73 { PCI_VENDOR_ID_TOSHIBA_2, PCI_DEVICE_ID_TOSHIBA_SPIDER_NET,
74 PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0UL },
75 { 0, }
76};
77
78MODULE_DEVICE_TABLE(pci, spider_net_pci_tbl);
79
80/**
81 * spider_net_read_reg - reads an SMMIO register of a card
82 * @card: device structure
83 * @reg: register to read from
84 *
85 * returns the content of the specified SMMIO register.
86 */
87static u32
88spider_net_read_reg(struct spider_net_card *card, u32 reg)
89{
90 u32 value;
91
92 value = readl(card->regs + reg);
93 value = le32_to_cpu(value);
94
95 return value;
96}
97
98/**
99 * spider_net_write_reg - writes to an SMMIO register of a card
100 * @card: device structure
101 * @reg: register to write to
102 * @value: value to write into the specified SMMIO register
103 */
104static void
105spider_net_write_reg(struct spider_net_card *card, u32 reg, u32 value)
106{
107 value = cpu_to_le32(value);
108 writel(value, card->regs + reg);
109}
110
111/**
112 * spider_net_write_reg_sync - writes to an SMMIO register of a card
113 * @card: device structure
114 * @reg: register to write to
115 * @value: value to write into the specified SMMIO register
116 *
117 * Unlike spider_net_write_reg, this will also make sure the
118 * data arrives on the card by reading the reg again.
119 */
120static void
121spider_net_write_reg_sync(struct spider_net_card *card, u32 reg, u32 value)
122{
123 value = cpu_to_le32(value);
124 writel(value, card->regs + reg);
125 (void)readl(card->regs + reg);
126}
127
128/**
129 * spider_net_rx_irq_off - switch off rx irq on this spider card
130 * @card: device structure
131 *
132 * switches off rx irq by masking them out in the GHIINTnMSK register
133 */
134static void
135spider_net_rx_irq_off(struct spider_net_card *card)
136{
137 u32 regvalue;
138 unsigned long flags;
139
140 spin_lock_irqsave(&card->intmask_lock, flags);
141 regvalue = spider_net_read_reg(card, SPIDER_NET_GHIINT0MSK);
142 regvalue &= ~SPIDER_NET_RXINT;
143 spider_net_write_reg_sync(card, SPIDER_NET_GHIINT0MSK, regvalue);
144 spin_unlock_irqrestore(&card->intmask_lock, flags);
145}
146
147/** spider_net_write_phy - write to phy register
148 * @netdev: adapter to be written to
149 * @mii_id: id of MII
150 * @reg: PHY register
151 * @val: value to be written to phy register
152 *
153 * spider_net_write_phy_register writes to an arbitrary PHY
154 * register via the spider GPCWOPCMD register. We assume the queue does
155 * not run full (not more than 15 commands outstanding).
156 **/
157static void
158spider_net_write_phy(struct net_device *netdev, int mii_id,
159 int reg, int val)
160{
161 struct spider_net_card *card = netdev_priv(netdev);
162 u32 writevalue;
163
164 writevalue = ((u32)mii_id << 21) |
165 ((u32)reg << 16) | ((u32)val);
166
167 spider_net_write_reg(card, SPIDER_NET_GPCWOPCMD, writevalue);
168}
169
170/** spider_net_read_phy - read from phy register
171 * @netdev: network device to be read from
172 * @mii_id: id of MII
173 * @reg: PHY register
174 *
175 * Returns value read from PHY register
176 *
177 * spider_net_write_phy reads from an arbitrary PHY
178 * register via the spider GPCROPCMD register
179 **/
180static int
181spider_net_read_phy(struct net_device *netdev, int mii_id, int reg)
182{
183 struct spider_net_card *card = netdev_priv(netdev);
184 u32 readvalue;
185
186 readvalue = ((u32)mii_id << 21) | ((u32)reg << 16);
187 spider_net_write_reg(card, SPIDER_NET_GPCROPCMD, readvalue);
188
189 /* we don't use semaphores to wait for an SPIDER_NET_GPROPCMPINT
190 * interrupt, as we poll for the completion of the read operation
191 * in spider_net_read_phy. Should take about 50 us */
192 do {
193 readvalue = spider_net_read_reg(card, SPIDER_NET_GPCROPCMD);
194 } while (readvalue & SPIDER_NET_GPREXEC);
195
196 readvalue &= SPIDER_NET_GPRDAT_MASK;
197
198 return readvalue;
199}
200
201/**
202 * spider_net_rx_irq_on - switch on rx irq on this spider card
203 * @card: device structure
204 *
205 * switches on rx irq by enabling them in the GHIINTnMSK register
206 */
207static void
208spider_net_rx_irq_on(struct spider_net_card *card)
209{
210 u32 regvalue;
211 unsigned long flags;
212
213 spin_lock_irqsave(&card->intmask_lock, flags);
214 regvalue = spider_net_read_reg(card, SPIDER_NET_GHIINT0MSK);
215 regvalue |= SPIDER_NET_RXINT;
216 spider_net_write_reg_sync(card, SPIDER_NET_GHIINT0MSK, regvalue);
217 spin_unlock_irqrestore(&card->intmask_lock, flags);
218}
219
220/**
221 * spider_net_tx_irq_off - switch off tx irq on this spider card
222 * @card: device structure
223 *
224 * switches off tx irq by masking them out in the GHIINTnMSK register
225 */
226static void
227spider_net_tx_irq_off(struct spider_net_card *card)
228{
229 u32 regvalue;
230 unsigned long flags;
231
232 spin_lock_irqsave(&card->intmask_lock, flags);
233 regvalue = spider_net_read_reg(card, SPIDER_NET_GHIINT0MSK);
234 regvalue &= ~SPIDER_NET_TXINT;
235 spider_net_write_reg_sync(card, SPIDER_NET_GHIINT0MSK, regvalue);
236 spin_unlock_irqrestore(&card->intmask_lock, flags);
237}
238
239/**
240 * spider_net_tx_irq_on - switch on tx irq on this spider card
241 * @card: device structure
242 *
243 * switches on tx irq by enabling them in the GHIINTnMSK register
244 */
245static void
246spider_net_tx_irq_on(struct spider_net_card *card)
247{
248 u32 regvalue;
249 unsigned long flags;
250
251 spin_lock_irqsave(&card->intmask_lock, flags);
252 regvalue = spider_net_read_reg(card, SPIDER_NET_GHIINT0MSK);
253 regvalue |= SPIDER_NET_TXINT;
254 spider_net_write_reg_sync(card, SPIDER_NET_GHIINT0MSK, regvalue);
255 spin_unlock_irqrestore(&card->intmask_lock, flags);
256}
257
258/**
259 * spider_net_set_promisc - sets the unicast address or the promiscuous mode
260 * @card: card structure
261 *
262 * spider_net_set_promisc sets the unicast destination address filter and
263 * thus either allows for non-promisc mode or promisc mode
264 */
265static void
266spider_net_set_promisc(struct spider_net_card *card)
267{
268 u32 macu, macl;
269 struct net_device *netdev = card->netdev;
270
271 if (netdev->flags & IFF_PROMISC) {
272 /* clear destination entry 0 */
273 spider_net_write_reg(card, SPIDER_NET_GMRUAFILnR, 0);
274 spider_net_write_reg(card, SPIDER_NET_GMRUAFILnR + 0x04, 0);
275 spider_net_write_reg(card, SPIDER_NET_GMRUA0FIL15R,
276 SPIDER_NET_PROMISC_VALUE);
277 } else {
278 macu = netdev->dev_addr[0];
279 macu <<= 8;
280 macu |= netdev->dev_addr[1];
281 memcpy(&macl, &netdev->dev_addr[2], sizeof(macl));
282
283 macu |= SPIDER_NET_UA_DESCR_VALUE;
284 spider_net_write_reg(card, SPIDER_NET_GMRUAFILnR, macu);
285 spider_net_write_reg(card, SPIDER_NET_GMRUAFILnR + 0x04, macl);
286 spider_net_write_reg(card, SPIDER_NET_GMRUA0FIL15R,
287 SPIDER_NET_NONPROMISC_VALUE);
288 }
289}
290
291/**
292 * spider_net_get_mac_address - read mac address from spider card
293 * @card: device structure
294 *
295 * reads MAC address from GMACUNIMACU and GMACUNIMACL registers
296 */
297static int
298spider_net_get_mac_address(struct net_device *netdev)
299{
300 struct spider_net_card *card = netdev_priv(netdev);
301 u32 macl, macu;
302
303 macl = spider_net_read_reg(card, SPIDER_NET_GMACUNIMACL);
304 macu = spider_net_read_reg(card, SPIDER_NET_GMACUNIMACU);
305
306 netdev->dev_addr[0] = (macu >> 24) & 0xff;
307 netdev->dev_addr[1] = (macu >> 16) & 0xff;
308 netdev->dev_addr[2] = (macu >> 8) & 0xff;
309 netdev->dev_addr[3] = macu & 0xff;
310 netdev->dev_addr[4] = (macl >> 8) & 0xff;
311 netdev->dev_addr[5] = macl & 0xff;
312
313 if (!is_valid_ether_addr(&netdev->dev_addr[0]))
314 return -EINVAL;
315
316 return 0;
317}
318
319/**
320 * spider_net_get_descr_status -- returns the status of a descriptor
321 * @descr: descriptor to look at
322 *
323 * returns the status as in the dmac_cmd_status field of the descriptor
324 */
325static enum spider_net_descr_status
326spider_net_get_descr_status(struct spider_net_descr *descr)
327{
328 u32 cmd_status;
329 rmb();
330 cmd_status = descr->dmac_cmd_status;
331 rmb();
332 cmd_status >>= SPIDER_NET_DESCR_IND_PROC_SHIFT;
333 /* no need to mask out any bits, as cmd_status is 32 bits wide only
334 * (and unsigned) */
335 return cmd_status;
336}
337
338/**
339 * spider_net_set_descr_status -- sets the status of a descriptor
340 * @descr: descriptor to change
341 * @status: status to set in the descriptor
342 *
343 * changes the status to the specified value. Doesn't change other bits
344 * in the status
345 */
346static void
347spider_net_set_descr_status(struct spider_net_descr *descr,
348 enum spider_net_descr_status status)
349{
350 u32 cmd_status;
351 /* read the status */
352 mb();
353 cmd_status = descr->dmac_cmd_status;
354 /* clean the upper 4 bits */
355 cmd_status &= SPIDER_NET_DESCR_IND_PROC_MASKO;
356 /* add the status to it */
357 cmd_status |= ((u32)status)<<SPIDER_NET_DESCR_IND_PROC_SHIFT;
358 /* and write it back */
359 descr->dmac_cmd_status = cmd_status;
360 wmb();
361}
362
363/**
364 * spider_net_free_chain - free descriptor chain
365 * @card: card structure
366 * @chain: address of chain
367 *
368 */
369static void
370spider_net_free_chain(struct spider_net_card *card,
371 struct spider_net_descr_chain *chain)
372{
373 struct spider_net_descr *descr;
374
375 for (descr = chain->tail; !descr->bus_addr; descr = descr->next) {
376 pci_unmap_single(card->pdev, descr->bus_addr,
377 SPIDER_NET_DESCR_SIZE, PCI_DMA_BIDIRECTIONAL);
378 descr->bus_addr = 0;
379 }
380}
381
382/**
383 * spider_net_init_chain - links descriptor chain
384 * @card: card structure
385 * @chain: address of chain
386 * @start_descr: address of descriptor array
387 * @no: number of descriptors
388 *
389 * we manage a circular list that mirrors the hardware structure,
390 * except that the hardware uses bus addresses.
391 *
392 * returns 0 on success, <0 on failure
393 */
394static int
395spider_net_init_chain(struct spider_net_card *card,
396 struct spider_net_descr_chain *chain,
397 struct spider_net_descr *start_descr, int no)
398{
399 int i;
400 struct spider_net_descr *descr;
401
402 spin_lock_init(&card->chain_lock);
403
404 descr = start_descr;
405 memset(descr, 0, sizeof(*descr) * no);
406
407 /* set up the hardware pointers in each descriptor */
408 for (i=0; i<no; i++, descr++) {
409 spider_net_set_descr_status(descr, SPIDER_NET_DESCR_NOT_IN_USE);
410
411 descr->bus_addr =
412 pci_map_single(card->pdev, descr,
413 SPIDER_NET_DESCR_SIZE,
414 PCI_DMA_BIDIRECTIONAL);
415
416 if (descr->bus_addr == DMA_ERROR_CODE)
417 goto iommu_error;
418
419 descr->next = descr + 1;
420 descr->prev = descr - 1;
421
422 }
423 /* do actual circular list */
424 (descr-1)->next = start_descr;
425 start_descr->prev = descr-1;
426
427 descr = start_descr;
428 for (i=0; i < no; i++, descr++) {
429 descr->next_descr_addr = descr->next->bus_addr;
430 }
431
432 chain->head = start_descr;
433 chain->tail = start_descr;
434
435 return 0;
436
437iommu_error:
438 descr = start_descr;
439 for (i=0; i < no; i++, descr++)
440 if (descr->bus_addr)
441 pci_unmap_single(card->pdev, descr->bus_addr,
442 SPIDER_NET_DESCR_SIZE, PCI_DMA_BIDIRECTIONAL);
443 return -ENOMEM;
444}
445
446/**
447 * spider_net_free_rx_chain_contents - frees descr contents in rx chain
448 * @card: card structure
449 *
450 * returns 0 on success, <0 on failure
451 */
452static void
453spider_net_free_rx_chain_contents(struct spider_net_card *card)
454{
455 struct spider_net_descr *descr;
456
457 descr = card->rx_chain.head;
458 while (descr->next != card->rx_chain.head) {
459 if (descr->skb) {
460 dev_kfree_skb(descr->skb);
461 pci_unmap_single(card->pdev, descr->buf_addr,
462 SPIDER_NET_MAX_MTU,
463 PCI_DMA_BIDIRECTIONAL);
464 }
465 descr = descr->next;
466 }
467}
468
469/**
470 * spider_net_prepare_rx_descr - reinitializes a rx descriptor
471 * @card: card structure
472 * @descr: descriptor to re-init
473 *
474 * return 0 on succes, <0 on failure
475 *
476 * allocates a new rx skb, iommu-maps it and attaches it to the descriptor.
477 * Activate the descriptor state-wise
478 */
479static int
480spider_net_prepare_rx_descr(struct spider_net_card *card,
481 struct spider_net_descr *descr)
482{
483 int error = 0;
484 int offset;
485 int bufsize;
486
487 /* we need to round up the buffer size to a multiple of 128 */
488 bufsize = (SPIDER_NET_MAX_MTU + SPIDER_NET_RXBUF_ALIGN - 1) &
489 (~(SPIDER_NET_RXBUF_ALIGN - 1));
490
491 /* and we need to have it 128 byte aligned, therefore we allocate a
492 * bit more */
493 /* allocate an skb */
494 descr->skb = dev_alloc_skb(bufsize + SPIDER_NET_RXBUF_ALIGN - 1);
495 if (!descr->skb) {
496 if (net_ratelimit())
497 if (netif_msg_rx_err(card))
498 pr_err("Not enough memory to allocate "
499 "rx buffer\n");
500 return -ENOMEM;
501 }
502 descr->buf_size = bufsize;
503 descr->result_size = 0;
504 descr->valid_size = 0;
505 descr->data_status = 0;
506 descr->data_error = 0;
507
508 offset = ((unsigned long)descr->skb->data) &
509 (SPIDER_NET_RXBUF_ALIGN - 1);
510 if (offset)
511 skb_reserve(descr->skb, SPIDER_NET_RXBUF_ALIGN - offset);
512 /* io-mmu-map the skb */
513 descr->buf_addr = pci_map_single(card->pdev, descr->skb->data,
514 SPIDER_NET_MAX_MTU,
515 PCI_DMA_BIDIRECTIONAL);
516 if (descr->buf_addr == DMA_ERROR_CODE) {
517 dev_kfree_skb_any(descr->skb);
518 if (netif_msg_rx_err(card))
519 pr_err("Could not iommu-map rx buffer\n");
520 spider_net_set_descr_status(descr, SPIDER_NET_DESCR_NOT_IN_USE);
521 } else {
522 descr->dmac_cmd_status = SPIDER_NET_DMAC_RX_CARDOWNED;
523 }
524
525 return error;
526}
527
528/**
529 * spider_net_enable_rxctails - sets RX dmac chain tail addresses
530 * @card: card structure
531 *
532 * spider_net_enable_rxctails sets the RX DMAC chain tail adresses in the
533 * chip by writing to the appropriate register. DMA is enabled in
534 * spider_net_enable_rxdmac.
535 */
536static void
537spider_net_enable_rxchtails(struct spider_net_card *card)
538{
539 /* assume chain is aligned correctly */
540 spider_net_write_reg(card, SPIDER_NET_GDADCHA ,
541 card->rx_chain.tail->bus_addr);
542}
543
544/**
545 * spider_net_enable_rxdmac - enables a receive DMA controller
546 * @card: card structure
547 *
548 * spider_net_enable_rxdmac enables the DMA controller by setting RX_DMA_EN
549 * in the GDADMACCNTR register
550 */
551static void
552spider_net_enable_rxdmac(struct spider_net_card *card)
553{
554 spider_net_write_reg(card, SPIDER_NET_GDADMACCNTR,
555 SPIDER_NET_DMA_RX_VALUE);
556}
557
558/**
559 * spider_net_refill_rx_chain - refills descriptors/skbs in the rx chains
560 * @card: card structure
561 *
562 * refills descriptors in all chains (last used chain first): allocates skbs
563 * and iommu-maps them.
564 */
565static void
566spider_net_refill_rx_chain(struct spider_net_card *card)
567{
568 struct spider_net_descr_chain *chain;
569 int count = 0;
570 unsigned long flags;
571
572 chain = &card->rx_chain;
573
574 spin_lock_irqsave(&card->chain_lock, flags);
575 while (spider_net_get_descr_status(chain->head) ==
576 SPIDER_NET_DESCR_NOT_IN_USE) {
577 if (spider_net_prepare_rx_descr(card, chain->head))
578 break;
579 count++;
580 chain->head = chain->head->next;
581 }
582 spin_unlock_irqrestore(&card->chain_lock, flags);
583
584 /* could be optimized, only do that, if we know the DMA processing
585 * has terminated */
586 if (count)
587 spider_net_enable_rxdmac(card);
588}
589
590/**
591 * spider_net_alloc_rx_skbs - allocates rx skbs in rx descriptor chains
592 * @card: card structure
593 *
594 * returns 0 on success, <0 on failure
595 */
596static int
597spider_net_alloc_rx_skbs(struct spider_net_card *card)
598{
599 int result;
600 struct spider_net_descr_chain *chain;
601
602 result = -ENOMEM;
603
604 chain = &card->rx_chain;
605 /* put at least one buffer into the chain. if this fails,
606 * we've got a problem. if not, spider_net_refill_rx_chain
607 * will do the rest at the end of this function */
608 if (spider_net_prepare_rx_descr(card, chain->head))
609 goto error;
610 else
611 chain->head = chain->head->next;
612
613 /* this will allocate the rest of the rx buffers; if not, it's
614 * business as usual later on */
615 spider_net_refill_rx_chain(card);
616 return 0;
617
618error:
619 spider_net_free_rx_chain_contents(card);
620 return result;
621}
622
623/**
624 * spider_net_release_tx_descr - processes a used tx descriptor
625 * @card: card structure
626 * @descr: descriptor to release
627 *
628 * releases a used tx descriptor (unmapping, freeing of skb)
629 */
630static void
631spider_net_release_tx_descr(struct spider_net_card *card,
632 struct spider_net_descr *descr)
633{
634 struct sk_buff *skb;
635
636 /* unmap the skb */
637 skb = descr->skb;
638 pci_unmap_single(card->pdev, descr->buf_addr, skb->len,
639 PCI_DMA_BIDIRECTIONAL);
640
641 dev_kfree_skb_any(skb);
642
643 /* set status to not used */
644 spider_net_set_descr_status(descr, SPIDER_NET_DESCR_NOT_IN_USE);
645}
646
647/**
648 * spider_net_release_tx_chain - processes sent tx descriptors
649 * @card: adapter structure
650 * @brutal: if set, don't care about whether descriptor seems to be in use
651 *
652 * releases the tx descriptors that spider has finished with (if non-brutal)
653 * or simply release tx descriptors (if brutal)
654 */
655static void
656spider_net_release_tx_chain(struct spider_net_card *card, int brutal)
657{
658 struct spider_net_descr_chain *tx_chain = &card->tx_chain;
659 enum spider_net_descr_status status;
660
661 spider_net_tx_irq_off(card);
662
663 /* no lock for chain needed, if this is only executed once at a time */
664again:
665 for (;;) {
666 status = spider_net_get_descr_status(tx_chain->tail);
667 switch (status) {
668 case SPIDER_NET_DESCR_CARDOWNED:
669 if (!brutal) goto out;
670 /* fallthrough, if we release the descriptors
671 * brutally (then we don't care about
672 * SPIDER_NET_DESCR_CARDOWNED) */
673 case SPIDER_NET_DESCR_RESPONSE_ERROR:
674 case SPIDER_NET_DESCR_PROTECTION_ERROR:
675 case SPIDER_NET_DESCR_FORCE_END:
676 if (netif_msg_tx_err(card))
677 pr_err("%s: forcing end of tx descriptor "
678 "with status x%02x\n",
679 card->netdev->name, status);
680 card->netdev_stats.tx_dropped++;
681 break;
682
683 case SPIDER_NET_DESCR_COMPLETE:
684 card->netdev_stats.tx_packets++;
685 card->netdev_stats.tx_bytes +=
686 tx_chain->tail->skb->len;
687 break;
688
689 default: /* any other value (== SPIDER_NET_DESCR_NOT_IN_USE) */
690 goto out;
691 }
692 spider_net_release_tx_descr(card, tx_chain->tail);
693 tx_chain->tail = tx_chain->tail->next;
694 }
695out:
696 netif_wake_queue(card->netdev);
697
698 if (!brutal) {
699 /* switch on tx irqs (while we are still in the interrupt
700 * handler, so we don't get an interrupt), check again
701 * for done descriptors. This results in fewer interrupts */
702 spider_net_tx_irq_on(card);
703 status = spider_net_get_descr_status(tx_chain->tail);
704 switch (status) {
705 case SPIDER_NET_DESCR_RESPONSE_ERROR:
706 case SPIDER_NET_DESCR_PROTECTION_ERROR:
707 case SPIDER_NET_DESCR_FORCE_END:
708 case SPIDER_NET_DESCR_COMPLETE:
709 goto again;
710 default:
711 break;
712 }
713 }
714
715}
716
717/**
718 * spider_net_get_multicast_hash - generates hash for multicast filter table
719 * @addr: multicast address
720 *
721 * returns the hash value.
722 *
723 * spider_net_get_multicast_hash calculates a hash value for a given multicast
724 * address, that is used to set the multicast filter tables
725 */
726static u8
727spider_net_get_multicast_hash(struct net_device *netdev, __u8 *addr)
728{
729 /* FIXME: an addr of 01:00:5e:00:00:01 must result in 0xa9,
730 * ff:ff:ff:ff:ff:ff must result in 0xfd */
731 u32 crc;
732 u8 hash;
733
734 crc = crc32_be(~0, addr, netdev->addr_len);
735
736 hash = (crc >> 27);
737 hash <<= 3;
738 hash |= crc & 7;
739
740 return hash;
741}
742
743/**
744 * spider_net_set_multi - sets multicast addresses and promisc flags
745 * @netdev: interface device structure
746 *
747 * spider_net_set_multi configures multicast addresses as needed for the
748 * netdev interface. It also sets up multicast, allmulti and promisc
749 * flags appropriately
750 */
751static void
752spider_net_set_multi(struct net_device *netdev)
753{
754 struct dev_mc_list *mc;
755 u8 hash;
756 int i;
757 u32 reg;
758 struct spider_net_card *card = netdev_priv(netdev);
759 unsigned long bitmask[SPIDER_NET_MULTICAST_HASHES / BITS_PER_LONG] =
760 {0, };
761
762 spider_net_set_promisc(card);
763
764 if (netdev->flags & IFF_ALLMULTI) {
765 for (i = 0; i < SPIDER_NET_MULTICAST_HASHES; i++) {
766 set_bit(i, bitmask);
767 }
768 goto write_hash;
769 }
770
771 /* well, we know, what the broadcast hash value is: it's xfd
772 hash = spider_net_get_multicast_hash(netdev, netdev->broadcast); */
773 set_bit(0xfd, bitmask);
774
775 for (mc = netdev->mc_list; mc; mc = mc->next) {
776 hash = spider_net_get_multicast_hash(netdev, mc->dmi_addr);
777 set_bit(hash, bitmask);
778 }
779
780write_hash:
781 for (i = 0; i < SPIDER_NET_MULTICAST_HASHES / 4; i++) {
782 reg = 0;
783 if (test_bit(i * 4, bitmask))
784 reg += 0x08;
785 reg <<= 8;
786 if (test_bit(i * 4 + 1, bitmask))
787 reg += 0x08;
788 reg <<= 8;
789 if (test_bit(i * 4 + 2, bitmask))
790 reg += 0x08;
791 reg <<= 8;
792 if (test_bit(i * 4 + 3, bitmask))
793 reg += 0x08;
794
795 spider_net_write_reg(card, SPIDER_NET_GMRMHFILnR + i * 4, reg);
796 }
797}
798
799/**
800 * spider_net_disable_rxdmac - disables the receive DMA controller
801 * @card: card structure
802 *
803 * spider_net_disable_rxdmac terminates processing on the DMA controller by
804 * turing off DMA and issueing a force end
805 */
806static void
807spider_net_disable_rxdmac(struct spider_net_card *card)
808{
809 spider_net_write_reg(card, SPIDER_NET_GDADMACCNTR,
810 SPIDER_NET_DMA_RX_FEND_VALUE);
811}
812
813/**
814 * spider_net_stop - called upon ifconfig down
815 * @netdev: interface device structure
816 *
817 * always returns 0
818 */
819int
820spider_net_stop(struct net_device *netdev)
821{
822 struct spider_net_card *card = netdev_priv(netdev);
823
824 netif_poll_disable(netdev);
825 netif_carrier_off(netdev);
826 netif_stop_queue(netdev);
827
828 /* disable/mask all interrupts */
829 spider_net_write_reg(card, SPIDER_NET_GHIINT0MSK, 0);
830 spider_net_write_reg(card, SPIDER_NET_GHIINT1MSK, 0);
831 spider_net_write_reg(card, SPIDER_NET_GHIINT2MSK, 0);
832
833 /* free_irq(netdev->irq, netdev);*/
834 free_irq(to_pci_dev(netdev->class_dev.dev)->irq, netdev);
835
836 spider_net_write_reg(card, SPIDER_NET_GDTDMACCNTR,
837 SPIDER_NET_DMA_TX_FEND_VALUE);
838
839 /* turn off DMA, force end */
840 spider_net_disable_rxdmac(card);
841
842 /* release chains */
843 spider_net_release_tx_chain(card, 1);
844
845 spider_net_free_chain(card, &card->tx_chain);
846 spider_net_free_chain(card, &card->rx_chain);
847
848 return 0;
849}
850
851/**
852 * spider_net_get_next_tx_descr - returns the next available tx descriptor
853 * @card: device structure to get descriptor from
854 *
855 * returns the address of the next descriptor, or NULL if not available.
856 */
857static struct spider_net_descr *
858spider_net_get_next_tx_descr(struct spider_net_card *card)
859{
860 /* check, if head points to not-in-use descr */
861 if ( spider_net_get_descr_status(card->tx_chain.head) ==
862 SPIDER_NET_DESCR_NOT_IN_USE ) {
863 return card->tx_chain.head;
864 } else {
865 return NULL;
866 }
867}
868
869/**
870 * spider_net_set_txdescr_cmdstat - sets the tx descriptor command field
871 * @descr: descriptor structure to fill out
872 * @skb: packet to consider
873 *
874 * fills out the command and status field of the descriptor structure,
875 * depending on hardware checksum settings. This function assumes a wmb()
876 * has executed before.
877 */
878static void
879spider_net_set_txdescr_cmdstat(struct spider_net_descr *descr,
880 struct sk_buff *skb)
881{
882 if (skb->ip_summed != CHECKSUM_HW) {
883 descr->dmac_cmd_status = SPIDER_NET_DMAC_CMDSTAT_NOCS;
884 return;
885 }
886
887 /* is packet ip?
888 * if yes: tcp? udp? */
889 if (skb->protocol == htons(ETH_P_IP)) {
890 if (skb->nh.iph->protocol == IPPROTO_TCP) {
891 descr->dmac_cmd_status = SPIDER_NET_DMAC_CMDSTAT_TCPCS;
892 } else if (skb->nh.iph->protocol == IPPROTO_UDP) {
893 descr->dmac_cmd_status = SPIDER_NET_DMAC_CMDSTAT_UDPCS;
894 } else { /* the stack should checksum non-tcp and non-udp
895 packets on his own: NETIF_F_IP_CSUM */
896 descr->dmac_cmd_status = SPIDER_NET_DMAC_CMDSTAT_NOCS;
897 }
898 }
899}
900
901/**
902 * spider_net_prepare_tx_descr - fill tx descriptor with skb data
903 * @card: card structure
904 * @descr: descriptor structure to fill out
905 * @skb: packet to use
906 *
907 * returns 0 on success, <0 on failure.
908 *
909 * fills out the descriptor structure with skb data and len. Copies data,
910 * if needed (32bit DMA!)
911 */
912static int
913spider_net_prepare_tx_descr(struct spider_net_card *card,
914 struct spider_net_descr *descr,
915 struct sk_buff *skb)
916{
917 descr->buf_addr = pci_map_single(card->pdev, skb->data,
918 skb->len, PCI_DMA_BIDIRECTIONAL);
919 if (descr->buf_addr == DMA_ERROR_CODE) {
920 if (netif_msg_tx_err(card))
921 pr_err("could not iommu-map packet (%p, %i). "
922 "Dropping packet\n", skb->data, skb->len);
923 return -ENOMEM;
924 }
925
926 descr->buf_size = skb->len;
927 descr->skb = skb;
928 descr->data_status = 0;
929
930 /* make sure the above values are in memory before we change the
931 * status */
932 wmb();
933
934 spider_net_set_txdescr_cmdstat(descr,skb);
935
936 return 0;
937}
938
939/**
940 * spider_net_kick_tx_dma - enables TX DMA processing
941 * @card: card structure
942 * @descr: descriptor address to enable TX processing at
943 *
944 * spider_net_kick_tx_dma writes the current tx chain head as start address
945 * of the tx descriptor chain and enables the transmission DMA engine
946 */
947static void
948spider_net_kick_tx_dma(struct spider_net_card *card,
949 struct spider_net_descr *descr)
950{
951 /* this is the only descriptor in the output chain.
952 * Enable TX DMA */
953
954 spider_net_write_reg(card, SPIDER_NET_GDTDCHA,
955 descr->bus_addr);
956
957 spider_net_write_reg(card, SPIDER_NET_GDTDMACCNTR,
958 SPIDER_NET_DMA_TX_VALUE);
959}
960
961/**
962 * spider_net_xmit - transmits a frame over the device
963 * @skb: packet to send out
964 * @netdev: interface device structure
965 *
966 * returns 0 on success, <0 on failure
967 */
968static int
969spider_net_xmit(struct sk_buff *skb, struct net_device *netdev)
970{
971 struct spider_net_card *card = netdev_priv(netdev);
972 struct spider_net_descr *descr;
973 int result;
974
975 descr = spider_net_get_next_tx_descr(card);
976
977 if (!descr) {
978 netif_stop_queue(netdev);
979
980 descr = spider_net_get_next_tx_descr(card);
981 if (!descr)
982 goto error;
983 else
984 netif_start_queue(netdev);
985 }
986
987 result = spider_net_prepare_tx_descr(card, descr, skb);
988 if (result)
989 goto error;
990
991 card->tx_chain.head = card->tx_chain.head->next;
992
993 /* make sure the status from spider_net_prepare_tx_descr is in
994 * memory before we check out the previous descriptor */
995 wmb();
996
997 if (spider_net_get_descr_status(descr->prev) !=
998 SPIDER_NET_DESCR_CARDOWNED)
999 spider_net_kick_tx_dma(card, descr);
1000
1001 return NETDEV_TX_OK;
1002
1003error:
1004 card->netdev_stats.tx_dropped++;
1005 return NETDEV_TX_LOCKED;
1006}
1007
1008/**
1009 * spider_net_do_ioctl - called for device ioctls
1010 * @netdev: interface device structure
1011 * @ifr: request parameter structure for ioctl
1012 * @cmd: command code for ioctl
1013 *
1014 * returns 0 on success, <0 on failure. Currently, we have no special ioctls.
1015 * -EOPNOTSUPP is returned, if an unknown ioctl was requested
1016 */
1017static int
1018spider_net_do_ioctl(struct net_device *netdev, struct ifreq *ifr, int cmd)
1019{
1020 switch (cmd) {
1021 default:
1022 return -EOPNOTSUPP;
1023 }
1024}
1025
1026/**
1027 * spider_net_pass_skb_up - takes an skb from a descriptor and passes it on
1028 * @descr: descriptor to process
1029 * @card: card structure
1030 *
1031 * returns 1 on success, 0 if no packet was passed to the stack
1032 *
1033 * iommu-unmaps the skb, fills out skb structure and passes the data to the
1034 * stack. The descriptor state is not changed.
1035 */
1036static int
1037spider_net_pass_skb_up(struct spider_net_descr *descr,
1038 struct spider_net_card *card)
1039{
1040 struct sk_buff *skb;
1041 struct net_device *netdev;
1042 u32 data_status, data_error;
1043
1044 data_status = descr->data_status;
1045 data_error = descr->data_error;
1046
1047 netdev = card->netdev;
1048
1049 /* check for errors in the data_error flag */
1050 if ((data_error & SPIDER_NET_DATA_ERROR_MASK) &&
1051 netif_msg_rx_err(card))
1052 pr_err("error in received descriptor found, "
1053 "data_status=x%08x, data_error=x%08x\n",
1054 data_status, data_error);
1055
1056 /* prepare skb, unmap descriptor */
1057 skb = descr->skb;
1058 pci_unmap_single(card->pdev, descr->buf_addr, SPIDER_NET_MAX_MTU,
1059 PCI_DMA_BIDIRECTIONAL);
1060
1061 /* the cases we'll throw away the packet immediately */
1062 if (data_error & SPIDER_NET_DESTROY_RX_FLAGS)
1063 return 0;
1064
1065 skb->dev = netdev;
1066 skb_put(skb, descr->valid_size);
1067
1068 /* the card seems to add 2 bytes of junk in front
1069 * of the ethernet frame */
1070#define SPIDER_MISALIGN 2
1071 skb_pull(skb, SPIDER_MISALIGN);
1072 skb->protocol = eth_type_trans(skb, netdev);
1073
1074 /* checksum offload */
1075 if (card->options.rx_csum) {
1076 if ( (data_status & SPIDER_NET_DATA_STATUS_CHK_MASK) &&
1077 (!(data_error & SPIDER_NET_DATA_ERROR_CHK_MASK)) )
1078 skb->ip_summed = CHECKSUM_UNNECESSARY;
1079 else
1080 skb->ip_summed = CHECKSUM_NONE;
1081 } else {
1082 skb->ip_summed = CHECKSUM_NONE;
1083 }
1084
1085 if (data_status & SPIDER_NET_VLAN_PACKET) {
1086 /* further enhancements: HW-accel VLAN
1087 * vlan_hwaccel_receive_skb
1088 */
1089 }
1090
1091 /* pass skb up to stack */
1092 netif_receive_skb(skb);
1093
1094 /* update netdevice statistics */
1095 card->netdev_stats.rx_packets++;
1096 card->netdev_stats.rx_bytes += skb->len;
1097
1098 return 1;
1099}
1100
1101/**
1102 * spider_net_decode_descr - processes an rx descriptor
1103 * @card: card structure
1104 *
1105 * returns 1 if a packet has been sent to the stack, otherwise 0
1106 *
1107 * processes an rx descriptor by iommu-unmapping the data buffer and passing
1108 * the packet up to the stack
1109 */
1110static int
1111spider_net_decode_one_descr(struct spider_net_card *card)
1112{
1113 enum spider_net_descr_status status;
1114 struct spider_net_descr *descr;
1115 struct spider_net_descr_chain *chain;
1116 int result;
1117
1118 chain = &card->rx_chain;
1119 descr = chain->tail;
1120
1121 status = spider_net_get_descr_status(descr);
1122
1123 if (status == SPIDER_NET_DESCR_CARDOWNED) {
1124 /* nothing in the descriptor yet */
1125 return 0;
1126 }
1127
1128 if (status == SPIDER_NET_DESCR_NOT_IN_USE) {
1129 /* not initialized yet, I bet chain->tail == chain->head
1130 * and the ring is empty */
1131 spider_net_refill_rx_chain(card);
1132 return 0;
1133 }
1134
1135 /* descriptor definitively used -- move on head */
1136 chain->tail = descr->next;
1137
1138 result = 0;
1139 if ( (status == SPIDER_NET_DESCR_RESPONSE_ERROR) ||
1140 (status == SPIDER_NET_DESCR_PROTECTION_ERROR) ||
1141 (status == SPIDER_NET_DESCR_FORCE_END) ) {
1142 if (netif_msg_rx_err(card))
1143 pr_err("%s: dropping RX descriptor with state %d\n",
1144 card->netdev->name, status);
1145 card->netdev_stats.rx_dropped++;
1146 goto refill;
1147 }
1148
1149 if ( (status != SPIDER_NET_DESCR_COMPLETE) &&
1150 (status != SPIDER_NET_DESCR_FRAME_END) ) {
1151 if (netif_msg_rx_err(card))
1152 pr_err("%s: RX descriptor with state %d\n",
1153 card->netdev->name, status);
1154 goto refill;
1155 }
1156
1157 /* ok, we've got a packet in descr */
1158 result = spider_net_pass_skb_up(descr, card);
1159refill:
1160 spider_net_set_descr_status(descr, SPIDER_NET_DESCR_NOT_IN_USE);
1161 /* change the descriptor state: */
1162 spider_net_refill_rx_chain(card);
1163
1164 return result;
1165}
1166
1167/**
1168 * spider_net_poll - NAPI poll function called by the stack to return packets
1169 * @netdev: interface device structure
1170 * @budget: number of packets we can pass to the stack at most
1171 *
1172 * returns 0 if no more packets available to the driver/stack. Returns 1,
1173 * if the quota is exceeded, but the driver has still packets.
1174 *
1175 * spider_net_poll returns all packets from the rx descriptors to the stack
1176 * (using netif_receive_skb). If all/enough packets are up, the driver
1177 * reenables interrupts and returns 0. If not, 1 is returned.
1178 */
1179static int
1180spider_net_poll(struct net_device *netdev, int *budget)
1181{
1182 struct spider_net_card *card = netdev_priv(netdev);
1183 int packets_to_do, packets_done = 0;
1184 int no_more_packets = 0;
1185
1186 packets_to_do = min(*budget, netdev->quota);
1187
1188 while (packets_to_do) {
1189 if (spider_net_decode_one_descr(card)) {
1190 packets_done++;
1191 packets_to_do--;
1192 } else {
1193 /* no more packets for the stack */
1194 no_more_packets = 1;
1195 break;
1196 }
1197 }
1198
1199 netdev->quota -= packets_done;
1200 *budget -= packets_done;
1201
1202 /* if all packets are in the stack, enable interrupts and return 0 */
1203 /* if not, return 1 */
1204 if (no_more_packets) {
1205 netif_rx_complete(netdev);
1206 spider_net_rx_irq_on(card);
1207 return 0;
1208 }
1209
1210 return 1;
1211}
1212
1213/**
1214 * spider_net_vlan_rx_reg - initializes VLAN structures in the driver and card
1215 * @netdev: interface device structure
1216 * @grp: vlan_group structure that is registered (NULL on destroying interface)
1217 */
1218static void
1219spider_net_vlan_rx_reg(struct net_device *netdev, struct vlan_group *grp)
1220{
1221 /* further enhancement... yet to do */
1222 return;
1223}
1224
1225/**
1226 * spider_net_vlan_rx_add - adds VLAN id to the card filter
1227 * @netdev: interface device structure
1228 * @vid: VLAN id to add
1229 */
1230static void
1231spider_net_vlan_rx_add(struct net_device *netdev, uint16_t vid)
1232{
1233 /* further enhancement... yet to do */
1234 /* add vid to card's VLAN filter table */
1235 return;
1236}
1237
1238/**
1239 * spider_net_vlan_rx_kill - removes VLAN id to the card filter
1240 * @netdev: interface device structure
1241 * @vid: VLAN id to remove
1242 */
1243static void
1244spider_net_vlan_rx_kill(struct net_device *netdev, uint16_t vid)
1245{
1246 /* further enhancement... yet to do */
1247 /* remove vid from card's VLAN filter table */
1248}
1249
1250/**
1251 * spider_net_get_stats - get interface statistics
1252 * @netdev: interface device structure
1253 *
1254 * returns the interface statistics residing in the spider_net_card struct
1255 */
1256static struct net_device_stats *
1257spider_net_get_stats(struct net_device *netdev)
1258{
1259 struct spider_net_card *card = netdev_priv(netdev);
1260 struct net_device_stats *stats = &card->netdev_stats;
1261 return stats;
1262}
1263
1264/**
1265 * spider_net_change_mtu - changes the MTU of an interface
1266 * @netdev: interface device structure
1267 * @new_mtu: new MTU value
1268 *
1269 * returns 0 on success, <0 on failure
1270 */
1271static int
1272spider_net_change_mtu(struct net_device *netdev, int new_mtu)
1273{
1274 /* no need to re-alloc skbs or so -- the max mtu is about 2.3k
1275 * and mtu is outbound only anyway */
1276 if ( (new_mtu < SPIDER_NET_MIN_MTU ) ||
1277 (new_mtu > SPIDER_NET_MAX_MTU) )
1278 return -EINVAL;
1279 netdev->mtu = new_mtu;
1280 return 0;
1281}
1282
1283/**
1284 * spider_net_set_mac - sets the MAC of an interface
1285 * @netdev: interface device structure
1286 * @ptr: pointer to new MAC address
1287 *
1288 * Returns 0 on success, <0 on failure. Currently, we don't support this
1289 * and will always return EOPNOTSUPP.
1290 */
1291static int
1292spider_net_set_mac(struct net_device *netdev, void *p)
1293{
1294 struct spider_net_card *card = netdev_priv(netdev);
1295 u32 macl, macu, regvalue;
1296 struct sockaddr *addr = p;
1297
1298 if (!is_valid_ether_addr(addr->sa_data))
1299 return -EADDRNOTAVAIL;
1300
1301 /* switch off GMACTPE and GMACRPE */
1302 regvalue = spider_net_read_reg(card, SPIDER_NET_GMACOPEMD);
1303 regvalue &= ~((1 << 5) | (1 << 6));
1304 spider_net_write_reg(card, SPIDER_NET_GMACOPEMD, regvalue);
1305
1306 /* write mac */
1307 macu = (addr->sa_data[0]<<24) + (addr->sa_data[1]<<16) +
1308 (addr->sa_data[2]<<8) + (addr->sa_data[3]);
1309 macl = (addr->sa_data[4]<<8) + (addr->sa_data[5]);
1310 spider_net_write_reg(card, SPIDER_NET_GMACUNIMACU, macu);
1311 spider_net_write_reg(card, SPIDER_NET_GMACUNIMACL, macl);
1312
1313 /* switch GMACTPE and GMACRPE back on */
1314 regvalue = spider_net_read_reg(card, SPIDER_NET_GMACOPEMD);
1315 regvalue |= ((1 << 5) | (1 << 6));
1316 spider_net_write_reg(card, SPIDER_NET_GMACOPEMD, regvalue);
1317
1318 spider_net_set_promisc(card);
1319
1320 /* look up, whether we have been successful */
1321 if (spider_net_get_mac_address(netdev))
1322 return -EADDRNOTAVAIL;
1323 if (memcmp(netdev->dev_addr,addr->sa_data,netdev->addr_len))
1324 return -EADDRNOTAVAIL;
1325
1326 return 0;
1327}
1328
1329/**
1330 * spider_net_enable_txdmac - enables a TX DMA controller
1331 * @card: card structure
1332 *
1333 * spider_net_enable_txdmac enables the TX DMA controller by setting the
1334 * descriptor chain tail address
1335 */
1336static void
1337spider_net_enable_txdmac(struct spider_net_card *card)
1338{
1339 /* assume chain is aligned correctly */
1340 spider_net_write_reg(card, SPIDER_NET_GDTDCHA,
1341 card->tx_chain.tail->bus_addr);
1342}
1343
1344/**
1345 * spider_net_handle_error_irq - handles errors raised by an interrupt
1346 * @card: card structure
1347 * @status_reg: interrupt status register 0 (GHIINT0STS)
1348 *
1349 * spider_net_handle_error_irq treats or ignores all error conditions
1350 * found when an interrupt is presented
1351 */
1352static void
1353spider_net_handle_error_irq(struct spider_net_card *card, u32 status_reg)
1354{
1355 u32 error_reg1, error_reg2;
1356 u32 i;
1357 int show_error = 1;
1358
1359 error_reg1 = spider_net_read_reg(card, SPIDER_NET_GHIINT1STS);
1360 error_reg2 = spider_net_read_reg(card, SPIDER_NET_GHIINT2STS);
1361
1362 /* check GHIINT0STS ************************************/
1363 if (status_reg)
1364 for (i = 0; i < 32; i++)
1365 if (status_reg & (1<<i))
1366 switch (i)
1367 {
1368 /* let error_reg1 and error_reg2 evaluation decide, what to do
1369 case SPIDER_NET_PHYINT:
1370 case SPIDER_NET_GMAC2INT:
1371 case SPIDER_NET_GMAC1INT:
1372 case SPIDER_NET_GIPSINT:
1373 case SPIDER_NET_GFIFOINT:
1374 case SPIDER_NET_DMACINT:
1375 case SPIDER_NET_GSYSINT:
1376 break; */
1377
1378 case SPIDER_NET_GPWOPCMPINT:
1379 /* PHY write operation completed */
1380 show_error = 0;
1381 break;
1382 case SPIDER_NET_GPROPCMPINT:
1383 /* PHY read operation completed */
1384 /* we don't use semaphores, as we poll for the completion
1385 * of the read operation in spider_net_read_phy. Should take
1386 * about 50 us */
1387 show_error = 0;
1388 break;
1389 case SPIDER_NET_GPWFFINT:
1390 /* PHY command queue full */
1391 if (netif_msg_intr(card))
1392 pr_err("PHY write queue full\n");
1393 show_error = 0;
1394 break;
1395
1396 /* case SPIDER_NET_GRMDADRINT: not used. print a message */
1397 /* case SPIDER_NET_GRMARPINT: not used. print a message */
1398 /* case SPIDER_NET_GRMMPINT: not used. print a message */
1399
1400 case SPIDER_NET_GDTDEN0INT:
1401 /* someone has set TX_DMA_EN to 0 */
1402 show_error = 0;
1403 break;
1404
1405 case SPIDER_NET_GDDDEN0INT: /* fallthrough */
1406 case SPIDER_NET_GDCDEN0INT: /* fallthrough */
1407 case SPIDER_NET_GDBDEN0INT: /* fallthrough */
1408 case SPIDER_NET_GDADEN0INT:
1409 /* someone has set RX_DMA_EN to 0 */
1410 show_error = 0;
1411 break;
1412
1413 /* RX interrupts */
1414 case SPIDER_NET_GDDFDCINT:
1415 case SPIDER_NET_GDCFDCINT:
1416 case SPIDER_NET_GDBFDCINT:
1417 case SPIDER_NET_GDAFDCINT:
1418 /* case SPIDER_NET_GDNMINT: not used. print a message */
1419 /* case SPIDER_NET_GCNMINT: not used. print a message */
1420 /* case SPIDER_NET_GBNMINT: not used. print a message */
1421 /* case SPIDER_NET_GANMINT: not used. print a message */
1422 /* case SPIDER_NET_GRFNMINT: not used. print a message */
1423 show_error = 0;
1424 break;
1425
1426 /* TX interrupts */
1427 case SPIDER_NET_GDTFDCINT:
1428 show_error = 0;
1429 break;
1430 case SPIDER_NET_GTTEDINT:
1431 show_error = 0;
1432 break;
1433 case SPIDER_NET_GDTDCEINT:
1434 /* chain end. If a descriptor should be sent, kick off
1435 * tx dma
1436 if (card->tx_chain.tail == card->tx_chain.head)
1437 spider_net_kick_tx_dma(card);
1438 show_error = 0; */
1439 break;
1440
1441 /* case SPIDER_NET_G1TMCNTINT: not used. print a message */
1442 /* case SPIDER_NET_GFREECNTINT: not used. print a message */
1443 }
1444
1445 /* check GHIINT1STS ************************************/
1446 if (error_reg1)
1447 for (i = 0; i < 32; i++)
1448 if (error_reg1 & (1<<i))
1449 switch (i)
1450 {
1451 case SPIDER_NET_GTMFLLINT:
1452 if (netif_msg_intr(card))
1453 pr_err("Spider TX RAM full\n");
1454 show_error = 0;
1455 break;
1456 case SPIDER_NET_GRMFLLINT:
1457 if (netif_msg_intr(card))
1458 pr_err("Spider RX RAM full, incoming packets "
1459 "might be discarded !\n");
1460 netif_rx_schedule(card->netdev);
1461 spider_net_enable_rxchtails(card);
1462 spider_net_enable_rxdmac(card);
1463 break;
1464
1465 /* case SPIDER_NET_GTMSHTINT: problem, print a message */
1466 case SPIDER_NET_GDTINVDINT:
1467 /* allrighty. tx from previous descr ok */
1468 show_error = 0;
1469 break;
1470 /* case SPIDER_NET_GRFDFLLINT: print a message down there */
1471 /* case SPIDER_NET_GRFCFLLINT: print a message down there */
1472 /* case SPIDER_NET_GRFBFLLINT: print a message down there */
1473 /* case SPIDER_NET_GRFAFLLINT: print a message down there */
1474
1475 /* chain end */
1476 case SPIDER_NET_GDDDCEINT: /* fallthrough */
1477 case SPIDER_NET_GDCDCEINT: /* fallthrough */
1478 case SPIDER_NET_GDBDCEINT: /* fallthrough */
1479 case SPIDER_NET_GDADCEINT:
1480 if (netif_msg_intr(card))
1481 pr_err("got descriptor chain end interrupt, "
1482 "restarting DMAC %c.\n",
1483 'D'+i-SPIDER_NET_GDDDCEINT);
1484 spider_net_refill_rx_chain(card);
1485 show_error = 0;
1486 break;
1487
1488 /* invalid descriptor */
1489 case SPIDER_NET_GDDINVDINT: /* fallthrough */
1490 case SPIDER_NET_GDCINVDINT: /* fallthrough */
1491 case SPIDER_NET_GDBINVDINT: /* fallthrough */
1492 case SPIDER_NET_GDAINVDINT:
1493 /* could happen when rx chain is full */
1494 spider_net_refill_rx_chain(card);
1495 show_error = 0;
1496 break;
1497
1498 /* case SPIDER_NET_GDTRSERINT: problem, print a message */
1499 /* case SPIDER_NET_GDDRSERINT: problem, print a message */
1500 /* case SPIDER_NET_GDCRSERINT: problem, print a message */
1501 /* case SPIDER_NET_GDBRSERINT: problem, print a message */
1502 /* case SPIDER_NET_GDARSERINT: problem, print a message */
1503 /* case SPIDER_NET_GDSERINT: problem, print a message */
1504 /* case SPIDER_NET_GDTPTERINT: problem, print a message */
1505 /* case SPIDER_NET_GDDPTERINT: problem, print a message */
1506 /* case SPIDER_NET_GDCPTERINT: problem, print a message */
1507 /* case SPIDER_NET_GDBPTERINT: problem, print a message */
1508 /* case SPIDER_NET_GDAPTERINT: problem, print a message */
1509 default:
1510 show_error = 1;
1511 break;
1512 }
1513
1514 /* check GHIINT2STS ************************************/
1515 if (error_reg2)
1516 for (i = 0; i < 32; i++)
1517 if (error_reg2 & (1<<i))
1518 switch (i)
1519 {
1520 /* there is nothing we can (want to) do at this time. Log a
1521 * message, we can switch on and off the specific values later on
1522 case SPIDER_NET_GPROPERINT:
1523 case SPIDER_NET_GMCTCRSNGINT:
1524 case SPIDER_NET_GMCTLCOLINT:
1525 case SPIDER_NET_GMCTTMOTINT:
1526 case SPIDER_NET_GMCRCAERINT:
1527 case SPIDER_NET_GMCRCALERINT:
1528 case SPIDER_NET_GMCRALNERINT:
1529 case SPIDER_NET_GMCROVRINT:
1530 case SPIDER_NET_GMCRRNTINT:
1531 case SPIDER_NET_GMCRRXERINT:
1532 case SPIDER_NET_GTITCSERINT:
1533 case SPIDER_NET_GTIFMTERINT:
1534 case SPIDER_NET_GTIPKTRVKINT:
1535 case SPIDER_NET_GTISPINGINT:
1536 case SPIDER_NET_GTISADNGINT:
1537 case SPIDER_NET_GTISPDNGINT:
1538 case SPIDER_NET_GRIFMTERINT:
1539 case SPIDER_NET_GRIPKTRVKINT:
1540 case SPIDER_NET_GRISPINGINT:
1541 case SPIDER_NET_GRISADNGINT:
1542 case SPIDER_NET_GRISPDNGINT:
1543 break;
1544 */
1545 default:
1546 break;
1547 }
1548
1549 if ((show_error) && (netif_msg_intr(card)))
1550 pr_err("Got error interrupt, GHIINT0STS = 0x%08x, "
1551 "GHIINT1STS = 0x%08x, GHIINT2STS = 0x%08x\n",
1552 status_reg, error_reg1, error_reg2);
1553
1554 /* clear interrupt sources */
1555 spider_net_write_reg(card, SPIDER_NET_GHIINT1STS, error_reg1);
1556 spider_net_write_reg(card, SPIDER_NET_GHIINT2STS, error_reg2);
1557}
1558
1559/**
1560 * spider_net_interrupt - interrupt handler for spider_net
1561 * @irq: interupt number
1562 * @ptr: pointer to net_device
1563 * @regs: PU registers
1564 *
1565 * returns IRQ_HANDLED, if interrupt was for driver, or IRQ_NONE, if no
1566 * interrupt found raised by card.
1567 *
1568 * This is the interrupt handler, that turns off
1569 * interrupts for this device and makes the stack poll the driver
1570 */
1571static irqreturn_t
1572spider_net_interrupt(int irq, void *ptr, struct pt_regs *regs)
1573{
1574 struct net_device *netdev = ptr;
1575 struct spider_net_card *card = netdev_priv(netdev);
1576 u32 status_reg;
1577
1578 status_reg = spider_net_read_reg(card, SPIDER_NET_GHIINT0STS);
1579
1580 if (!status_reg)
1581 return IRQ_NONE;
1582
1583 if (status_reg & SPIDER_NET_TXINT)
1584 spider_net_release_tx_chain(card, 0);
1585
1586 if (status_reg & SPIDER_NET_RXINT ) {
1587 spider_net_rx_irq_off(card);
1588 netif_rx_schedule(netdev);
1589 }
1590
1591 /* we do this after rx and tx processing, as we want the tx chain
1592 * processed to see, whether we should restart tx dma processing */
1593 spider_net_handle_error_irq(card, status_reg);
1594
1595 /* clear interrupt sources */
1596 spider_net_write_reg(card, SPIDER_NET_GHIINT0STS, status_reg);
1597
1598 return IRQ_HANDLED;
1599}
1600
1601#ifdef CONFIG_NET_POLL_CONTROLLER
1602/**
1603 * spider_net_poll_controller - artificial interrupt for netconsole etc.
1604 * @netdev: interface device structure
1605 *
1606 * see Documentation/networking/netconsole.txt
1607 */
1608static void
1609spider_net_poll_controller(struct net_device *netdev)
1610{
1611 disable_irq(netdev->irq);
1612 spider_net_interrupt(netdev->irq, netdev, NULL);
1613 enable_irq(netdev->irq);
1614}
1615#endif /* CONFIG_NET_POLL_CONTROLLER */
1616
1617/**
1618 * spider_net_init_card - initializes the card
1619 * @card: card structure
1620 *
1621 * spider_net_init_card initializes the card so that other registers can
1622 * be used
1623 */
1624static void
1625spider_net_init_card(struct spider_net_card *card)
1626{
1627 spider_net_write_reg(card, SPIDER_NET_CKRCTRL,
1628 SPIDER_NET_CKRCTRL_STOP_VALUE);
1629
1630 spider_net_write_reg(card, SPIDER_NET_CKRCTRL,
1631 SPIDER_NET_CKRCTRL_RUN_VALUE);
1632}
1633
1634/**
1635 * spider_net_enable_card - enables the card by setting all kinds of regs
1636 * @card: card structure
1637 *
1638 * spider_net_enable_card sets a lot of SMMIO registers to enable the device
1639 */
1640static void
1641spider_net_enable_card(struct spider_net_card *card)
1642{
1643 int i;
1644 /* the following array consists of (register),(value) pairs
1645 * that are set in this function. A register of 0 ends the list */
1646 u32 regs[][2] = {
1647 { SPIDER_NET_GRESUMINTNUM, 0 },
1648 { SPIDER_NET_GREINTNUM, 0 },
1649
1650 /* set interrupt frame number registers */
1651 /* clear the single DMA engine registers first */
1652 { SPIDER_NET_GFAFRMNUM, SPIDER_NET_GFXFRAMES_VALUE },
1653 { SPIDER_NET_GFBFRMNUM, SPIDER_NET_GFXFRAMES_VALUE },
1654 { SPIDER_NET_GFCFRMNUM, SPIDER_NET_GFXFRAMES_VALUE },
1655 { SPIDER_NET_GFDFRMNUM, SPIDER_NET_GFXFRAMES_VALUE },
1656 /* then set, what we really need */
1657 { SPIDER_NET_GFFRMNUM, SPIDER_NET_FRAMENUM_VALUE },
1658
1659 /* timer counter registers and stuff */
1660 { SPIDER_NET_GFREECNNUM, 0 },
1661 { SPIDER_NET_GONETIMENUM, 0 },
1662 { SPIDER_NET_GTOUTFRMNUM, 0 },
1663
1664 /* RX mode setting */
1665 { SPIDER_NET_GRXMDSET, SPIDER_NET_RXMODE_VALUE },
1666 /* TX mode setting */
1667 { SPIDER_NET_GTXMDSET, SPIDER_NET_TXMODE_VALUE },
1668 /* IPSEC mode setting */
1669 { SPIDER_NET_GIPSECINIT, SPIDER_NET_IPSECINIT_VALUE },
1670
1671 { SPIDER_NET_GFTRESTRT, SPIDER_NET_RESTART_VALUE },
1672
1673 { SPIDER_NET_GMRWOLCTRL, 0 },
1674 { SPIDER_NET_GTESTMD, 0 },
1675
1676 { SPIDER_NET_GMACINTEN, 0 },
1677
1678 /* flow control stuff */
1679 { SPIDER_NET_GMACAPAUSE, SPIDER_NET_MACAPAUSE_VALUE },
1680 { SPIDER_NET_GMACTXPAUSE, SPIDER_NET_TXPAUSE_VALUE },
1681
1682 { SPIDER_NET_GMACBSTLMT, SPIDER_NET_BURSTLMT_VALUE },
1683 { 0, 0}
1684 };
1685
1686 i = 0;
1687 while (regs[i][0]) {
1688 spider_net_write_reg(card, regs[i][0], regs[i][1]);
1689 i++;
1690 }
1691
1692 /* clear unicast filter table entries 1 to 14 */
1693 for (i = 1; i <= 14; i++) {
1694 spider_net_write_reg(card,
1695 SPIDER_NET_GMRUAFILnR + i * 8,
1696 0x00080000);
1697 spider_net_write_reg(card,
1698 SPIDER_NET_GMRUAFILnR + i * 8 + 4,
1699 0x00000000);
1700 }
1701
1702 spider_net_write_reg(card, SPIDER_NET_GMRUA0FIL15R, 0x08080000);
1703
1704 spider_net_write_reg(card, SPIDER_NET_ECMODE, SPIDER_NET_ECMODE_VALUE);
1705
1706 /* set chain tail adress for RX chains and
1707 * enable DMA */
1708 spider_net_enable_rxchtails(card);
1709 spider_net_enable_rxdmac(card);
1710
1711 spider_net_write_reg(card, SPIDER_NET_GRXDMAEN, SPIDER_NET_WOL_VALUE);
1712
1713 /* set chain tail adress for TX chain */
1714 spider_net_enable_txdmac(card);
1715
1716 spider_net_write_reg(card, SPIDER_NET_GMACLENLMT,
1717 SPIDER_NET_LENLMT_VALUE);
1718 spider_net_write_reg(card, SPIDER_NET_GMACMODE,
1719 SPIDER_NET_MACMODE_VALUE);
1720 spider_net_write_reg(card, SPIDER_NET_GMACOPEMD,
1721 SPIDER_NET_OPMODE_VALUE);
1722
1723 /* set interrupt mask registers */
1724 spider_net_write_reg(card, SPIDER_NET_GHIINT0MSK,
1725 SPIDER_NET_INT0_MASK_VALUE);
1726 spider_net_write_reg(card, SPIDER_NET_GHIINT1MSK,
1727 SPIDER_NET_INT1_MASK_VALUE);
1728 spider_net_write_reg(card, SPIDER_NET_GHIINT2MSK,
1729 SPIDER_NET_INT2_MASK_VALUE);
1730}
1731
1732/**
1733 * spider_net_open - called upon ifonfig up
1734 * @netdev: interface device structure
1735 *
1736 * returns 0 on success, <0 on failure
1737 *
1738 * spider_net_open allocates all the descriptors and memory needed for
1739 * operation, sets up multicast list and enables interrupts
1740 */
1741int
1742spider_net_open(struct net_device *netdev)
1743{
1744 struct spider_net_card *card = netdev_priv(netdev);
1745 int result;
1746
1747 result = -ENOMEM;
1748 if (spider_net_init_chain(card, &card->tx_chain,
1749 card->descr, tx_descriptors))
1750 goto alloc_tx_failed;
1751 if (spider_net_init_chain(card, &card->rx_chain,
1752 card->descr + tx_descriptors, rx_descriptors))
1753 goto alloc_rx_failed;
1754
1755 /* allocate rx skbs */
1756 if (spider_net_alloc_rx_skbs(card))
1757 goto alloc_skbs_failed;
1758
1759 spider_net_set_multi(netdev);
1760
1761 /* further enhancement: setup hw vlan, if needed */
1762
1763 result = -EBUSY;
1764 if (request_irq(netdev->irq, spider_net_interrupt,
1765 SA_SHIRQ, netdev->name, netdev))
1766 goto register_int_failed;
1767
1768 spider_net_enable_card(card);
1769
1770 netif_start_queue(netdev);
1771 netif_carrier_on(netdev);
1772 netif_poll_enable(netdev);
1773
1774 return 0;
1775
1776register_int_failed:
1777 spider_net_free_rx_chain_contents(card);
1778alloc_skbs_failed:
1779 spider_net_free_chain(card, &card->rx_chain);
1780alloc_rx_failed:
1781 spider_net_free_chain(card, &card->tx_chain);
1782alloc_tx_failed:
1783 return result;
1784}
1785
1786/**
1787 * spider_net_setup_phy - setup PHY
1788 * @card: card structure
1789 *
1790 * returns 0 on success, <0 on failure
1791 *
1792 * spider_net_setup_phy is used as part of spider_net_probe. Sets
1793 * the PHY to 1000 Mbps
1794 **/
1795static int
1796spider_net_setup_phy(struct spider_net_card *card)
1797{
1798 struct mii_phy *phy = &card->phy;
1799
1800 spider_net_write_reg(card, SPIDER_NET_GDTDMASEL,
1801 SPIDER_NET_DMASEL_VALUE);
1802 spider_net_write_reg(card, SPIDER_NET_GPCCTRL,
1803 SPIDER_NET_PHY_CTRL_VALUE);
1804 phy->mii_id = 1;
1805 phy->dev = card->netdev;
1806 phy->mdio_read = spider_net_read_phy;
1807 phy->mdio_write = spider_net_write_phy;
1808
1809 mii_phy_probe(phy, phy->mii_id);
1810
1811 if (phy->def->ops->setup_forced)
1812 phy->def->ops->setup_forced(phy, SPEED_1000, DUPLEX_FULL);
1813
1814 /* the following two writes could be moved to sungem_phy.c */
1815 /* enable fiber mode */
1816 spider_net_write_phy(card->netdev, 1, MII_NCONFIG, 0x9020);
1817 /* LEDs active in both modes, autosense prio = fiber */
1818 spider_net_write_phy(card->netdev, 1, MII_NCONFIG, 0x945f);
1819
1820 phy->def->ops->read_link(phy);
1821 pr_info("Found %s with %i Mbps, %s-duplex.\n", phy->def->name,
1822 phy->speed, phy->duplex==1 ? "Full" : "Half");
1823
1824 return 0;
1825}
1826
1827/**
1828 * spider_net_download_firmware - loads firmware into the adapter
1829 * @card: card structure
1830 * @firmware: firmware pointer
1831 *
1832 * spider_net_download_firmware loads the firmware opened by
1833 * spider_net_init_firmware into the adapter.
1834 */
1835static void
1836spider_net_download_firmware(struct spider_net_card *card,
1837 const struct firmware *firmware)
1838{
1839 int sequencer, i;
1840 u32 *fw_ptr = (u32 *)firmware->data;
1841
1842 /* stop sequencers */
1843 spider_net_write_reg(card, SPIDER_NET_GSINIT,
1844 SPIDER_NET_STOP_SEQ_VALUE);
1845
1846 for (sequencer = 0; sequencer < 6; sequencer++) {
1847 spider_net_write_reg(card,
1848 SPIDER_NET_GSnPRGADR + sequencer * 8, 0);
1849 for (i = 0; i < SPIDER_NET_FIRMWARE_LEN; i++) {
1850 spider_net_write_reg(card, SPIDER_NET_GSnPRGDAT +
1851 sequencer * 8, *fw_ptr);
1852 fw_ptr++;
1853 }
1854 }
1855
1856 spider_net_write_reg(card, SPIDER_NET_GSINIT,
1857 SPIDER_NET_RUN_SEQ_VALUE);
1858}
1859
1860/**
1861 * spider_net_init_firmware - reads in firmware parts
1862 * @card: card structure
1863 *
1864 * Returns 0 on success, <0 on failure
1865 *
1866 * spider_net_init_firmware opens the sequencer firmware and does some basic
1867 * checks. This function opens and releases the firmware structure. A call
1868 * to download the firmware is performed before the release.
1869 *
1870 * Firmware format
1871 * ===============
1872 * spider_fw.bin is expected to be a file containing 6*1024*4 bytes, 4k being
1873 * the program for each sequencer. Use the command
1874 * tail -q -n +2 Seq_code1_0x088.txt Seq_code2_0x090.txt \
1875 * Seq_code3_0x098.txt Seq_code4_0x0A0.txt Seq_code5_0x0A8.txt \
1876 * Seq_code6_0x0B0.txt | xxd -r -p -c4 > spider_fw.bin
1877 *
1878 * to generate spider_fw.bin, if you have sequencer programs with something
1879 * like the following contents for each sequencer:
1880 * <ONE LINE COMMENT>
1881 * <FIRST 4-BYTES-WORD FOR SEQUENCER>
1882 * <SECOND 4-BYTES-WORD FOR SEQUENCER>
1883 * ...
1884 * <1024th 4-BYTES-WORD FOR SEQUENCER>
1885 */
1886static int
1887spider_net_init_firmware(struct spider_net_card *card)
1888{
1889 const struct firmware *firmware;
1890 int err = -EIO;
1891
1892 if (request_firmware(&firmware,
1893 SPIDER_NET_FIRMWARE_NAME, &card->pdev->dev) < 0) {
1894 if (netif_msg_probe(card))
1895 pr_err("Couldn't read in sequencer data file %s.\n",
1896 SPIDER_NET_FIRMWARE_NAME);
1897 firmware = NULL;
1898 goto out;
1899 }
1900
1901 if (firmware->size != 6 * SPIDER_NET_FIRMWARE_LEN * sizeof(u32)) {
1902 if (netif_msg_probe(card))
1903 pr_err("Invalid size of sequencer data file %s.\n",
1904 SPIDER_NET_FIRMWARE_NAME);
1905 goto out;
1906 }
1907
1908 spider_net_download_firmware(card, firmware);
1909
1910 err = 0;
1911out:
1912 release_firmware(firmware);
1913
1914 return err;
1915}
1916
1917/**
1918 * spider_net_workaround_rxramfull - work around firmware bug
1919 * @card: card structure
1920 *
1921 * no return value
1922 **/
1923static void
1924spider_net_workaround_rxramfull(struct spider_net_card *card)
1925{
1926 int i, sequencer = 0;
1927
1928 /* cancel reset */
1929 spider_net_write_reg(card, SPIDER_NET_CKRCTRL,
1930 SPIDER_NET_CKRCTRL_RUN_VALUE);
1931
1932 /* empty sequencer data */
1933 for (sequencer = 0; sequencer < 6; sequencer++) {
1934 spider_net_write_reg(card, SPIDER_NET_GSnPRGDAT +
1935 sequencer * 8, 0x0);
1936 for (i = 0; i < SPIDER_NET_FIRMWARE_LEN; i++) {
1937 spider_net_write_reg(card, SPIDER_NET_GSnPRGDAT +
1938 sequencer * 8, 0x0);
1939 }
1940 }
1941
1942 /* set sequencer operation */
1943 spider_net_write_reg(card, SPIDER_NET_GSINIT, 0x000000fe);
1944
1945 /* reset */
1946 spider_net_write_reg(card, SPIDER_NET_CKRCTRL,
1947 SPIDER_NET_CKRCTRL_STOP_VALUE);
1948}
1949
1950/**
1951 * spider_net_tx_timeout_task - task scheduled by the watchdog timeout
1952 * function (to be called not under interrupt status)
1953 * @data: data, is interface device structure
1954 *
1955 * called as task when tx hangs, resets interface (if interface is up)
1956 */
1957static void
1958spider_net_tx_timeout_task(void *data)
1959{
1960 struct net_device *netdev = data;
1961 struct spider_net_card *card = netdev_priv(netdev);
1962
1963 if (!(netdev->flags & IFF_UP))
1964 goto out;
1965
1966 netif_device_detach(netdev);
1967 spider_net_stop(netdev);
1968
1969 spider_net_workaround_rxramfull(card);
1970 spider_net_init_card(card);
1971
1972 if (spider_net_setup_phy(card))
1973 goto out;
1974 if (spider_net_init_firmware(card))
1975 goto out;
1976
1977 spider_net_open(netdev);
1978 spider_net_kick_tx_dma(card, card->tx_chain.head);
1979 netif_device_attach(netdev);
1980
1981out:
1982 atomic_dec(&card->tx_timeout_task_counter);
1983}
1984
1985/**
1986 * spider_net_tx_timeout - called when the tx timeout watchdog kicks in.
1987 * @netdev: interface device structure
1988 *
1989 * called, if tx hangs. Schedules a task that resets the interface
1990 */
1991static void
1992spider_net_tx_timeout(struct net_device *netdev)
1993{
1994 struct spider_net_card *card;
1995
1996 card = netdev_priv(netdev);
1997 atomic_inc(&card->tx_timeout_task_counter);
1998 if (netdev->flags & IFF_UP)
1999 schedule_work(&card->tx_timeout_task);
2000 else
2001 atomic_dec(&card->tx_timeout_task_counter);
2002}
2003
2004/**
2005 * spider_net_setup_netdev_ops - initialization of net_device operations
2006 * @netdev: net_device structure
2007 *
2008 * fills out function pointers in the net_device structure
2009 */
2010static void
2011spider_net_setup_netdev_ops(struct net_device *netdev)
2012{
2013 netdev->open = &spider_net_open;
2014 netdev->stop = &spider_net_stop;
2015 netdev->hard_start_xmit = &spider_net_xmit;
2016 netdev->get_stats = &spider_net_get_stats;
2017 netdev->set_multicast_list = &spider_net_set_multi;
2018 netdev->set_mac_address = &spider_net_set_mac;
2019 netdev->change_mtu = &spider_net_change_mtu;
2020 netdev->do_ioctl = &spider_net_do_ioctl;
2021 /* tx watchdog */
2022 netdev->tx_timeout = &spider_net_tx_timeout;
2023 netdev->watchdog_timeo = SPIDER_NET_WATCHDOG_TIMEOUT;
2024 /* NAPI */
2025 netdev->poll = &spider_net_poll;
2026 netdev->weight = SPIDER_NET_NAPI_WEIGHT;
2027 /* HW VLAN */
2028 netdev->vlan_rx_register = &spider_net_vlan_rx_reg;
2029 netdev->vlan_rx_add_vid = &spider_net_vlan_rx_add;
2030 netdev->vlan_rx_kill_vid = &spider_net_vlan_rx_kill;
2031#ifdef CONFIG_NET_POLL_CONTROLLER
2032 /* poll controller */
2033 netdev->poll_controller = &spider_net_poll_controller;
2034#endif /* CONFIG_NET_POLL_CONTROLLER */
2035 /* ethtool ops */
2036 netdev->ethtool_ops = &spider_net_ethtool_ops;
2037}
2038
2039/**
2040 * spider_net_setup_netdev - initialization of net_device
2041 * @card: card structure
2042 *
2043 * Returns 0 on success or <0 on failure
2044 *
2045 * spider_net_setup_netdev initializes the net_device structure
2046 **/
2047static int
2048spider_net_setup_netdev(struct spider_net_card *card)
2049{
2050 int result;
2051 struct net_device *netdev = card->netdev;
2052 struct device_node *dn;
2053 struct sockaddr addr;
2054 u8 *mac;
2055
2056 SET_MODULE_OWNER(netdev);
2057 SET_NETDEV_DEV(netdev, &card->pdev->dev);
2058
2059 pci_set_drvdata(card->pdev, netdev);
2060 spin_lock_init(&card->intmask_lock);
2061 netdev->irq = card->pdev->irq;
2062
2063 card->options.rx_csum = SPIDER_NET_RX_CSUM_DEFAULT;
2064
2065 spider_net_setup_netdev_ops(netdev);
2066
2067 netdev->features = 0;
2068 /* some time: NETIF_F_HW_VLAN_TX | NETIF_F_HW_VLAN_RX |
2069 * NETIF_F_HW_VLAN_FILTER */
2070
2071 netdev->irq = card->pdev->irq;
2072
2073 dn = pci_device_to_OF_node(card->pdev);
2074 if (!dn)
2075 return -EIO;
2076
2077 mac = (u8 *)get_property(dn, "local-mac-address", NULL);
2078 if (!mac)
2079 return -EIO;
2080 memcpy(addr.sa_data, mac, ETH_ALEN);
2081
2082 result = spider_net_set_mac(netdev, &addr);
2083 if ((result) && (netif_msg_probe(card)))
2084 pr_err("Failed to set MAC address: %i\n", result);
2085
2086 result = register_netdev(netdev);
2087 if (result) {
2088 if (netif_msg_probe(card))
2089 pr_err("Couldn't register net_device: %i\n",
2090 result);
2091 return result;
2092 }
2093
2094 if (netif_msg_probe(card))
2095 pr_info("Initialized device %s.\n", netdev->name);
2096
2097 return 0;
2098}
2099
2100/**
2101 * spider_net_alloc_card - allocates net_device and card structure
2102 *
2103 * returns the card structure or NULL in case of errors
2104 *
2105 * the card and net_device structures are linked to each other
2106 */
2107static struct spider_net_card *
2108spider_net_alloc_card(void)
2109{
2110 struct net_device *netdev;
2111 struct spider_net_card *card;
2112 size_t alloc_size;
2113
2114 alloc_size = sizeof (*card) +
2115 sizeof (struct spider_net_descr) * rx_descriptors +
2116 sizeof (struct spider_net_descr) * tx_descriptors;
2117 netdev = alloc_etherdev(alloc_size);
2118 if (!netdev)
2119 return NULL;
2120
2121 card = netdev_priv(netdev);
2122 card->netdev = netdev;
2123 card->msg_enable = SPIDER_NET_DEFAULT_MSG;
2124 INIT_WORK(&card->tx_timeout_task, spider_net_tx_timeout_task, netdev);
2125 init_waitqueue_head(&card->waitq);
2126 atomic_set(&card->tx_timeout_task_counter, 0);
2127
2128 return card;
2129}
2130
2131/**
2132 * spider_net_undo_pci_setup - releases PCI ressources
2133 * @card: card structure
2134 *
2135 * spider_net_undo_pci_setup releases the mapped regions
2136 */
2137static void
2138spider_net_undo_pci_setup(struct spider_net_card *card)
2139{
2140 iounmap(card->regs);
2141 pci_release_regions(card->pdev);
2142}
2143
2144/**
2145 * spider_net_setup_pci_dev - sets up the device in terms of PCI operations
2146 * @card: card structure
2147 * @pdev: PCI device
2148 *
2149 * Returns the card structure or NULL if any errors occur
2150 *
2151 * spider_net_setup_pci_dev initializes pdev and together with the
2152 * functions called in spider_net_open configures the device so that
2153 * data can be transferred over it
2154 * The net_device structure is attached to the card structure, if the
2155 * function returns without error.
2156 **/
2157static struct spider_net_card *
2158spider_net_setup_pci_dev(struct pci_dev *pdev)
2159{
2160 struct spider_net_card *card;
2161 unsigned long mmio_start, mmio_len;
2162
2163 if (pci_enable_device(pdev)) {
2164 pr_err("Couldn't enable PCI device\n");
2165 return NULL;
2166 }
2167
2168 if (!(pci_resource_flags(pdev, 0) & IORESOURCE_MEM)) {
2169 pr_err("Couldn't find proper PCI device base address.\n");
2170 goto out_disable_dev;
2171 }
2172
2173 if (pci_request_regions(pdev, spider_net_driver_name)) {
2174 pr_err("Couldn't obtain PCI resources, aborting.\n");
2175 goto out_disable_dev;
2176 }
2177
2178 pci_set_master(pdev);
2179
2180 card = spider_net_alloc_card();
2181 if (!card) {
2182 pr_err("Couldn't allocate net_device structure, "
2183 "aborting.\n");
2184 goto out_release_regions;
2185 }
2186 card->pdev = pdev;
2187
2188 /* fetch base address and length of first resource */
2189 mmio_start = pci_resource_start(pdev, 0);
2190 mmio_len = pci_resource_len(pdev, 0);
2191
2192 card->netdev->mem_start = mmio_start;
2193 card->netdev->mem_end = mmio_start + mmio_len;
2194 card->regs = ioremap(mmio_start, mmio_len);
2195
2196 if (!card->regs) {
2197 pr_err("Couldn't obtain PCI resources, aborting.\n");
2198 goto out_release_regions;
2199 }
2200
2201 return card;
2202
2203out_release_regions:
2204 pci_release_regions(pdev);
2205out_disable_dev:
2206 pci_disable_device(pdev);
2207 pci_set_drvdata(pdev, NULL);
2208 return NULL;
2209}
2210
2211/**
2212 * spider_net_probe - initialization of a device
2213 * @pdev: PCI device
2214 * @ent: entry in the device id list
2215 *
2216 * Returns 0 on success, <0 on failure
2217 *
2218 * spider_net_probe initializes pdev and registers a net_device
2219 * structure for it. After that, the device can be ifconfig'ed up
2220 **/
2221static int __devinit
2222spider_net_probe(struct pci_dev *pdev, const struct pci_device_id *ent)
2223{
2224 int err = -EIO;
2225 struct spider_net_card *card;
2226
2227 card = spider_net_setup_pci_dev(pdev);
2228 if (!card)
2229 goto out;
2230
2231 spider_net_workaround_rxramfull(card);
2232 spider_net_init_card(card);
2233
2234 err = spider_net_setup_phy(card);
2235 if (err)
2236 goto out_undo_pci;
2237
2238 err = spider_net_init_firmware(card);
2239 if (err)
2240 goto out_undo_pci;
2241
2242 err = spider_net_setup_netdev(card);
2243 if (err)
2244 goto out_undo_pci;
2245
2246 return 0;
2247
2248out_undo_pci:
2249 spider_net_undo_pci_setup(card);
2250 free_netdev(card->netdev);
2251out:
2252 return err;
2253}
2254
2255/**
2256 * spider_net_remove - removal of a device
2257 * @pdev: PCI device
2258 *
2259 * Returns 0 on success, <0 on failure
2260 *
2261 * spider_net_remove is called to remove the device and unregisters the
2262 * net_device
2263 **/
2264static void __devexit
2265spider_net_remove(struct pci_dev *pdev)
2266{
2267 struct net_device *netdev;
2268 struct spider_net_card *card;
2269
2270 netdev = pci_get_drvdata(pdev);
2271 card = netdev_priv(netdev);
2272
2273 wait_event(card->waitq,
2274 atomic_read(&card->tx_timeout_task_counter) == 0);
2275
2276 unregister_netdev(netdev);
2277
2278 /* switch off card */
2279 spider_net_write_reg(card, SPIDER_NET_CKRCTRL,
2280 SPIDER_NET_CKRCTRL_STOP_VALUE);
2281 spider_net_write_reg(card, SPIDER_NET_CKRCTRL,
2282 SPIDER_NET_CKRCTRL_RUN_VALUE);
2283
2284 spider_net_undo_pci_setup(card);
2285 free_netdev(netdev);
2286}
2287
2288static struct pci_driver spider_net_driver = {
2289 .owner = THIS_MODULE,
2290 .name = spider_net_driver_name,
2291 .id_table = spider_net_pci_tbl,
2292 .probe = spider_net_probe,
2293 .remove = __devexit_p(spider_net_remove)
2294};
2295
2296/**
2297 * spider_net_init - init function when the driver is loaded
2298 *
2299 * spider_net_init registers the device driver
2300 */
2301static int __init spider_net_init(void)
2302{
2303 if (rx_descriptors < SPIDER_NET_RX_DESCRIPTORS_MIN) {
2304 rx_descriptors = SPIDER_NET_RX_DESCRIPTORS_MIN;
2305 pr_info("adjusting rx descriptors to %i.\n", rx_descriptors);
2306 }
2307 if (rx_descriptors > SPIDER_NET_RX_DESCRIPTORS_MAX) {
2308 rx_descriptors = SPIDER_NET_RX_DESCRIPTORS_MAX;
2309 pr_info("adjusting rx descriptors to %i.\n", rx_descriptors);
2310 }
2311 if (tx_descriptors < SPIDER_NET_TX_DESCRIPTORS_MIN) {
2312 tx_descriptors = SPIDER_NET_TX_DESCRIPTORS_MIN;
2313 pr_info("adjusting tx descriptors to %i.\n", tx_descriptors);
2314 }
2315 if (tx_descriptors > SPIDER_NET_TX_DESCRIPTORS_MAX) {
2316 tx_descriptors = SPIDER_NET_TX_DESCRIPTORS_MAX;
2317 pr_info("adjusting tx descriptors to %i.\n", tx_descriptors);
2318 }
2319
2320 return pci_register_driver(&spider_net_driver);
2321}
2322
2323/**
2324 * spider_net_cleanup - exit function when driver is unloaded
2325 *
2326 * spider_net_cleanup unregisters the device driver
2327 */
2328static void __exit spider_net_cleanup(void)
2329{
2330 pci_unregister_driver(&spider_net_driver);
2331}
2332
2333module_init(spider_net_init);
2334module_exit(spider_net_cleanup);
diff --git a/drivers/net/spider_net.h b/drivers/net/spider_net.h
new file mode 100644
index 00000000000..22b2f234735
--- /dev/null
+++ b/drivers/net/spider_net.h
@@ -0,0 +1,469 @@
1/*
2 * Network device driver for Cell Processor-Based Blade
3 *
4 * (C) Copyright IBM Corp. 2005
5 *
6 * Authors : Utz Bacher <utz.bacher@de.ibm.com>
7 * Jens Osterkamp <Jens.Osterkamp@de.ibm.com>
8 *
9 * This program is free software; you can redistribute it and/or modify
10 * it under the terms of the GNU General Public License as published by
11 * the Free Software Foundation; either version 2, or (at your option)
12 * any later version.
13 *
14 * This program is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 * GNU General Public License for more details.
18 *
19 * You should have received a copy of the GNU General Public License
20 * along with this program; if not, write to the Free Software
21 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
22 */
23
24#ifndef _SPIDER_NET_H
25#define _SPIDER_NET_H
26
27#include "sungem_phy.h"
28
29extern int spider_net_stop(struct net_device *netdev);
30extern int spider_net_open(struct net_device *netdev);
31
32extern struct ethtool_ops spider_net_ethtool_ops;
33
34extern char spider_net_driver_name[];
35
36#define SPIDER_NET_MAX_MTU 2308
37#define SPIDER_NET_MIN_MTU 64
38
39#define SPIDER_NET_RXBUF_ALIGN 128
40
41#define SPIDER_NET_RX_DESCRIPTORS_DEFAULT 64
42#define SPIDER_NET_RX_DESCRIPTORS_MIN 16
43#define SPIDER_NET_RX_DESCRIPTORS_MAX 256
44
45#define SPIDER_NET_TX_DESCRIPTORS_DEFAULT 64
46#define SPIDER_NET_TX_DESCRIPTORS_MIN 16
47#define SPIDER_NET_TX_DESCRIPTORS_MAX 256
48
49#define SPIDER_NET_RX_CSUM_DEFAULT 1
50
51#define SPIDER_NET_WATCHDOG_TIMEOUT 5*HZ
52#define SPIDER_NET_NAPI_WEIGHT 64
53
54#define SPIDER_NET_FIRMWARE_LEN 1024
55#define SPIDER_NET_FIRMWARE_NAME "spider_fw.bin"
56
57/** spider_net SMMIO registers */
58#define SPIDER_NET_GHIINT0STS 0x00000000
59#define SPIDER_NET_GHIINT1STS 0x00000004
60#define SPIDER_NET_GHIINT2STS 0x00000008
61#define SPIDER_NET_GHIINT0MSK 0x00000010
62#define SPIDER_NET_GHIINT1MSK 0x00000014
63#define SPIDER_NET_GHIINT2MSK 0x00000018
64
65#define SPIDER_NET_GRESUMINTNUM 0x00000020
66#define SPIDER_NET_GREINTNUM 0x00000024
67
68#define SPIDER_NET_GFFRMNUM 0x00000028
69#define SPIDER_NET_GFAFRMNUM 0x0000002c
70#define SPIDER_NET_GFBFRMNUM 0x00000030
71#define SPIDER_NET_GFCFRMNUM 0x00000034
72#define SPIDER_NET_GFDFRMNUM 0x00000038
73
74/* clear them (don't use it) */
75#define SPIDER_NET_GFREECNNUM 0x0000003c
76#define SPIDER_NET_GONETIMENUM 0x00000040
77
78#define SPIDER_NET_GTOUTFRMNUM 0x00000044
79
80#define SPIDER_NET_GTXMDSET 0x00000050
81#define SPIDER_NET_GPCCTRL 0x00000054
82#define SPIDER_NET_GRXMDSET 0x00000058
83#define SPIDER_NET_GIPSECINIT 0x0000005c
84#define SPIDER_NET_GFTRESTRT 0x00000060
85#define SPIDER_NET_GRXDMAEN 0x00000064
86#define SPIDER_NET_GMRWOLCTRL 0x00000068
87#define SPIDER_NET_GPCWOPCMD 0x0000006c
88#define SPIDER_NET_GPCROPCMD 0x00000070
89#define SPIDER_NET_GTTFRMCNT 0x00000078
90#define SPIDER_NET_GTESTMD 0x0000007c
91
92#define SPIDER_NET_GSINIT 0x00000080
93#define SPIDER_NET_GSnPRGADR 0x00000084
94#define SPIDER_NET_GSnPRGDAT 0x00000088
95
96#define SPIDER_NET_GMACOPEMD 0x00000100
97#define SPIDER_NET_GMACLENLMT 0x00000108
98#define SPIDER_NET_GMACINTEN 0x00000118
99#define SPIDER_NET_GMACPHYCTRL 0x00000120
100
101#define SPIDER_NET_GMACAPAUSE 0x00000154
102#define SPIDER_NET_GMACTXPAUSE 0x00000164
103
104#define SPIDER_NET_GMACMODE 0x000001b0
105#define SPIDER_NET_GMACBSTLMT 0x000001b4
106
107#define SPIDER_NET_GMACUNIMACU 0x000001c0
108#define SPIDER_NET_GMACUNIMACL 0x000001c8
109
110#define SPIDER_NET_GMRMHFILnR 0x00000400
111#define SPIDER_NET_MULTICAST_HASHES 256
112
113#define SPIDER_NET_GMRUAFILnR 0x00000500
114#define SPIDER_NET_GMRUA0FIL15R 0x00000578
115
116/* RX DMA controller registers, all 0x00000a.. are for DMA controller A,
117 * 0x00000b.. for DMA controller B, etc. */
118#define SPIDER_NET_GDADCHA 0x00000a00
119#define SPIDER_NET_GDADMACCNTR 0x00000a04
120#define SPIDER_NET_GDACTDPA 0x00000a08
121#define SPIDER_NET_GDACTDCNT 0x00000a0c
122#define SPIDER_NET_GDACDBADDR 0x00000a20
123#define SPIDER_NET_GDACDBSIZE 0x00000a24
124#define SPIDER_NET_GDACNEXTDA 0x00000a28
125#define SPIDER_NET_GDACCOMST 0x00000a2c
126#define SPIDER_NET_GDAWBCOMST 0x00000a30
127#define SPIDER_NET_GDAWBRSIZE 0x00000a34
128#define SPIDER_NET_GDAWBVSIZE 0x00000a38
129#define SPIDER_NET_GDAWBTRST 0x00000a3c
130#define SPIDER_NET_GDAWBTRERR 0x00000a40
131
132/* TX DMA controller registers */
133#define SPIDER_NET_GDTDCHA 0x00000e00
134#define SPIDER_NET_GDTDMACCNTR 0x00000e04
135#define SPIDER_NET_GDTCDPA 0x00000e08
136#define SPIDER_NET_GDTDMASEL 0x00000e14
137
138#define SPIDER_NET_ECMODE 0x00000f00
139/* clock and reset control register */
140#define SPIDER_NET_CKRCTRL 0x00000ff0
141
142/** SCONFIG registers */
143#define SPIDER_NET_SCONFIG_IOACTE 0x00002810
144
145/** hardcoded register values */
146#define SPIDER_NET_INT0_MASK_VALUE 0x3f7fe3ff
147#define SPIDER_NET_INT1_MASK_VALUE 0xffffffff
148/* no MAC aborts -> auto retransmission */
149#define SPIDER_NET_INT2_MASK_VALUE 0xfffffff1
150
151/* clear counter when interrupt sources are cleared
152#define SPIDER_NET_FRAMENUM_VALUE 0x0001f001 */
153/* we rely on flagged descriptor interrupts */
154#define SPIDER_NET_FRAMENUM_VALUE 0x00000000
155/* set this first, then the FRAMENUM_VALUE */
156#define SPIDER_NET_GFXFRAMES_VALUE 0x00000000
157
158#define SPIDER_NET_STOP_SEQ_VALUE 0x00000000
159#define SPIDER_NET_RUN_SEQ_VALUE 0x0000007e
160
161#define SPIDER_NET_PHY_CTRL_VALUE 0x00040040
162/* #define SPIDER_NET_PHY_CTRL_VALUE 0x01070080*/
163#define SPIDER_NET_RXMODE_VALUE 0x00000011
164/* auto retransmission in case of MAC aborts */
165#define SPIDER_NET_TXMODE_VALUE 0x00010000
166#define SPIDER_NET_RESTART_VALUE 0x00000000
167#define SPIDER_NET_WOL_VALUE 0x00001111
168#if 0
169#define SPIDER_NET_WOL_VALUE 0x00000000
170#endif
171#define SPIDER_NET_IPSECINIT_VALUE 0x00f000f8
172
173/* pause frames: automatic, no upper retransmission count */
174/* outside loopback mode: ETOMOD signal dont matter, not connected */
175#define SPIDER_NET_OPMODE_VALUE 0x00000063
176/*#define SPIDER_NET_OPMODE_VALUE 0x001b0062*/
177#define SPIDER_NET_LENLMT_VALUE 0x00000908
178
179#define SPIDER_NET_MACAPAUSE_VALUE 0x00000800 /* about 1 ms */
180#define SPIDER_NET_TXPAUSE_VALUE 0x00000000
181
182#define SPIDER_NET_MACMODE_VALUE 0x00000001
183#define SPIDER_NET_BURSTLMT_VALUE 0x00000200 /* about 16 us */
184
185/* 1(0) enable r/tx dma
186 * 0000000 fixed to 0
187 *
188 * 000000 fixed to 0
189 * 0(1) en/disable descr writeback on force end
190 * 0(1) force end
191 *
192 * 000000 fixed to 0
193 * 00 burst alignment: 128 bytes
194 *
195 * 00000 fixed to 0
196 * 0 descr writeback size 32 bytes
197 * 0(1) descr chain end interrupt enable
198 * 0(1) descr status writeback enable */
199
200/* to set RX_DMA_EN */
201#define SPIDER_NET_DMA_RX_VALUE 0x80000000
202#define SPIDER_NET_DMA_RX_FEND_VALUE 0x00030003
203/* to set TX_DMA_EN */
204#define SPIDER_NET_DMA_TX_VALUE 0x80000000
205#define SPIDER_NET_DMA_TX_FEND_VALUE 0x00030003
206
207/* SPIDER_NET_UA_DESCR_VALUE is OR'ed with the unicast address */
208#define SPIDER_NET_UA_DESCR_VALUE 0x00080000
209#define SPIDER_NET_PROMISC_VALUE 0x00080000
210#define SPIDER_NET_NONPROMISC_VALUE 0x00000000
211
212#define SPIDER_NET_DMASEL_VALUE 0x00000001
213
214#define SPIDER_NET_ECMODE_VALUE 0x00000000
215
216#define SPIDER_NET_CKRCTRL_RUN_VALUE 0x1fff010f
217#define SPIDER_NET_CKRCTRL_STOP_VALUE 0x0000010f
218
219#define SPIDER_NET_SBIMSTATE_VALUE 0x00000000
220#define SPIDER_NET_SBTMSTATE_VALUE 0x00000000
221
222/* SPIDER_NET_GHIINT0STS bits, in reverse order so that they can be used
223 * with 1 << SPIDER_NET_... */
224enum spider_net_int0_status {
225 SPIDER_NET_GPHYINT = 0,
226 SPIDER_NET_GMAC2INT,
227 SPIDER_NET_GMAC1INT,
228 SPIDER_NET_GIPSINT,
229 SPIDER_NET_GFIFOINT,
230 SPIDER_NET_GDMACINT,
231 SPIDER_NET_GSYSINT,
232 SPIDER_NET_GPWOPCMPINT,
233 SPIDER_NET_GPROPCMPINT,
234 SPIDER_NET_GPWFFINT,
235 SPIDER_NET_GRMDADRINT,
236 SPIDER_NET_GRMARPINT,
237 SPIDER_NET_GRMMPINT,
238 SPIDER_NET_GDTDEN0INT,
239 SPIDER_NET_GDDDEN0INT,
240 SPIDER_NET_GDCDEN0INT,
241 SPIDER_NET_GDBDEN0INT,
242 SPIDER_NET_GDADEN0INT,
243 SPIDER_NET_GDTFDCINT,
244 SPIDER_NET_GDDFDCINT,
245 SPIDER_NET_GDCFDCINT,
246 SPIDER_NET_GDBFDCINT,
247 SPIDER_NET_GDAFDCINT,
248 SPIDER_NET_GTTEDINT,
249 SPIDER_NET_GDTDCEINT,
250 SPIDER_NET_GRFDNMINT,
251 SPIDER_NET_GRFCNMINT,
252 SPIDER_NET_GRFBNMINT,
253 SPIDER_NET_GRFANMINT,
254 SPIDER_NET_GRFNMINT,
255 SPIDER_NET_G1TMCNTINT,
256 SPIDER_NET_GFREECNTINT
257};
258/* GHIINT1STS bits */
259enum spider_net_int1_status {
260 SPIDER_NET_GTMFLLINT = 0,
261 SPIDER_NET_GRMFLLINT,
262 SPIDER_NET_GTMSHTINT,
263 SPIDER_NET_GDTINVDINT,
264 SPIDER_NET_GRFDFLLINT,
265 SPIDER_NET_GDDDCEINT,
266 SPIDER_NET_GDDINVDINT,
267 SPIDER_NET_GRFCFLLINT,
268 SPIDER_NET_GDCDCEINT,
269 SPIDER_NET_GDCINVDINT,
270 SPIDER_NET_GRFBFLLINT,
271 SPIDER_NET_GDBDCEINT,
272 SPIDER_NET_GDBINVDINT,
273 SPIDER_NET_GRFAFLLINT,
274 SPIDER_NET_GDADCEINT,
275 SPIDER_NET_GDAINVDINT,
276 SPIDER_NET_GDTRSERINT,
277 SPIDER_NET_GDDRSERINT,
278 SPIDER_NET_GDCRSERINT,
279 SPIDER_NET_GDBRSERINT,
280 SPIDER_NET_GDARSERINT,
281 SPIDER_NET_GDSERINT,
282 SPIDER_NET_GDTPTERINT,
283 SPIDER_NET_GDDPTERINT,
284 SPIDER_NET_GDCPTERINT,
285 SPIDER_NET_GDBPTERINT,
286 SPIDER_NET_GDAPTERINT
287};
288/* GHIINT2STS bits */
289enum spider_net_int2_status {
290 SPIDER_NET_GPROPERINT = 0,
291 SPIDER_NET_GMCTCRSNGINT,
292 SPIDER_NET_GMCTLCOLINT,
293 SPIDER_NET_GMCTTMOTINT,
294 SPIDER_NET_GMCRCAERINT,
295 SPIDER_NET_GMCRCALERINT,
296 SPIDER_NET_GMCRALNERINT,
297 SPIDER_NET_GMCROVRINT,
298 SPIDER_NET_GMCRRNTINT,
299 SPIDER_NET_GMCRRXERINT,
300 SPIDER_NET_GTITCSERINT,
301 SPIDER_NET_GTIFMTERINT,
302 SPIDER_NET_GTIPKTRVKINT,
303 SPIDER_NET_GTISPINGINT,
304 SPIDER_NET_GTISADNGINT,
305 SPIDER_NET_GTISPDNGINT,
306 SPIDER_NET_GRIFMTERINT,
307 SPIDER_NET_GRIPKTRVKINT,
308 SPIDER_NET_GRISPINGINT,
309 SPIDER_NET_GRISADNGINT,
310 SPIDER_NET_GRISPDNGINT
311};
312
313#define SPIDER_NET_TXINT ( (1 << SPIDER_NET_GTTEDINT) | \
314 (1 << SPIDER_NET_GDTDCEINT) | \
315 (1 << SPIDER_NET_GDTFDCINT) )
316
317/* we rely on flagged descriptor interrupts*/
318#define SPIDER_NET_RXINT ( (1 << SPIDER_NET_GDAFDCINT) | \
319 (1 << SPIDER_NET_GRMFLLINT) )
320
321#define SPIDER_NET_GPREXEC 0x80000000
322#define SPIDER_NET_GPRDAT_MASK 0x0000ffff
323
324/* descriptor bits
325 *
326 * 1010 descriptor ready
327 * 0 descr in middle of chain
328 * 000 fixed to 0
329 *
330 * 0 no interrupt on completion
331 * 000 fixed to 0
332 * 1 no ipsec processing
333 * 1 last descriptor for this frame
334 * 00 no checksum
335 * 10 tcp checksum
336 * 11 udp checksum
337 *
338 * 00 fixed to 0
339 * 0 fixed to 0
340 * 0 no interrupt on response errors
341 * 0 no interrupt on invalid descr
342 * 0 no interrupt on dma process termination
343 * 0 no interrupt on descr chain end
344 * 0 no interrupt on descr complete
345 *
346 * 000 fixed to 0
347 * 0 response error interrupt status
348 * 0 invalid descr status
349 * 0 dma termination status
350 * 0 descr chain end status
351 * 0 descr complete status */
352#define SPIDER_NET_DMAC_CMDSTAT_NOCS 0xa00c0000
353#define SPIDER_NET_DMAC_CMDSTAT_TCPCS 0xa00e0000
354#define SPIDER_NET_DMAC_CMDSTAT_UDPCS 0xa00f0000
355#define SPIDER_NET_DESCR_IND_PROC_SHIFT 28
356#define SPIDER_NET_DESCR_IND_PROC_MASKO 0x0fffffff
357
358/* descr ready, descr is in middle of chain, get interrupt on completion */
359#define SPIDER_NET_DMAC_RX_CARDOWNED 0xa0800000
360
361/* multicast is no problem */
362#define SPIDER_NET_DATA_ERROR_MASK 0xffffbfff
363
364enum spider_net_descr_status {
365 SPIDER_NET_DESCR_COMPLETE = 0x00, /* used in rx and tx */
366 SPIDER_NET_DESCR_RESPONSE_ERROR = 0x01, /* used in rx and tx */
367 SPIDER_NET_DESCR_PROTECTION_ERROR = 0x02, /* used in rx and tx */
368 SPIDER_NET_DESCR_FRAME_END = 0x04, /* used in rx */
369 SPIDER_NET_DESCR_FORCE_END = 0x05, /* used in rx and tx */
370 SPIDER_NET_DESCR_CARDOWNED = 0x0a, /* used in rx and tx */
371 SPIDER_NET_DESCR_NOT_IN_USE /* any other value */
372};
373
374struct spider_net_descr {
375 /* as defined by the hardware */
376 dma_addr_t buf_addr;
377 u32 buf_size;
378 dma_addr_t next_descr_addr;
379 u32 dmac_cmd_status;
380 u32 result_size;
381 u32 valid_size; /* all zeroes for tx */
382 u32 data_status;
383 u32 data_error; /* all zeroes for tx */
384
385 /* used in the driver */
386 struct sk_buff *skb;
387 dma_addr_t bus_addr;
388 struct spider_net_descr *next;
389 struct spider_net_descr *prev;
390} __attribute__((aligned(32)));
391
392struct spider_net_descr_chain {
393 /* we walk from tail to head */
394 struct spider_net_descr *head;
395 struct spider_net_descr *tail;
396};
397
398/* descriptor data_status bits */
399#define SPIDER_NET_RXIPCHK 29
400#define SPIDER_NET_TCPUDPIPCHK 28
401#define SPIDER_NET_DATA_STATUS_CHK_MASK (1 << SPIDER_NET_RXIPCHK | \
402 1 << SPIDER_NET_TCPUDPIPCHK)
403
404#define SPIDER_NET_VLAN_PACKET 21
405
406/* descriptor data_error bits */
407#define SPIDER_NET_RXIPCHKERR 27
408#define SPIDER_NET_RXTCPCHKERR 26
409#define SPIDER_NET_DATA_ERROR_CHK_MASK (1 << SPIDER_NET_RXIPCHKERR | \
410 1 << SPIDER_NET_RXTCPCHKERR)
411
412/* the cases we don't pass the packet to the stack */
413#define SPIDER_NET_DESTROY_RX_FLAGS 0x70138000
414
415#define SPIDER_NET_DESCR_SIZE 32
416
417/* this will be bigger some time */
418struct spider_net_options {
419 int rx_csum; /* for rx: if 0 ip_summed=NONE,
420 if 1 and hw has verified, ip_summed=UNNECESSARY */
421};
422
423#define SPIDER_NET_DEFAULT_MSG ( NETIF_MSG_DRV | \
424 NETIF_MSG_PROBE | \
425 NETIF_MSG_LINK | \
426 NETIF_MSG_TIMER | \
427 NETIF_MSG_IFDOWN | \
428 NETIF_MSG_IFUP | \
429 NETIF_MSG_RX_ERR | \
430 NETIF_MSG_TX_ERR | \
431 NETIF_MSG_TX_QUEUED | \
432 NETIF_MSG_INTR | \
433 NETIF_MSG_TX_DONE | \
434 NETIF_MSG_RX_STATUS | \
435 NETIF_MSG_PKTDATA | \
436 NETIF_MSG_HW | \
437 NETIF_MSG_WOL )
438
439struct spider_net_card {
440 struct net_device *netdev;
441 struct pci_dev *pdev;
442 struct mii_phy phy;
443
444 void __iomem *regs;
445
446 struct spider_net_descr_chain tx_chain;
447 struct spider_net_descr_chain rx_chain;
448 spinlock_t chain_lock;
449
450 struct net_device_stats netdev_stats;
451
452 struct spider_net_options options;
453
454 spinlock_t intmask_lock;
455
456 struct work_struct tx_timeout_task;
457 atomic_t tx_timeout_task_counter;
458 wait_queue_head_t waitq;
459
460 /* for ethtool */
461 int msg_enable;
462
463 struct spider_net_descr descr[0];
464};
465
466#define pr_err(fmt,arg...) \
467 printk(KERN_ERR fmt ,##arg)
468
469#endif
diff --git a/drivers/net/spider_net_ethtool.c b/drivers/net/spider_net_ethtool.c
new file mode 100644
index 00000000000..d42e60ba74c
--- /dev/null
+++ b/drivers/net/spider_net_ethtool.c
@@ -0,0 +1,126 @@
1/*
2 * Network device driver for Cell Processor-Based Blade
3 *
4 * (C) Copyright IBM Corp. 2005
5 *
6 * Authors : Utz Bacher <utz.bacher@de.ibm.com>
7 * Jens Osterkamp <Jens.Osterkamp@de.ibm.com>
8 *
9 * This program is free software; you can redistribute it and/or modify
10 * it under the terms of the GNU General Public License as published by
11 * the Free Software Foundation; either version 2, or (at your option)
12 * any later version.
13 *
14 * This program is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 * GNU General Public License for more details.
18 *
19 * You should have received a copy of the GNU General Public License
20 * along with this program; if not, write to the Free Software
21 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
22 */
23
24#include <linux/netdevice.h>
25#include <linux/ethtool.h>
26#include <linux/pci.h>
27
28#include "spider_net.h"
29
30static int
31spider_net_ethtool_get_settings(struct net_device *netdev,
32 struct ethtool_cmd *cmd)
33{
34 struct spider_net_card *card;
35 card = netdev_priv(netdev);
36
37 cmd->supported = (SUPPORTED_1000baseT_Full |
38 SUPPORTED_FIBRE);
39 cmd->advertising = (ADVERTISED_1000baseT_Full |
40 ADVERTISED_FIBRE);
41 cmd->port = PORT_FIBRE;
42 cmd->speed = card->phy.speed;
43 cmd->duplex = DUPLEX_FULL;
44
45 return 0;
46}
47
48static void
49spider_net_ethtool_get_drvinfo(struct net_device *netdev,
50 struct ethtool_drvinfo *drvinfo)
51{
52 struct spider_net_card *card;
53 card = netdev_priv(netdev);
54
55 /* clear and fill out info */
56 memset(drvinfo, 0, sizeof(struct ethtool_drvinfo));
57 strncpy(drvinfo->driver, spider_net_driver_name, 32);
58 strncpy(drvinfo->version, "0.1", 32);
59 strcpy(drvinfo->fw_version, "no information");
60 strncpy(drvinfo->bus_info, pci_name(card->pdev), 32);
61}
62
63static void
64spider_net_ethtool_get_wol(struct net_device *netdev,
65 struct ethtool_wolinfo *wolinfo)
66{
67 /* no support for wol */
68 wolinfo->supported = 0;
69 wolinfo->wolopts = 0;
70}
71
72static u32
73spider_net_ethtool_get_msglevel(struct net_device *netdev)
74{
75 struct spider_net_card *card;
76 card = netdev_priv(netdev);
77 return card->msg_enable;
78}
79
80static void
81spider_net_ethtool_set_msglevel(struct net_device *netdev,
82 u32 level)
83{
84 struct spider_net_card *card;
85 card = netdev_priv(netdev);
86 card->msg_enable = level;
87}
88
89static int
90spider_net_ethtool_nway_reset(struct net_device *netdev)
91{
92 if (netif_running(netdev)) {
93 spider_net_stop(netdev);
94 spider_net_open(netdev);
95 }
96 return 0;
97}
98
99static u32
100spider_net_ethtool_get_rx_csum(struct net_device *netdev)
101{
102 struct spider_net_card *card = netdev->priv;
103
104 return card->options.rx_csum;
105}
106
107static int
108spider_net_ethtool_set_rx_csum(struct net_device *netdev, u32 n)
109{
110 struct spider_net_card *card = netdev->priv;
111
112 card->options.rx_csum = n;
113 return 0;
114}
115
116struct ethtool_ops spider_net_ethtool_ops = {
117 .get_settings = spider_net_ethtool_get_settings,
118 .get_drvinfo = spider_net_ethtool_get_drvinfo,
119 .get_wol = spider_net_ethtool_get_wol,
120 .get_msglevel = spider_net_ethtool_get_msglevel,
121 .set_msglevel = spider_net_ethtool_set_msglevel,
122 .nway_reset = spider_net_ethtool_nway_reset,
123 .get_rx_csum = spider_net_ethtool_get_rx_csum,
124 .set_rx_csum = spider_net_ethtool_set_rx_csum,
125};
126
diff --git a/drivers/net/sun3lance.c b/drivers/net/sun3lance.c
index 1f43bbfbc1c..5c8fcd40ef4 100644
--- a/drivers/net/sun3lance.c
+++ b/drivers/net/sun3lance.c
@@ -162,7 +162,7 @@ struct lance_private {
162#define MEM lp->mem 162#define MEM lp->mem
163#define DREG lp->iobase[0] 163#define DREG lp->iobase[0]
164#define AREG lp->iobase[1] 164#define AREG lp->iobase[1]
165#define REGA(a) ( AREG = (a), DREG ) 165#define REGA(a) (*( AREG = (a), &DREG ))
166 166
167/* Definitions for the Lance */ 167/* Definitions for the Lance */
168 168
diff --git a/drivers/net/sungem.c b/drivers/net/sungem.c
index 2608e7a3d21..3f67a42e850 100644
--- a/drivers/net/sungem.c
+++ b/drivers/net/sungem.c
@@ -948,6 +948,7 @@ static irqreturn_t gem_interrupt(int irq, void *dev_id, struct pt_regs *regs)
948 u32 gem_status = readl(gp->regs + GREG_STAT); 948 u32 gem_status = readl(gp->regs + GREG_STAT);
949 949
950 if (gem_status == 0) { 950 if (gem_status == 0) {
951 netif_poll_enable(dev);
951 spin_unlock_irqrestore(&gp->lock, flags); 952 spin_unlock_irqrestore(&gp->lock, flags);
952 return IRQ_NONE; 953 return IRQ_NONE;
953 } 954 }
diff --git a/drivers/net/sungem.h b/drivers/net/sungem.h
index 7143fd7cf3f..ff8ae5f7997 100644
--- a/drivers/net/sungem.h
+++ b/drivers/net/sungem.h
@@ -1020,7 +1020,7 @@ struct gem {
1020 1020
1021 struct gem_init_block *init_block; 1021 struct gem_init_block *init_block;
1022 struct sk_buff *rx_skbs[RX_RING_SIZE]; 1022 struct sk_buff *rx_skbs[RX_RING_SIZE];
1023 struct sk_buff *tx_skbs[RX_RING_SIZE]; 1023 struct sk_buff *tx_skbs[TX_RING_SIZE];
1024 dma_addr_t gblock_dvma; 1024 dma_addr_t gblock_dvma;
1025 1025
1026 struct pci_dev *pdev; 1026 struct pci_dev *pdev;
diff --git a/drivers/net/tg3.c b/drivers/net/tg3.c
index af8263a1580..dc57352e5a9 100644
--- a/drivers/net/tg3.c
+++ b/drivers/net/tg3.c
@@ -36,6 +36,7 @@
36#include <linux/ip.h> 36#include <linux/ip.h>
37#include <linux/tcp.h> 37#include <linux/tcp.h>
38#include <linux/workqueue.h> 38#include <linux/workqueue.h>
39#include <linux/prefetch.h>
39 40
40#include <net/checksum.h> 41#include <net/checksum.h>
41 42
@@ -66,8 +67,8 @@
66 67
67#define DRV_MODULE_NAME "tg3" 68#define DRV_MODULE_NAME "tg3"
68#define PFX DRV_MODULE_NAME ": " 69#define PFX DRV_MODULE_NAME ": "
69#define DRV_MODULE_VERSION "3.37" 70#define DRV_MODULE_VERSION "3.39"
70#define DRV_MODULE_RELDATE "August 25, 2005" 71#define DRV_MODULE_RELDATE "September 5, 2005"
71 72
72#define TG3_DEF_MAC_MODE 0 73#define TG3_DEF_MAC_MODE 0
73#define TG3_DEF_RX_MODE 0 74#define TG3_DEF_RX_MODE 0
@@ -121,12 +122,9 @@
121 TG3_RX_RCB_RING_SIZE(tp)) 122 TG3_RX_RCB_RING_SIZE(tp))
122#define TG3_TX_RING_BYTES (sizeof(struct tg3_tx_buffer_desc) * \ 123#define TG3_TX_RING_BYTES (sizeof(struct tg3_tx_buffer_desc) * \
123 TG3_TX_RING_SIZE) 124 TG3_TX_RING_SIZE)
124#define TX_RING_GAP(TP) \
125 (TG3_TX_RING_SIZE - (TP)->tx_pending)
126#define TX_BUFFS_AVAIL(TP) \ 125#define TX_BUFFS_AVAIL(TP) \
127 (((TP)->tx_cons <= (TP)->tx_prod) ? \ 126 ((TP)->tx_pending - \
128 (TP)->tx_cons + (TP)->tx_pending - (TP)->tx_prod : \ 127 (((TP)->tx_prod - (TP)->tx_cons) & (TG3_TX_RING_SIZE - 1)))
129 (TP)->tx_cons - (TP)->tx_prod - TX_RING_GAP(TP))
130#define NEXT_TX(N) (((N) + 1) & (TG3_TX_RING_SIZE - 1)) 128#define NEXT_TX(N) (((N) + 1) & (TG3_TX_RING_SIZE - 1))
131 129
132#define RX_PKT_BUF_SZ (1536 + tp->rx_offset + 64) 130#define RX_PKT_BUF_SZ (1536 + tp->rx_offset + 64)
@@ -490,7 +488,8 @@ static void tg3_disable_ints(struct tg3 *tp)
490 488
491static inline void tg3_cond_int(struct tg3 *tp) 489static inline void tg3_cond_int(struct tg3 *tp)
492{ 490{
493 if (tp->hw_status->status & SD_STATUS_UPDATED) 491 if (!(tp->tg3_flags & TG3_FLAG_TAGGED_STATUS) &&
492 (tp->hw_status->status & SD_STATUS_UPDATED))
494 tw32(GRC_LOCAL_CTRL, tp->grc_local_ctrl | GRC_LCLCTRL_SETINT); 493 tw32(GRC_LOCAL_CTRL, tp->grc_local_ctrl | GRC_LCLCTRL_SETINT);
495} 494}
496 495
@@ -2880,9 +2879,13 @@ static void tg3_tx(struct tg3 *tp)
2880 2879
2881 tp->tx_cons = sw_idx; 2880 tp->tx_cons = sw_idx;
2882 2881
2883 if (netif_queue_stopped(tp->dev) && 2882 if (unlikely(netif_queue_stopped(tp->dev))) {
2884 (TX_BUFFS_AVAIL(tp) > TG3_TX_WAKEUP_THRESH)) 2883 spin_lock(&tp->tx_lock);
2885 netif_wake_queue(tp->dev); 2884 if (netif_queue_stopped(tp->dev) &&
2885 (TX_BUFFS_AVAIL(tp) > TG3_TX_WAKEUP_THRESH))
2886 netif_wake_queue(tp->dev);
2887 spin_unlock(&tp->tx_lock);
2888 }
2886} 2889}
2887 2890
2888/* Returns size of skb allocated or < 0 on error. 2891/* Returns size of skb allocated or < 0 on error.
@@ -3198,9 +3201,7 @@ static int tg3_poll(struct net_device *netdev, int *budget)
3198 3201
3199 /* run TX completion thread */ 3202 /* run TX completion thread */
3200 if (sblk->idx[0].tx_consumer != tp->tx_cons) { 3203 if (sblk->idx[0].tx_consumer != tp->tx_cons) {
3201 spin_lock(&tp->tx_lock);
3202 tg3_tx(tp); 3204 tg3_tx(tp);
3203 spin_unlock(&tp->tx_lock);
3204 } 3205 }
3205 3206
3206 /* run RX thread, within the bounds set by NAPI. 3207 /* run RX thread, within the bounds set by NAPI.
@@ -3220,18 +3221,17 @@ static int tg3_poll(struct net_device *netdev, int *budget)
3220 netdev->quota -= work_done; 3221 netdev->quota -= work_done;
3221 } 3222 }
3222 3223
3223 if (tp->tg3_flags & TG3_FLAG_TAGGED_STATUS) 3224 if (tp->tg3_flags & TG3_FLAG_TAGGED_STATUS) {
3224 tp->last_tag = sblk->status_tag; 3225 tp->last_tag = sblk->status_tag;
3225 rmb(); 3226 rmb();
3226 sblk->status &= ~SD_STATUS_UPDATED; 3227 } else
3228 sblk->status &= ~SD_STATUS_UPDATED;
3227 3229
3228 /* if no more work, tell net stack and NIC we're done */ 3230 /* if no more work, tell net stack and NIC we're done */
3229 done = !tg3_has_work(tp); 3231 done = !tg3_has_work(tp);
3230 if (done) { 3232 if (done) {
3231 spin_lock(&tp->lock);
3232 netif_rx_complete(netdev); 3233 netif_rx_complete(netdev);
3233 tg3_restart_ints(tp); 3234 tg3_restart_ints(tp);
3234 spin_unlock(&tp->lock);
3235 } 3235 }
3236 3236
3237 return (done ? 0 : 1); 3237 return (done ? 0 : 1);
@@ -3279,8 +3279,9 @@ static irqreturn_t tg3_msi(int irq, void *dev_id, struct pt_regs *regs)
3279{ 3279{
3280 struct net_device *dev = dev_id; 3280 struct net_device *dev = dev_id;
3281 struct tg3 *tp = netdev_priv(dev); 3281 struct tg3 *tp = netdev_priv(dev);
3282 struct tg3_hw_status *sblk = tp->hw_status;
3283 3282
3283 prefetch(tp->hw_status);
3284 prefetch(&tp->rx_rcb[tp->rx_rcb_ptr]);
3284 /* 3285 /*
3285 * Writing any value to intr-mbox-0 clears PCI INTA# and 3286 * Writing any value to intr-mbox-0 clears PCI INTA# and
3286 * chip-internal interrupt pending events. 3287 * chip-internal interrupt pending events.
@@ -3289,19 +3290,9 @@ static irqreturn_t tg3_msi(int irq, void *dev_id, struct pt_regs *regs)
3289 * event coalescing. 3290 * event coalescing.
3290 */ 3291 */
3291 tw32_mailbox(MAILBOX_INTERRUPT_0 + TG3_64BIT_REG_LOW, 0x00000001); 3292 tw32_mailbox(MAILBOX_INTERRUPT_0 + TG3_64BIT_REG_LOW, 0x00000001);
3292 tp->last_tag = sblk->status_tag; 3293 if (likely(!tg3_irq_sync(tp)))
3293 rmb();
3294 if (tg3_irq_sync(tp))
3295 goto out;
3296 sblk->status &= ~SD_STATUS_UPDATED;
3297 if (likely(tg3_has_work(tp)))
3298 netif_rx_schedule(dev); /* schedule NAPI poll */ 3294 netif_rx_schedule(dev); /* schedule NAPI poll */
3299 else { 3295
3300 /* No work, re-enable interrupts. */
3301 tw32_mailbox(MAILBOX_INTERRUPT_0 + TG3_64BIT_REG_LOW,
3302 tp->last_tag << 24);
3303 }
3304out:
3305 return IRQ_RETVAL(1); 3296 return IRQ_RETVAL(1);
3306} 3297}
3307 3298
@@ -3331,9 +3322,10 @@ static irqreturn_t tg3_interrupt(int irq, void *dev_id, struct pt_regs *regs)
3331 if (tg3_irq_sync(tp)) 3322 if (tg3_irq_sync(tp))
3332 goto out; 3323 goto out;
3333 sblk->status &= ~SD_STATUS_UPDATED; 3324 sblk->status &= ~SD_STATUS_UPDATED;
3334 if (likely(tg3_has_work(tp))) 3325 if (likely(tg3_has_work(tp))) {
3326 prefetch(&tp->rx_rcb[tp->rx_rcb_ptr]);
3335 netif_rx_schedule(dev); /* schedule NAPI poll */ 3327 netif_rx_schedule(dev); /* schedule NAPI poll */
3336 else { 3328 } else {
3337 /* No work, shared interrupt perhaps? re-enable 3329 /* No work, shared interrupt perhaps? re-enable
3338 * interrupts, and flush that PCI write 3330 * interrupts, and flush that PCI write
3339 */ 3331 */
@@ -3359,7 +3351,7 @@ static irqreturn_t tg3_interrupt_tagged(int irq, void *dev_id, struct pt_regs *r
3359 * Reading the PCI State register will confirm whether the 3351 * Reading the PCI State register will confirm whether the
3360 * interrupt is ours and will flush the status block. 3352 * interrupt is ours and will flush the status block.
3361 */ 3353 */
3362 if ((sblk->status & SD_STATUS_UPDATED) || 3354 if ((sblk->status_tag != tp->last_tag) ||
3363 !(tr32(TG3PCI_PCISTATE) & PCISTATE_INT_NOT_ACTIVE)) { 3355 !(tr32(TG3PCI_PCISTATE) & PCISTATE_INT_NOT_ACTIVE)) {
3364 /* 3356 /*
3365 * writing any value to intr-mbox-0 clears PCI INTA# and 3357 * writing any value to intr-mbox-0 clears PCI INTA# and
@@ -3370,19 +3362,17 @@ static irqreturn_t tg3_interrupt_tagged(int irq, void *dev_id, struct pt_regs *r
3370 */ 3362 */
3371 tw32_mailbox(MAILBOX_INTERRUPT_0 + TG3_64BIT_REG_LOW, 3363 tw32_mailbox(MAILBOX_INTERRUPT_0 + TG3_64BIT_REG_LOW,
3372 0x00000001); 3364 0x00000001);
3373 tp->last_tag = sblk->status_tag;
3374 rmb();
3375 if (tg3_irq_sync(tp)) 3365 if (tg3_irq_sync(tp))
3376 goto out; 3366 goto out;
3377 sblk->status &= ~SD_STATUS_UPDATED; 3367 if (netif_rx_schedule_prep(dev)) {
3378 if (likely(tg3_has_work(tp))) 3368 prefetch(&tp->rx_rcb[tp->rx_rcb_ptr]);
3379 netif_rx_schedule(dev); /* schedule NAPI poll */ 3369 /* Update last_tag to mark that this status has been
3380 else { 3370 * seen. Because interrupt may be shared, we may be
3381 /* no work, shared interrupt perhaps? re-enable 3371 * racing with tg3_poll(), so only update last_tag
3382 * interrupts, and flush that PCI write 3372 * if tg3_poll() is not scheduled.
3383 */ 3373 */
3384 tw32_mailbox_f(MAILBOX_INTERRUPT_0 + TG3_64BIT_REG_LOW, 3374 tp->last_tag = sblk->status_tag;
3385 tp->last_tag << 24); 3375 __netif_rx_schedule(dev);
3386 } 3376 }
3387 } else { /* shared interrupt */ 3377 } else { /* shared interrupt */
3388 handled = 0; 3378 handled = 0;
@@ -3716,8 +3706,11 @@ static int tg3_start_xmit(struct sk_buff *skb, struct net_device *dev)
3716 tw32_tx_mbox((MAILBOX_SNDHOST_PROD_IDX_0 + TG3_64BIT_REG_LOW), entry); 3706 tw32_tx_mbox((MAILBOX_SNDHOST_PROD_IDX_0 + TG3_64BIT_REG_LOW), entry);
3717 3707
3718 tp->tx_prod = entry; 3708 tp->tx_prod = entry;
3719 if (TX_BUFFS_AVAIL(tp) <= (MAX_SKB_FRAGS + 1)) 3709 if (TX_BUFFS_AVAIL(tp) <= (MAX_SKB_FRAGS + 1)) {
3720 netif_stop_queue(dev); 3710 netif_stop_queue(dev);
3711 if (TX_BUFFS_AVAIL(tp) > TG3_TX_WAKEUP_THRESH)
3712 netif_wake_queue(tp->dev);
3713 }
3721 3714
3722out_unlock: 3715out_unlock:
3723 mmiowb(); 3716 mmiowb();
@@ -5960,7 +5953,7 @@ static int tg3_reset_hw(struct tg3 *tp)
5960 tw32(MAC_LED_CTRL, tp->led_ctrl); 5953 tw32(MAC_LED_CTRL, tp->led_ctrl);
5961 5954
5962 tw32(MAC_MI_STAT, MAC_MI_STAT_LNKSTAT_ATTN_ENAB); 5955 tw32(MAC_MI_STAT, MAC_MI_STAT_LNKSTAT_ATTN_ENAB);
5963 if (tp->tg3_flags2 & TG3_FLG2_PHY_SERDES) { 5956 if (tp->tg3_flags2 & TG3_FLG2_ANY_SERDES) {
5964 tw32_f(MAC_RX_MODE, RX_MODE_RESET); 5957 tw32_f(MAC_RX_MODE, RX_MODE_RESET);
5965 udelay(10); 5958 udelay(10);
5966 } 5959 }
@@ -6242,6 +6235,7 @@ static int tg3_test_interrupt(struct tg3 *tp)
6242 if (err) 6235 if (err)
6243 return err; 6236 return err;
6244 6237
6238 tp->hw_status->status &= ~SD_STATUS_UPDATED;
6245 tg3_enable_ints(tp); 6239 tg3_enable_ints(tp);
6246 6240
6247 tw32_f(HOSTCC_MODE, tp->coalesce_mode | HOSTCC_MODE_ENABLE | 6241 tw32_f(HOSTCC_MODE, tp->coalesce_mode | HOSTCC_MODE_ENABLE |
@@ -7557,6 +7551,38 @@ static void tg3_get_strings (struct net_device *dev, u32 stringset, u8 *buf)
7557 } 7551 }
7558} 7552}
7559 7553
7554static int tg3_phys_id(struct net_device *dev, u32 data)
7555{
7556 struct tg3 *tp = netdev_priv(dev);
7557 int i;
7558
7559 if (!netif_running(tp->dev))
7560 return -EAGAIN;
7561
7562 if (data == 0)
7563 data = 2;
7564
7565 for (i = 0; i < (data * 2); i++) {
7566 if ((i % 2) == 0)
7567 tw32(MAC_LED_CTRL, LED_CTRL_LNKLED_OVERRIDE |
7568 LED_CTRL_1000MBPS_ON |
7569 LED_CTRL_100MBPS_ON |
7570 LED_CTRL_10MBPS_ON |
7571 LED_CTRL_TRAFFIC_OVERRIDE |
7572 LED_CTRL_TRAFFIC_BLINK |
7573 LED_CTRL_TRAFFIC_LED);
7574
7575 else
7576 tw32(MAC_LED_CTRL, LED_CTRL_LNKLED_OVERRIDE |
7577 LED_CTRL_TRAFFIC_OVERRIDE);
7578
7579 if (msleep_interruptible(500))
7580 break;
7581 }
7582 tw32(MAC_LED_CTRL, tp->led_ctrl);
7583 return 0;
7584}
7585
7560static void tg3_get_ethtool_stats (struct net_device *dev, 7586static void tg3_get_ethtool_stats (struct net_device *dev,
7561 struct ethtool_stats *estats, u64 *tmp_stats) 7587 struct ethtool_stats *estats, u64 *tmp_stats)
7562{ 7588{
@@ -7616,7 +7642,7 @@ static int tg3_test_link(struct tg3 *tp)
7616 if (!netif_running(tp->dev)) 7642 if (!netif_running(tp->dev))
7617 return -ENODEV; 7643 return -ENODEV;
7618 7644
7619 if (tp->tg3_flags2 & TG3_FLG2_PHY_SERDES) 7645 if (tp->tg3_flags2 & TG3_FLG2_ANY_SERDES)
7620 max = TG3_SERDES_TIMEOUT_SEC; 7646 max = TG3_SERDES_TIMEOUT_SEC;
7621 else 7647 else
7622 max = TG3_COPPER_TIMEOUT_SEC; 7648 max = TG3_COPPER_TIMEOUT_SEC;
@@ -7901,9 +7927,12 @@ static int tg3_test_memory(struct tg3 *tp)
7901 return err; 7927 return err;
7902} 7928}
7903 7929
7904static int tg3_test_loopback(struct tg3 *tp) 7930#define TG3_MAC_LOOPBACK 0
7931#define TG3_PHY_LOOPBACK 1
7932
7933static int tg3_run_loopback(struct tg3 *tp, int loopback_mode)
7905{ 7934{
7906 u32 mac_mode, send_idx, rx_start_idx, rx_idx, tx_idx, opaque_key; 7935 u32 mac_mode, rx_start_idx, rx_idx, tx_idx, opaque_key;
7907 u32 desc_idx; 7936 u32 desc_idx;
7908 struct sk_buff *skb, *rx_skb; 7937 struct sk_buff *skb, *rx_skb;
7909 u8 *tx_data; 7938 u8 *tx_data;
@@ -7911,18 +7940,26 @@ static int tg3_test_loopback(struct tg3 *tp)
7911 int num_pkts, tx_len, rx_len, i, err; 7940 int num_pkts, tx_len, rx_len, i, err;
7912 struct tg3_rx_buffer_desc *desc; 7941 struct tg3_rx_buffer_desc *desc;
7913 7942
7914 if (!netif_running(tp->dev)) 7943 if (loopback_mode == TG3_MAC_LOOPBACK) {
7915 return -ENODEV; 7944 mac_mode = (tp->mac_mode & ~MAC_MODE_PORT_MODE_MASK) |
7945 MAC_MODE_PORT_INT_LPBACK | MAC_MODE_LINK_POLARITY |
7946 MAC_MODE_PORT_MODE_GMII;
7947 tw32(MAC_MODE, mac_mode);
7948 } else if (loopback_mode == TG3_PHY_LOOPBACK) {
7949 mac_mode = (tp->mac_mode & ~MAC_MODE_PORT_MODE_MASK) |
7950 MAC_MODE_LINK_POLARITY | MAC_MODE_PORT_MODE_GMII;
7951 if ((tp->phy_id & PHY_ID_MASK) == PHY_ID_BCM5401)
7952 mac_mode &= ~MAC_MODE_LINK_POLARITY;
7953 tw32(MAC_MODE, mac_mode);
7954
7955 tg3_writephy(tp, MII_BMCR, BMCR_LOOPBACK | BMCR_FULLDPLX |
7956 BMCR_SPEED1000);
7957 }
7958 else
7959 return -EINVAL;
7916 7960
7917 err = -EIO; 7961 err = -EIO;
7918 7962
7919 tg3_reset_hw(tp);
7920
7921 mac_mode = (tp->mac_mode & ~MAC_MODE_PORT_MODE_MASK) |
7922 MAC_MODE_PORT_INT_LPBACK | MAC_MODE_LINK_POLARITY |
7923 MAC_MODE_PORT_MODE_GMII;
7924 tw32(MAC_MODE, mac_mode);
7925
7926 tx_len = 1514; 7963 tx_len = 1514;
7927 skb = dev_alloc_skb(tx_len); 7964 skb = dev_alloc_skb(tx_len);
7928 tx_data = skb_put(skb, tx_len); 7965 tx_data = skb_put(skb, tx_len);
@@ -7943,15 +7980,15 @@ static int tg3_test_loopback(struct tg3 *tp)
7943 7980
7944 rx_start_idx = tp->hw_status->idx[0].rx_producer; 7981 rx_start_idx = tp->hw_status->idx[0].rx_producer;
7945 7982
7946 send_idx = 0;
7947 num_pkts = 0; 7983 num_pkts = 0;
7948 7984
7949 tg3_set_txd(tp, send_idx, map, tx_len, 0, 1); 7985 tg3_set_txd(tp, tp->tx_prod, map, tx_len, 0, 1);
7950 7986
7951 send_idx++; 7987 tp->tx_prod++;
7952 num_pkts++; 7988 num_pkts++;
7953 7989
7954 tw32_tx_mbox(MAILBOX_SNDHOST_PROD_IDX_0 + TG3_64BIT_REG_LOW, send_idx); 7990 tw32_tx_mbox(MAILBOX_SNDHOST_PROD_IDX_0 + TG3_64BIT_REG_LOW,
7991 tp->tx_prod);
7955 tr32_mailbox(MAILBOX_SNDHOST_PROD_IDX_0 + TG3_64BIT_REG_LOW); 7992 tr32_mailbox(MAILBOX_SNDHOST_PROD_IDX_0 + TG3_64BIT_REG_LOW);
7956 7993
7957 udelay(10); 7994 udelay(10);
@@ -7964,7 +8001,7 @@ static int tg3_test_loopback(struct tg3 *tp)
7964 8001
7965 tx_idx = tp->hw_status->idx[0].tx_consumer; 8002 tx_idx = tp->hw_status->idx[0].tx_consumer;
7966 rx_idx = tp->hw_status->idx[0].rx_producer; 8003 rx_idx = tp->hw_status->idx[0].rx_producer;
7967 if ((tx_idx == send_idx) && 8004 if ((tx_idx == tp->tx_prod) &&
7968 (rx_idx == (rx_start_idx + num_pkts))) 8005 (rx_idx == (rx_start_idx + num_pkts)))
7969 break; 8006 break;
7970 } 8007 }
@@ -7972,7 +8009,7 @@ static int tg3_test_loopback(struct tg3 *tp)
7972 pci_unmap_single(tp->pdev, map, tx_len, PCI_DMA_TODEVICE); 8009 pci_unmap_single(tp->pdev, map, tx_len, PCI_DMA_TODEVICE);
7973 dev_kfree_skb(skb); 8010 dev_kfree_skb(skb);
7974 8011
7975 if (tx_idx != send_idx) 8012 if (tx_idx != tp->tx_prod)
7976 goto out; 8013 goto out;
7977 8014
7978 if (rx_idx != rx_start_idx + num_pkts) 8015 if (rx_idx != rx_start_idx + num_pkts)
@@ -8008,6 +8045,30 @@ out:
8008 return err; 8045 return err;
8009} 8046}
8010 8047
8048#define TG3_MAC_LOOPBACK_FAILED 1
8049#define TG3_PHY_LOOPBACK_FAILED 2
8050#define TG3_LOOPBACK_FAILED (TG3_MAC_LOOPBACK_FAILED | \
8051 TG3_PHY_LOOPBACK_FAILED)
8052
8053static int tg3_test_loopback(struct tg3 *tp)
8054{
8055 int err = 0;
8056
8057 if (!netif_running(tp->dev))
8058 return TG3_LOOPBACK_FAILED;
8059
8060 tg3_reset_hw(tp);
8061
8062 if (tg3_run_loopback(tp, TG3_MAC_LOOPBACK))
8063 err |= TG3_MAC_LOOPBACK_FAILED;
8064 if (!(tp->tg3_flags2 & TG3_FLG2_PHY_SERDES)) {
8065 if (tg3_run_loopback(tp, TG3_PHY_LOOPBACK))
8066 err |= TG3_PHY_LOOPBACK_FAILED;
8067 }
8068
8069 return err;
8070}
8071
8011static void tg3_self_test(struct net_device *dev, struct ethtool_test *etest, 8072static void tg3_self_test(struct net_device *dev, struct ethtool_test *etest,
8012 u64 *data) 8073 u64 *data)
8013{ 8074{
@@ -8048,10 +8109,8 @@ static void tg3_self_test(struct net_device *dev, struct ethtool_test *etest,
8048 etest->flags |= ETH_TEST_FL_FAILED; 8109 etest->flags |= ETH_TEST_FL_FAILED;
8049 data[3] = 1; 8110 data[3] = 1;
8050 } 8111 }
8051 if (tg3_test_loopback(tp) != 0) { 8112 if ((data[4] = tg3_test_loopback(tp)) != 0)
8052 etest->flags |= ETH_TEST_FL_FAILED; 8113 etest->flags |= ETH_TEST_FL_FAILED;
8053 data[4] = 1;
8054 }
8055 8114
8056 tg3_full_unlock(tp); 8115 tg3_full_unlock(tp);
8057 8116
@@ -8239,6 +8298,7 @@ static struct ethtool_ops tg3_ethtool_ops = {
8239 .self_test_count = tg3_get_test_count, 8298 .self_test_count = tg3_get_test_count,
8240 .self_test = tg3_self_test, 8299 .self_test = tg3_self_test,
8241 .get_strings = tg3_get_strings, 8300 .get_strings = tg3_get_strings,
8301 .phys_id = tg3_phys_id,
8242 .get_stats_count = tg3_get_stats_count, 8302 .get_stats_count = tg3_get_stats_count,
8243 .get_ethtool_stats = tg3_get_ethtool_stats, 8303 .get_ethtool_stats = tg3_get_ethtool_stats,
8244 .get_coalesce = tg3_get_coalesce, 8304 .get_coalesce = tg3_get_coalesce,
@@ -8303,7 +8363,8 @@ static void __devinit tg3_get_nvram_info(struct tg3 *tp)
8303 tw32(NVRAM_CFG1, nvcfg1); 8363 tw32(NVRAM_CFG1, nvcfg1);
8304 } 8364 }
8305 8365
8306 if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5750) { 8366 if ((GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5750) ||
8367 (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5780)) {
8307 switch (nvcfg1 & NVRAM_CFG1_VENDOR_MASK) { 8368 switch (nvcfg1 & NVRAM_CFG1_VENDOR_MASK) {
8308 case FLASH_VENDOR_ATMEL_FLASH_BUFFERED: 8369 case FLASH_VENDOR_ATMEL_FLASH_BUFFERED:
8309 tp->nvram_jedecnum = JEDEC_ATMEL; 8370 tp->nvram_jedecnum = JEDEC_ATMEL;
@@ -8717,8 +8778,9 @@ static int tg3_nvram_write_block_buffered(struct tg3 *tp, u32 offset, u32 len,
8717 if (i == (len - 4)) 8778 if (i == (len - 4))
8718 nvram_cmd |= NVRAM_CMD_LAST; 8779 nvram_cmd |= NVRAM_CMD_LAST;
8719 8780
8720 if ((tp->nvram_jedecnum == JEDEC_ST) && 8781 if ((GET_ASIC_REV(tp->pci_chip_rev_id) != ASIC_REV_5752) &&
8721 (nvram_cmd & NVRAM_CMD_FIRST)) { 8782 (tp->nvram_jedecnum == JEDEC_ST) &&
8783 (nvram_cmd & NVRAM_CMD_FIRST)) {
8722 8784
8723 if ((ret = tg3_nvram_exec_cmd(tp, 8785 if ((ret = tg3_nvram_exec_cmd(tp,
8724 NVRAM_CMD_WREN | NVRAM_CMD_GO | 8786 NVRAM_CMD_WREN | NVRAM_CMD_GO |
diff --git a/drivers/net/tulip/uli526x.c b/drivers/net/tulip/uli526x.c
index 5ae22b7bc5c..1a431633625 100644
--- a/drivers/net/tulip/uli526x.c
+++ b/drivers/net/tulip/uli526x.c
@@ -21,7 +21,6 @@
21#include <linux/kernel.h> 21#include <linux/kernel.h>
22#include <linux/string.h> 22#include <linux/string.h>
23#include <linux/timer.h> 23#include <linux/timer.h>
24#include <linux/ptrace.h>
25#include <linux/errno.h> 24#include <linux/errno.h>
26#include <linux/ioport.h> 25#include <linux/ioport.h>
27#include <linux/slab.h> 26#include <linux/slab.h>
@@ -34,6 +33,7 @@
34#include <linux/skbuff.h> 33#include <linux/skbuff.h>
35#include <linux/delay.h> 34#include <linux/delay.h>
36#include <linux/spinlock.h> 35#include <linux/spinlock.h>
36#include <linux/dma-mapping.h>
37 37
38#include <asm/processor.h> 38#include <asm/processor.h>
39#include <asm/bitops.h> 39#include <asm/bitops.h>
diff --git a/drivers/net/tun.c b/drivers/net/tun.c
index effab0b9adc..50b8c6754b1 100644
--- a/drivers/net/tun.c
+++ b/drivers/net/tun.c
@@ -18,6 +18,9 @@
18/* 18/*
19 * Changes: 19 * Changes:
20 * 20 *
21 * Mike Kershaw <dragorn@kismetwireless.net> 2005/08/14
22 * Add TUNSETLINK ioctl to set the link encapsulation
23 *
21 * Mark Smith <markzzzsmith@yahoo.com.au> 24 * Mark Smith <markzzzsmith@yahoo.com.au>
22 * Use random_ether_addr() for tap MAC address. 25 * Use random_ether_addr() for tap MAC address.
23 * 26 *
@@ -612,6 +615,18 @@ static int tun_chr_ioctl(struct inode *inode, struct file *file,
612 DBG(KERN_INFO "%s: owner set to %d\n", tun->dev->name, tun->owner); 615 DBG(KERN_INFO "%s: owner set to %d\n", tun->dev->name, tun->owner);
613 break; 616 break;
614 617
618 case TUNSETLINK:
619 /* Only allow setting the type when the interface is down */
620 if (tun->dev->flags & IFF_UP) {
621 DBG(KERN_INFO "%s: Linktype set failed because interface is up\n",
622 tun->dev->name);
623 return -EBUSY;
624 } else {
625 tun->dev->type = (int) arg;
626 DBG(KERN_INFO "%s: linktype set to %d\n", tun->dev->name, tun->dev->type);
627 }
628 break;
629
615#ifdef TUN_DEBUG 630#ifdef TUN_DEBUG
616 case TUNSETDEBUG: 631 case TUNSETDEBUG:
617 tun->debug = arg; 632 tun->debug = arg;
diff --git a/drivers/net/wan/syncppp.c b/drivers/net/wan/syncppp.c
index f58c794a963..b56a7b516d2 100644
--- a/drivers/net/wan/syncppp.c
+++ b/drivers/net/wan/syncppp.c
@@ -1440,6 +1440,7 @@ static void sppp_print_bytes (u_char *p, u16 len)
1440 * @skb: The buffer to process 1440 * @skb: The buffer to process
1441 * @dev: The device it arrived on 1441 * @dev: The device it arrived on
1442 * @p: Unused 1442 * @p: Unused
1443 * @orig_dev: Unused
1443 * 1444 *
1444 * Protocol glue. This drives the deferred processing mode the poorer 1445 * Protocol glue. This drives the deferred processing mode the poorer
1445 * cards use. This can be called directly by cards that do not have 1446 * cards use. This can be called directly by cards that do not have
diff --git a/drivers/net/wireless/Kconfig b/drivers/net/wireless/Kconfig
index dd7dbf7b14d..00a07f32a81 100644
--- a/drivers/net/wireless/Kconfig
+++ b/drivers/net/wireless/Kconfig
@@ -289,8 +289,8 @@ config APPLE_AIRPORT
289 a non-standard interface 289 a non-standard interface
290 290
291config PLX_HERMES 291config PLX_HERMES
292 tristate "Hermes in PLX9052 based PCI adaptor support (Netgear MA301 etc.) (EXPERIMENTAL)" 292 tristate "Hermes in PLX9052 based PCI adaptor support (Netgear MA301 etc.)"
293 depends on PCI && HERMES && EXPERIMENTAL 293 depends on PCI && HERMES
294 help 294 help
295 Enable support for PCMCIA cards supported by the "Hermes" (aka 295 Enable support for PCMCIA cards supported by the "Hermes" (aka
296 orinoco) driver when used in PLX9052 based PCI adaptors. These 296 orinoco) driver when used in PLX9052 based PCI adaptors. These
@@ -299,12 +299,9 @@ config PLX_HERMES
299 802.11b PCMCIA cards can be used in desktop machines. The Netgear 299 802.11b PCMCIA cards can be used in desktop machines. The Netgear
300 MA301 is such an adaptor. 300 MA301 is such an adaptor.
301 301
302 Support for these adaptors is so far still incomplete and buggy.
303 You have been warned.
304
305config TMD_HERMES 302config TMD_HERMES
306 tristate "Hermes in TMD7160 based PCI adaptor support (EXPERIMENTAL)" 303 tristate "Hermes in TMD7160 based PCI adaptor support"
307 depends on PCI && HERMES && EXPERIMENTAL 304 depends on PCI && HERMES
308 help 305 help
309 Enable support for PCMCIA cards supported by the "Hermes" (aka 306 Enable support for PCMCIA cards supported by the "Hermes" (aka
310 orinoco) driver when used in TMD7160 based PCI adaptors. These 307 orinoco) driver when used in TMD7160 based PCI adaptors. These
@@ -312,12 +309,18 @@ config TMD_HERMES
312 PCI <-> PCMCIA bridge. Several vendors sell such adaptors so that 309 PCI <-> PCMCIA bridge. Several vendors sell such adaptors so that
313 802.11b PCMCIA cards can be used in desktop machines. 310 802.11b PCMCIA cards can be used in desktop machines.
314 311
315 Support for these adaptors is so far still incomplete and buggy. 312config NORTEL_HERMES
316 You have been warned. 313 tristate "Nortel emobility PCI adaptor support"
314 depends on PCI && HERMES
315 help
316 Enable support for PCMCIA cards supported by the "Hermes" (aka
317 orinoco) driver when used in Nortel emobility PCI adaptors. These
318 adaptors are not full PCMCIA controllers, but act as a more limited
319 PCI <-> PCMCIA bridge.
317 320
318config PCI_HERMES 321config PCI_HERMES
319 tristate "Prism 2.5 PCI 802.11b adaptor support (EXPERIMENTAL)" 322 tristate "Prism 2.5 PCI 802.11b adaptor support"
320 depends on PCI && HERMES && EXPERIMENTAL 323 depends on PCI && HERMES
321 help 324 help
322 Enable support for PCI and mini-PCI 802.11b wireless NICs based on 325 Enable support for PCI and mini-PCI 802.11b wireless NICs based on
323 the Prism 2.5 chipset. These are true PCI cards, not the 802.11b 326 the Prism 2.5 chipset. These are true PCI cards, not the 802.11b
@@ -372,6 +375,19 @@ config PCMCIA_HERMES
372 configure your card and that /etc/pcmcia/wireless.opts works: 375 configure your card and that /etc/pcmcia/wireless.opts works:
373 <http://www.hpl.hp.com/personal/Jean_Tourrilhes/Linux/Tools.html>. 376 <http://www.hpl.hp.com/personal/Jean_Tourrilhes/Linux/Tools.html>.
374 377
378config PCMCIA_SPECTRUM
379 tristate "Symbol Spectrum24 Trilogy PCMCIA card support"
380 depends on NET_RADIO && PCMCIA && HERMES
381 ---help---
382
383 This is a driver for 802.11b cards using RAM-loadable Symbol
384 firmware, such as Symbol Wireless Networker LA4100, CompactFlash
385 cards by Socket Communications and Intel PRO/Wireless 2011B.
386
387 This driver requires firmware download on startup. Utilities
388 for downloading Symbol firmware are available at
389 <http://sourceforge.net/projects/orinoco/>
390
375config AIRO_CS 391config AIRO_CS
376 tristate "Cisco/Aironet 34X/35X/4500/4800 PCMCIA cards" 392 tristate "Cisco/Aironet 34X/35X/4500/4800 PCMCIA cards"
377 depends on NET_RADIO && PCMCIA && (BROKEN || !M32R) 393 depends on NET_RADIO && PCMCIA && (BROKEN || !M32R)
diff --git a/drivers/net/wireless/Makefile b/drivers/net/wireless/Makefile
index 0953cc0cdee..3a6f7ba326c 100644
--- a/drivers/net/wireless/Makefile
+++ b/drivers/net/wireless/Makefile
@@ -22,6 +22,8 @@ obj-$(CONFIG_APPLE_AIRPORT) += airport.o
22obj-$(CONFIG_PLX_HERMES) += orinoco_plx.o 22obj-$(CONFIG_PLX_HERMES) += orinoco_plx.o
23obj-$(CONFIG_PCI_HERMES) += orinoco_pci.o 23obj-$(CONFIG_PCI_HERMES) += orinoco_pci.o
24obj-$(CONFIG_TMD_HERMES) += orinoco_tmd.o 24obj-$(CONFIG_TMD_HERMES) += orinoco_tmd.o
25obj-$(CONFIG_NORTEL_HERMES) += orinoco_nortel.o
26obj-$(CONFIG_PCMCIA_SPECTRUM) += spectrum_cs.o
25 27
26obj-$(CONFIG_AIRO) += airo.o 28obj-$(CONFIG_AIRO) += airo.o
27obj-$(CONFIG_AIRO_CS) += airo_cs.o airo.o 29obj-$(CONFIG_AIRO_CS) += airo_cs.o airo.o
diff --git a/drivers/net/wireless/airo.c b/drivers/net/wireless/airo.c
index 6db1fb6461d..2be65d308fb 100644
--- a/drivers/net/wireless/airo.c
+++ b/drivers/net/wireless/airo.c
@@ -1308,7 +1308,7 @@ static int micsetup(struct airo_info *ai) {
1308 int i; 1308 int i;
1309 1309
1310 if (ai->tfm == NULL) 1310 if (ai->tfm == NULL)
1311 ai->tfm = crypto_alloc_tfm("aes", 0); 1311 ai->tfm = crypto_alloc_tfm("aes", CRYPTO_TFM_REQ_MAY_SLEEP);
1312 1312
1313 if (ai->tfm == NULL) { 1313 if (ai->tfm == NULL) {
1314 printk(KERN_ERR "airo: failed to load transform for AES\n"); 1314 printk(KERN_ERR "airo: failed to load transform for AES\n");
@@ -2239,7 +2239,7 @@ static void airo_read_stats(struct airo_info *ai) {
2239 u32 *vals = stats_rid.vals; 2239 u32 *vals = stats_rid.vals;
2240 2240
2241 clear_bit(JOB_STATS, &ai->flags); 2241 clear_bit(JOB_STATS, &ai->flags);
2242 if (ai->power) { 2242 if (ai->power.event) {
2243 up(&ai->sem); 2243 up(&ai->sem);
2244 return; 2244 return;
2245 } 2245 }
@@ -2410,8 +2410,7 @@ void stop_airo_card( struct net_device *dev, int freeres )
2410 } 2410 }
2411 } 2411 }
2412#ifdef MICSUPPORT 2412#ifdef MICSUPPORT
2413 if (ai->tfm) 2413 crypto_free_tfm(ai->tfm);
2414 crypto_free_tfm(ai->tfm);
2415#endif 2414#endif
2416 del_airo_dev( dev ); 2415 del_airo_dev( dev );
2417 free_netdev( dev ); 2416 free_netdev( dev );
@@ -2969,7 +2968,7 @@ static int airo_thread(void *data) {
2969 break; 2968 break;
2970 } 2969 }
2971 2970
2972 if (ai->power || test_bit(FLAG_FLASHING, &ai->flags)) { 2971 if (ai->power.event || test_bit(FLAG_FLASHING, &ai->flags)) {
2973 up(&ai->sem); 2972 up(&ai->sem);
2974 continue; 2973 continue;
2975 } 2974 }
@@ -3259,7 +3258,7 @@ badrx:
3259 wstats.noise = apriv->wstats.qual.noise; 3258 wstats.noise = apriv->wstats.qual.noise;
3260 wstats.updated = IW_QUAL_LEVEL_UPDATED 3259 wstats.updated = IW_QUAL_LEVEL_UPDATED
3261 | IW_QUAL_QUAL_UPDATED 3260 | IW_QUAL_QUAL_UPDATED
3262 | IW_QUAL_NOISE_UPDATED; 3261 | IW_QUAL_DBM;
3263 /* Update spy records */ 3262 /* Update spy records */
3264 wireless_spy_update(dev, sa, &wstats); 3263 wireless_spy_update(dev, sa, &wstats);
3265 } 3264 }
@@ -3605,7 +3604,7 @@ void mpi_receive_802_11 (struct airo_info *ai)
3605 wstats.noise = ai->wstats.qual.noise; 3604 wstats.noise = ai->wstats.qual.noise;
3606 wstats.updated = IW_QUAL_QUAL_UPDATED 3605 wstats.updated = IW_QUAL_QUAL_UPDATED
3607 | IW_QUAL_LEVEL_UPDATED 3606 | IW_QUAL_LEVEL_UPDATED
3608 | IW_QUAL_NOISE_UPDATED; 3607 | IW_QUAL_DBM;
3609 /* Update spy records */ 3608 /* Update spy records */
3610 wireless_spy_update(ai->dev, sa, &wstats); 3609 wireless_spy_update(ai->dev, sa, &wstats);
3611 } 3610 }
@@ -5521,7 +5520,7 @@ static int airo_pci_resume(struct pci_dev *pdev)
5521 pci_restore_state(pdev); 5520 pci_restore_state(pdev);
5522 pci_enable_wake(pdev, pci_choose_state(pdev, ai->power), 0); 5521 pci_enable_wake(pdev, pci_choose_state(pdev, ai->power), 0);
5523 5522
5524 if (ai->power > 1) { 5523 if (ai->power.event > 1) {
5525 reset_card(dev, 0); 5524 reset_card(dev, 0);
5526 mpi_init_descriptors(ai); 5525 mpi_init_descriptors(ai);
5527 setup_card(ai, dev->dev_addr, 0); 5526 setup_card(ai, dev->dev_addr, 0);
@@ -6490,22 +6489,20 @@ static int airo_get_range(struct net_device *dev,
6490 range->max_qual.qual = 100; /* % */ 6489 range->max_qual.qual = 100; /* % */
6491 else 6490 else
6492 range->max_qual.qual = airo_get_max_quality(&cap_rid); 6491 range->max_qual.qual = airo_get_max_quality(&cap_rid);
6493 range->max_qual.level = 0; /* 0 means we use dBm */ 6492 range->max_qual.level = 0x100 - 120; /* -120 dBm */
6494 range->max_qual.noise = 0; 6493 range->max_qual.noise = 0x100 - 120; /* -120 dBm */
6495 range->max_qual.updated = 0;
6496 6494
6497 /* Experimental measurements - boundary 11/5.5 Mb/s */ 6495 /* Experimental measurements - boundary 11/5.5 Mb/s */
6498 /* Note : with or without the (local->rssi), results 6496 /* Note : with or without the (local->rssi), results
6499 * are somewhat different. - Jean II */ 6497 * are somewhat different. - Jean II */
6500 if (local->rssi) { 6498 if (local->rssi) {
6501 range->avg_qual.qual = 50; /* % */ 6499 range->avg_qual.qual = 50; /* % */
6502 range->avg_qual.level = 186; /* -70 dBm */ 6500 range->avg_qual.level = 0x100 - 70; /* -70 dBm */
6503 } else { 6501 } else {
6504 range->avg_qual.qual = airo_get_avg_quality(&cap_rid); 6502 range->avg_qual.qual = airo_get_avg_quality(&cap_rid);
6505 range->avg_qual.level = 176; /* -80 dBm */ 6503 range->avg_qual.level = 0x100 - 80; /* -80 dBm */
6506 } 6504 }
6507 range->avg_qual.noise = 0; 6505 range->avg_qual.noise = 0x100 - 85; /* -85 dBm */
6508 range->avg_qual.updated = 0;
6509 6506
6510 for(i = 0 ; i < 8 ; i++) { 6507 for(i = 0 ; i < 8 ; i++) {
6511 range->bitrate[i] = cap_rid.supportedRates[i] * 500000; 6508 range->bitrate[i] = cap_rid.supportedRates[i] * 500000;
@@ -6728,15 +6725,17 @@ static int airo_get_aplist(struct net_device *dev,
6728 if (local->rssi) { 6725 if (local->rssi) {
6729 qual[i].level = 0x100 - BSSList.dBm; 6726 qual[i].level = 0x100 - BSSList.dBm;
6730 qual[i].qual = airo_dbm_to_pct( local->rssi, BSSList.dBm ); 6727 qual[i].qual = airo_dbm_to_pct( local->rssi, BSSList.dBm );
6731 qual[i].updated = IW_QUAL_QUAL_UPDATED; 6728 qual[i].updated = IW_QUAL_QUAL_UPDATED
6729 | IW_QUAL_LEVEL_UPDATED
6730 | IW_QUAL_DBM;
6732 } else { 6731 } else {
6733 qual[i].level = (BSSList.dBm + 321) / 2; 6732 qual[i].level = (BSSList.dBm + 321) / 2;
6734 qual[i].qual = 0; 6733 qual[i].qual = 0;
6735 qual[i].updated = IW_QUAL_QUAL_INVALID; 6734 qual[i].updated = IW_QUAL_QUAL_INVALID
6735 | IW_QUAL_LEVEL_UPDATED
6736 | IW_QUAL_DBM;
6736 } 6737 }
6737 qual[i].noise = local->wstats.qual.noise; 6738 qual[i].noise = local->wstats.qual.noise;
6738 qual[i].updated = IW_QUAL_LEVEL_UPDATED
6739 | IW_QUAL_NOISE_UPDATED;
6740 if (BSSList.index == 0xffff) 6739 if (BSSList.index == 0xffff)
6741 break; 6740 break;
6742 } 6741 }
@@ -6862,15 +6861,17 @@ static inline char *airo_translate_scan(struct net_device *dev,
6862 if (ai->rssi) { 6861 if (ai->rssi) {
6863 iwe.u.qual.level = 0x100 - bss->dBm; 6862 iwe.u.qual.level = 0x100 - bss->dBm;
6864 iwe.u.qual.qual = airo_dbm_to_pct( ai->rssi, bss->dBm ); 6863 iwe.u.qual.qual = airo_dbm_to_pct( ai->rssi, bss->dBm );
6865 iwe.u.qual.updated = IW_QUAL_QUAL_UPDATED; 6864 iwe.u.qual.updated = IW_QUAL_QUAL_UPDATED
6865 | IW_QUAL_LEVEL_UPDATED
6866 | IW_QUAL_DBM;
6866 } else { 6867 } else {
6867 iwe.u.qual.level = (bss->dBm + 321) / 2; 6868 iwe.u.qual.level = (bss->dBm + 321) / 2;
6868 iwe.u.qual.qual = 0; 6869 iwe.u.qual.qual = 0;
6869 iwe.u.qual.updated = IW_QUAL_QUAL_INVALID; 6870 iwe.u.qual.updated = IW_QUAL_QUAL_INVALID
6871 | IW_QUAL_LEVEL_UPDATED
6872 | IW_QUAL_DBM;
6870 } 6873 }
6871 iwe.u.qual.noise = ai->wstats.qual.noise; 6874 iwe.u.qual.noise = ai->wstats.qual.noise;
6872 iwe.u.qual.updated = IW_QUAL_LEVEL_UPDATED
6873 | IW_QUAL_NOISE_UPDATED;
6874 current_ev = iwe_stream_add_event(current_ev, end_buf, &iwe, IW_EV_QUAL_LEN); 6875 current_ev = iwe_stream_add_event(current_ev, end_buf, &iwe, IW_EV_QUAL_LEN);
6875 6876
6876 /* Add encryption capability */ 6877 /* Add encryption capability */
@@ -7123,7 +7124,7 @@ static int airo_ioctl(struct net_device *dev, struct ifreq *rq, int cmd)
7123 int rc = 0; 7124 int rc = 0;
7124 struct airo_info *ai = (struct airo_info *)dev->priv; 7125 struct airo_info *ai = (struct airo_info *)dev->priv;
7125 7126
7126 if (ai->power) 7127 if (ai->power.event)
7127 return 0; 7128 return 0;
7128 7129
7129 switch (cmd) { 7130 switch (cmd) {
@@ -7202,7 +7203,7 @@ static void airo_read_wireless_stats(struct airo_info *local)
7202 7203
7203 /* Get stats out of the card */ 7204 /* Get stats out of the card */
7204 clear_bit(JOB_WSTATS, &local->flags); 7205 clear_bit(JOB_WSTATS, &local->flags);
7205 if (local->power) { 7206 if (local->power.event) {
7206 up(&local->sem); 7207 up(&local->sem);
7207 return; 7208 return;
7208 } 7209 }
@@ -7223,13 +7224,12 @@ static void airo_read_wireless_stats(struct airo_info *local)
7223 local->wstats.qual.level = (status_rid.normalizedSignalStrength + 321) / 2; 7224 local->wstats.qual.level = (status_rid.normalizedSignalStrength + 321) / 2;
7224 local->wstats.qual.qual = airo_get_quality(&status_rid, &cap_rid); 7225 local->wstats.qual.qual = airo_get_quality(&status_rid, &cap_rid);
7225 } 7226 }
7226 local->wstats.qual.updated = IW_QUAL_QUAL_UPDATED | IW_QUAL_LEVEL_UPDATED;
7227 if (status_rid.len >= 124) { 7227 if (status_rid.len >= 124) {
7228 local->wstats.qual.noise = 0x100 - status_rid.noisedBm; 7228 local->wstats.qual.noise = 0x100 - status_rid.noisedBm;
7229 local->wstats.qual.updated |= IW_QUAL_NOISE_UPDATED; 7229 local->wstats.qual.updated = IW_QUAL_ALL_UPDATED | IW_QUAL_DBM;
7230 } else { 7230 } else {
7231 local->wstats.qual.noise = 0; 7231 local->wstats.qual.noise = 0;
7232 local->wstats.qual.updated |= IW_QUAL_NOISE_INVALID; 7232 local->wstats.qual.updated = IW_QUAL_QUAL_UPDATED | IW_QUAL_LEVEL_UPDATED | IW_QUAL_NOISE_INVALID | IW_QUAL_DBM;
7233 } 7233 }
7234 7234
7235 /* Packets discarded in the wireless adapter due to wireless 7235 /* Packets discarded in the wireless adapter due to wireless
diff --git a/drivers/net/wireless/atmel.c b/drivers/net/wireless/atmel.c
index f48a6e72922..587869d86ee 100644
--- a/drivers/net/wireless/atmel.c
+++ b/drivers/net/wireless/atmel.c
@@ -1593,7 +1593,6 @@ struct net_device *init_atmel_card( unsigned short irq, int port, const AtmelFWT
1593 dev->set_mac_address = atmel_set_mac_address; 1593 dev->set_mac_address = atmel_set_mac_address;
1594 dev->hard_start_xmit = start_tx; 1594 dev->hard_start_xmit = start_tx;
1595 dev->get_stats = atmel_get_stats; 1595 dev->get_stats = atmel_get_stats;
1596 dev->get_wireless_stats = atmel_get_wireless_stats;
1597 dev->wireless_handlers = (struct iw_handler_def *)&atmel_handler_def; 1596 dev->wireless_handlers = (struct iw_handler_def *)&atmel_handler_def;
1598 dev->do_ioctl = atmel_ioctl; 1597 dev->do_ioctl = atmel_ioctl;
1599 dev->irq = irq; 1598 dev->irq = irq;
@@ -2411,7 +2410,8 @@ static const struct iw_handler_def atmel_handler_def =
2411 .num_private_args = sizeof(atmel_private_args)/sizeof(struct iw_priv_args), 2410 .num_private_args = sizeof(atmel_private_args)/sizeof(struct iw_priv_args),
2412 .standard = (iw_handler *) atmel_handler, 2411 .standard = (iw_handler *) atmel_handler,
2413 .private = (iw_handler *) atmel_private_handler, 2412 .private = (iw_handler *) atmel_private_handler,
2414 .private_args = (struct iw_priv_args *) atmel_private_args 2413 .private_args = (struct iw_priv_args *) atmel_private_args,
2414 .get_wireless_stats = atmel_get_wireless_stats
2415}; 2415};
2416 2416
2417static int atmel_ioctl(struct net_device *dev, struct ifreq *rq, int cmd) 2417static int atmel_ioctl(struct net_device *dev, struct ifreq *rq, int cmd)
@@ -2424,19 +2424,6 @@ static int atmel_ioctl(struct net_device *dev, struct ifreq *rq, int cmd)
2424 char domain[REGDOMAINSZ+1]; 2424 char domain[REGDOMAINSZ+1];
2425 2425
2426 switch (cmd) { 2426 switch (cmd) {
2427 case SIOCGIWPRIV:
2428 if(wrq->u.data.pointer) {
2429 /* Set the number of ioctl available */
2430 wrq->u.data.length = sizeof(atmel_private_args) / sizeof(atmel_private_args[0]);
2431
2432 /* Copy structure to the user buffer */
2433 if (copy_to_user(wrq->u.data.pointer,
2434 (u_char *) atmel_private_args,
2435 sizeof(atmel_private_args)))
2436 rc = -EFAULT;
2437 }
2438 break;
2439
2440 case ATMELIDIFC: 2427 case ATMELIDIFC:
2441 wrq->u.param.value = ATMELMAGIC; 2428 wrq->u.param.value = ATMELMAGIC;
2442 break; 2429 break;
diff --git a/drivers/net/wireless/hostap/hostap_pci.c b/drivers/net/wireless/hostap/hostap_pci.c
index 4f567ef6178..025f8cdb556 100644
--- a/drivers/net/wireless/hostap/hostap_pci.c
+++ b/drivers/net/wireless/hostap/hostap_pci.c
@@ -416,7 +416,7 @@ static int prism2_pci_suspend(struct pci_dev *pdev, pm_message_t state)
416 prism2_suspend(dev); 416 prism2_suspend(dev);
417 pci_save_state(pdev); 417 pci_save_state(pdev);
418 pci_disable_device(pdev); 418 pci_disable_device(pdev);
419 pci_set_power_state(pdev, 3); 419 pci_set_power_state(pdev, PCI_D3hot);
420 420
421 return 0; 421 return 0;
422} 422}
diff --git a/drivers/net/wireless/ipw2100.c b/drivers/net/wireless/ipw2100.c
index a47fce4bead..2414e6493aa 100644
--- a/drivers/net/wireless/ipw2100.c
+++ b/drivers/net/wireless/ipw2100.c
@@ -327,38 +327,38 @@ static struct iw_handler_def ipw2100_wx_handler_def;
327 327
328static inline void read_register(struct net_device *dev, u32 reg, u32 *val) 328static inline void read_register(struct net_device *dev, u32 reg, u32 *val)
329{ 329{
330 *val = readl((void *)(dev->base_addr + reg)); 330 *val = readl((void __iomem *)(dev->base_addr + reg));
331 IPW_DEBUG_IO("r: 0x%08X => 0x%08X\n", reg, *val); 331 IPW_DEBUG_IO("r: 0x%08X => 0x%08X\n", reg, *val);
332} 332}
333 333
334static inline void write_register(struct net_device *dev, u32 reg, u32 val) 334static inline void write_register(struct net_device *dev, u32 reg, u32 val)
335{ 335{
336 writel(val, (void *)(dev->base_addr + reg)); 336 writel(val, (void __iomem *)(dev->base_addr + reg));
337 IPW_DEBUG_IO("w: 0x%08X <= 0x%08X\n", reg, val); 337 IPW_DEBUG_IO("w: 0x%08X <= 0x%08X\n", reg, val);
338} 338}
339 339
340static inline void read_register_word(struct net_device *dev, u32 reg, u16 *val) 340static inline void read_register_word(struct net_device *dev, u32 reg, u16 *val)
341{ 341{
342 *val = readw((void *)(dev->base_addr + reg)); 342 *val = readw((void __iomem *)(dev->base_addr + reg));
343 IPW_DEBUG_IO("r: 0x%08X => %04X\n", reg, *val); 343 IPW_DEBUG_IO("r: 0x%08X => %04X\n", reg, *val);
344} 344}
345 345
346static inline void read_register_byte(struct net_device *dev, u32 reg, u8 *val) 346static inline void read_register_byte(struct net_device *dev, u32 reg, u8 *val)
347{ 347{
348 *val = readb((void *)(dev->base_addr + reg)); 348 *val = readb((void __iomem *)(dev->base_addr + reg));
349 IPW_DEBUG_IO("r: 0x%08X => %02X\n", reg, *val); 349 IPW_DEBUG_IO("r: 0x%08X => %02X\n", reg, *val);
350} 350}
351 351
352static inline void write_register_word(struct net_device *dev, u32 reg, u16 val) 352static inline void write_register_word(struct net_device *dev, u32 reg, u16 val)
353{ 353{
354 writew(val, (void *)(dev->base_addr + reg)); 354 writew(val, (void __iomem *)(dev->base_addr + reg));
355 IPW_DEBUG_IO("w: 0x%08X <= %04X\n", reg, val); 355 IPW_DEBUG_IO("w: 0x%08X <= %04X\n", reg, val);
356} 356}
357 357
358 358
359static inline void write_register_byte(struct net_device *dev, u32 reg, u8 val) 359static inline void write_register_byte(struct net_device *dev, u32 reg, u8 val)
360{ 360{
361 writeb(val, (void *)(dev->base_addr + reg)); 361 writeb(val, (void __iomem *)(dev->base_addr + reg));
362 IPW_DEBUG_IO("w: 0x%08X =< %02X\n", reg, val); 362 IPW_DEBUG_IO("w: 0x%08X =< %02X\n", reg, val);
363} 363}
364 364
@@ -498,7 +498,7 @@ static inline void read_nic_memory(struct net_device *dev, u32 addr, u32 len,
498static inline int ipw2100_hw_is_adapter_in_system(struct net_device *dev) 498static inline int ipw2100_hw_is_adapter_in_system(struct net_device *dev)
499{ 499{
500 return (dev->base_addr && 500 return (dev->base_addr &&
501 (readl((void *)(dev->base_addr + IPW_REG_DOA_DEBUG_AREA_START)) 501 (readl((void __iomem *)(dev->base_addr + IPW_REG_DOA_DEBUG_AREA_START))
502 == IPW_DATA_DOA_DEBUG_VALUE)); 502 == IPW_DATA_DOA_DEBUG_VALUE));
503} 503}
504 504
@@ -2125,19 +2125,19 @@ static void isr_indicate_scanning(struct ipw2100_priv *priv, u32 status)
2125} 2125}
2126 2126
2127static const struct ipw2100_status_indicator status_handlers[] = { 2127static const struct ipw2100_status_indicator status_handlers[] = {
2128 IPW2100_HANDLER(IPW_STATE_INITIALIZED, 0), 2128 IPW2100_HANDLER(IPW_STATE_INITIALIZED, NULL),
2129 IPW2100_HANDLER(IPW_STATE_COUNTRY_FOUND, 0), 2129 IPW2100_HANDLER(IPW_STATE_COUNTRY_FOUND, NULL),
2130 IPW2100_HANDLER(IPW_STATE_ASSOCIATED, isr_indicate_associated), 2130 IPW2100_HANDLER(IPW_STATE_ASSOCIATED, isr_indicate_associated),
2131 IPW2100_HANDLER(IPW_STATE_ASSN_LOST, isr_indicate_association_lost), 2131 IPW2100_HANDLER(IPW_STATE_ASSN_LOST, isr_indicate_association_lost),
2132 IPW2100_HANDLER(IPW_STATE_ASSN_CHANGED, 0), 2132 IPW2100_HANDLER(IPW_STATE_ASSN_CHANGED, NULL),
2133 IPW2100_HANDLER(IPW_STATE_SCAN_COMPLETE, isr_scan_complete), 2133 IPW2100_HANDLER(IPW_STATE_SCAN_COMPLETE, isr_scan_complete),
2134 IPW2100_HANDLER(IPW_STATE_ENTERED_PSP, 0), 2134 IPW2100_HANDLER(IPW_STATE_ENTERED_PSP, NULL),
2135 IPW2100_HANDLER(IPW_STATE_LEFT_PSP, 0), 2135 IPW2100_HANDLER(IPW_STATE_LEFT_PSP, NULL),
2136 IPW2100_HANDLER(IPW_STATE_RF_KILL, isr_indicate_rf_kill), 2136 IPW2100_HANDLER(IPW_STATE_RF_KILL, isr_indicate_rf_kill),
2137 IPW2100_HANDLER(IPW_STATE_DISABLED, 0), 2137 IPW2100_HANDLER(IPW_STATE_DISABLED, NULL),
2138 IPW2100_HANDLER(IPW_STATE_POWER_DOWN, 0), 2138 IPW2100_HANDLER(IPW_STATE_POWER_DOWN, NULL),
2139 IPW2100_HANDLER(IPW_STATE_SCANNING, isr_indicate_scanning), 2139 IPW2100_HANDLER(IPW_STATE_SCANNING, isr_indicate_scanning),
2140 IPW2100_HANDLER(-1, 0) 2140 IPW2100_HANDLER(-1, NULL)
2141}; 2141};
2142 2142
2143 2143
@@ -6327,7 +6327,7 @@ static void ipw2100_irq_tasklet(struct ipw2100_priv *priv);
6327 6327
6328static struct net_device *ipw2100_alloc_device( 6328static struct net_device *ipw2100_alloc_device(
6329 struct pci_dev *pci_dev, 6329 struct pci_dev *pci_dev,
6330 char *base_addr, 6330 void __iomem *base_addr,
6331 unsigned long mem_start, 6331 unsigned long mem_start,
6332 unsigned long mem_len) 6332 unsigned long mem_len)
6333{ 6333{
@@ -6474,7 +6474,7 @@ static int ipw2100_pci_init_one(struct pci_dev *pci_dev,
6474 const struct pci_device_id *ent) 6474 const struct pci_device_id *ent)
6475{ 6475{
6476 unsigned long mem_start, mem_len, mem_flags; 6476 unsigned long mem_start, mem_len, mem_flags;
6477 char *base_addr = NULL; 6477 void __iomem *base_addr = NULL;
6478 struct net_device *dev = NULL; 6478 struct net_device *dev = NULL;
6479 struct ipw2100_priv *priv = NULL; 6479 struct ipw2100_priv *priv = NULL;
6480 int err = 0; 6480 int err = 0;
@@ -6664,7 +6664,7 @@ static int ipw2100_pci_init_one(struct pci_dev *pci_dev,
6664 } 6664 }
6665 6665
6666 if (base_addr) 6666 if (base_addr)
6667 iounmap((char*)base_addr); 6667 iounmap(base_addr);
6668 6668
6669 pci_release_regions(pci_dev); 6669 pci_release_regions(pci_dev);
6670 pci_disable_device(pci_dev); 6670 pci_disable_device(pci_dev);
@@ -6714,7 +6714,7 @@ static void __devexit ipw2100_pci_remove_one(struct pci_dev *pci_dev)
6714 free_irq(dev->irq, priv); 6714 free_irq(dev->irq, priv);
6715 6715
6716 if (dev->base_addr) 6716 if (dev->base_addr)
6717 iounmap((unsigned char *)dev->base_addr); 6717 iounmap((void __iomem *)dev->base_addr);
6718 6718
6719 free_ieee80211(dev); 6719 free_ieee80211(dev);
6720 } 6720 }
@@ -8574,6 +8574,7 @@ static int ipw2100_ucode_download(struct ipw2100_priv *priv,
8574 struct net_device *dev = priv->net_dev; 8574 struct net_device *dev = priv->net_dev;
8575 const unsigned char *microcode_data = fw->uc.data; 8575 const unsigned char *microcode_data = fw->uc.data;
8576 unsigned int microcode_data_left = fw->uc.size; 8576 unsigned int microcode_data_left = fw->uc.size;
8577 void __iomem *reg = (void __iomem *)dev->base_addr;
8577 8578
8578 struct symbol_alive_response response; 8579 struct symbol_alive_response response;
8579 int i, j; 8580 int i, j;
@@ -8581,23 +8582,23 @@ static int ipw2100_ucode_download(struct ipw2100_priv *priv,
8581 8582
8582 /* Symbol control */ 8583 /* Symbol control */
8583 write_nic_word(dev, IPW2100_CONTROL_REG, 0x703); 8584 write_nic_word(dev, IPW2100_CONTROL_REG, 0x703);
8584 readl((void *)(dev->base_addr)); 8585 readl(reg);
8585 write_nic_word(dev, IPW2100_CONTROL_REG, 0x707); 8586 write_nic_word(dev, IPW2100_CONTROL_REG, 0x707);
8586 readl((void *)(dev->base_addr)); 8587 readl(reg);
8587 8588
8588 /* HW config */ 8589 /* HW config */
8589 write_nic_byte(dev, 0x210014, 0x72); /* fifo width =16 */ 8590 write_nic_byte(dev, 0x210014, 0x72); /* fifo width =16 */
8590 readl((void *)(dev->base_addr)); 8591 readl(reg);
8591 write_nic_byte(dev, 0x210014, 0x72); /* fifo width =16 */ 8592 write_nic_byte(dev, 0x210014, 0x72); /* fifo width =16 */
8592 readl((void *)(dev->base_addr)); 8593 readl(reg);
8593 8594
8594 /* EN_CS_ACCESS bit to reset control store pointer */ 8595 /* EN_CS_ACCESS bit to reset control store pointer */
8595 write_nic_byte(dev, 0x210000, 0x40); 8596 write_nic_byte(dev, 0x210000, 0x40);
8596 readl((void *)(dev->base_addr)); 8597 readl(reg);
8597 write_nic_byte(dev, 0x210000, 0x0); 8598 write_nic_byte(dev, 0x210000, 0x0);
8598 readl((void *)(dev->base_addr)); 8599 readl(reg);
8599 write_nic_byte(dev, 0x210000, 0x40); 8600 write_nic_byte(dev, 0x210000, 0x40);
8600 readl((void *)(dev->base_addr)); 8601 readl(reg);
8601 8602
8602 /* copy microcode from buffer into Symbol */ 8603 /* copy microcode from buffer into Symbol */
8603 8604
@@ -8609,31 +8610,31 @@ static int ipw2100_ucode_download(struct ipw2100_priv *priv,
8609 8610
8610 /* EN_CS_ACCESS bit to reset the control store pointer */ 8611 /* EN_CS_ACCESS bit to reset the control store pointer */
8611 write_nic_byte(dev, 0x210000, 0x0); 8612 write_nic_byte(dev, 0x210000, 0x0);
8612 readl((void *)(dev->base_addr)); 8613 readl(reg);
8613 8614
8614 /* Enable System (Reg 0) 8615 /* Enable System (Reg 0)
8615 * first enable causes garbage in RX FIFO */ 8616 * first enable causes garbage in RX FIFO */
8616 write_nic_byte(dev, 0x210000, 0x0); 8617 write_nic_byte(dev, 0x210000, 0x0);
8617 readl((void *)(dev->base_addr)); 8618 readl(reg);
8618 write_nic_byte(dev, 0x210000, 0x80); 8619 write_nic_byte(dev, 0x210000, 0x80);
8619 readl((void *)(dev->base_addr)); 8620 readl(reg);
8620 8621
8621 /* Reset External Baseband Reg */ 8622 /* Reset External Baseband Reg */
8622 write_nic_word(dev, IPW2100_CONTROL_REG, 0x703); 8623 write_nic_word(dev, IPW2100_CONTROL_REG, 0x703);
8623 readl((void *)(dev->base_addr)); 8624 readl(reg);
8624 write_nic_word(dev, IPW2100_CONTROL_REG, 0x707); 8625 write_nic_word(dev, IPW2100_CONTROL_REG, 0x707);
8625 readl((void *)(dev->base_addr)); 8626 readl(reg);
8626 8627
8627 /* HW Config (Reg 5) */ 8628 /* HW Config (Reg 5) */
8628 write_nic_byte(dev, 0x210014, 0x72); // fifo width =16 8629 write_nic_byte(dev, 0x210014, 0x72); // fifo width =16
8629 readl((void *)(dev->base_addr)); 8630 readl(reg);
8630 write_nic_byte(dev, 0x210014, 0x72); // fifo width =16 8631 write_nic_byte(dev, 0x210014, 0x72); // fifo width =16
8631 readl((void *)(dev->base_addr)); 8632 readl(reg);
8632 8633
8633 /* Enable System (Reg 0) 8634 /* Enable System (Reg 0)
8634 * second enable should be OK */ 8635 * second enable should be OK */
8635 write_nic_byte(dev, 0x210000, 0x00); // clear enable system 8636 write_nic_byte(dev, 0x210000, 0x00); // clear enable system
8636 readl((void *)(dev->base_addr)); 8637 readl(reg);
8637 write_nic_byte(dev, 0x210000, 0x80); // set enable system 8638 write_nic_byte(dev, 0x210000, 0x80); // set enable system
8638 8639
8639 /* check Symbol is enabled - upped this from 5 as it wasn't always 8640 /* check Symbol is enabled - upped this from 5 as it wasn't always
diff --git a/drivers/net/wireless/ipw2200.c b/drivers/net/wireless/ipw2200.c
index 6d0b6b1df4c..b7f275c00de 100644
--- a/drivers/net/wireless/ipw2200.c
+++ b/drivers/net/wireless/ipw2200.c
@@ -72,7 +72,8 @@ static void ipw_rx_queue_replenish(void *);
72static int ipw_up(struct ipw_priv *); 72static int ipw_up(struct ipw_priv *);
73static void ipw_down(struct ipw_priv *); 73static void ipw_down(struct ipw_priv *);
74static int ipw_config(struct ipw_priv *); 74static int ipw_config(struct ipw_priv *);
75static int init_supported_rates(struct ipw_priv *priv, struct ipw_supported_rates *prates); 75static int init_supported_rates(struct ipw_priv *priv,
76 struct ipw_supported_rates *prates);
76 77
77static u8 band_b_active_channel[MAX_B_CHANNELS] = { 78static u8 band_b_active_channel[MAX_B_CHANNELS] = {
78 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 0 79 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 0
@@ -102,7 +103,7 @@ static int is_valid_channel(int mode_mask, int channel)
102} 103}
103 104
104static char *snprint_line(char *buf, size_t count, 105static char *snprint_line(char *buf, size_t count,
105 const u8 *data, u32 len, u32 ofs) 106 const u8 * data, u32 len, u32 ofs)
106{ 107{
107 int out, i, j, l; 108 int out, i, j, l;
108 char c; 109 char c;
@@ -136,7 +137,7 @@ static char *snprint_line(char *buf, size_t count,
136 return buf; 137 return buf;
137} 138}
138 139
139static void printk_buf(int level, const u8 *data, u32 len) 140static void printk_buf(int level, const u8 * data, u32 len)
140{ 141{
141 char line[81]; 142 char line[81];
142 u32 ofs = 0; 143 u32 ofs = 0;
@@ -161,21 +162,24 @@ static u8 _ipw_read_reg8(struct ipw_priv *ipw, u32 reg);
161static void _ipw_write_reg8(struct ipw_priv *priv, u32 reg, u8 value); 162static void _ipw_write_reg8(struct ipw_priv *priv, u32 reg, u8 value);
162static inline void ipw_write_reg8(struct ipw_priv *a, u32 b, u8 c) 163static inline void ipw_write_reg8(struct ipw_priv *a, u32 b, u8 c)
163{ 164{
164 IPW_DEBUG_IO("%s %d: write_indirect8(0x%08X, 0x%08X)\n", __FILE__, __LINE__, (u32)(b), (u32)(c)); 165 IPW_DEBUG_IO("%s %d: write_indirect8(0x%08X, 0x%08X)\n", __FILE__,
166 __LINE__, (u32) (b), (u32) (c));
165 _ipw_write_reg8(a, b, c); 167 _ipw_write_reg8(a, b, c);
166} 168}
167 169
168static void _ipw_write_reg16(struct ipw_priv *priv, u32 reg, u16 value); 170static void _ipw_write_reg16(struct ipw_priv *priv, u32 reg, u16 value);
169static inline void ipw_write_reg16(struct ipw_priv *a, u32 b, u16 c) 171static inline void ipw_write_reg16(struct ipw_priv *a, u32 b, u16 c)
170{ 172{
171 IPW_DEBUG_IO("%s %d: write_indirect16(0x%08X, 0x%08X)\n", __FILE__, __LINE__, (u32)(b), (u32)(c)); 173 IPW_DEBUG_IO("%s %d: write_indirect16(0x%08X, 0x%08X)\n", __FILE__,
174 __LINE__, (u32) (b), (u32) (c));
172 _ipw_write_reg16(a, b, c); 175 _ipw_write_reg16(a, b, c);
173} 176}
174 177
175static void _ipw_write_reg32(struct ipw_priv *priv, u32 reg, u32 value); 178static void _ipw_write_reg32(struct ipw_priv *priv, u32 reg, u32 value);
176static inline void ipw_write_reg32(struct ipw_priv *a, u32 b, u32 c) 179static inline void ipw_write_reg32(struct ipw_priv *a, u32 b, u32 c)
177{ 180{
178 IPW_DEBUG_IO("%s %d: write_indirect32(0x%08X, 0x%08X)\n", __FILE__, __LINE__, (u32)(b), (u32)(c)); 181 IPW_DEBUG_IO("%s %d: write_indirect32(0x%08X, 0x%08X)\n", __FILE__,
182 __LINE__, (u32) (b), (u32) (c));
179 _ipw_write_reg32(a, b, c); 183 _ipw_write_reg32(a, b, c);
180} 184}
181 185
@@ -195,24 +199,30 @@ static inline void ipw_write_reg32(struct ipw_priv *a, u32 b, u32 c)
195 _ipw_write32(ipw, ofs, val) 199 _ipw_write32(ipw, ofs, val)
196 200
197#define _ipw_read8(ipw, ofs) readb((ipw)->hw_base + (ofs)) 201#define _ipw_read8(ipw, ofs) readb((ipw)->hw_base + (ofs))
198static inline u8 __ipw_read8(char *f, u32 l, struct ipw_priv *ipw, u32 ofs) { 202static inline u8 __ipw_read8(char *f, u32 l, struct ipw_priv *ipw, u32 ofs)
199 IPW_DEBUG_IO("%s %d: read_direct8(0x%08X)\n", f, l, (u32)(ofs)); 203{
204 IPW_DEBUG_IO("%s %d: read_direct8(0x%08X)\n", f, l, (u32) (ofs));
200 return _ipw_read8(ipw, ofs); 205 return _ipw_read8(ipw, ofs);
201} 206}
207
202#define ipw_read8(ipw, ofs) __ipw_read8(__FILE__, __LINE__, ipw, ofs) 208#define ipw_read8(ipw, ofs) __ipw_read8(__FILE__, __LINE__, ipw, ofs)
203 209
204#define _ipw_read16(ipw, ofs) readw((ipw)->hw_base + (ofs)) 210#define _ipw_read16(ipw, ofs) readw((ipw)->hw_base + (ofs))
205static inline u16 __ipw_read16(char *f, u32 l, struct ipw_priv *ipw, u32 ofs) { 211static inline u16 __ipw_read16(char *f, u32 l, struct ipw_priv *ipw, u32 ofs)
206 IPW_DEBUG_IO("%s %d: read_direct16(0x%08X)\n", f, l, (u32)(ofs)); 212{
213 IPW_DEBUG_IO("%s %d: read_direct16(0x%08X)\n", f, l, (u32) (ofs));
207 return _ipw_read16(ipw, ofs); 214 return _ipw_read16(ipw, ofs);
208} 215}
216
209#define ipw_read16(ipw, ofs) __ipw_read16(__FILE__, __LINE__, ipw, ofs) 217#define ipw_read16(ipw, ofs) __ipw_read16(__FILE__, __LINE__, ipw, ofs)
210 218
211#define _ipw_read32(ipw, ofs) readl((ipw)->hw_base + (ofs)) 219#define _ipw_read32(ipw, ofs) readl((ipw)->hw_base + (ofs))
212static inline u32 __ipw_read32(char *f, u32 l, struct ipw_priv *ipw, u32 ofs) { 220static inline u32 __ipw_read32(char *f, u32 l, struct ipw_priv *ipw, u32 ofs)
213 IPW_DEBUG_IO("%s %d: read_direct32(0x%08X)\n", f, l, (u32)(ofs)); 221{
222 IPW_DEBUG_IO("%s %d: read_direct32(0x%08X)\n", f, l, (u32) (ofs));
214 return _ipw_read32(ipw, ofs); 223 return _ipw_read32(ipw, ofs);
215} 224}
225
216#define ipw_read32(ipw, ofs) __ipw_read32(__FILE__, __LINE__, ipw, ofs) 226#define ipw_read32(ipw, ofs) __ipw_read32(__FILE__, __LINE__, ipw, ofs)
217 227
218static void _ipw_read_indirect(struct ipw_priv *, u32, u8 *, int); 228static void _ipw_read_indirect(struct ipw_priv *, u32, u8 *, int);
@@ -220,34 +230,30 @@ static void _ipw_read_indirect(struct ipw_priv *, u32, u8 *, int);
220 IPW_DEBUG_IO("%s %d: read_inddirect(0x%08X) %d bytes\n", __FILE__, __LINE__, (u32)(b), d); \ 230 IPW_DEBUG_IO("%s %d: read_inddirect(0x%08X) %d bytes\n", __FILE__, __LINE__, (u32)(b), d); \
221 _ipw_read_indirect(a, b, c, d) 231 _ipw_read_indirect(a, b, c, d)
222 232
223static void _ipw_write_indirect(struct ipw_priv *priv, u32 addr, u8 *data, int num); 233static void _ipw_write_indirect(struct ipw_priv *priv, u32 addr, u8 * data,
234 int num);
224#define ipw_write_indirect(a, b, c, d) \ 235#define ipw_write_indirect(a, b, c, d) \
225 IPW_DEBUG_IO("%s %d: write_indirect(0x%08X) %d bytes\n", __FILE__, __LINE__, (u32)(b), d); \ 236 IPW_DEBUG_IO("%s %d: write_indirect(0x%08X) %d bytes\n", __FILE__, __LINE__, (u32)(b), d); \
226 _ipw_write_indirect(a, b, c, d) 237 _ipw_write_indirect(a, b, c, d)
227 238
228/* indirect write s */ 239/* indirect write s */
229static void _ipw_write_reg32(struct ipw_priv *priv, u32 reg, 240static void _ipw_write_reg32(struct ipw_priv *priv, u32 reg, u32 value)
230 u32 value)
231{ 241{
232 IPW_DEBUG_IO(" %p : reg = 0x%8X : value = 0x%8X\n", 242 IPW_DEBUG_IO(" %p : reg = 0x%8X : value = 0x%8X\n", priv, reg, value);
233 priv, reg, value);
234 _ipw_write32(priv, CX2_INDIRECT_ADDR, reg); 243 _ipw_write32(priv, CX2_INDIRECT_ADDR, reg);
235 _ipw_write32(priv, CX2_INDIRECT_DATA, value); 244 _ipw_write32(priv, CX2_INDIRECT_DATA, value);
236} 245}
237 246
238
239static void _ipw_write_reg8(struct ipw_priv *priv, u32 reg, u8 value) 247static void _ipw_write_reg8(struct ipw_priv *priv, u32 reg, u8 value)
240{ 248{
241 IPW_DEBUG_IO(" reg = 0x%8X : value = 0x%8X\n", reg, value); 249 IPW_DEBUG_IO(" reg = 0x%8X : value = 0x%8X\n", reg, value);
242 _ipw_write32(priv, CX2_INDIRECT_ADDR, reg & CX2_INDIRECT_ADDR_MASK); 250 _ipw_write32(priv, CX2_INDIRECT_ADDR, reg & CX2_INDIRECT_ADDR_MASK);
243 _ipw_write8(priv, CX2_INDIRECT_DATA, value); 251 _ipw_write8(priv, CX2_INDIRECT_DATA, value);
244 IPW_DEBUG_IO(" reg = 0x%8lX : value = 0x%8X\n", 252 IPW_DEBUG_IO(" reg = 0x%8lX : value = 0x%8X\n",
245 (unsigned long)(priv->hw_base + CX2_INDIRECT_DATA), 253 (unsigned long)(priv->hw_base + CX2_INDIRECT_DATA), value);
246 value);
247} 254}
248 255
249static void _ipw_write_reg16(struct ipw_priv *priv, u32 reg, 256static void _ipw_write_reg16(struct ipw_priv *priv, u32 reg, u16 value)
250 u16 value)
251{ 257{
252 IPW_DEBUG_IO(" reg = 0x%8X : value = 0x%8X\n", reg, value); 258 IPW_DEBUG_IO(" reg = 0x%8X : value = 0x%8X\n", reg, value);
253 _ipw_write32(priv, CX2_INDIRECT_ADDR, reg & CX2_INDIRECT_ADDR_MASK); 259 _ipw_write32(priv, CX2_INDIRECT_ADDR, reg & CX2_INDIRECT_ADDR_MASK);
@@ -262,7 +268,7 @@ static u8 _ipw_read_reg8(struct ipw_priv *priv, u32 reg)
262 _ipw_write32(priv, CX2_INDIRECT_ADDR, reg & CX2_INDIRECT_ADDR_MASK); 268 _ipw_write32(priv, CX2_INDIRECT_ADDR, reg & CX2_INDIRECT_ADDR_MASK);
263 IPW_DEBUG_IO(" reg = 0x%8X : \n", reg); 269 IPW_DEBUG_IO(" reg = 0x%8X : \n", reg);
264 word = _ipw_read32(priv, CX2_INDIRECT_DATA); 270 word = _ipw_read32(priv, CX2_INDIRECT_DATA);
265 return (word >> ((reg & 0x3)*8)) & 0xff; 271 return (word >> ((reg & 0x3) * 8)) & 0xff;
266} 272}
267 273
268static u32 _ipw_read_reg32(struct ipw_priv *priv, u32 reg) 274static u32 _ipw_read_reg32(struct ipw_priv *priv, u32 reg)
@@ -302,7 +308,7 @@ static void _ipw_read_indirect(struct ipw_priv *priv, u32 addr, u8 * buf,
302 _ipw_write32(priv, CX2_AUTOINC_ADDR, aligned_addr); 308 _ipw_write32(priv, CX2_AUTOINC_ADDR, aligned_addr);
303 aligned_len = num & CX2_INDIRECT_ADDR_MASK; 309 aligned_len = num & CX2_INDIRECT_ADDR_MASK;
304 for (i = 0; i < aligned_len; i += 4, buf += 4, aligned_addr += 4) 310 for (i = 0; i < aligned_len; i += 4, buf += 4, aligned_addr += 4)
305 *(u32*)buf = ipw_read32(priv, CX2_AUTOINC_DATA); 311 *(u32 *) buf = ipw_read32(priv, CX2_AUTOINC_DATA);
306 312
307 /* Copy the last nibble */ 313 /* Copy the last nibble */
308 dif_len = num - aligned_len; 314 dif_len = num - aligned_len;
@@ -311,7 +317,7 @@ static void _ipw_read_indirect(struct ipw_priv *priv, u32 addr, u8 * buf,
311 *buf = ipw_read8(priv, CX2_INDIRECT_DATA + i); 317 *buf = ipw_read8(priv, CX2_INDIRECT_DATA + i);
312} 318}
313 319
314static void _ipw_write_indirect(struct ipw_priv *priv, u32 addr, u8 *buf, 320static void _ipw_write_indirect(struct ipw_priv *priv, u32 addr, u8 * buf,
315 int num) 321 int num)
316{ 322{
317 u32 aligned_addr = addr & CX2_INDIRECT_ADDR_MASK; 323 u32 aligned_addr = addr & CX2_INDIRECT_ADDR_MASK;
@@ -335,7 +341,7 @@ static void _ipw_write_indirect(struct ipw_priv *priv, u32 addr, u8 *buf,
335 _ipw_write32(priv, CX2_AUTOINC_ADDR, aligned_addr); 341 _ipw_write32(priv, CX2_AUTOINC_ADDR, aligned_addr);
336 aligned_len = num & CX2_INDIRECT_ADDR_MASK; 342 aligned_len = num & CX2_INDIRECT_ADDR_MASK;
337 for (i = 0; i < aligned_len; i += 4, buf += 4, aligned_addr += 4) 343 for (i = 0; i < aligned_len; i += 4, buf += 4, aligned_addr += 4)
338 _ipw_write32(priv, CX2_AUTOINC_DATA, *(u32*)buf); 344 _ipw_write32(priv, CX2_AUTOINC_DATA, *(u32 *) buf);
339 345
340 /* Copy the last nibble */ 346 /* Copy the last nibble */
341 dif_len = num - aligned_len; 347 dif_len = num - aligned_len;
@@ -428,20 +434,18 @@ static void ipw_dump_nic_error_log(struct ipw_priv *priv)
428 } 434 }
429 435
430 for (i = ERROR_START_OFFSET; 436 for (i = ERROR_START_OFFSET;
431 i <= count * ERROR_ELEM_SIZE; 437 i <= count * ERROR_ELEM_SIZE; i += ERROR_ELEM_SIZE) {
432 i += ERROR_ELEM_SIZE) { 438 desc = ipw_read_reg32(priv, base + i);
433 desc = ipw_read_reg32(priv, base + i); 439 time = ipw_read_reg32(priv, base + i + 1 * sizeof(u32));
434 time = ipw_read_reg32(priv, base + i + 1*sizeof(u32)); 440 blink1 = ipw_read_reg32(priv, base + i + 2 * sizeof(u32));
435 blink1 = ipw_read_reg32(priv, base + i + 2*sizeof(u32)); 441 blink2 = ipw_read_reg32(priv, base + i + 3 * sizeof(u32));
436 blink2 = ipw_read_reg32(priv, base + i + 3*sizeof(u32)); 442 ilink1 = ipw_read_reg32(priv, base + i + 4 * sizeof(u32));
437 ilink1 = ipw_read_reg32(priv, base + i + 4*sizeof(u32)); 443 ilink2 = ipw_read_reg32(priv, base + i + 5 * sizeof(u32));
438 ilink2 = ipw_read_reg32(priv, base + i + 5*sizeof(u32)); 444 idata = ipw_read_reg32(priv, base + i + 6 * sizeof(u32));
439 idata = ipw_read_reg32(priv, base + i + 6*sizeof(u32));
440 445
441 IPW_ERROR( 446 IPW_ERROR("%s %i 0x%08x 0x%08x 0x%08x 0x%08x 0x%08x\n",
442 "%s %i 0x%08x 0x%08x 0x%08x 0x%08x 0x%08x\n", 447 ipw_error_desc(desc), time, blink1, blink2,
443 ipw_error_desc(desc), time, blink1, blink2, 448 ilink1, ilink2, idata);
444 ilink1, ilink2, idata);
445 } 449 }
446} 450}
447 451
@@ -456,11 +460,10 @@ static void ipw_dump_nic_event_log(struct ipw_priv *priv)
456 IPW_ERROR("Start IPW Event Log Dump:\n"); 460 IPW_ERROR("Start IPW Event Log Dump:\n");
457 461
458 for (i = EVENT_START_OFFSET; 462 for (i = EVENT_START_OFFSET;
459 i <= count * EVENT_ELEM_SIZE; 463 i <= count * EVENT_ELEM_SIZE; i += EVENT_ELEM_SIZE) {
460 i += EVENT_ELEM_SIZE) {
461 ev = ipw_read_reg32(priv, base + i); 464 ev = ipw_read_reg32(priv, base + i);
462 time = ipw_read_reg32(priv, base + i + 1*sizeof(u32)); 465 time = ipw_read_reg32(priv, base + i + 1 * sizeof(u32));
463 data = ipw_read_reg32(priv, base + i + 2*sizeof(u32)); 466 data = ipw_read_reg32(priv, base + i + 2 * sizeof(u32));
464 467
465#ifdef CONFIG_IPW_DEBUG 468#ifdef CONFIG_IPW_DEBUG
466 IPW_ERROR("%i\t0x%08x\t%i\n", time, data, ev); 469 IPW_ERROR("%i\t0x%08x\t%i\n", time, data, ev);
@@ -468,8 +471,7 @@ static void ipw_dump_nic_event_log(struct ipw_priv *priv)
468 } 471 }
469} 472}
470 473
471static int ipw_get_ordinal(struct ipw_priv *priv, u32 ord, void *val, 474static int ipw_get_ordinal(struct ipw_priv *priv, u32 ord, void *val, u32 * len)
472 u32 *len)
473{ 475{
474 u32 addr, field_info, field_len, field_count, total_len; 476 u32 addr, field_info, field_len, field_count, total_len;
475 477
@@ -513,11 +515,11 @@ static int ipw_get_ordinal(struct ipw_priv *priv, u32 ord, void *val,
513 } 515 }
514 516
515 IPW_DEBUG_ORD("Reading TABLE0[%i] from offset 0x%08x\n", 517 IPW_DEBUG_ORD("Reading TABLE0[%i] from offset 0x%08x\n",
516 ord, priv->table0_addr + (ord << 2)); 518 ord, priv->table0_addr + (ord << 2));
517 519
518 *len = sizeof(u32); 520 *len = sizeof(u32);
519 ord <<= 2; 521 ord <<= 2;
520 *((u32 *)val) = ipw_read32(priv, priv->table0_addr + ord); 522 *((u32 *) val) = ipw_read32(priv, priv->table0_addr + ord);
521 break; 523 break;
522 524
523 case IPW_ORD_TABLE_1_MASK: 525 case IPW_ORD_TABLE_1_MASK:
@@ -545,7 +547,8 @@ static int ipw_get_ordinal(struct ipw_priv *priv, u32 ord, void *val,
545 return -EINVAL; 547 return -EINVAL;
546 } 548 }
547 549
548 *((u32 *)val) = ipw_read_reg32(priv, (priv->table1_addr + (ord << 2))); 550 *((u32 *) val) =
551 ipw_read_reg32(priv, (priv->table1_addr + (ord << 2)));
549 *len = sizeof(u32); 552 *len = sizeof(u32);
550 break; 553 break;
551 554
@@ -573,13 +576,16 @@ static int ipw_get_ordinal(struct ipw_priv *priv, u32 ord, void *val,
573 576
574 /* get the second DW of statistics ; 577 /* get the second DW of statistics ;
575 * two 16-bit words - first is length, second is count */ 578 * two 16-bit words - first is length, second is count */
576 field_info = ipw_read_reg32(priv, priv->table2_addr + (ord << 3) + sizeof(u32)); 579 field_info =
580 ipw_read_reg32(priv,
581 priv->table2_addr + (ord << 3) +
582 sizeof(u32));
577 583
578 /* get each entry length */ 584 /* get each entry length */
579 field_len = *((u16 *)&field_info); 585 field_len = *((u16 *) & field_info);
580 586
581 /* get number of entries */ 587 /* get number of entries */
582 field_count = *(((u16 *)&field_info) + 1); 588 field_count = *(((u16 *) & field_info) + 1);
583 589
584 /* abort if not enought memory */ 590 /* abort if not enought memory */
585 total_len = field_len * field_count; 591 total_len = field_len * field_count;
@@ -604,7 +610,6 @@ static int ipw_get_ordinal(struct ipw_priv *priv, u32 ord, void *val,
604 610
605 } 611 }
606 612
607
608 return 0; 613 return 0;
609} 614}
610 615
@@ -624,7 +629,7 @@ static void ipw_init_ordinals(struct ipw_priv *priv)
624 629
625 priv->table2_addr = ipw_read32(priv, IPW_ORDINALS_TABLE_2); 630 priv->table2_addr = ipw_read32(priv, IPW_ORDINALS_TABLE_2);
626 priv->table2_len = ipw_read_reg32(priv, priv->table2_addr); 631 priv->table2_len = ipw_read_reg32(priv, priv->table2_addr);
627 priv->table2_len &= 0x0000ffff; /* use first two bytes */ 632 priv->table2_len &= 0x0000ffff; /* use first two bytes */
628 633
629 IPW_DEBUG_ORD("table 2 offset at 0x%08x, len = %i\n", 634 IPW_DEBUG_ORD("table 2 offset at 0x%08x, len = %i\n",
630 priv->table2_addr, priv->table2_len); 635 priv->table2_addr, priv->table2_len);
@@ -643,7 +648,7 @@ static ssize_t show_debug_level(struct device_driver *d, char *buf)
643 return sprintf(buf, "0x%08X\n", ipw_debug_level); 648 return sprintf(buf, "0x%08X\n", ipw_debug_level);
644} 649}
645static ssize_t store_debug_level(struct device_driver *d, 650static ssize_t store_debug_level(struct device_driver *d,
646 const char *buf, size_t count) 651 const char *buf, size_t count)
647{ 652{
648 char *p = (char *)buf; 653 char *p = (char *)buf;
649 u32 val; 654 u32 val;
@@ -668,11 +673,12 @@ static DRIVER_ATTR(debug_level, S_IWUSR | S_IRUGO,
668 show_debug_level, store_debug_level); 673 show_debug_level, store_debug_level);
669 674
670static ssize_t show_status(struct device *d, 675static ssize_t show_status(struct device *d,
671 struct device_attribute *attr, char *buf) 676 struct device_attribute *attr, char *buf)
672{ 677{
673 struct ipw_priv *p = d->driver_data; 678 struct ipw_priv *p = d->driver_data;
674 return sprintf(buf, "0x%08x\n", (int)p->status); 679 return sprintf(buf, "0x%08x\n", (int)p->status);
675} 680}
681
676static DEVICE_ATTR(status, S_IRUGO, show_status, NULL); 682static DEVICE_ATTR(status, S_IRUGO, show_status, NULL);
677 683
678static ssize_t show_cfg(struct device *d, struct device_attribute *attr, 684static ssize_t show_cfg(struct device *d, struct device_attribute *attr,
@@ -681,10 +687,11 @@ static ssize_t show_cfg(struct device *d, struct device_attribute *attr,
681 struct ipw_priv *p = d->driver_data; 687 struct ipw_priv *p = d->driver_data;
682 return sprintf(buf, "0x%08x\n", (int)p->config); 688 return sprintf(buf, "0x%08x\n", (int)p->config);
683} 689}
690
684static DEVICE_ATTR(cfg, S_IRUGO, show_cfg, NULL); 691static DEVICE_ATTR(cfg, S_IRUGO, show_cfg, NULL);
685 692
686static ssize_t show_nic_type(struct device *d, 693static ssize_t show_nic_type(struct device *d,
687 struct device_attribute *attr, char *buf) 694 struct device_attribute *attr, char *buf)
688{ 695{
689 struct ipw_priv *p = d->driver_data; 696 struct ipw_priv *p = d->driver_data;
690 u8 type = p->eeprom[EEPROM_NIC_TYPE]; 697 u8 type = p->eeprom[EEPROM_NIC_TYPE];
@@ -704,44 +711,50 @@ static ssize_t show_nic_type(struct device *d,
704 711
705 return sprintf(buf, "UNKNOWN\n"); 712 return sprintf(buf, "UNKNOWN\n");
706} 713}
714
707static DEVICE_ATTR(nic_type, S_IRUGO, show_nic_type, NULL); 715static DEVICE_ATTR(nic_type, S_IRUGO, show_nic_type, NULL);
708 716
709static ssize_t dump_error_log(struct device *d, 717static ssize_t dump_error_log(struct device *d,
710 struct device_attribute *attr, const char *buf, size_t count) 718 struct device_attribute *attr, const char *buf,
719 size_t count)
711{ 720{
712 char *p = (char *)buf; 721 char *p = (char *)buf;
713 722
714 if (p[0] == '1') 723 if (p[0] == '1')
715 ipw_dump_nic_error_log((struct ipw_priv*)d->driver_data); 724 ipw_dump_nic_error_log((struct ipw_priv *)d->driver_data);
716 725
717 return strnlen(buf, count); 726 return strnlen(buf, count);
718} 727}
728
719static DEVICE_ATTR(dump_errors, S_IWUSR, NULL, dump_error_log); 729static DEVICE_ATTR(dump_errors, S_IWUSR, NULL, dump_error_log);
720 730
721static ssize_t dump_event_log(struct device *d, 731static ssize_t dump_event_log(struct device *d,
722 struct device_attribute *attr, const char *buf, size_t count) 732 struct device_attribute *attr, const char *buf,
733 size_t count)
723{ 734{
724 char *p = (char *)buf; 735 char *p = (char *)buf;
725 736
726 if (p[0] == '1') 737 if (p[0] == '1')
727 ipw_dump_nic_event_log((struct ipw_priv*)d->driver_data); 738 ipw_dump_nic_event_log((struct ipw_priv *)d->driver_data);
728 739
729 return strnlen(buf, count); 740 return strnlen(buf, count);
730} 741}
742
731static DEVICE_ATTR(dump_events, S_IWUSR, NULL, dump_event_log); 743static DEVICE_ATTR(dump_events, S_IWUSR, NULL, dump_event_log);
732 744
733static ssize_t show_ucode_version(struct device *d, 745static ssize_t show_ucode_version(struct device *d,
734 struct device_attribute *attr, char *buf) 746 struct device_attribute *attr, char *buf)
735{ 747{
736 u32 len = sizeof(u32), tmp = 0; 748 u32 len = sizeof(u32), tmp = 0;
737 struct ipw_priv *p = d->driver_data; 749 struct ipw_priv *p = d->driver_data;
738 750
739 if(ipw_get_ordinal(p, IPW_ORD_STAT_UCODE_VERSION, &tmp, &len)) 751 if (ipw_get_ordinal(p, IPW_ORD_STAT_UCODE_VERSION, &tmp, &len))
740 return 0; 752 return 0;
741 753
742 return sprintf(buf, "0x%08x\n", tmp); 754 return sprintf(buf, "0x%08x\n", tmp);
743} 755}
744static DEVICE_ATTR(ucode_version, S_IWUSR|S_IRUGO, show_ucode_version, NULL); 756
757static DEVICE_ATTR(ucode_version, S_IWUSR | S_IRUGO, show_ucode_version, NULL);
745 758
746static ssize_t show_rtc(struct device *d, struct device_attribute *attr, 759static ssize_t show_rtc(struct device *d, struct device_attribute *attr,
747 char *buf) 760 char *buf)
@@ -749,36 +762,38 @@ static ssize_t show_rtc(struct device *d, struct device_attribute *attr,
749 u32 len = sizeof(u32), tmp = 0; 762 u32 len = sizeof(u32), tmp = 0;
750 struct ipw_priv *p = d->driver_data; 763 struct ipw_priv *p = d->driver_data;
751 764
752 if(ipw_get_ordinal(p, IPW_ORD_STAT_RTC, &tmp, &len)) 765 if (ipw_get_ordinal(p, IPW_ORD_STAT_RTC, &tmp, &len))
753 return 0; 766 return 0;
754 767
755 return sprintf(buf, "0x%08x\n", tmp); 768 return sprintf(buf, "0x%08x\n", tmp);
756} 769}
757static DEVICE_ATTR(rtc, S_IWUSR|S_IRUGO, show_rtc, NULL); 770
771static DEVICE_ATTR(rtc, S_IWUSR | S_IRUGO, show_rtc, NULL);
758 772
759/* 773/*
760 * Add a device attribute to view/control the delay between eeprom 774 * Add a device attribute to view/control the delay between eeprom
761 * operations. 775 * operations.
762 */ 776 */
763static ssize_t show_eeprom_delay(struct device *d, 777static ssize_t show_eeprom_delay(struct device *d,
764 struct device_attribute *attr, char *buf) 778 struct device_attribute *attr, char *buf)
765{ 779{
766 int n = ((struct ipw_priv*)d->driver_data)->eeprom_delay; 780 int n = ((struct ipw_priv *)d->driver_data)->eeprom_delay;
767 return sprintf(buf, "%i\n", n); 781 return sprintf(buf, "%i\n", n);
768} 782}
769static ssize_t store_eeprom_delay(struct device *d, 783static ssize_t store_eeprom_delay(struct device *d,
770 struct device_attribute *attr, const char *buf, 784 struct device_attribute *attr,
771 size_t count) 785 const char *buf, size_t count)
772{ 786{
773 struct ipw_priv *p = d->driver_data; 787 struct ipw_priv *p = d->driver_data;
774 sscanf(buf, "%i", &p->eeprom_delay); 788 sscanf(buf, "%i", &p->eeprom_delay);
775 return strnlen(buf, count); 789 return strnlen(buf, count);
776} 790}
777static DEVICE_ATTR(eeprom_delay, S_IWUSR|S_IRUGO, 791
778 show_eeprom_delay,store_eeprom_delay); 792static DEVICE_ATTR(eeprom_delay, S_IWUSR | S_IRUGO,
793 show_eeprom_delay, store_eeprom_delay);
779 794
780static ssize_t show_command_event_reg(struct device *d, 795static ssize_t show_command_event_reg(struct device *d,
781 struct device_attribute *attr, char *buf) 796 struct device_attribute *attr, char *buf)
782{ 797{
783 u32 reg = 0; 798 u32 reg = 0;
784 struct ipw_priv *p = d->driver_data; 799 struct ipw_priv *p = d->driver_data;
@@ -787,8 +802,8 @@ static ssize_t show_command_event_reg(struct device *d,
787 return sprintf(buf, "0x%08x\n", reg); 802 return sprintf(buf, "0x%08x\n", reg);
788} 803}
789static ssize_t store_command_event_reg(struct device *d, 804static ssize_t store_command_event_reg(struct device *d,
790 struct device_attribute *attr, const char *buf, 805 struct device_attribute *attr,
791 size_t count) 806 const char *buf, size_t count)
792{ 807{
793 u32 reg; 808 u32 reg;
794 struct ipw_priv *p = d->driver_data; 809 struct ipw_priv *p = d->driver_data;
@@ -797,11 +812,12 @@ static ssize_t store_command_event_reg(struct device *d,
797 ipw_write_reg32(p, CX2_INTERNAL_CMD_EVENT, reg); 812 ipw_write_reg32(p, CX2_INTERNAL_CMD_EVENT, reg);
798 return strnlen(buf, count); 813 return strnlen(buf, count);
799} 814}
800static DEVICE_ATTR(command_event_reg, S_IWUSR|S_IRUGO, 815
801 show_command_event_reg,store_command_event_reg); 816static DEVICE_ATTR(command_event_reg, S_IWUSR | S_IRUGO,
817 show_command_event_reg, store_command_event_reg);
802 818
803static ssize_t show_mem_gpio_reg(struct device *d, 819static ssize_t show_mem_gpio_reg(struct device *d,
804 struct device_attribute *attr, char *buf) 820 struct device_attribute *attr, char *buf)
805{ 821{
806 u32 reg = 0; 822 u32 reg = 0;
807 struct ipw_priv *p = d->driver_data; 823 struct ipw_priv *p = d->driver_data;
@@ -810,8 +826,8 @@ static ssize_t show_mem_gpio_reg(struct device *d,
810 return sprintf(buf, "0x%08x\n", reg); 826 return sprintf(buf, "0x%08x\n", reg);
811} 827}
812static ssize_t store_mem_gpio_reg(struct device *d, 828static ssize_t store_mem_gpio_reg(struct device *d,
813 struct device_attribute *attr, const char *buf, 829 struct device_attribute *attr,
814 size_t count) 830 const char *buf, size_t count)
815{ 831{
816 u32 reg; 832 u32 reg;
817 struct ipw_priv *p = d->driver_data; 833 struct ipw_priv *p = d->driver_data;
@@ -820,11 +836,12 @@ static ssize_t store_mem_gpio_reg(struct device *d,
820 ipw_write_reg32(p, 0x301100, reg); 836 ipw_write_reg32(p, 0x301100, reg);
821 return strnlen(buf, count); 837 return strnlen(buf, count);
822} 838}
823static DEVICE_ATTR(mem_gpio_reg, S_IWUSR|S_IRUGO, 839
824 show_mem_gpio_reg,store_mem_gpio_reg); 840static DEVICE_ATTR(mem_gpio_reg, S_IWUSR | S_IRUGO,
841 show_mem_gpio_reg, store_mem_gpio_reg);
825 842
826static ssize_t show_indirect_dword(struct device *d, 843static ssize_t show_indirect_dword(struct device *d,
827 struct device_attribute *attr, char *buf) 844 struct device_attribute *attr, char *buf)
828{ 845{
829 u32 reg = 0; 846 u32 reg = 0;
830 struct ipw_priv *priv = d->driver_data; 847 struct ipw_priv *priv = d->driver_data;
@@ -836,8 +853,8 @@ static ssize_t show_indirect_dword(struct device *d,
836 return sprintf(buf, "0x%08x\n", reg); 853 return sprintf(buf, "0x%08x\n", reg);
837} 854}
838static ssize_t store_indirect_dword(struct device *d, 855static ssize_t store_indirect_dword(struct device *d,
839 struct device_attribute *attr, const char *buf, 856 struct device_attribute *attr,
840 size_t count) 857 const char *buf, size_t count)
841{ 858{
842 struct ipw_priv *priv = d->driver_data; 859 struct ipw_priv *priv = d->driver_data;
843 860
@@ -845,11 +862,12 @@ static ssize_t store_indirect_dword(struct device *d,
845 priv->status |= STATUS_INDIRECT_DWORD; 862 priv->status |= STATUS_INDIRECT_DWORD;
846 return strnlen(buf, count); 863 return strnlen(buf, count);
847} 864}
848static DEVICE_ATTR(indirect_dword, S_IWUSR|S_IRUGO, 865
849 show_indirect_dword,store_indirect_dword); 866static DEVICE_ATTR(indirect_dword, S_IWUSR | S_IRUGO,
867 show_indirect_dword, store_indirect_dword);
850 868
851static ssize_t show_indirect_byte(struct device *d, 869static ssize_t show_indirect_byte(struct device *d,
852 struct device_attribute *attr, char *buf) 870 struct device_attribute *attr, char *buf)
853{ 871{
854 u8 reg = 0; 872 u8 reg = 0;
855 struct ipw_priv *priv = d->driver_data; 873 struct ipw_priv *priv = d->driver_data;
@@ -861,8 +879,8 @@ static ssize_t show_indirect_byte(struct device *d,
861 return sprintf(buf, "0x%02x\n", reg); 879 return sprintf(buf, "0x%02x\n", reg);
862} 880}
863static ssize_t store_indirect_byte(struct device *d, 881static ssize_t store_indirect_byte(struct device *d,
864 struct device_attribute *attr, const char *buf, 882 struct device_attribute *attr,
865 size_t count) 883 const char *buf, size_t count)
866{ 884{
867 struct ipw_priv *priv = d->driver_data; 885 struct ipw_priv *priv = d->driver_data;
868 886
@@ -870,11 +888,12 @@ static ssize_t store_indirect_byte(struct device *d,
870 priv->status |= STATUS_INDIRECT_BYTE; 888 priv->status |= STATUS_INDIRECT_BYTE;
871 return strnlen(buf, count); 889 return strnlen(buf, count);
872} 890}
873static DEVICE_ATTR(indirect_byte, S_IWUSR|S_IRUGO, 891
892static DEVICE_ATTR(indirect_byte, S_IWUSR | S_IRUGO,
874 show_indirect_byte, store_indirect_byte); 893 show_indirect_byte, store_indirect_byte);
875 894
876static ssize_t show_direct_dword(struct device *d, 895static ssize_t show_direct_dword(struct device *d,
877 struct device_attribute *attr, char *buf) 896 struct device_attribute *attr, char *buf)
878{ 897{
879 u32 reg = 0; 898 u32 reg = 0;
880 struct ipw_priv *priv = d->driver_data; 899 struct ipw_priv *priv = d->driver_data;
@@ -887,8 +906,8 @@ static ssize_t show_direct_dword(struct device *d,
887 return sprintf(buf, "0x%08x\n", reg); 906 return sprintf(buf, "0x%08x\n", reg);
888} 907}
889static ssize_t store_direct_dword(struct device *d, 908static ssize_t store_direct_dword(struct device *d,
890 struct device_attribute *attr, const char *buf, 909 struct device_attribute *attr,
891 size_t count) 910 const char *buf, size_t count)
892{ 911{
893 struct ipw_priv *priv = d->driver_data; 912 struct ipw_priv *priv = d->driver_data;
894 913
@@ -896,9 +915,9 @@ static ssize_t store_direct_dword(struct device *d,
896 priv->status |= STATUS_DIRECT_DWORD; 915 priv->status |= STATUS_DIRECT_DWORD;
897 return strnlen(buf, count); 916 return strnlen(buf, count);
898} 917}
899static DEVICE_ATTR(direct_dword, S_IWUSR|S_IRUGO,
900 show_direct_dword,store_direct_dword);
901 918
919static DEVICE_ATTR(direct_dword, S_IWUSR | S_IRUGO,
920 show_direct_dword, store_direct_dword);
902 921
903static inline int rf_kill_active(struct ipw_priv *priv) 922static inline int rf_kill_active(struct ipw_priv *priv)
904{ 923{
@@ -911,7 +930,7 @@ static inline int rf_kill_active(struct ipw_priv *priv)
911} 930}
912 931
913static ssize_t show_rf_kill(struct device *d, struct device_attribute *attr, 932static ssize_t show_rf_kill(struct device *d, struct device_attribute *attr,
914 char *buf) 933 char *buf)
915{ 934{
916 /* 0 - RF kill not enabled 935 /* 0 - RF kill not enabled
917 1 - SW based RF kill active (sysfs) 936 1 - SW based RF kill active (sysfs)
@@ -919,7 +938,7 @@ static ssize_t show_rf_kill(struct device *d, struct device_attribute *attr,
919 3 - Both HW and SW baed RF kill active */ 938 3 - Both HW and SW baed RF kill active */
920 struct ipw_priv *priv = d->driver_data; 939 struct ipw_priv *priv = d->driver_data;
921 int val = ((priv->status & STATUS_RF_KILL_SW) ? 0x1 : 0x0) | 940 int val = ((priv->status & STATUS_RF_KILL_SW) ? 0x1 : 0x0) |
922 (rf_kill_active(priv) ? 0x2 : 0x0); 941 (rf_kill_active(priv) ? 0x2 : 0x0);
923 return sprintf(buf, "%i\n", val); 942 return sprintf(buf, "%i\n", val);
924} 943}
925 944
@@ -927,7 +946,7 @@ static int ipw_radio_kill_sw(struct ipw_priv *priv, int disable_radio)
927{ 946{
928 if ((disable_radio ? 1 : 0) == 947 if ((disable_radio ? 1 : 0) ==
929 (priv->status & STATUS_RF_KILL_SW ? 1 : 0)) 948 (priv->status & STATUS_RF_KILL_SW ? 1 : 0))
930 return 0 ; 949 return 0;
931 950
932 IPW_DEBUG_RF_KILL("Manual SW RF Kill set to: RADIO %s\n", 951 IPW_DEBUG_RF_KILL("Manual SW RF Kill set to: RADIO %s\n",
933 disable_radio ? "OFF" : "ON"); 952 disable_radio ? "OFF" : "ON");
@@ -956,8 +975,8 @@ static int ipw_radio_kill_sw(struct ipw_priv *priv, int disable_radio)
956 return 1; 975 return 1;
957} 976}
958 977
959static ssize_t store_rf_kill(struct device *d, struct device_attribute *attr, 978static ssize_t store_rf_kill(struct device *d, struct device_attribute *attr,
960 const char *buf, size_t count) 979 const char *buf, size_t count)
961{ 980{
962 struct ipw_priv *priv = d->driver_data; 981 struct ipw_priv *priv = d->driver_data;
963 982
@@ -965,7 +984,8 @@ static ssize_t store_rf_kill(struct device *d, struct device_attribute *attr,
965 984
966 return count; 985 return count;
967} 986}
968static DEVICE_ATTR(rf_kill, S_IWUSR|S_IRUGO, show_rf_kill, store_rf_kill); 987
988static DEVICE_ATTR(rf_kill, S_IWUSR | S_IRUGO, show_rf_kill, store_rf_kill);
969 989
970static void ipw_irq_tasklet(struct ipw_priv *priv) 990static void ipw_irq_tasklet(struct ipw_priv *priv)
971{ 991{
@@ -990,7 +1010,7 @@ static void ipw_irq_tasklet(struct ipw_priv *priv)
990 1010
991 if (inta & CX2_INTA_BIT_TX_CMD_QUEUE) { 1011 if (inta & CX2_INTA_BIT_TX_CMD_QUEUE) {
992 IPW_DEBUG_HC("Command completed.\n"); 1012 IPW_DEBUG_HC("Command completed.\n");
993 rc = ipw_queue_tx_reclaim( priv, &priv->txq_cmd, -1); 1013 rc = ipw_queue_tx_reclaim(priv, &priv->txq_cmd, -1);
994 priv->status &= ~STATUS_HCMD_ACTIVE; 1014 priv->status &= ~STATUS_HCMD_ACTIVE;
995 wake_up_interruptible(&priv->wait_command_queue); 1015 wake_up_interruptible(&priv->wait_command_queue);
996 handled |= CX2_INTA_BIT_TX_CMD_QUEUE; 1016 handled |= CX2_INTA_BIT_TX_CMD_QUEUE;
@@ -998,25 +1018,25 @@ static void ipw_irq_tasklet(struct ipw_priv *priv)
998 1018
999 if (inta & CX2_INTA_BIT_TX_QUEUE_1) { 1019 if (inta & CX2_INTA_BIT_TX_QUEUE_1) {
1000 IPW_DEBUG_TX("TX_QUEUE_1\n"); 1020 IPW_DEBUG_TX("TX_QUEUE_1\n");
1001 rc = ipw_queue_tx_reclaim( priv, &priv->txq[0], 0); 1021 rc = ipw_queue_tx_reclaim(priv, &priv->txq[0], 0);
1002 handled |= CX2_INTA_BIT_TX_QUEUE_1; 1022 handled |= CX2_INTA_BIT_TX_QUEUE_1;
1003 } 1023 }
1004 1024
1005 if (inta & CX2_INTA_BIT_TX_QUEUE_2) { 1025 if (inta & CX2_INTA_BIT_TX_QUEUE_2) {
1006 IPW_DEBUG_TX("TX_QUEUE_2\n"); 1026 IPW_DEBUG_TX("TX_QUEUE_2\n");
1007 rc = ipw_queue_tx_reclaim( priv, &priv->txq[1], 1); 1027 rc = ipw_queue_tx_reclaim(priv, &priv->txq[1], 1);
1008 handled |= CX2_INTA_BIT_TX_QUEUE_2; 1028 handled |= CX2_INTA_BIT_TX_QUEUE_2;
1009 } 1029 }
1010 1030
1011 if (inta & CX2_INTA_BIT_TX_QUEUE_3) { 1031 if (inta & CX2_INTA_BIT_TX_QUEUE_3) {
1012 IPW_DEBUG_TX("TX_QUEUE_3\n"); 1032 IPW_DEBUG_TX("TX_QUEUE_3\n");
1013 rc = ipw_queue_tx_reclaim( priv, &priv->txq[2], 2); 1033 rc = ipw_queue_tx_reclaim(priv, &priv->txq[2], 2);
1014 handled |= CX2_INTA_BIT_TX_QUEUE_3; 1034 handled |= CX2_INTA_BIT_TX_QUEUE_3;
1015 } 1035 }
1016 1036
1017 if (inta & CX2_INTA_BIT_TX_QUEUE_4) { 1037 if (inta & CX2_INTA_BIT_TX_QUEUE_4) {
1018 IPW_DEBUG_TX("TX_QUEUE_4\n"); 1038 IPW_DEBUG_TX("TX_QUEUE_4\n");
1019 rc = ipw_queue_tx_reclaim( priv, &priv->txq[3], 3); 1039 rc = ipw_queue_tx_reclaim(priv, &priv->txq[3], 3);
1020 handled |= CX2_INTA_BIT_TX_QUEUE_4; 1040 handled |= CX2_INTA_BIT_TX_QUEUE_4;
1021 } 1041 }
1022 1042
@@ -1074,8 +1094,7 @@ static void ipw_irq_tasklet(struct ipw_priv *priv)
1074 } 1094 }
1075 1095
1076 if (handled != inta) { 1096 if (handled != inta) {
1077 IPW_ERROR("Unhandled INTA bits 0x%08x\n", 1097 IPW_ERROR("Unhandled INTA bits 0x%08x\n", inta & ~handled);
1078 inta & ~handled);
1079 } 1098 }
1080 1099
1081 /* enable all interrupts */ 1100 /* enable all interrupts */
@@ -1143,7 +1162,7 @@ static char *get_cmd_string(u8 cmd)
1143 return "UNKNOWN"; 1162 return "UNKNOWN";
1144 } 1163 }
1145} 1164}
1146#endif /* CONFIG_IPW_DEBUG */ 1165#endif /* CONFIG_IPW_DEBUG */
1147 1166
1148#define HOST_COMPLETE_TIMEOUT HZ 1167#define HOST_COMPLETE_TIMEOUT HZ
1149static int ipw_send_cmd(struct ipw_priv *priv, struct host_cmd *cmd) 1168static int ipw_send_cmd(struct ipw_priv *priv, struct host_cmd *cmd)
@@ -1159,15 +1178,16 @@ static int ipw_send_cmd(struct ipw_priv *priv, struct host_cmd *cmd)
1159 1178
1160 IPW_DEBUG_HC("Sending %s command (#%d), %d bytes\n", 1179 IPW_DEBUG_HC("Sending %s command (#%d), %d bytes\n",
1161 get_cmd_string(cmd->cmd), cmd->cmd, cmd->len); 1180 get_cmd_string(cmd->cmd), cmd->cmd, cmd->len);
1162 printk_buf(IPW_DL_HOST_COMMAND, (u8*)cmd->param, cmd->len); 1181 printk_buf(IPW_DL_HOST_COMMAND, (u8 *) cmd->param, cmd->len);
1163 1182
1164 rc = ipw_queue_tx_hcmd(priv, cmd->cmd, &cmd->param, cmd->len, 0); 1183 rc = ipw_queue_tx_hcmd(priv, cmd->cmd, &cmd->param, cmd->len, 0);
1165 if (rc) 1184 if (rc)
1166 return rc; 1185 return rc;
1167 1186
1168 rc = wait_event_interruptible_timeout( 1187 rc = wait_event_interruptible_timeout(priv->wait_command_queue,
1169 priv->wait_command_queue, !(priv->status & STATUS_HCMD_ACTIVE), 1188 !(priv->
1170 HOST_COMPLETE_TIMEOUT); 1189 status & STATUS_HCMD_ACTIVE),
1190 HOST_COMPLETE_TIMEOUT);
1171 if (rc == 0) { 1191 if (rc == 0) {
1172 IPW_DEBUG_INFO("Command completion failed out after %dms.\n", 1192 IPW_DEBUG_INFO("Command completion failed out after %dms.\n",
1173 jiffies_to_msecs(HOST_COMPLETE_TIMEOUT)); 1193 jiffies_to_msecs(HOST_COMPLETE_TIMEOUT));
@@ -1215,7 +1235,7 @@ static int ipw_send_system_config(struct ipw_priv *priv,
1215 return -1; 1235 return -1;
1216 } 1236 }
1217 1237
1218 memcpy(&cmd.param,config,sizeof(*config)); 1238 memcpy(&cmd.param, config, sizeof(*config));
1219 if (ipw_send_cmd(priv, &cmd)) { 1239 if (ipw_send_cmd(priv, &cmd)) {
1220 IPW_ERROR("failed to send SYSTEM_CONFIG command\n"); 1240 IPW_ERROR("failed to send SYSTEM_CONFIG command\n");
1221 return -1; 1241 return -1;
@@ -1224,7 +1244,7 @@ static int ipw_send_system_config(struct ipw_priv *priv,
1224 return 0; 1244 return 0;
1225} 1245}
1226 1246
1227static int ipw_send_ssid(struct ipw_priv *priv, u8 *ssid, int len) 1247static int ipw_send_ssid(struct ipw_priv *priv, u8 * ssid, int len)
1228{ 1248{
1229 struct host_cmd cmd = { 1249 struct host_cmd cmd = {
1230 .cmd = IPW_CMD_SSID, 1250 .cmd = IPW_CMD_SSID,
@@ -1245,7 +1265,7 @@ static int ipw_send_ssid(struct ipw_priv *priv, u8 *ssid, int len)
1245 return 0; 1265 return 0;
1246} 1266}
1247 1267
1248static int ipw_send_adapter_address(struct ipw_priv *priv, u8 *mac) 1268static int ipw_send_adapter_address(struct ipw_priv *priv, u8 * mac)
1249{ 1269{
1250 struct host_cmd cmd = { 1270 struct host_cmd cmd = {
1251 .cmd = IPW_CMD_ADAPTER_ADDRESS, 1271 .cmd = IPW_CMD_ADAPTER_ADDRESS,
@@ -1284,9 +1304,6 @@ static void ipw_adapter_restart(void *adapter)
1284 } 1304 }
1285} 1305}
1286 1306
1287
1288
1289
1290#define IPW_SCAN_CHECK_WATCHDOG (5 * HZ) 1307#define IPW_SCAN_CHECK_WATCHDOG (5 * HZ)
1291 1308
1292static void ipw_scan_check(void *data) 1309static void ipw_scan_check(void *data)
@@ -1313,7 +1330,7 @@ static int ipw_send_scan_request_ext(struct ipw_priv *priv,
1313 return -1; 1330 return -1;
1314 } 1331 }
1315 1332
1316 memcpy(&cmd.param,request,sizeof(*request)); 1333 memcpy(&cmd.param, request, sizeof(*request));
1317 if (ipw_send_cmd(priv, &cmd)) { 1334 if (ipw_send_cmd(priv, &cmd)) {
1318 IPW_ERROR("failed to send SCAN_REQUEST_EXT command\n"); 1335 IPW_ERROR("failed to send SCAN_REQUEST_EXT command\n");
1319 return -1; 1336 return -1;
@@ -1351,7 +1368,7 @@ static int ipw_set_sensitivity(struct ipw_priv *priv, u16 sens)
1351 .len = sizeof(struct ipw_sensitivity_calib) 1368 .len = sizeof(struct ipw_sensitivity_calib)
1352 }; 1369 };
1353 struct ipw_sensitivity_calib *calib = (struct ipw_sensitivity_calib *) 1370 struct ipw_sensitivity_calib *calib = (struct ipw_sensitivity_calib *)
1354 &cmd.param; 1371 &cmd.param;
1355 calib->beacon_rssi_raw = sens; 1372 calib->beacon_rssi_raw = sens;
1356 if (ipw_send_cmd(priv, &cmd)) { 1373 if (ipw_send_cmd(priv, &cmd)) {
1357 IPW_ERROR("failed to send SENSITIVITY CALIB command\n"); 1374 IPW_ERROR("failed to send SENSITIVITY CALIB command\n");
@@ -1374,7 +1391,7 @@ static int ipw_send_associate(struct ipw_priv *priv,
1374 return -1; 1391 return -1;
1375 } 1392 }
1376 1393
1377 memcpy(&cmd.param,associate,sizeof(*associate)); 1394 memcpy(&cmd.param, associate, sizeof(*associate));
1378 if (ipw_send_cmd(priv, &cmd)) { 1395 if (ipw_send_cmd(priv, &cmd)) {
1379 IPW_ERROR("failed to send ASSOCIATE command\n"); 1396 IPW_ERROR("failed to send ASSOCIATE command\n");
1380 return -1; 1397 return -1;
@@ -1396,7 +1413,7 @@ static int ipw_send_supported_rates(struct ipw_priv *priv,
1396 return -1; 1413 return -1;
1397 } 1414 }
1398 1415
1399 memcpy(&cmd.param,rates,sizeof(*rates)); 1416 memcpy(&cmd.param, rates, sizeof(*rates));
1400 if (ipw_send_cmd(priv, &cmd)) { 1417 if (ipw_send_cmd(priv, &cmd)) {
1401 IPW_ERROR("failed to send SUPPORTED_RATES command\n"); 1418 IPW_ERROR("failed to send SUPPORTED_RATES command\n");
1402 return -1; 1419 return -1;
@@ -1440,7 +1457,7 @@ static int ipw_send_card_disable(struct ipw_priv *priv, u32 phy_off)
1440 return -1; 1457 return -1;
1441 } 1458 }
1442 1459
1443 *((u32*)&cmd.param) = phy_off; 1460 *((u32 *) & cmd.param) = phy_off;
1444 1461
1445 if (ipw_send_cmd(priv, &cmd)) { 1462 if (ipw_send_cmd(priv, &cmd)) {
1446 IPW_ERROR("failed to send CARD_DISABLE command\n"); 1463 IPW_ERROR("failed to send CARD_DISABLE command\n");
@@ -1451,8 +1468,7 @@ static int ipw_send_card_disable(struct ipw_priv *priv, u32 phy_off)
1451} 1468}
1452#endif 1469#endif
1453 1470
1454static int ipw_send_tx_power(struct ipw_priv *priv, 1471static int ipw_send_tx_power(struct ipw_priv *priv, struct ipw_tx_power *power)
1455 struct ipw_tx_power *power)
1456{ 1472{
1457 struct host_cmd cmd = { 1473 struct host_cmd cmd = {
1458 .cmd = IPW_CMD_TX_POWER, 1474 .cmd = IPW_CMD_TX_POWER,
@@ -1464,7 +1480,7 @@ static int ipw_send_tx_power(struct ipw_priv *priv,
1464 return -1; 1480 return -1;
1465 } 1481 }
1466 1482
1467 memcpy(&cmd.param,power,sizeof(*power)); 1483 memcpy(&cmd.param, power, sizeof(*power));
1468 if (ipw_send_cmd(priv, &cmd)) { 1484 if (ipw_send_cmd(priv, &cmd)) {
1469 IPW_ERROR("failed to send TX_POWER command\n"); 1485 IPW_ERROR("failed to send TX_POWER command\n");
1470 return -1; 1486 return -1;
@@ -1527,7 +1543,7 @@ static int ipw_send_power_mode(struct ipw_priv *priv, u32 mode)
1527 .cmd = IPW_CMD_POWER_MODE, 1543 .cmd = IPW_CMD_POWER_MODE,
1528 .len = sizeof(u32) 1544 .len = sizeof(u32)
1529 }; 1545 };
1530 u32 *param = (u32*)(&cmd.param); 1546 u32 *param = (u32 *) (&cmd.param);
1531 1547
1532 if (!priv) { 1548 if (!priv) {
1533 IPW_ERROR("Invalid args\n"); 1549 IPW_ERROR("Invalid args\n");
@@ -1585,67 +1601,67 @@ static inline void eeprom_write_reg(struct ipw_priv *p, u32 data)
1585} 1601}
1586 1602
1587/* perform a chip select operation */ 1603/* perform a chip select operation */
1588static inline void eeprom_cs(struct ipw_priv* priv) 1604static inline void eeprom_cs(struct ipw_priv *priv)
1589{ 1605{
1590 eeprom_write_reg(priv,0); 1606 eeprom_write_reg(priv, 0);
1591 eeprom_write_reg(priv,EEPROM_BIT_CS); 1607 eeprom_write_reg(priv, EEPROM_BIT_CS);
1592 eeprom_write_reg(priv,EEPROM_BIT_CS|EEPROM_BIT_SK); 1608 eeprom_write_reg(priv, EEPROM_BIT_CS | EEPROM_BIT_SK);
1593 eeprom_write_reg(priv,EEPROM_BIT_CS); 1609 eeprom_write_reg(priv, EEPROM_BIT_CS);
1594} 1610}
1595 1611
1596/* perform a chip select operation */ 1612/* perform a chip select operation */
1597static inline void eeprom_disable_cs(struct ipw_priv* priv) 1613static inline void eeprom_disable_cs(struct ipw_priv *priv)
1598{ 1614{
1599 eeprom_write_reg(priv,EEPROM_BIT_CS); 1615 eeprom_write_reg(priv, EEPROM_BIT_CS);
1600 eeprom_write_reg(priv,0); 1616 eeprom_write_reg(priv, 0);
1601 eeprom_write_reg(priv,EEPROM_BIT_SK); 1617 eeprom_write_reg(priv, EEPROM_BIT_SK);
1602} 1618}
1603 1619
1604/* push a single bit down to the eeprom */ 1620/* push a single bit down to the eeprom */
1605static inline void eeprom_write_bit(struct ipw_priv *p,u8 bit) 1621static inline void eeprom_write_bit(struct ipw_priv *p, u8 bit)
1606{ 1622{
1607 int d = ( bit ? EEPROM_BIT_DI : 0); 1623 int d = (bit ? EEPROM_BIT_DI : 0);
1608 eeprom_write_reg(p,EEPROM_BIT_CS|d); 1624 eeprom_write_reg(p, EEPROM_BIT_CS | d);
1609 eeprom_write_reg(p,EEPROM_BIT_CS|d|EEPROM_BIT_SK); 1625 eeprom_write_reg(p, EEPROM_BIT_CS | d | EEPROM_BIT_SK);
1610} 1626}
1611 1627
1612/* push an opcode followed by an address down to the eeprom */ 1628/* push an opcode followed by an address down to the eeprom */
1613static void eeprom_op(struct ipw_priv* priv, u8 op, u8 addr) 1629static void eeprom_op(struct ipw_priv *priv, u8 op, u8 addr)
1614{ 1630{
1615 int i; 1631 int i;
1616 1632
1617 eeprom_cs(priv); 1633 eeprom_cs(priv);
1618 eeprom_write_bit(priv,1); 1634 eeprom_write_bit(priv, 1);
1619 eeprom_write_bit(priv,op&2); 1635 eeprom_write_bit(priv, op & 2);
1620 eeprom_write_bit(priv,op&1); 1636 eeprom_write_bit(priv, op & 1);
1621 for ( i=7; i>=0; i-- ) { 1637 for (i = 7; i >= 0; i--) {
1622 eeprom_write_bit(priv,addr&(1<<i)); 1638 eeprom_write_bit(priv, addr & (1 << i));
1623 } 1639 }
1624} 1640}
1625 1641
1626/* pull 16 bits off the eeprom, one bit at a time */ 1642/* pull 16 bits off the eeprom, one bit at a time */
1627static u16 eeprom_read_u16(struct ipw_priv* priv, u8 addr) 1643static u16 eeprom_read_u16(struct ipw_priv *priv, u8 addr)
1628{ 1644{
1629 int i; 1645 int i;
1630 u16 r=0; 1646 u16 r = 0;
1631 1647
1632 /* Send READ Opcode */ 1648 /* Send READ Opcode */
1633 eeprom_op(priv,EEPROM_CMD_READ,addr); 1649 eeprom_op(priv, EEPROM_CMD_READ, addr);
1634 1650
1635 /* Send dummy bit */ 1651 /* Send dummy bit */
1636 eeprom_write_reg(priv,EEPROM_BIT_CS); 1652 eeprom_write_reg(priv, EEPROM_BIT_CS);
1637 1653
1638 /* Read the byte off the eeprom one bit at a time */ 1654 /* Read the byte off the eeprom one bit at a time */
1639 for ( i=0; i<16; i++ ) { 1655 for (i = 0; i < 16; i++) {
1640 u32 data = 0; 1656 u32 data = 0;
1641 eeprom_write_reg(priv,EEPROM_BIT_CS|EEPROM_BIT_SK); 1657 eeprom_write_reg(priv, EEPROM_BIT_CS | EEPROM_BIT_SK);
1642 eeprom_write_reg(priv,EEPROM_BIT_CS); 1658 eeprom_write_reg(priv, EEPROM_BIT_CS);
1643 data = ipw_read_reg32(priv,FW_MEM_REG_EEPROM_ACCESS); 1659 data = ipw_read_reg32(priv, FW_MEM_REG_EEPROM_ACCESS);
1644 r = (r<<1) | ((data & EEPROM_BIT_DO)?1:0); 1660 r = (r << 1) | ((data & EEPROM_BIT_DO) ? 1 : 0);
1645 } 1661 }
1646 1662
1647 /* Send another dummy bit */ 1663 /* Send another dummy bit */
1648 eeprom_write_reg(priv,0); 1664 eeprom_write_reg(priv, 0);
1649 eeprom_disable_cs(priv); 1665 eeprom_disable_cs(priv);
1650 1666
1651 return r; 1667 return r;
@@ -1653,9 +1669,9 @@ static u16 eeprom_read_u16(struct ipw_priv* priv, u8 addr)
1653 1669
1654/* helper function for pulling the mac address out of the private */ 1670/* helper function for pulling the mac address out of the private */
1655/* data's copy of the eeprom data */ 1671/* data's copy of the eeprom data */
1656static void eeprom_parse_mac(struct ipw_priv* priv, u8* mac) 1672static void eeprom_parse_mac(struct ipw_priv *priv, u8 * mac)
1657{ 1673{
1658 u8* ee = (u8*)priv->eeprom; 1674 u8 *ee = (u8 *) priv->eeprom;
1659 memcpy(mac, &ee[EEPROM_MAC_ADDRESS], 6); 1675 memcpy(mac, &ee[EEPROM_MAC_ADDRESS], 6);
1660} 1676}
1661 1677
@@ -1670,26 +1686,25 @@ static void eeprom_parse_mac(struct ipw_priv* priv, u8* mac)
1670static void ipw_eeprom_init_sram(struct ipw_priv *priv) 1686static void ipw_eeprom_init_sram(struct ipw_priv *priv)
1671{ 1687{
1672 int i; 1688 int i;
1673 u16 *eeprom = (u16 *)priv->eeprom; 1689 u16 *eeprom = (u16 *) priv->eeprom;
1674 1690
1675 IPW_DEBUG_TRACE(">>\n"); 1691 IPW_DEBUG_TRACE(">>\n");
1676 1692
1677 /* read entire contents of eeprom into private buffer */ 1693 /* read entire contents of eeprom into private buffer */
1678 for ( i=0; i<128; i++ ) 1694 for (i = 0; i < 128; i++)
1679 eeprom[i] = eeprom_read_u16(priv,(u8)i); 1695 eeprom[i] = eeprom_read_u16(priv, (u8) i);
1680 1696
1681 /* 1697 /*
1682 If the data looks correct, then copy it to our private 1698 If the data looks correct, then copy it to our private
1683 copy. Otherwise let the firmware know to perform the operation 1699 copy. Otherwise let the firmware know to perform the operation
1684 on it's own 1700 on it's own
1685 */ 1701 */
1686 if ((priv->eeprom + EEPROM_VERSION) != 0) { 1702 if ((priv->eeprom + EEPROM_VERSION) != 0) {
1687 IPW_DEBUG_INFO("Writing EEPROM data into SRAM\n"); 1703 IPW_DEBUG_INFO("Writing EEPROM data into SRAM\n");
1688 1704
1689 /* write the eeprom data to sram */ 1705 /* write the eeprom data to sram */
1690 for( i=0; i<CX2_EEPROM_IMAGE_SIZE; i++ ) 1706 for (i = 0; i < CX2_EEPROM_IMAGE_SIZE; i++)
1691 ipw_write8(priv, IPW_EEPROM_DATA + i, 1707 ipw_write8(priv, IPW_EEPROM_DATA + i, priv->eeprom[i]);
1692 priv->eeprom[i]);
1693 1708
1694 /* Do not load eeprom data on fatal error or suspend */ 1709 /* Do not load eeprom data on fatal error or suspend */
1695 ipw_write32(priv, IPW_EEPROM_LOAD_DISABLE, 0); 1710 ipw_write32(priv, IPW_EEPROM_LOAD_DISABLE, 0);
@@ -1703,11 +1718,11 @@ static void ipw_eeprom_init_sram(struct ipw_priv *priv)
1703 IPW_DEBUG_TRACE("<<\n"); 1718 IPW_DEBUG_TRACE("<<\n");
1704} 1719}
1705 1720
1706
1707static inline void ipw_zero_memory(struct ipw_priv *priv, u32 start, u32 count) 1721static inline void ipw_zero_memory(struct ipw_priv *priv, u32 start, u32 count)
1708{ 1722{
1709 count >>= 2; 1723 count >>= 2;
1710 if (!count) return; 1724 if (!count)
1725 return;
1711 _ipw_write32(priv, CX2_AUTOINC_ADDR, start); 1726 _ipw_write32(priv, CX2_AUTOINC_ADDR, start);
1712 while (count--) 1727 while (count--)
1713 _ipw_write32(priv, CX2_AUTOINC_DATA, 0); 1728 _ipw_write32(priv, CX2_AUTOINC_DATA, 0);
@@ -1721,7 +1736,7 @@ static inline void ipw_fw_dma_reset_command_blocks(struct ipw_priv *priv)
1721} 1736}
1722 1737
1723static int ipw_fw_dma_enable(struct ipw_priv *priv) 1738static int ipw_fw_dma_enable(struct ipw_priv *priv)
1724{ /* start dma engine but no transfers yet*/ 1739{ /* start dma engine but no transfers yet */
1725 1740
1726 IPW_DEBUG_FW(">> : \n"); 1741 IPW_DEBUG_FW(">> : \n");
1727 1742
@@ -1749,12 +1764,16 @@ static void ipw_fw_dma_abort(struct ipw_priv *priv)
1749 IPW_DEBUG_FW("<< \n"); 1764 IPW_DEBUG_FW("<< \n");
1750} 1765}
1751 1766
1752static int ipw_fw_dma_write_command_block(struct ipw_priv *priv, int index, struct command_block *cb) 1767static int ipw_fw_dma_write_command_block(struct ipw_priv *priv, int index,
1768 struct command_block *cb)
1753{ 1769{
1754 u32 address = CX2_SHARED_SRAM_DMA_CONTROL + (sizeof(struct command_block) * index); 1770 u32 address =
1771 CX2_SHARED_SRAM_DMA_CONTROL +
1772 (sizeof(struct command_block) * index);
1755 IPW_DEBUG_FW(">> :\n"); 1773 IPW_DEBUG_FW(">> :\n");
1756 1774
1757 ipw_write_indirect(priv, address, (u8*)cb, (int)sizeof(struct command_block)); 1775 ipw_write_indirect(priv, address, (u8 *) cb,
1776 (int)sizeof(struct command_block));
1758 1777
1759 IPW_DEBUG_FW("<< :\n"); 1778 IPW_DEBUG_FW("<< :\n");
1760 return 0; 1779 return 0;
@@ -1764,17 +1783,20 @@ static int ipw_fw_dma_write_command_block(struct ipw_priv *priv, int index, stru
1764static int ipw_fw_dma_kick(struct ipw_priv *priv) 1783static int ipw_fw_dma_kick(struct ipw_priv *priv)
1765{ 1784{
1766 u32 control = 0; 1785 u32 control = 0;
1767 u32 index=0; 1786 u32 index = 0;
1768 1787
1769 IPW_DEBUG_FW(">> :\n"); 1788 IPW_DEBUG_FW(">> :\n");
1770 1789
1771 for (index = 0; index < priv->sram_desc.last_cb_index; index++) 1790 for (index = 0; index < priv->sram_desc.last_cb_index; index++)
1772 ipw_fw_dma_write_command_block(priv, index, &priv->sram_desc.cb_list[index]); 1791 ipw_fw_dma_write_command_block(priv, index,
1792 &priv->sram_desc.cb_list[index]);
1773 1793
1774 /* Enable the DMA in the CSR register */ 1794 /* Enable the DMA in the CSR register */
1775 ipw_clear_bit(priv, CX2_RESET_REG,CX2_RESET_REG_MASTER_DISABLED | CX2_RESET_REG_STOP_MASTER); 1795 ipw_clear_bit(priv, CX2_RESET_REG,
1796 CX2_RESET_REG_MASTER_DISABLED |
1797 CX2_RESET_REG_STOP_MASTER);
1776 1798
1777 /* Set the Start bit. */ 1799 /* Set the Start bit. */
1778 control = DMA_CONTROL_SMALL_CB_CONST_VALUE | DMA_CB_START; 1800 control = DMA_CONTROL_SMALL_CB_CONST_VALUE | DMA_CB_START;
1779 ipw_write_reg32(priv, CX2_DMA_I_DMA_CONTROL, control); 1801 ipw_write_reg32(priv, CX2_DMA_I_DMA_CONTROL, control);
1780 1802
@@ -1785,25 +1807,25 @@ static int ipw_fw_dma_kick(struct ipw_priv *priv)
1785static void ipw_fw_dma_dump_command_block(struct ipw_priv *priv) 1807static void ipw_fw_dma_dump_command_block(struct ipw_priv *priv)
1786{ 1808{
1787 u32 address; 1809 u32 address;
1788 u32 register_value=0; 1810 u32 register_value = 0;
1789 u32 cb_fields_address=0; 1811 u32 cb_fields_address = 0;
1790 1812
1791 IPW_DEBUG_FW(">> :\n"); 1813 IPW_DEBUG_FW(">> :\n");
1792 address = ipw_read_reg32(priv,CX2_DMA_I_CURRENT_CB); 1814 address = ipw_read_reg32(priv, CX2_DMA_I_CURRENT_CB);
1793 IPW_DEBUG_FW_INFO("Current CB is 0x%x \n",address); 1815 IPW_DEBUG_FW_INFO("Current CB is 0x%x \n", address);
1794 1816
1795 /* Read the DMA Controlor register */ 1817 /* Read the DMA Controlor register */
1796 register_value = ipw_read_reg32(priv, CX2_DMA_I_DMA_CONTROL); 1818 register_value = ipw_read_reg32(priv, CX2_DMA_I_DMA_CONTROL);
1797 IPW_DEBUG_FW_INFO("CX2_DMA_I_DMA_CONTROL is 0x%x \n",register_value); 1819 IPW_DEBUG_FW_INFO("CX2_DMA_I_DMA_CONTROL is 0x%x \n", register_value);
1798 1820
1799 /* Print the CB values*/ 1821 /* Print the CB values */
1800 cb_fields_address = address; 1822 cb_fields_address = address;
1801 register_value = ipw_read_reg32(priv, cb_fields_address); 1823 register_value = ipw_read_reg32(priv, cb_fields_address);
1802 IPW_DEBUG_FW_INFO("Current CB ControlField is 0x%x \n",register_value); 1824 IPW_DEBUG_FW_INFO("Current CB ControlField is 0x%x \n", register_value);
1803 1825
1804 cb_fields_address += sizeof(u32); 1826 cb_fields_address += sizeof(u32);
1805 register_value = ipw_read_reg32(priv, cb_fields_address); 1827 register_value = ipw_read_reg32(priv, cb_fields_address);
1806 IPW_DEBUG_FW_INFO("Current CB Source Field is 0x%x \n",register_value); 1828 IPW_DEBUG_FW_INFO("Current CB Source Field is 0x%x \n", register_value);
1807 1829
1808 cb_fields_address += sizeof(u32); 1830 cb_fields_address += sizeof(u32);
1809 register_value = ipw_read_reg32(priv, cb_fields_address); 1831 register_value = ipw_read_reg32(priv, cb_fields_address);
@@ -1812,7 +1834,7 @@ static void ipw_fw_dma_dump_command_block(struct ipw_priv *priv)
1812 1834
1813 cb_fields_address += sizeof(u32); 1835 cb_fields_address += sizeof(u32);
1814 register_value = ipw_read_reg32(priv, cb_fields_address); 1836 register_value = ipw_read_reg32(priv, cb_fields_address);
1815 IPW_DEBUG_FW_INFO("Current CB Status Field is 0x%x \n",register_value); 1837 IPW_DEBUG_FW_INFO("Current CB Status Field is 0x%x \n", register_value);
1816 1838
1817 IPW_DEBUG_FW(">> :\n"); 1839 IPW_DEBUG_FW(">> :\n");
1818} 1840}
@@ -1823,13 +1845,13 @@ static int ipw_fw_dma_command_block_index(struct ipw_priv *priv)
1823 u32 current_cb_index = 0; 1845 u32 current_cb_index = 0;
1824 1846
1825 IPW_DEBUG_FW("<< :\n"); 1847 IPW_DEBUG_FW("<< :\n");
1826 current_cb_address= ipw_read_reg32(priv, CX2_DMA_I_CURRENT_CB); 1848 current_cb_address = ipw_read_reg32(priv, CX2_DMA_I_CURRENT_CB);
1827 1849
1828 current_cb_index = (current_cb_address - CX2_SHARED_SRAM_DMA_CONTROL )/ 1850 current_cb_index = (current_cb_address - CX2_SHARED_SRAM_DMA_CONTROL) /
1829 sizeof (struct command_block); 1851 sizeof(struct command_block);
1830 1852
1831 IPW_DEBUG_FW_INFO("Current CB index 0x%x address = 0x%X \n", 1853 IPW_DEBUG_FW_INFO("Current CB index 0x%x address = 0x%X \n",
1832 current_cb_index, current_cb_address ); 1854 current_cb_index, current_cb_address);
1833 1855
1834 IPW_DEBUG_FW(">> :\n"); 1856 IPW_DEBUG_FW(">> :\n");
1835 return current_cb_index; 1857 return current_cb_index;
@@ -1840,15 +1862,14 @@ static int ipw_fw_dma_add_command_block(struct ipw_priv *priv,
1840 u32 src_address, 1862 u32 src_address,
1841 u32 dest_address, 1863 u32 dest_address,
1842 u32 length, 1864 u32 length,
1843 int interrupt_enabled, 1865 int interrupt_enabled, int is_last)
1844 int is_last)
1845{ 1866{
1846 1867
1847 u32 control = CB_VALID | CB_SRC_LE | CB_DEST_LE | CB_SRC_AUTOINC | 1868 u32 control = CB_VALID | CB_SRC_LE | CB_DEST_LE | CB_SRC_AUTOINC |
1848 CB_SRC_IO_GATED | CB_DEST_AUTOINC | CB_SRC_SIZE_LONG | 1869 CB_SRC_IO_GATED | CB_DEST_AUTOINC | CB_SRC_SIZE_LONG |
1849 CB_DEST_SIZE_LONG; 1870 CB_DEST_SIZE_LONG;
1850 struct command_block *cb; 1871 struct command_block *cb;
1851 u32 last_cb_element=0; 1872 u32 last_cb_element = 0;
1852 1873
1853 IPW_DEBUG_FW_INFO("src_address=0x%x dest_address=0x%x length=0x%x\n", 1874 IPW_DEBUG_FW_INFO("src_address=0x%x dest_address=0x%x length=0x%x\n",
1854 src_address, dest_address, length); 1875 src_address, dest_address, length);
@@ -1861,7 +1882,7 @@ static int ipw_fw_dma_add_command_block(struct ipw_priv *priv,
1861 priv->sram_desc.last_cb_index++; 1882 priv->sram_desc.last_cb_index++;
1862 1883
1863 /* Calculate the new CB control word */ 1884 /* Calculate the new CB control word */
1864 if (interrupt_enabled ) 1885 if (interrupt_enabled)
1865 control |= CB_INT_ENABLED; 1886 control |= CB_INT_ENABLED;
1866 1887
1867 if (is_last) 1888 if (is_last)
@@ -1870,7 +1891,7 @@ static int ipw_fw_dma_add_command_block(struct ipw_priv *priv,
1870 control |= length; 1891 control |= length;
1871 1892
1872 /* Calculate the CB Element's checksum value */ 1893 /* Calculate the CB Element's checksum value */
1873 cb->status = control ^src_address ^dest_address; 1894 cb->status = control ^ src_address ^ dest_address;
1874 1895
1875 /* Copy the Source and Destination addresses */ 1896 /* Copy the Source and Destination addresses */
1876 cb->dest_addr = dest_address; 1897 cb->dest_addr = dest_address;
@@ -1883,22 +1904,21 @@ static int ipw_fw_dma_add_command_block(struct ipw_priv *priv,
1883} 1904}
1884 1905
1885static int ipw_fw_dma_add_buffer(struct ipw_priv *priv, 1906static int ipw_fw_dma_add_buffer(struct ipw_priv *priv,
1886 u32 src_phys, 1907 u32 src_phys, u32 dest_address, u32 length)
1887 u32 dest_address,
1888 u32 length)
1889{ 1908{
1890 u32 bytes_left = length; 1909 u32 bytes_left = length;
1891 u32 src_offset=0; 1910 u32 src_offset = 0;
1892 u32 dest_offset=0; 1911 u32 dest_offset = 0;
1893 int status = 0; 1912 int status = 0;
1894 IPW_DEBUG_FW(">> \n"); 1913 IPW_DEBUG_FW(">> \n");
1895 IPW_DEBUG_FW_INFO("src_phys=0x%x dest_address=0x%x length=0x%x\n", 1914 IPW_DEBUG_FW_INFO("src_phys=0x%x dest_address=0x%x length=0x%x\n",
1896 src_phys, dest_address, length); 1915 src_phys, dest_address, length);
1897 while (bytes_left > CB_MAX_LENGTH) { 1916 while (bytes_left > CB_MAX_LENGTH) {
1898 status = ipw_fw_dma_add_command_block( priv, 1917 status = ipw_fw_dma_add_command_block(priv,
1899 src_phys + src_offset, 1918 src_phys + src_offset,
1900 dest_address + dest_offset, 1919 dest_address +
1901 CB_MAX_LENGTH, 0, 0); 1920 dest_offset,
1921 CB_MAX_LENGTH, 0, 0);
1902 if (status) { 1922 if (status) {
1903 IPW_DEBUG_FW_INFO(": Failed\n"); 1923 IPW_DEBUG_FW_INFO(": Failed\n");
1904 return -1; 1924 return -1;
@@ -1912,18 +1932,18 @@ static int ipw_fw_dma_add_buffer(struct ipw_priv *priv,
1912 1932
1913 /* add the buffer tail */ 1933 /* add the buffer tail */
1914 if (bytes_left > 0) { 1934 if (bytes_left > 0) {
1915 status = ipw_fw_dma_add_command_block( 1935 status =
1916 priv, src_phys + src_offset, 1936 ipw_fw_dma_add_command_block(priv, src_phys + src_offset,
1917 dest_address + dest_offset, 1937 dest_address + dest_offset,
1918 bytes_left, 0, 0); 1938 bytes_left, 0, 0);
1919 if (status) { 1939 if (status) {
1920 IPW_DEBUG_FW_INFO(": Failed on the buffer tail\n"); 1940 IPW_DEBUG_FW_INFO(": Failed on the buffer tail\n");
1921 return -1; 1941 return -1;
1922 } else 1942 } else
1923 IPW_DEBUG_FW_INFO(": Adding new cb - the buffer tail\n"); 1943 IPW_DEBUG_FW_INFO
1944 (": Adding new cb - the buffer tail\n");
1924 } 1945 }
1925 1946
1926
1927 IPW_DEBUG_FW("<< \n"); 1947 IPW_DEBUG_FW("<< \n");
1928 return 0; 1948 return 0;
1929} 1949}
@@ -1937,7 +1957,7 @@ static int ipw_fw_dma_wait(struct ipw_priv *priv)
1937 1957
1938 current_index = ipw_fw_dma_command_block_index(priv); 1958 current_index = ipw_fw_dma_command_block_index(priv);
1939 IPW_DEBUG_FW_INFO("sram_desc.last_cb_index:0x%8X\n", 1959 IPW_DEBUG_FW_INFO("sram_desc.last_cb_index:0x%8X\n",
1940 (int) priv->sram_desc.last_cb_index); 1960 (int)priv->sram_desc.last_cb_index);
1941 1961
1942 while (current_index < priv->sram_desc.last_cb_index) { 1962 while (current_index < priv->sram_desc.last_cb_index) {
1943 udelay(50); 1963 udelay(50);
@@ -1955,8 +1975,8 @@ static int ipw_fw_dma_wait(struct ipw_priv *priv)
1955 1975
1956 ipw_fw_dma_abort(priv); 1976 ipw_fw_dma_abort(priv);
1957 1977
1958 /*Disable the DMA in the CSR register*/ 1978 /*Disable the DMA in the CSR register */
1959 ipw_set_bit(priv, CX2_RESET_REG, 1979 ipw_set_bit(priv, CX2_RESET_REG,
1960 CX2_RESET_REG_MASTER_DISABLED | CX2_RESET_REG_STOP_MASTER); 1980 CX2_RESET_REG_MASTER_DISABLED | CX2_RESET_REG_STOP_MASTER);
1961 1981
1962 IPW_DEBUG_FW("<< dmaWaitSync \n"); 1982 IPW_DEBUG_FW("<< dmaWaitSync \n");
@@ -2011,8 +2031,7 @@ static inline int ipw_poll_bit(struct ipw_priv *priv, u32 addr, u32 mask,
2011 * image and the caller is handling the memory allocation and clean up. 2031 * image and the caller is handling the memory allocation and clean up.
2012 */ 2032 */
2013 2033
2014 2034static int ipw_stop_master(struct ipw_priv *priv)
2015static int ipw_stop_master(struct ipw_priv * priv)
2016{ 2035{
2017 int rc; 2036 int rc;
2018 2037
@@ -2071,14 +2090,13 @@ struct fw_chunk {
2071#define IPW_FW_NAME(x) "ipw2200_" x ".fw" 2090#define IPW_FW_NAME(x) "ipw2200_" x ".fw"
2072#endif 2091#endif
2073 2092
2074static int ipw_load_ucode(struct ipw_priv *priv, u8 * data, 2093static int ipw_load_ucode(struct ipw_priv *priv, u8 * data, size_t len)
2075 size_t len)
2076{ 2094{
2077 int rc = 0, i, addr; 2095 int rc = 0, i, addr;
2078 u8 cr = 0; 2096 u8 cr = 0;
2079 u16 *image; 2097 u16 *image;
2080 2098
2081 image = (u16 *)data; 2099 image = (u16 *) data;
2082 2100
2083 IPW_DEBUG_TRACE(">> \n"); 2101 IPW_DEBUG_TRACE(">> \n");
2084 2102
@@ -2087,7 +2105,7 @@ static int ipw_load_ucode(struct ipw_priv *priv, u8 * data,
2087 if (rc < 0) 2105 if (rc < 0)
2088 return rc; 2106 return rc;
2089 2107
2090// spin_lock_irqsave(&priv->lock, flags); 2108// spin_lock_irqsave(&priv->lock, flags);
2091 2109
2092 for (addr = CX2_SHARED_LOWER_BOUND; 2110 for (addr = CX2_SHARED_LOWER_BOUND;
2093 addr < CX2_REGISTER_DOMAIN1_END; addr += 4) { 2111 addr < CX2_REGISTER_DOMAIN1_END; addr += 4) {
@@ -2099,7 +2117,7 @@ static int ipw_load_ucode(struct ipw_priv *priv, u8 * data,
2099 /* destroy DMA queues */ 2117 /* destroy DMA queues */
2100 /* reset sequence */ 2118 /* reset sequence */
2101 2119
2102 ipw_write_reg32(priv, CX2_MEM_HALT_AND_RESET ,CX2_BIT_HALT_RESET_ON); 2120 ipw_write_reg32(priv, CX2_MEM_HALT_AND_RESET, CX2_BIT_HALT_RESET_ON);
2103 ipw_arc_release(priv); 2121 ipw_arc_release(priv);
2104 ipw_write_reg32(priv, CX2_MEM_HALT_AND_RESET, CX2_BIT_HALT_RESET_OFF); 2122 ipw_write_reg32(priv, CX2_MEM_HALT_AND_RESET, CX2_BIT_HALT_RESET_OFF);
2105 mdelay(1); 2123 mdelay(1);
@@ -2128,13 +2146,11 @@ static int ipw_load_ucode(struct ipw_priv *priv, u8 * data,
2128 for (i = 0; i < len / 2; i++) 2146 for (i = 0; i < len / 2; i++)
2129 ipw_write_reg16(priv, CX2_BASEBAND_CONTROL_STORE, image[i]); 2147 ipw_write_reg16(priv, CX2_BASEBAND_CONTROL_STORE, image[i]);
2130 2148
2131
2132 /* enable DINO */ 2149 /* enable DINO */
2133 ipw_write_reg8(priv, CX2_BASEBAND_CONTROL_STATUS, 0); 2150 ipw_write_reg8(priv, CX2_BASEBAND_CONTROL_STATUS, 0);
2134 ipw_write_reg8(priv, CX2_BASEBAND_CONTROL_STATUS, 2151 ipw_write_reg8(priv, CX2_BASEBAND_CONTROL_STATUS, DINO_ENABLE_SYSTEM);
2135 DINO_ENABLE_SYSTEM );
2136 2152
2137 /* this is where the igx / win driver deveates from the VAP driver.*/ 2153 /* this is where the igx / win driver deveates from the VAP driver. */
2138 2154
2139 /* wait for alive response */ 2155 /* wait for alive response */
2140 for (i = 0; i < 100; i++) { 2156 for (i = 0; i < 100; i++) {
@@ -2151,25 +2167,24 @@ static int ipw_load_ucode(struct ipw_priv *priv, u8 * data,
2151 2167
2152 for (i = 0; i < ARRAY_SIZE(response_buffer); i++) 2168 for (i = 0; i < ARRAY_SIZE(response_buffer); i++)
2153 response_buffer[i] = 2169 response_buffer[i] =
2154 ipw_read_reg32(priv, 2170 ipw_read_reg32(priv, CX2_BASEBAND_RX_FIFO_READ);
2155 CX2_BASEBAND_RX_FIFO_READ);
2156 memcpy(&priv->dino_alive, response_buffer, 2171 memcpy(&priv->dino_alive, response_buffer,
2157 sizeof(priv->dino_alive)); 2172 sizeof(priv->dino_alive));
2158 if (priv->dino_alive.alive_command == 1 2173 if (priv->dino_alive.alive_command == 1
2159 && priv->dino_alive.ucode_valid == 1) { 2174 && priv->dino_alive.ucode_valid == 1) {
2160 rc = 0; 2175 rc = 0;
2161 IPW_DEBUG_INFO( 2176 IPW_DEBUG_INFO
2162 "Microcode OK, rev. %d (0x%x) dev. %d (0x%x) " 2177 ("Microcode OK, rev. %d (0x%x) dev. %d (0x%x) "
2163 "of %02d/%02d/%02d %02d:%02d\n", 2178 "of %02d/%02d/%02d %02d:%02d\n",
2164 priv->dino_alive.software_revision, 2179 priv->dino_alive.software_revision,
2165 priv->dino_alive.software_revision, 2180 priv->dino_alive.software_revision,
2166 priv->dino_alive.device_identifier, 2181 priv->dino_alive.device_identifier,
2167 priv->dino_alive.device_identifier, 2182 priv->dino_alive.device_identifier,
2168 priv->dino_alive.time_stamp[0], 2183 priv->dino_alive.time_stamp[0],
2169 priv->dino_alive.time_stamp[1], 2184 priv->dino_alive.time_stamp[1],
2170 priv->dino_alive.time_stamp[2], 2185 priv->dino_alive.time_stamp[2],
2171 priv->dino_alive.time_stamp[3], 2186 priv->dino_alive.time_stamp[3],
2172 priv->dino_alive.time_stamp[4]); 2187 priv->dino_alive.time_stamp[4]);
2173 } else { 2188 } else {
2174 IPW_DEBUG_INFO("Microcode is not alive\n"); 2189 IPW_DEBUG_INFO("Microcode is not alive\n");
2175 rc = -EINVAL; 2190 rc = -EINVAL;
@@ -2183,13 +2198,12 @@ static int ipw_load_ucode(struct ipw_priv *priv, u8 * data,
2183 firmware have problem getting alive resp. */ 2198 firmware have problem getting alive resp. */
2184 ipw_write_reg8(priv, CX2_BASEBAND_CONTROL_STATUS, 0); 2199 ipw_write_reg8(priv, CX2_BASEBAND_CONTROL_STATUS, 0);
2185 2200
2186// spin_unlock_irqrestore(&priv->lock, flags); 2201// spin_unlock_irqrestore(&priv->lock, flags);
2187 2202
2188 return rc; 2203 return rc;
2189} 2204}
2190 2205
2191static int ipw_load_firmware(struct ipw_priv *priv, u8 * data, 2206static int ipw_load_firmware(struct ipw_priv *priv, u8 * data, size_t len)
2192 size_t len)
2193{ 2207{
2194 int rc = -1; 2208 int rc = -1;
2195 int offset = 0; 2209 int offset = 0;
@@ -2231,7 +2245,7 @@ static int ipw_load_firmware(struct ipw_priv *priv, u8 * data,
2231 offset += chunk->length; 2245 offset += chunk->length;
2232 } while (offset < len); 2246 } while (offset < len);
2233 2247
2234 /* Run the DMA and wait for the answer*/ 2248 /* Run the DMA and wait for the answer */
2235 rc = ipw_fw_dma_kick(priv); 2249 rc = ipw_fw_dma_kick(priv);
2236 if (rc) { 2250 if (rc) {
2237 IPW_ERROR("dmaKick Failed\n"); 2251 IPW_ERROR("dmaKick Failed\n");
@@ -2243,8 +2257,8 @@ static int ipw_load_firmware(struct ipw_priv *priv, u8 * data,
2243 IPW_ERROR("dmaWaitSync Failed\n"); 2257 IPW_ERROR("dmaWaitSync Failed\n");
2244 goto out; 2258 goto out;
2245 } 2259 }
2246 out: 2260 out:
2247 pci_free_consistent( priv->pci_dev, len, shared_virt, shared_phys); 2261 pci_free_consistent(priv->pci_dev, len, shared_virt, shared_phys);
2248 return rc; 2262 return rc;
2249} 2263}
2250 2264
@@ -2253,7 +2267,7 @@ static int ipw_stop_nic(struct ipw_priv *priv)
2253{ 2267{
2254 int rc = 0; 2268 int rc = 0;
2255 2269
2256 /* stop*/ 2270 /* stop */
2257 ipw_write32(priv, CX2_RESET_REG, CX2_RESET_REG_STOP_MASTER); 2271 ipw_write32(priv, CX2_RESET_REG, CX2_RESET_REG_STOP_MASTER);
2258 2272
2259 rc = ipw_poll_bit(priv, CX2_RESET_REG, 2273 rc = ipw_poll_bit(priv, CX2_RESET_REG,
@@ -2272,14 +2286,15 @@ static void ipw_start_nic(struct ipw_priv *priv)
2272{ 2286{
2273 IPW_DEBUG_TRACE(">>\n"); 2287 IPW_DEBUG_TRACE(">>\n");
2274 2288
2275 /* prvHwStartNic release ARC*/ 2289 /* prvHwStartNic release ARC */
2276 ipw_clear_bit(priv, CX2_RESET_REG, 2290 ipw_clear_bit(priv, CX2_RESET_REG,
2277 CX2_RESET_REG_MASTER_DISABLED | 2291 CX2_RESET_REG_MASTER_DISABLED |
2278 CX2_RESET_REG_STOP_MASTER | 2292 CX2_RESET_REG_STOP_MASTER |
2279 CBD_RESET_REG_PRINCETON_RESET); 2293 CBD_RESET_REG_PRINCETON_RESET);
2280 2294
2281 /* enable power management */ 2295 /* enable power management */
2282 ipw_set_bit(priv, CX2_GP_CNTRL_RW, CX2_GP_CNTRL_BIT_HOST_ALLOWS_STANDBY); 2296 ipw_set_bit(priv, CX2_GP_CNTRL_RW,
2297 CX2_GP_CNTRL_BIT_HOST_ALLOWS_STANDBY);
2283 2298
2284 IPW_DEBUG_TRACE("<<\n"); 2299 IPW_DEBUG_TRACE("<<\n");
2285} 2300}
@@ -2295,12 +2310,13 @@ static int ipw_init_nic(struct ipw_priv *priv)
2295 ipw_set_bit(priv, CX2_GP_CNTRL_RW, CX2_GP_CNTRL_BIT_INIT_DONE); 2310 ipw_set_bit(priv, CX2_GP_CNTRL_RW, CX2_GP_CNTRL_BIT_INIT_DONE);
2296 2311
2297 /* low-level PLL activation */ 2312 /* low-level PLL activation */
2298 ipw_write32(priv, CX2_READ_INT_REGISTER, CX2_BIT_INT_HOST_SRAM_READ_INT_REGISTER); 2313 ipw_write32(priv, CX2_READ_INT_REGISTER,
2314 CX2_BIT_INT_HOST_SRAM_READ_INT_REGISTER);
2299 2315
2300 /* wait for clock stabilization */ 2316 /* wait for clock stabilization */
2301 rc = ipw_poll_bit(priv, CX2_GP_CNTRL_RW, 2317 rc = ipw_poll_bit(priv, CX2_GP_CNTRL_RW,
2302 CX2_GP_CNTRL_BIT_CLOCK_READY, 250); 2318 CX2_GP_CNTRL_BIT_CLOCK_READY, 250);
2303 if (rc < 0 ) 2319 if (rc < 0)
2304 IPW_DEBUG_INFO("FAILED wait for clock stablization\n"); 2320 IPW_DEBUG_INFO("FAILED wait for clock stablization\n");
2305 2321
2306 /* assert SW reset */ 2322 /* assert SW reset */
@@ -2315,7 +2331,6 @@ static int ipw_init_nic(struct ipw_priv *priv)
2315 return 0; 2331 return 0;
2316} 2332}
2317 2333
2318
2319/* Call this function from process context, it will sleep in request_firmware. 2334/* Call this function from process context, it will sleep in request_firmware.
2320 * Probe is an ok place to call this from. 2335 * Probe is an ok place to call this from.
2321 */ 2336 */
@@ -2383,8 +2398,7 @@ static inline void ipw_rx_queue_reset(struct ipw_priv *priv,
2383 * to an SKB, so we need to unmap and free potential storage */ 2398 * to an SKB, so we need to unmap and free potential storage */
2384 if (rxq->pool[i].skb != NULL) { 2399 if (rxq->pool[i].skb != NULL) {
2385 pci_unmap_single(priv->pci_dev, rxq->pool[i].dma_addr, 2400 pci_unmap_single(priv->pci_dev, rxq->pool[i].dma_addr,
2386 CX2_RX_BUF_SIZE, 2401 CX2_RX_BUF_SIZE, PCI_DMA_FROMDEVICE);
2387 PCI_DMA_FROMDEVICE);
2388 dev_kfree_skb(rxq->pool[i].skb); 2402 dev_kfree_skb(rxq->pool[i].skb);
2389 } 2403 }
2390 list_add_tail(&rxq->pool[i].list, &rxq->rx_used); 2404 list_add_tail(&rxq->pool[i].list, &rxq->rx_used);
@@ -2438,12 +2452,12 @@ static int ipw_load(struct ipw_priv *priv)
2438 if (rc) 2452 if (rc)
2439 goto error; 2453 goto error;
2440 2454
2441 rc = ipw_get_fw(priv, &firmware, IPW_FW_NAME("sniffer")); 2455 rc = ipw_get_fw(priv, &firmware,
2456 IPW_FW_NAME("sniffer"));
2442 break; 2457 break;
2443#endif 2458#endif
2444 case IW_MODE_INFRA: 2459 case IW_MODE_INFRA:
2445 rc = ipw_get_fw(priv, &ucode, 2460 rc = ipw_get_fw(priv, &ucode, IPW_FW_NAME("bss_ucode"));
2446 IPW_FW_NAME("bss_ucode"));
2447 if (rc) 2461 if (rc)
2448 goto error; 2462 goto error;
2449 2463
@@ -2471,7 +2485,7 @@ static int ipw_load(struct ipw_priv *priv)
2471 goto error; 2485 goto error;
2472 } 2486 }
2473 2487
2474 retry: 2488 retry:
2475 /* Ensure interrupts are disabled */ 2489 /* Ensure interrupts are disabled */
2476 ipw_write32(priv, CX2_INTA_MASK_R, ~CX2_INTA_MASK_ALL); 2490 ipw_write32(priv, CX2_INTA_MASK_R, ~CX2_INTA_MASK_ALL);
2477 priv->status &= ~STATUS_INT_ENABLED; 2491 priv->status &= ~STATUS_INT_ENABLED;
@@ -2528,7 +2542,7 @@ static int ipw_load(struct ipw_priv *priv)
2528 rc = ipw_load_firmware(priv, firmware->data + 2542 rc = ipw_load_firmware(priv, firmware->data +
2529 sizeof(struct fw_header), 2543 sizeof(struct fw_header),
2530 firmware->size - sizeof(struct fw_header)); 2544 firmware->size - sizeof(struct fw_header));
2531 if (rc < 0 ) { 2545 if (rc < 0) {
2532 IPW_ERROR("Unable to load firmware\n"); 2546 IPW_ERROR("Unable to load firmware\n");
2533 goto error; 2547 goto error;
2534 } 2548 }
@@ -2593,7 +2607,7 @@ static int ipw_load(struct ipw_priv *priv)
2593#endif 2607#endif
2594 return 0; 2608 return 0;
2595 2609
2596 error: 2610 error:
2597 if (priv->rxq) { 2611 if (priv->rxq) {
2598 ipw_rx_queue_free(priv, priv->rxq); 2612 ipw_rx_queue_free(priv, priv->rxq);
2599 priv->rxq = NULL; 2613 priv->rxq = NULL;
@@ -2671,8 +2685,7 @@ static inline int ipw_queue_inc_wrap(int index, int n_bd)
2671 * (not offset within BAR, full address) 2685 * (not offset within BAR, full address)
2672 */ 2686 */
2673static void ipw_queue_init(struct ipw_priv *priv, struct clx2_queue *q, 2687static void ipw_queue_init(struct ipw_priv *priv, struct clx2_queue *q,
2674 int count, u32 read, u32 write, 2688 int count, u32 read, u32 write, u32 base, u32 size)
2675 u32 base, u32 size)
2676{ 2689{
2677 q->n_bd = count; 2690 q->n_bd = count;
2678 2691
@@ -2698,8 +2711,7 @@ static void ipw_queue_init(struct ipw_priv *priv, struct clx2_queue *q,
2698 2711
2699static int ipw_queue_tx_init(struct ipw_priv *priv, 2712static int ipw_queue_tx_init(struct ipw_priv *priv,
2700 struct clx2_tx_queue *q, 2713 struct clx2_tx_queue *q,
2701 int count, u32 read, u32 write, 2714 int count, u32 read, u32 write, u32 base, u32 size)
2702 u32 base, u32 size)
2703{ 2715{
2704 struct pci_dev *dev = priv->pci_dev; 2716 struct pci_dev *dev = priv->pci_dev;
2705 2717
@@ -2709,10 +2721,11 @@ static int ipw_queue_tx_init(struct ipw_priv *priv,
2709 return -ENOMEM; 2721 return -ENOMEM;
2710 } 2722 }
2711 2723
2712 q->bd = pci_alloc_consistent(dev,sizeof(q->bd[0])*count, &q->q.dma_addr); 2724 q->bd =
2725 pci_alloc_consistent(dev, sizeof(q->bd[0]) * count, &q->q.dma_addr);
2713 if (!q->bd) { 2726 if (!q->bd) {
2714 IPW_ERROR("pci_alloc_consistent(%zd) failed\n", 2727 IPW_ERROR("pci_alloc_consistent(%zd) failed\n",
2715 sizeof(q->bd[0]) * count); 2728 sizeof(q->bd[0]) * count);
2716 kfree(q->txb); 2729 kfree(q->txb);
2717 q->txb = NULL; 2730 q->txb = NULL;
2718 return -ENOMEM; 2731 return -ENOMEM;
@@ -2768,8 +2781,7 @@ static void ipw_queue_tx_free_tfd(struct ipw_priv *priv,
2768 * @param dev 2781 * @param dev
2769 * @param q 2782 * @param q
2770 */ 2783 */
2771static void ipw_queue_tx_free(struct ipw_priv *priv, 2784static void ipw_queue_tx_free(struct ipw_priv *priv, struct clx2_tx_queue *txq)
2772 struct clx2_tx_queue *txq)
2773{ 2785{
2774 struct clx2_queue *q = &txq->q; 2786 struct clx2_queue *q = &txq->q;
2775 struct pci_dev *dev = priv->pci_dev; 2787 struct pci_dev *dev = priv->pci_dev;
@@ -2784,7 +2796,7 @@ static void ipw_queue_tx_free(struct ipw_priv *priv,
2784 } 2796 }
2785 2797
2786 /* free buffers belonging to queue itself */ 2798 /* free buffers belonging to queue itself */
2787 pci_free_consistent(dev, sizeof(txq->bd[0])*q->n_bd, txq->bd, 2799 pci_free_consistent(dev, sizeof(txq->bd[0]) * q->n_bd, txq->bd,
2788 q->dma_addr); 2800 q->dma_addr);
2789 kfree(txq->txb); 2801 kfree(txq->txb);
2790 2802
@@ -2792,7 +2804,6 @@ static void ipw_queue_tx_free(struct ipw_priv *priv,
2792 memset(txq, 0, sizeof(*txq)); 2804 memset(txq, 0, sizeof(*txq));
2793} 2805}
2794 2806
2795
2796/** 2807/**
2797 * Destroy all DMA queues and structures 2808 * Destroy all DMA queues and structures
2798 * 2809 *
@@ -2825,7 +2836,7 @@ static void inline __maybe_wake_tx(struct ipw_priv *priv)
2825 2836
2826} 2837}
2827 2838
2828static inline void ipw_create_bssid(struct ipw_priv *priv, u8 *bssid) 2839static inline void ipw_create_bssid(struct ipw_priv *priv, u8 * bssid)
2829{ 2840{
2830 /* First 3 bytes are manufacturer */ 2841 /* First 3 bytes are manufacturer */
2831 bssid[0] = priv->mac_addr[0]; 2842 bssid[0] = priv->mac_addr[0];
@@ -2833,13 +2844,13 @@ static inline void ipw_create_bssid(struct ipw_priv *priv, u8 *bssid)
2833 bssid[2] = priv->mac_addr[2]; 2844 bssid[2] = priv->mac_addr[2];
2834 2845
2835 /* Last bytes are random */ 2846 /* Last bytes are random */
2836 get_random_bytes(&bssid[3], ETH_ALEN-3); 2847 get_random_bytes(&bssid[3], ETH_ALEN - 3);
2837 2848
2838 bssid[0] &= 0xfe; /* clear multicast bit */ 2849 bssid[0] &= 0xfe; /* clear multicast bit */
2839 bssid[0] |= 0x02; /* set local assignment bit (IEEE802) */ 2850 bssid[0] |= 0x02; /* set local assignment bit (IEEE802) */
2840} 2851}
2841 2852
2842static inline u8 ipw_add_station(struct ipw_priv *priv, u8 *bssid) 2853static inline u8 ipw_add_station(struct ipw_priv *priv, u8 * bssid)
2843{ 2854{
2844 struct ipw_station_entry entry; 2855 struct ipw_station_entry entry;
2845 int i; 2856 int i;
@@ -2866,14 +2877,13 @@ static inline u8 ipw_add_station(struct ipw_priv *priv, u8 *bssid)
2866 memcpy(entry.mac_addr, bssid, ETH_ALEN); 2877 memcpy(entry.mac_addr, bssid, ETH_ALEN);
2867 memcpy(priv->stations[i], bssid, ETH_ALEN); 2878 memcpy(priv->stations[i], bssid, ETH_ALEN);
2868 ipw_write_direct(priv, IPW_STATION_TABLE_LOWER + i * sizeof(entry), 2879 ipw_write_direct(priv, IPW_STATION_TABLE_LOWER + i * sizeof(entry),
2869 &entry, 2880 &entry, sizeof(entry));
2870 sizeof(entry));
2871 priv->num_stations++; 2881 priv->num_stations++;
2872 2882
2873 return i; 2883 return i;
2874} 2884}
2875 2885
2876static inline u8 ipw_find_station(struct ipw_priv *priv, u8 *bssid) 2886static inline u8 ipw_find_station(struct ipw_priv *priv, u8 * bssid)
2877{ 2887{
2878 int i; 2888 int i;
2879 2889
@@ -2944,26 +2954,34 @@ static const struct ipw_status_code ipw_status_codes[] = {
2944 "association exists"}, 2954 "association exists"},
2945 {0x0C, "Association denied due to reason outside the scope of this " 2955 {0x0C, "Association denied due to reason outside the scope of this "
2946 "standard"}, 2956 "standard"},
2947 {0x0D, "Responding station does not support the specified authentication " 2957 {0x0D,
2958 "Responding station does not support the specified authentication "
2948 "algorithm"}, 2959 "algorithm"},
2949 {0x0E, "Received an Authentication frame with authentication sequence " 2960 {0x0E,
2961 "Received an Authentication frame with authentication sequence "
2950 "transaction sequence number out of expected sequence"}, 2962 "transaction sequence number out of expected sequence"},
2951 {0x0F, "Authentication rejected because of challenge failure"}, 2963 {0x0F, "Authentication rejected because of challenge failure"},
2952 {0x10, "Authentication rejected due to timeout waiting for next " 2964 {0x10, "Authentication rejected due to timeout waiting for next "
2953 "frame in sequence"}, 2965 "frame in sequence"},
2954 {0x11, "Association denied because AP is unable to handle additional " 2966 {0x11, "Association denied because AP is unable to handle additional "
2955 "associated stations"}, 2967 "associated stations"},
2956 {0x12, "Association denied due to requesting station not supporting all " 2968 {0x12,
2969 "Association denied due to requesting station not supporting all "
2957 "of the datarates in the BSSBasicServiceSet Parameter"}, 2970 "of the datarates in the BSSBasicServiceSet Parameter"},
2958 {0x13, "Association denied due to requesting station not supporting " 2971 {0x13,
2972 "Association denied due to requesting station not supporting "
2959 "short preamble operation"}, 2973 "short preamble operation"},
2960 {0x14, "Association denied due to requesting station not supporting " 2974 {0x14,
2975 "Association denied due to requesting station not supporting "
2961 "PBCC encoding"}, 2976 "PBCC encoding"},
2962 {0x15, "Association denied due to requesting station not supporting " 2977 {0x15,
2978 "Association denied due to requesting station not supporting "
2963 "channel agility"}, 2979 "channel agility"},
2964 {0x19, "Association denied due to requesting station not supporting " 2980 {0x19,
2981 "Association denied due to requesting station not supporting "
2965 "short slot operation"}, 2982 "short slot operation"},
2966 {0x1A, "Association denied due to requesting station not supporting " 2983 {0x1A,
2984 "Association denied due to requesting station not supporting "
2967 "DSSS-OFDM operation"}, 2985 "DSSS-OFDM operation"},
2968 {0x28, "Invalid Information Element"}, 2986 {0x28, "Invalid Information Element"},
2969 {0x29, "Group Cipher is not valid"}, 2987 {0x29, "Group Cipher is not valid"},
@@ -3043,7 +3061,6 @@ static void ipw_reset_stats(struct ipw_priv *priv)
3043 3061
3044} 3062}
3045 3063
3046
3047static inline u32 ipw_get_max_rate(struct ipw_priv *priv) 3064static inline u32 ipw_get_max_rate(struct ipw_priv *priv)
3048{ 3065{
3049 u32 i = 0x80000000; 3066 u32 i = 0x80000000;
@@ -3056,20 +3073,21 @@ static inline u32 ipw_get_max_rate(struct ipw_priv *priv)
3056 /* TODO: Verify that the rate is supported by the current rates 3073 /* TODO: Verify that the rate is supported by the current rates
3057 * list. */ 3074 * list. */
3058 3075
3059 while (i && !(mask & i)) i >>= 1; 3076 while (i && !(mask & i))
3077 i >>= 1;
3060 switch (i) { 3078 switch (i) {
3061 case IEEE80211_CCK_RATE_1MB_MASK: return 1000000; 3079 case IEEE80211_CCK_RATE_1MB_MASK: return 1000000;
3062 case IEEE80211_CCK_RATE_2MB_MASK: return 2000000; 3080 case IEEE80211_CCK_RATE_2MB_MASK: return 2000000;
3063 case IEEE80211_CCK_RATE_5MB_MASK: return 5500000; 3081 case IEEE80211_CCK_RATE_5MB_MASK: return 5500000;
3064 case IEEE80211_OFDM_RATE_6MB_MASK: return 6000000; 3082 case IEEE80211_OFDM_RATE_6MB_MASK: return 6000000;
3065 case IEEE80211_OFDM_RATE_9MB_MASK: return 9000000; 3083 case IEEE80211_OFDM_RATE_9MB_MASK: return 9000000;
3066 case IEEE80211_CCK_RATE_11MB_MASK: return 11000000; 3084 case IEEE80211_CCK_RATE_11MB_MASK: return 11000000;
3067 case IEEE80211_OFDM_RATE_12MB_MASK: return 12000000; 3085 case IEEE80211_OFDM_RATE_12MB_MASK: return 12000000;
3068 case IEEE80211_OFDM_RATE_18MB_MASK: return 18000000; 3086 case IEEE80211_OFDM_RATE_18MB_MASK: return 18000000;
3069 case IEEE80211_OFDM_RATE_24MB_MASK: return 24000000; 3087 case IEEE80211_OFDM_RATE_24MB_MASK: return 24000000;
3070 case IEEE80211_OFDM_RATE_36MB_MASK: return 36000000; 3088 case IEEE80211_OFDM_RATE_36MB_MASK: return 36000000;
3071 case IEEE80211_OFDM_RATE_48MB_MASK: return 48000000; 3089 case IEEE80211_OFDM_RATE_48MB_MASK: return 48000000;
3072 case IEEE80211_OFDM_RATE_54MB_MASK: return 54000000; 3090 case IEEE80211_OFDM_RATE_54MB_MASK: return 54000000;
3073 } 3091 }
3074 3092
3075 if (priv->ieee->mode == IEEE_B) 3093 if (priv->ieee->mode == IEEE_B)
@@ -3097,18 +3115,18 @@ static u32 ipw_get_current_rate(struct ipw_priv *priv)
3097 return ipw_get_max_rate(priv); 3115 return ipw_get_max_rate(priv);
3098 3116
3099 switch (rate) { 3117 switch (rate) {
3100 case IPW_TX_RATE_1MB: return 1000000; 3118 case IPW_TX_RATE_1MB: return 1000000;
3101 case IPW_TX_RATE_2MB: return 2000000; 3119 case IPW_TX_RATE_2MB: return 2000000;
3102 case IPW_TX_RATE_5MB: return 5500000; 3120 case IPW_TX_RATE_5MB: return 5500000;
3103 case IPW_TX_RATE_6MB: return 6000000; 3121 case IPW_TX_RATE_6MB: return 6000000;
3104 case IPW_TX_RATE_9MB: return 9000000; 3122 case IPW_TX_RATE_9MB: return 9000000;
3105 case IPW_TX_RATE_11MB: return 11000000; 3123 case IPW_TX_RATE_11MB: return 11000000;
3106 case IPW_TX_RATE_12MB: return 12000000; 3124 case IPW_TX_RATE_12MB: return 12000000;
3107 case IPW_TX_RATE_18MB: return 18000000; 3125 case IPW_TX_RATE_18MB: return 18000000;
3108 case IPW_TX_RATE_24MB: return 24000000; 3126 case IPW_TX_RATE_24MB: return 24000000;
3109 case IPW_TX_RATE_36MB: return 36000000; 3127 case IPW_TX_RATE_36MB: return 36000000;
3110 case IPW_TX_RATE_48MB: return 48000000; 3128 case IPW_TX_RATE_48MB: return 48000000;
3111 case IPW_TX_RATE_54MB: return 54000000; 3129 case IPW_TX_RATE_54MB: return 54000000;
3112 } 3130 }
3113 3131
3114 return 0; 3132 return 0;
@@ -3126,7 +3144,7 @@ static void ipw_gather_stats(struct ipw_priv *priv)
3126 u32 len = sizeof(u32); 3144 u32 len = sizeof(u32);
3127 s16 rssi; 3145 s16 rssi;
3128 u32 beacon_quality, signal_quality, tx_quality, rx_quality, 3146 u32 beacon_quality, signal_quality, tx_quality, rx_quality,
3129 rate_quality; 3147 rate_quality;
3130 3148
3131 if (!(priv->status & STATUS_ASSOCIATED)) { 3149 if (!(priv->status & STATUS_ASSOCIATED)) {
3132 priv->quality = 0; 3150 priv->quality = 0;
@@ -3136,13 +3154,12 @@ static void ipw_gather_stats(struct ipw_priv *priv)
3136 /* Update the statistics */ 3154 /* Update the statistics */
3137 ipw_get_ordinal(priv, IPW_ORD_STAT_MISSED_BEACONS, 3155 ipw_get_ordinal(priv, IPW_ORD_STAT_MISSED_BEACONS,
3138 &priv->missed_beacons, &len); 3156 &priv->missed_beacons, &len);
3139 missed_beacons_delta = priv->missed_beacons - 3157 missed_beacons_delta = priv->missed_beacons - priv->last_missed_beacons;
3140 priv->last_missed_beacons;
3141 priv->last_missed_beacons = priv->missed_beacons; 3158 priv->last_missed_beacons = priv->missed_beacons;
3142 if (priv->assoc_request.beacon_interval) { 3159 if (priv->assoc_request.beacon_interval) {
3143 missed_beacons_percent = missed_beacons_delta * 3160 missed_beacons_percent = missed_beacons_delta *
3144 (HZ * priv->assoc_request.beacon_interval) / 3161 (HZ * priv->assoc_request.beacon_interval) /
3145 (IPW_STATS_INTERVAL * 10); 3162 (IPW_STATS_INTERVAL * 10);
3146 } else { 3163 } else {
3147 missed_beacons_percent = 0; 3164 missed_beacons_percent = 0;
3148 } 3165 }
@@ -3179,28 +3196,26 @@ static void ipw_gather_stats(struct ipw_priv *priv)
3179 beacon_quality = 0; 3196 beacon_quality = 0;
3180 else 3197 else
3181 beacon_quality = (beacon_quality - BEACON_THRESHOLD) * 100 / 3198 beacon_quality = (beacon_quality - BEACON_THRESHOLD) * 100 /
3182 (100 - BEACON_THRESHOLD); 3199 (100 - BEACON_THRESHOLD);
3183 IPW_DEBUG_STATS("Missed beacon: %3d%% (%d%%)\n", 3200 IPW_DEBUG_STATS("Missed beacon: %3d%% (%d%%)\n",
3184 beacon_quality, missed_beacons_percent); 3201 beacon_quality, missed_beacons_percent);
3185 3202
3186 priv->last_rate = ipw_get_current_rate(priv); 3203 priv->last_rate = ipw_get_current_rate(priv);
3187 rate_quality = priv->last_rate * 40 / priv->last_rate + 60; 3204 rate_quality = priv->last_rate * 40 / priv->last_rate + 60;
3188 IPW_DEBUG_STATS("Rate quality : %3d%% (%dMbs)\n", 3205 IPW_DEBUG_STATS("Rate quality : %3d%% (%dMbs)\n",
3189 rate_quality, priv->last_rate / 1000000); 3206 rate_quality, priv->last_rate / 1000000);
3190 3207
3191 if (rx_packets_delta > 100 && 3208 if (rx_packets_delta > 100 && rx_packets_delta + rx_err_delta)
3192 rx_packets_delta + rx_err_delta)
3193 rx_quality = 100 - (rx_err_delta * 100) / 3209 rx_quality = 100 - (rx_err_delta * 100) /
3194 (rx_packets_delta + rx_err_delta); 3210 (rx_packets_delta + rx_err_delta);
3195 else 3211 else
3196 rx_quality = 100; 3212 rx_quality = 100;
3197 IPW_DEBUG_STATS("Rx quality : %3d%% (%u errors, %u packets)\n", 3213 IPW_DEBUG_STATS("Rx quality : %3d%% (%u errors, %u packets)\n",
3198 rx_quality, rx_err_delta, rx_packets_delta); 3214 rx_quality, rx_err_delta, rx_packets_delta);
3199 3215
3200 if (tx_packets_delta > 100 && 3216 if (tx_packets_delta > 100 && tx_packets_delta + tx_failures_delta)
3201 tx_packets_delta + tx_failures_delta)
3202 tx_quality = 100 - (tx_failures_delta * 100) / 3217 tx_quality = 100 - (tx_failures_delta * 100) /
3203 (tx_packets_delta + tx_failures_delta); 3218 (tx_packets_delta + tx_failures_delta);
3204 else 3219 else
3205 tx_quality = 100; 3220 tx_quality = 100;
3206 IPW_DEBUG_STATS("Tx quality : %3d%% (%u errors, %u packets)\n", 3221 IPW_DEBUG_STATS("Tx quality : %3d%% (%u errors, %u packets)\n",
@@ -3213,7 +3228,7 @@ static void ipw_gather_stats(struct ipw_priv *priv)
3213 signal_quality = 0; 3228 signal_quality = 0;
3214 else 3229 else
3215 signal_quality = (rssi - WORST_RSSI) * 100 / 3230 signal_quality = (rssi - WORST_RSSI) * 100 /
3216 (PERFECT_RSSI - WORST_RSSI); 3231 (PERFECT_RSSI - WORST_RSSI);
3217 IPW_DEBUG_STATS("Signal level : %3d%% (%d dBm)\n", 3232 IPW_DEBUG_STATS("Signal level : %3d%% (%d dBm)\n",
3218 signal_quality, rssi); 3233 signal_quality, rssi);
3219 3234
@@ -3221,25 +3236,20 @@ static void ipw_gather_stats(struct ipw_priv *priv)
3221 min(rate_quality, 3236 min(rate_quality,
3222 min(tx_quality, min(rx_quality, signal_quality)))); 3237 min(tx_quality, min(rx_quality, signal_quality))));
3223 if (quality == beacon_quality) 3238 if (quality == beacon_quality)
3224 IPW_DEBUG_STATS( 3239 IPW_DEBUG_STATS("Quality (%d%%): Clamped to missed beacons.\n",
3225 "Quality (%d%%): Clamped to missed beacons.\n", 3240 quality);
3226 quality);
3227 if (quality == rate_quality) 3241 if (quality == rate_quality)
3228 IPW_DEBUG_STATS( 3242 IPW_DEBUG_STATS("Quality (%d%%): Clamped to rate quality.\n",
3229 "Quality (%d%%): Clamped to rate quality.\n", 3243 quality);
3230 quality);
3231 if (quality == tx_quality) 3244 if (quality == tx_quality)
3232 IPW_DEBUG_STATS( 3245 IPW_DEBUG_STATS("Quality (%d%%): Clamped to Tx quality.\n",
3233 "Quality (%d%%): Clamped to Tx quality.\n", 3246 quality);
3234 quality);
3235 if (quality == rx_quality) 3247 if (quality == rx_quality)
3236 IPW_DEBUG_STATS( 3248 IPW_DEBUG_STATS("Quality (%d%%): Clamped to Rx quality.\n",
3237 "Quality (%d%%): Clamped to Rx quality.\n", 3249 quality);
3238 quality);
3239 if (quality == signal_quality) 3250 if (quality == signal_quality)
3240 IPW_DEBUG_STATS( 3251 IPW_DEBUG_STATS("Quality (%d%%): Clamped to signal quality.\n",
3241 "Quality (%d%%): Clamped to signal quality.\n", 3252 quality);
3242 quality);
3243 3253
3244 priv->quality = quality; 3254 priv->quality = quality;
3245 3255
@@ -3251,402 +3261,454 @@ static void ipw_gather_stats(struct ipw_priv *priv)
3251 * Handle host notification packet. 3261 * Handle host notification packet.
3252 * Called from interrupt routine 3262 * Called from interrupt routine
3253 */ 3263 */
3254static inline void ipw_rx_notification(struct ipw_priv* priv, 3264static inline void ipw_rx_notification(struct ipw_priv *priv,
3255 struct ipw_rx_notification *notif) 3265 struct ipw_rx_notification *notif)
3256{ 3266{
3257 IPW_DEBUG_NOTIF("type = %i (%d bytes)\n", 3267 IPW_DEBUG_NOTIF("type = %i (%d bytes)\n", notif->subtype, notif->size);
3258 notif->subtype, notif->size);
3259 3268
3260 switch (notif->subtype) { 3269 switch (notif->subtype) {
3261 case HOST_NOTIFICATION_STATUS_ASSOCIATED: { 3270 case HOST_NOTIFICATION_STATUS_ASSOCIATED:{
3262 struct notif_association *assoc = &notif->u.assoc; 3271 struct notif_association *assoc = &notif->u.assoc;
3263 3272
3264 switch (assoc->state) { 3273 switch (assoc->state) {
3265 case CMAS_ASSOCIATED: { 3274 case CMAS_ASSOCIATED:{
3266 IPW_DEBUG(IPW_DL_NOTIF | IPW_DL_STATE | IPW_DL_ASSOC, 3275 IPW_DEBUG(IPW_DL_NOTIF | IPW_DL_STATE |
3267 "associated: '%s' " MAC_FMT " \n", 3276 IPW_DL_ASSOC,
3268 escape_essid(priv->essid, priv->essid_len), 3277 "associated: '%s' " MAC_FMT
3269 MAC_ARG(priv->bssid)); 3278 " \n",
3270 3279 escape_essid(priv->essid,
3271 switch (priv->ieee->iw_mode) { 3280 priv->essid_len),
3272 case IW_MODE_INFRA: 3281 MAC_ARG(priv->bssid));
3273 memcpy(priv->ieee->bssid, priv->bssid, 3282
3274 ETH_ALEN); 3283 switch (priv->ieee->iw_mode) {
3275 break; 3284 case IW_MODE_INFRA:
3276 3285 memcpy(priv->ieee->bssid,
3277 case IW_MODE_ADHOC: 3286 priv->bssid, ETH_ALEN);
3278 memcpy(priv->ieee->bssid, priv->bssid, 3287 break;
3279 ETH_ALEN); 3288
3280 3289 case IW_MODE_ADHOC:
3281 /* clear out the station table */ 3290 memcpy(priv->ieee->bssid,
3282 priv->num_stations = 0; 3291 priv->bssid, ETH_ALEN);
3283 3292
3284 IPW_DEBUG_ASSOC("queueing adhoc check\n"); 3293 /* clear out the station table */
3285 queue_delayed_work(priv->workqueue, 3294 priv->num_stations = 0;
3286 &priv->adhoc_check, 3295
3287 priv->assoc_request.beacon_interval); 3296 IPW_DEBUG_ASSOC
3288 break; 3297 ("queueing adhoc check\n");
3289 } 3298 queue_delayed_work(priv->
3290 3299 workqueue,
3291 priv->status &= ~STATUS_ASSOCIATING; 3300 &priv->
3292 priv->status |= STATUS_ASSOCIATED; 3301 adhoc_check,
3293 3302 priv->
3294 netif_carrier_on(priv->net_dev); 3303 assoc_request.
3295 if (netif_queue_stopped(priv->net_dev)) { 3304 beacon_interval);
3296 IPW_DEBUG_NOTIF("waking queue\n"); 3305 break;
3297 netif_wake_queue(priv->net_dev); 3306 }
3298 } else { 3307
3299 IPW_DEBUG_NOTIF("starting queue\n"); 3308 priv->status &= ~STATUS_ASSOCIATING;
3300 netif_start_queue(priv->net_dev); 3309 priv->status |= STATUS_ASSOCIATED;
3301 } 3310
3302 3311 netif_carrier_on(priv->net_dev);
3303 ipw_reset_stats(priv); 3312 if (netif_queue_stopped(priv->net_dev)) {
3304 /* Ensure the rate is updated immediately */ 3313 IPW_DEBUG_NOTIF
3305 priv->last_rate = ipw_get_current_rate(priv); 3314 ("waking queue\n");
3306 schedule_work(&priv->gather_stats); 3315 netif_wake_queue(priv->net_dev);
3307 notify_wx_assoc_event(priv); 3316 } else {
3317 IPW_DEBUG_NOTIF
3318 ("starting queue\n");
3319 netif_start_queue(priv->
3320 net_dev);
3321 }
3322
3323 ipw_reset_stats(priv);
3324 /* Ensure the rate is updated immediately */
3325 priv->last_rate =
3326 ipw_get_current_rate(priv);
3327 schedule_work(&priv->gather_stats);
3328 notify_wx_assoc_event(priv);
3308 3329
3309/* queue_delayed_work(priv->workqueue, 3330/* queue_delayed_work(priv->workqueue,
3310 &priv->request_scan, 3331 &priv->request_scan,
3311 SCAN_ASSOCIATED_INTERVAL); 3332 SCAN_ASSOCIATED_INTERVAL);
3312*/ 3333*/
3313 break; 3334 break;
3314 } 3335 }
3315 3336
3316 case CMAS_AUTHENTICATED: { 3337 case CMAS_AUTHENTICATED:{
3317 if (priv->status & (STATUS_ASSOCIATED | STATUS_AUTH)) { 3338 if (priv->
3339 status & (STATUS_ASSOCIATED |
3340 STATUS_AUTH)) {
3318#ifdef CONFIG_IPW_DEBUG 3341#ifdef CONFIG_IPW_DEBUG
3319 struct notif_authenticate *auth = &notif->u.auth; 3342 struct notif_authenticate *auth
3320 IPW_DEBUG(IPW_DL_NOTIF | IPW_DL_STATE | IPW_DL_ASSOC, 3343 = &notif->u.auth;
3321 "deauthenticated: '%s' " MAC_FMT ": (0x%04X) - %s \n", 3344 IPW_DEBUG(IPW_DL_NOTIF |
3322 escape_essid(priv->essid, priv->essid_len), 3345 IPW_DL_STATE |
3323 MAC_ARG(priv->bssid), 3346 IPW_DL_ASSOC,
3324 ntohs(auth->status), 3347 "deauthenticated: '%s' "
3325 ipw_get_status_code(ntohs(auth->status))); 3348 MAC_FMT
3349 ": (0x%04X) - %s \n",
3350 escape_essid(priv->
3351 essid,
3352 priv->
3353 essid_len),
3354 MAC_ARG(priv->bssid),
3355 ntohs(auth->status),
3356 ipw_get_status_code
3357 (ntohs
3358 (auth->status)));
3326#endif 3359#endif
3327 3360
3328 priv->status &= ~(STATUS_ASSOCIATING | 3361 priv->status &=
3329 STATUS_AUTH | 3362 ~(STATUS_ASSOCIATING |
3330 STATUS_ASSOCIATED); 3363 STATUS_AUTH |
3364 STATUS_ASSOCIATED);
3365
3366 netif_carrier_off(priv->
3367 net_dev);
3368 netif_stop_queue(priv->net_dev);
3369 queue_work(priv->workqueue,
3370 &priv->request_scan);
3371 notify_wx_assoc_event(priv);
3372 break;
3373 }
3374
3375 IPW_DEBUG(IPW_DL_NOTIF | IPW_DL_STATE |
3376 IPW_DL_ASSOC,
3377 "authenticated: '%s' " MAC_FMT
3378 "\n",
3379 escape_essid(priv->essid,
3380 priv->essid_len),
3381 MAC_ARG(priv->bssid));
3382 break;
3383 }
3384
3385 case CMAS_INIT:{
3386 IPW_DEBUG(IPW_DL_NOTIF | IPW_DL_STATE |
3387 IPW_DL_ASSOC,
3388 "disassociated: '%s' " MAC_FMT
3389 " \n",
3390 escape_essid(priv->essid,
3391 priv->essid_len),
3392 MAC_ARG(priv->bssid));
3393
3394 priv->status &=
3395 ~(STATUS_DISASSOCIATING |
3396 STATUS_ASSOCIATING |
3397 STATUS_ASSOCIATED | STATUS_AUTH);
3398
3399 netif_stop_queue(priv->net_dev);
3400 if (!(priv->status & STATUS_ROAMING)) {
3401 netif_carrier_off(priv->
3402 net_dev);
3403 notify_wx_assoc_event(priv);
3404
3405 /* Cancel any queued work ... */
3406 cancel_delayed_work(&priv->
3407 request_scan);
3408 cancel_delayed_work(&priv->
3409 adhoc_check);
3410
3411 /* Queue up another scan... */
3412 queue_work(priv->workqueue,
3413 &priv->request_scan);
3414
3415 cancel_delayed_work(&priv->
3416 gather_stats);
3417 } else {
3418 priv->status |= STATUS_ROAMING;
3419 queue_work(priv->workqueue,
3420 &priv->request_scan);
3421 }
3422
3423 ipw_reset_stats(priv);
3424 break;
3425 }
3331 3426
3332 netif_carrier_off(priv->net_dev); 3427 default:
3333 netif_stop_queue(priv->net_dev); 3428 IPW_ERROR("assoc: unknown (%d)\n",
3334 queue_work(priv->workqueue, &priv->request_scan); 3429 assoc->state);
3335 notify_wx_assoc_event(priv);
3336 break; 3430 break;
3337 } 3431 }
3338 3432
3339 IPW_DEBUG(IPW_DL_NOTIF | IPW_DL_STATE | IPW_DL_ASSOC,
3340 "authenticated: '%s' " MAC_FMT "\n",
3341 escape_essid(priv->essid, priv->essid_len),
3342 MAC_ARG(priv->bssid));
3343 break; 3433 break;
3344 } 3434 }
3345 3435
3346 case CMAS_INIT: { 3436 case HOST_NOTIFICATION_STATUS_AUTHENTICATE:{
3347 IPW_DEBUG(IPW_DL_NOTIF | IPW_DL_STATE | IPW_DL_ASSOC, 3437 struct notif_authenticate *auth = &notif->u.auth;
3348 "disassociated: '%s' " MAC_FMT " \n", 3438 switch (auth->state) {
3349 escape_essid(priv->essid, priv->essid_len), 3439 case CMAS_AUTHENTICATED:
3350 MAC_ARG(priv->bssid)); 3440 IPW_DEBUG(IPW_DL_NOTIF | IPW_DL_STATE,
3441 "authenticated: '%s' " MAC_FMT " \n",
3442 escape_essid(priv->essid,
3443 priv->essid_len),
3444 MAC_ARG(priv->bssid));
3445 priv->status |= STATUS_AUTH;
3446 break;
3351 3447
3352 priv->status &= ~( 3448 case CMAS_INIT:
3353 STATUS_DISASSOCIATING | 3449 if (priv->status & STATUS_AUTH) {
3354 STATUS_ASSOCIATING | 3450 IPW_DEBUG(IPW_DL_NOTIF | IPW_DL_STATE |
3355 STATUS_ASSOCIATED | 3451 IPW_DL_ASSOC,
3356 STATUS_AUTH); 3452 "authentication failed (0x%04X): %s\n",
3453 ntohs(auth->status),
3454 ipw_get_status_code(ntohs
3455 (auth->
3456 status)));
3457 }
3458 IPW_DEBUG(IPW_DL_NOTIF | IPW_DL_STATE |
3459 IPW_DL_ASSOC,
3460 "deauthenticated: '%s' " MAC_FMT "\n",
3461 escape_essid(priv->essid,
3462 priv->essid_len),
3463 MAC_ARG(priv->bssid));
3357 3464
3358 netif_stop_queue(priv->net_dev); 3465 priv->status &= ~(STATUS_ASSOCIATING |
3359 if (!(priv->status & STATUS_ROAMING)) { 3466 STATUS_AUTH |
3360 netif_carrier_off(priv->net_dev); 3467 STATUS_ASSOCIATED);
3361 notify_wx_assoc_event(priv);
3362
3363 /* Cancel any queued work ... */
3364 cancel_delayed_work(&priv->request_scan);
3365 cancel_delayed_work(&priv->adhoc_check);
3366 3468
3367 /* Queue up another scan... */ 3469 netif_carrier_off(priv->net_dev);
3470 netif_stop_queue(priv->net_dev);
3368 queue_work(priv->workqueue, 3471 queue_work(priv->workqueue,
3369 &priv->request_scan); 3472 &priv->request_scan);
3473 notify_wx_assoc_event(priv);
3474 break;
3370 3475
3371 cancel_delayed_work(&priv->gather_stats); 3476 case CMAS_TX_AUTH_SEQ_1:
3372 } else { 3477 IPW_DEBUG(IPW_DL_NOTIF | IPW_DL_STATE |
3373 priv->status |= STATUS_ROAMING; 3478 IPW_DL_ASSOC, "AUTH_SEQ_1\n");
3374 queue_work(priv->workqueue, 3479 break;
3375 &priv->request_scan); 3480 case CMAS_RX_AUTH_SEQ_2:
3481 IPW_DEBUG(IPW_DL_NOTIF | IPW_DL_STATE |
3482 IPW_DL_ASSOC, "AUTH_SEQ_2\n");
3483 break;
3484 case CMAS_AUTH_SEQ_1_PASS:
3485 IPW_DEBUG(IPW_DL_NOTIF | IPW_DL_STATE |
3486 IPW_DL_ASSOC, "AUTH_SEQ_1_PASS\n");
3487 break;
3488 case CMAS_AUTH_SEQ_1_FAIL:
3489 IPW_DEBUG(IPW_DL_NOTIF | IPW_DL_STATE |
3490 IPW_DL_ASSOC, "AUTH_SEQ_1_FAIL\n");
3491 break;
3492 case CMAS_TX_AUTH_SEQ_3:
3493 IPW_DEBUG(IPW_DL_NOTIF | IPW_DL_STATE |
3494 IPW_DL_ASSOC, "AUTH_SEQ_3\n");
3495 break;
3496 case CMAS_RX_AUTH_SEQ_4:
3497 IPW_DEBUG(IPW_DL_NOTIF | IPW_DL_STATE |
3498 IPW_DL_ASSOC, "RX_AUTH_SEQ_4\n");
3499 break;
3500 case CMAS_AUTH_SEQ_2_PASS:
3501 IPW_DEBUG(IPW_DL_NOTIF | IPW_DL_STATE |
3502 IPW_DL_ASSOC, "AUTH_SEQ_2_PASS\n");
3503 break;
3504 case CMAS_AUTH_SEQ_2_FAIL:
3505 IPW_DEBUG(IPW_DL_NOTIF | IPW_DL_STATE |
3506 IPW_DL_ASSOC, "AUT_SEQ_2_FAIL\n");
3507 break;
3508 case CMAS_TX_ASSOC:
3509 IPW_DEBUG(IPW_DL_NOTIF | IPW_DL_STATE |
3510 IPW_DL_ASSOC, "TX_ASSOC\n");
3511 break;
3512 case CMAS_RX_ASSOC_RESP:
3513 IPW_DEBUG(IPW_DL_NOTIF | IPW_DL_STATE |
3514 IPW_DL_ASSOC, "RX_ASSOC_RESP\n");
3515 break;
3516 case CMAS_ASSOCIATED:
3517 IPW_DEBUG(IPW_DL_NOTIF | IPW_DL_STATE |
3518 IPW_DL_ASSOC, "ASSOCIATED\n");
3519 break;
3520 default:
3521 IPW_DEBUG_NOTIF("auth: failure - %d\n",
3522 auth->state);
3523 break;
3376 } 3524 }
3377
3378 ipw_reset_stats(priv);
3379 break;
3380 }
3381
3382 default:
3383 IPW_ERROR("assoc: unknown (%d)\n",
3384 assoc->state);
3385 break; 3525 break;
3386 } 3526 }
3387 3527
3388 break; 3528 case HOST_NOTIFICATION_STATUS_SCAN_CHANNEL_RESULT:{
3389 } 3529 struct notif_channel_result *x =
3530 &notif->u.channel_result;
3390 3531
3391 case HOST_NOTIFICATION_STATUS_AUTHENTICATE: { 3532 if (notif->size == sizeof(*x)) {
3392 struct notif_authenticate *auth = &notif->u.auth; 3533 IPW_DEBUG_SCAN("Scan result for channel %d\n",
3393 switch (auth->state) { 3534 x->channel_num);
3394 case CMAS_AUTHENTICATED: 3535 } else {
3395 IPW_DEBUG(IPW_DL_NOTIF | IPW_DL_STATE, 3536 IPW_DEBUG_SCAN("Scan result of wrong size %d "
3396 "authenticated: '%s' " MAC_FMT " \n", 3537 "(should be %zd)\n",
3397 escape_essid(priv->essid, priv->essid_len), 3538 notif->size, sizeof(*x));
3398 MAC_ARG(priv->bssid));
3399 priv->status |= STATUS_AUTH;
3400 break;
3401
3402 case CMAS_INIT:
3403 if (priv->status & STATUS_AUTH) {
3404 IPW_DEBUG(IPW_DL_NOTIF | IPW_DL_STATE | IPW_DL_ASSOC,
3405 "authentication failed (0x%04X): %s\n",
3406 ntohs(auth->status),
3407 ipw_get_status_code(ntohs(auth->status)));
3408 } 3539 }
3409 IPW_DEBUG(IPW_DL_NOTIF | IPW_DL_STATE | IPW_DL_ASSOC,
3410 "deauthenticated: '%s' " MAC_FMT "\n",
3411 escape_essid(priv->essid, priv->essid_len),
3412 MAC_ARG(priv->bssid));
3413
3414 priv->status &= ~(STATUS_ASSOCIATING |
3415 STATUS_AUTH |
3416 STATUS_ASSOCIATED);
3417
3418 netif_carrier_off(priv->net_dev);
3419 netif_stop_queue(priv->net_dev);
3420 queue_work(priv->workqueue, &priv->request_scan);
3421 notify_wx_assoc_event(priv);
3422 break;
3423
3424 case CMAS_TX_AUTH_SEQ_1:
3425 IPW_DEBUG(IPW_DL_NOTIF | IPW_DL_STATE | IPW_DL_ASSOC,
3426 "AUTH_SEQ_1\n");
3427 break;
3428 case CMAS_RX_AUTH_SEQ_2:
3429 IPW_DEBUG(IPW_DL_NOTIF | IPW_DL_STATE | IPW_DL_ASSOC,
3430 "AUTH_SEQ_2\n");
3431 break;
3432 case CMAS_AUTH_SEQ_1_PASS:
3433 IPW_DEBUG(IPW_DL_NOTIF | IPW_DL_STATE | IPW_DL_ASSOC,
3434 "AUTH_SEQ_1_PASS\n");
3435 break;
3436 case CMAS_AUTH_SEQ_1_FAIL:
3437 IPW_DEBUG(IPW_DL_NOTIF | IPW_DL_STATE | IPW_DL_ASSOC,
3438 "AUTH_SEQ_1_FAIL\n");
3439 break;
3440 case CMAS_TX_AUTH_SEQ_3:
3441 IPW_DEBUG(IPW_DL_NOTIF | IPW_DL_STATE | IPW_DL_ASSOC,
3442 "AUTH_SEQ_3\n");
3443 break;
3444 case CMAS_RX_AUTH_SEQ_4:
3445 IPW_DEBUG(IPW_DL_NOTIF | IPW_DL_STATE | IPW_DL_ASSOC,
3446 "RX_AUTH_SEQ_4\n");
3447 break;
3448 case CMAS_AUTH_SEQ_2_PASS:
3449 IPW_DEBUG(IPW_DL_NOTIF | IPW_DL_STATE | IPW_DL_ASSOC,
3450 "AUTH_SEQ_2_PASS\n");
3451 break;
3452 case CMAS_AUTH_SEQ_2_FAIL:
3453 IPW_DEBUG(IPW_DL_NOTIF | IPW_DL_STATE | IPW_DL_ASSOC,
3454 "AUT_SEQ_2_FAIL\n");
3455 break;
3456 case CMAS_TX_ASSOC:
3457 IPW_DEBUG(IPW_DL_NOTIF | IPW_DL_STATE | IPW_DL_ASSOC,
3458 "TX_ASSOC\n");
3459 break;
3460 case CMAS_RX_ASSOC_RESP:
3461 IPW_DEBUG(IPW_DL_NOTIF | IPW_DL_STATE | IPW_DL_ASSOC,
3462 "RX_ASSOC_RESP\n");
3463 break;
3464 case CMAS_ASSOCIATED:
3465 IPW_DEBUG(IPW_DL_NOTIF | IPW_DL_STATE | IPW_DL_ASSOC,
3466 "ASSOCIATED\n");
3467 break;
3468 default:
3469 IPW_DEBUG_NOTIF("auth: failure - %d\n", auth->state);
3470 break; 3540 break;
3471 } 3541 }
3472 break;
3473 }
3474
3475 case HOST_NOTIFICATION_STATUS_SCAN_CHANNEL_RESULT: {
3476 struct notif_channel_result *x = &notif->u.channel_result;
3477
3478 if (notif->size == sizeof(*x)) {
3479 IPW_DEBUG_SCAN("Scan result for channel %d\n",
3480 x->channel_num);
3481 } else {
3482 IPW_DEBUG_SCAN("Scan result of wrong size %d "
3483 "(should be %zd)\n",
3484 notif->size, sizeof(*x));
3485 }
3486 break;
3487 }
3488 3542
3489 case HOST_NOTIFICATION_STATUS_SCAN_COMPLETED: { 3543 case HOST_NOTIFICATION_STATUS_SCAN_COMPLETED:{
3490 struct notif_scan_complete* x = &notif->u.scan_complete; 3544 struct notif_scan_complete *x = &notif->u.scan_complete;
3491 if (notif->size == sizeof(*x)) { 3545 if (notif->size == sizeof(*x)) {
3492 IPW_DEBUG_SCAN("Scan completed: type %d, %d channels, " 3546 IPW_DEBUG_SCAN
3493 "%d status\n", 3547 ("Scan completed: type %d, %d channels, "
3494 x->scan_type, 3548 "%d status\n", x->scan_type,
3495 x->num_channels, 3549 x->num_channels, x->status);
3496 x->status); 3550 } else {
3497 } else { 3551 IPW_ERROR("Scan completed of wrong size %d "
3498 IPW_ERROR("Scan completed of wrong size %d " 3552 "(should be %zd)\n",
3499 "(should be %zd)\n", 3553 notif->size, sizeof(*x));
3500 notif->size, sizeof(*x)); 3554 }
3501 }
3502
3503 priv->status &= ~(STATUS_SCANNING | STATUS_SCAN_ABORTING);
3504
3505 cancel_delayed_work(&priv->scan_check);
3506
3507 if (!(priv->status & (STATUS_ASSOCIATED |
3508 STATUS_ASSOCIATING |
3509 STATUS_ROAMING |
3510 STATUS_DISASSOCIATING)))
3511 queue_work(priv->workqueue, &priv->associate);
3512 else if (priv->status & STATUS_ROAMING) {
3513 /* If a scan completed and we are in roam mode, then
3514 * the scan that completed was the one requested as a
3515 * result of entering roam... so, schedule the
3516 * roam work */
3517 queue_work(priv->workqueue, &priv->roam);
3518 } else if (priv->status & STATUS_SCAN_PENDING)
3519 queue_work(priv->workqueue, &priv->request_scan);
3520
3521 priv->ieee->scans++;
3522 break;
3523 }
3524 3555
3525 case HOST_NOTIFICATION_STATUS_FRAG_LENGTH: { 3556 priv->status &=
3526 struct notif_frag_length *x = &notif->u.frag_len; 3557 ~(STATUS_SCANNING | STATUS_SCAN_ABORTING);
3558
3559 cancel_delayed_work(&priv->scan_check);
3560
3561 if (!(priv->status & (STATUS_ASSOCIATED |
3562 STATUS_ASSOCIATING |
3563 STATUS_ROAMING |
3564 STATUS_DISASSOCIATING)))
3565 queue_work(priv->workqueue, &priv->associate);
3566 else if (priv->status & STATUS_ROAMING) {
3567 /* If a scan completed and we are in roam mode, then
3568 * the scan that completed was the one requested as a
3569 * result of entering roam... so, schedule the
3570 * roam work */
3571 queue_work(priv->workqueue, &priv->roam);
3572 } else if (priv->status & STATUS_SCAN_PENDING)
3573 queue_work(priv->workqueue,
3574 &priv->request_scan);
3527 3575
3528 if (notif->size == sizeof(*x)) { 3576 priv->ieee->scans++;
3529 IPW_ERROR("Frag length: %d\n", x->frag_length); 3577 break;
3530 } else {
3531 IPW_ERROR("Frag length of wrong size %d "
3532 "(should be %zd)\n",
3533 notif->size, sizeof(*x));
3534 } 3578 }
3535 break;
3536 }
3537 3579
3538 case HOST_NOTIFICATION_STATUS_LINK_DETERIORATION: { 3580 case HOST_NOTIFICATION_STATUS_FRAG_LENGTH:{
3539 struct notif_link_deterioration *x = 3581 struct notif_frag_length *x = &notif->u.frag_len;
3540 &notif->u.link_deterioration;
3541 if (notif->size==sizeof(*x)) {
3542 IPW_DEBUG(IPW_DL_NOTIF | IPW_DL_STATE,
3543 "link deterioration: '%s' " MAC_FMT " \n",
3544 escape_essid(priv->essid, priv->essid_len),
3545 MAC_ARG(priv->bssid));
3546 memcpy(&priv->last_link_deterioration, x, sizeof(*x));
3547 } else {
3548 IPW_ERROR("Link Deterioration of wrong size %d "
3549 "(should be %zd)\n",
3550 notif->size, sizeof(*x));
3551 }
3552 break;
3553 }
3554 3582
3555 case HOST_NOTIFICATION_DINO_CONFIG_RESPONSE: { 3583 if (notif->size == sizeof(*x)) {
3556 IPW_ERROR("Dino config\n"); 3584 IPW_ERROR("Frag length: %d\n", x->frag_length);
3557 if (priv->hcmd && priv->hcmd->cmd == HOST_CMD_DINO_CONFIG) { 3585 } else {
3558 /* TODO: Do anything special? */ 3586 IPW_ERROR("Frag length of wrong size %d "
3559 } else { 3587 "(should be %zd)\n",
3560 IPW_ERROR("Unexpected DINO_CONFIG_RESPONSE\n"); 3588 notif->size, sizeof(*x));
3589 }
3590 break;
3561 } 3591 }
3562 break;
3563 }
3564 3592
3565 case HOST_NOTIFICATION_STATUS_BEACON_STATE: { 3593 case HOST_NOTIFICATION_STATUS_LINK_DETERIORATION:{
3566 struct notif_beacon_state *x = &notif->u.beacon_state; 3594 struct notif_link_deterioration *x =
3567 if (notif->size != sizeof(*x)) { 3595 &notif->u.link_deterioration;
3568 IPW_ERROR("Beacon state of wrong size %d (should " 3596 if (notif->size == sizeof(*x)) {
3569 "be %zd)\n", notif->size, sizeof(*x)); 3597 IPW_DEBUG(IPW_DL_NOTIF | IPW_DL_STATE,
3598 "link deterioration: '%s' " MAC_FMT
3599 " \n", escape_essid(priv->essid,
3600 priv->essid_len),
3601 MAC_ARG(priv->bssid));
3602 memcpy(&priv->last_link_deterioration, x,
3603 sizeof(*x));
3604 } else {
3605 IPW_ERROR("Link Deterioration of wrong size %d "
3606 "(should be %zd)\n",
3607 notif->size, sizeof(*x));
3608 }
3570 break; 3609 break;
3571 } 3610 }
3572 3611
3573 if (x->state == HOST_NOTIFICATION_STATUS_BEACON_MISSING) { 3612 case HOST_NOTIFICATION_DINO_CONFIG_RESPONSE:{
3574 if (priv->status & STATUS_SCANNING) { 3613 IPW_ERROR("Dino config\n");
3575 /* Stop scan to keep fw from getting 3614 if (priv->hcmd
3576 * stuck... */ 3615 && priv->hcmd->cmd == HOST_CMD_DINO_CONFIG) {
3577 queue_work(priv->workqueue, 3616 /* TODO: Do anything special? */
3578 &priv->abort_scan); 3617 } else {
3618 IPW_ERROR("Unexpected DINO_CONFIG_RESPONSE\n");
3579 } 3619 }
3620 break;
3621 }
3580 3622
3581 if (x->number > priv->missed_beacon_threshold && 3623 case HOST_NOTIFICATION_STATUS_BEACON_STATE:{
3582 priv->status & STATUS_ASSOCIATED) { 3624 struct notif_beacon_state *x = &notif->u.beacon_state;
3583 IPW_DEBUG(IPW_DL_INFO | IPW_DL_NOTIF | 3625 if (notif->size != sizeof(*x)) {
3584 IPW_DL_STATE, 3626 IPW_ERROR
3585 "Missed beacon: %d - disassociate\n", 3627 ("Beacon state of wrong size %d (should "
3586 x->number); 3628 "be %zd)\n", notif->size, sizeof(*x));
3587 queue_work(priv->workqueue, 3629 break;
3588 &priv->disassociate);
3589 } else if (x->number > priv->roaming_threshold) {
3590 IPW_DEBUG(IPW_DL_NOTIF | IPW_DL_STATE,
3591 "Missed beacon: %d - initiate "
3592 "roaming\n",
3593 x->number);
3594 queue_work(priv->workqueue,
3595 &priv->roam);
3596 } else {
3597 IPW_DEBUG_NOTIF("Missed beacon: %d\n",
3598 x->number);
3599 } 3630 }
3600 3631
3601 priv->notif_missed_beacons = x->number; 3632 if (x->state == HOST_NOTIFICATION_STATUS_BEACON_MISSING) {
3633 if (priv->status & STATUS_SCANNING) {
3634 /* Stop scan to keep fw from getting
3635 * stuck... */
3636 queue_work(priv->workqueue,
3637 &priv->abort_scan);
3638 }
3639
3640 if (x->number > priv->missed_beacon_threshold &&
3641 priv->status & STATUS_ASSOCIATED) {
3642 IPW_DEBUG(IPW_DL_INFO | IPW_DL_NOTIF |
3643 IPW_DL_STATE,
3644 "Missed beacon: %d - disassociate\n",
3645 x->number);
3646 queue_work(priv->workqueue,
3647 &priv->disassociate);
3648 } else if (x->number > priv->roaming_threshold) {
3649 IPW_DEBUG(IPW_DL_NOTIF | IPW_DL_STATE,
3650 "Missed beacon: %d - initiate "
3651 "roaming\n", x->number);
3652 queue_work(priv->workqueue,
3653 &priv->roam);
3654 } else {
3655 IPW_DEBUG_NOTIF("Missed beacon: %d\n",
3656 x->number);
3657 }
3658
3659 priv->notif_missed_beacons = x->number;
3602 3660
3603 } 3661 }
3604 3662
3663 break;
3664 }
3605 3665
3606 break; 3666 case HOST_NOTIFICATION_STATUS_TGI_TX_KEY:{
3607 } 3667 struct notif_tgi_tx_key *x = &notif->u.tgi_tx_key;
3668 if (notif->size == sizeof(*x)) {
3669 IPW_ERROR("TGi Tx Key: state 0x%02x sec type "
3670 "0x%02x station %d\n",
3671 x->key_state, x->security_type,
3672 x->station_index);
3673 break;
3674 }
3608 3675
3609 case HOST_NOTIFICATION_STATUS_TGI_TX_KEY: { 3676 IPW_ERROR
3610 struct notif_tgi_tx_key *x = &notif->u.tgi_tx_key; 3677 ("TGi Tx Key of wrong size %d (should be %zd)\n",
3611 if (notif->size==sizeof(*x)) { 3678 notif->size, sizeof(*x));
3612 IPW_ERROR("TGi Tx Key: state 0x%02x sec type "
3613 "0x%02x station %d\n",
3614 x->key_state,x->security_type,
3615 x->station_index);
3616 break; 3679 break;
3617 } 3680 }
3618 3681
3619 IPW_ERROR("TGi Tx Key of wrong size %d (should be %zd)\n", 3682 case HOST_NOTIFICATION_CALIB_KEEP_RESULTS:{
3620 notif->size, sizeof(*x)); 3683 struct notif_calibration *x = &notif->u.calibration;
3621 break;
3622 }
3623 3684
3624 case HOST_NOTIFICATION_CALIB_KEEP_RESULTS: { 3685 if (notif->size == sizeof(*x)) {
3625 struct notif_calibration *x = &notif->u.calibration; 3686 memcpy(&priv->calib, x, sizeof(*x));
3687 IPW_DEBUG_INFO("TODO: Calibration\n");
3688 break;
3689 }
3626 3690
3627 if (notif->size == sizeof(*x)) { 3691 IPW_ERROR
3628 memcpy(&priv->calib, x, sizeof(*x)); 3692 ("Calibration of wrong size %d (should be %zd)\n",
3629 IPW_DEBUG_INFO("TODO: Calibration\n"); 3693 notif->size, sizeof(*x));
3630 break; 3694 break;
3631 } 3695 }
3632 3696
3633 IPW_ERROR("Calibration of wrong size %d (should be %zd)\n", 3697 case HOST_NOTIFICATION_NOISE_STATS:{
3634 notif->size, sizeof(*x)); 3698 if (notif->size == sizeof(u32)) {
3635 break; 3699 priv->last_noise =
3636 } 3700 (u8) (notif->u.noise.value & 0xff);
3701 average_add(&priv->average_noise,
3702 priv->last_noise);
3703 break;
3704 }
3637 3705
3638 case HOST_NOTIFICATION_NOISE_STATS: { 3706 IPW_ERROR
3639 if (notif->size == sizeof(u32)) { 3707 ("Noise stat is wrong size %d (should be %zd)\n",
3640 priv->last_noise = (u8)(notif->u.noise.value & 0xff); 3708 notif->size, sizeof(u32));
3641 average_add(&priv->average_noise, priv->last_noise);
3642 break; 3709 break;
3643 } 3710 }
3644 3711
3645 IPW_ERROR("Noise stat is wrong size %d (should be %zd)\n",
3646 notif->size, sizeof(u32));
3647 break;
3648 }
3649
3650 default: 3712 default:
3651 IPW_ERROR("Unknown notification: " 3713 IPW_ERROR("Unknown notification: "
3652 "subtype=%d,flags=0x%2x,size=%d\n", 3714 "subtype=%d,flags=0x%2x,size=%d\n",
@@ -3680,8 +3742,7 @@ static int ipw_queue_reset(struct ipw_priv *priv)
3680 rc = ipw_queue_tx_init(priv, &priv->txq[0], nTx, 3742 rc = ipw_queue_tx_init(priv, &priv->txq[0], nTx,
3681 CX2_TX_QUEUE_0_READ_INDEX, 3743 CX2_TX_QUEUE_0_READ_INDEX,
3682 CX2_TX_QUEUE_0_WRITE_INDEX, 3744 CX2_TX_QUEUE_0_WRITE_INDEX,
3683 CX2_TX_QUEUE_0_BD_BASE, 3745 CX2_TX_QUEUE_0_BD_BASE, CX2_TX_QUEUE_0_BD_SIZE);
3684 CX2_TX_QUEUE_0_BD_SIZE);
3685 if (rc) { 3746 if (rc) {
3686 IPW_ERROR("Tx 0 queue init failed\n"); 3747 IPW_ERROR("Tx 0 queue init failed\n");
3687 goto error; 3748 goto error;
@@ -3689,8 +3750,7 @@ static int ipw_queue_reset(struct ipw_priv *priv)
3689 rc = ipw_queue_tx_init(priv, &priv->txq[1], nTx, 3750 rc = ipw_queue_tx_init(priv, &priv->txq[1], nTx,
3690 CX2_TX_QUEUE_1_READ_INDEX, 3751 CX2_TX_QUEUE_1_READ_INDEX,
3691 CX2_TX_QUEUE_1_WRITE_INDEX, 3752 CX2_TX_QUEUE_1_WRITE_INDEX,
3692 CX2_TX_QUEUE_1_BD_BASE, 3753 CX2_TX_QUEUE_1_BD_BASE, CX2_TX_QUEUE_1_BD_SIZE);
3693 CX2_TX_QUEUE_1_BD_SIZE);
3694 if (rc) { 3754 if (rc) {
3695 IPW_ERROR("Tx 1 queue init failed\n"); 3755 IPW_ERROR("Tx 1 queue init failed\n");
3696 goto error; 3756 goto error;
@@ -3698,8 +3758,7 @@ static int ipw_queue_reset(struct ipw_priv *priv)
3698 rc = ipw_queue_tx_init(priv, &priv->txq[2], nTx, 3758 rc = ipw_queue_tx_init(priv, &priv->txq[2], nTx,
3699 CX2_TX_QUEUE_2_READ_INDEX, 3759 CX2_TX_QUEUE_2_READ_INDEX,
3700 CX2_TX_QUEUE_2_WRITE_INDEX, 3760 CX2_TX_QUEUE_2_WRITE_INDEX,
3701 CX2_TX_QUEUE_2_BD_BASE, 3761 CX2_TX_QUEUE_2_BD_BASE, CX2_TX_QUEUE_2_BD_SIZE);
3702 CX2_TX_QUEUE_2_BD_SIZE);
3703 if (rc) { 3762 if (rc) {
3704 IPW_ERROR("Tx 2 queue init failed\n"); 3763 IPW_ERROR("Tx 2 queue init failed\n");
3705 goto error; 3764 goto error;
@@ -3707,8 +3766,7 @@ static int ipw_queue_reset(struct ipw_priv *priv)
3707 rc = ipw_queue_tx_init(priv, &priv->txq[3], nTx, 3766 rc = ipw_queue_tx_init(priv, &priv->txq[3], nTx,
3708 CX2_TX_QUEUE_3_READ_INDEX, 3767 CX2_TX_QUEUE_3_READ_INDEX,
3709 CX2_TX_QUEUE_3_WRITE_INDEX, 3768 CX2_TX_QUEUE_3_WRITE_INDEX,
3710 CX2_TX_QUEUE_3_BD_BASE, 3769 CX2_TX_QUEUE_3_BD_BASE, CX2_TX_QUEUE_3_BD_SIZE);
3711 CX2_TX_QUEUE_3_BD_SIZE);
3712 if (rc) { 3770 if (rc) {
3713 IPW_ERROR("Tx 3 queue init failed\n"); 3771 IPW_ERROR("Tx 3 queue init failed\n");
3714 goto error; 3772 goto error;
@@ -3718,7 +3776,7 @@ static int ipw_queue_reset(struct ipw_priv *priv)
3718 priv->rx_pend_max = 0; 3776 priv->rx_pend_max = 0;
3719 return rc; 3777 return rc;
3720 3778
3721 error: 3779 error:
3722 ipw_tx_queue_free(priv); 3780 ipw_tx_queue_free(priv);
3723 return rc; 3781 return rc;
3724} 3782}
@@ -3746,8 +3804,8 @@ static int ipw_queue_tx_reclaim(struct ipw_priv *priv,
3746 hw_tail = ipw_read32(priv, q->reg_r); 3804 hw_tail = ipw_read32(priv, q->reg_r);
3747 if (hw_tail >= q->n_bd) { 3805 if (hw_tail >= q->n_bd) {
3748 IPW_ERROR 3806 IPW_ERROR
3749 ("Read index for DMA queue (%d) is out of range [0-%d)\n", 3807 ("Read index for DMA queue (%d) is out of range [0-%d)\n",
3750 hw_tail, q->n_bd); 3808 hw_tail, q->n_bd);
3751 goto done; 3809 goto done;
3752 } 3810 }
3753 for (; q->last_used != hw_tail; 3811 for (; q->last_used != hw_tail;
@@ -3755,7 +3813,7 @@ static int ipw_queue_tx_reclaim(struct ipw_priv *priv,
3755 ipw_queue_tx_free_tfd(priv, txq); 3813 ipw_queue_tx_free_tfd(priv, txq);
3756 priv->tx_packets++; 3814 priv->tx_packets++;
3757 } 3815 }
3758 done: 3816 done:
3759 if (ipw_queue_space(q) > q->low_mark && qindex >= 0) { 3817 if (ipw_queue_space(q) > q->low_mark && qindex >= 0) {
3760 __maybe_wake_tx(priv); 3818 __maybe_wake_tx(priv);
3761 } 3819 }
@@ -3795,8 +3853,6 @@ static int ipw_queue_tx_hcmd(struct ipw_priv *priv, int hcmd, void *buf,
3795 return 0; 3853 return 0;
3796} 3854}
3797 3855
3798
3799
3800/* 3856/*
3801 * Rx theory of operation 3857 * Rx theory of operation
3802 * 3858 *
@@ -3933,9 +3989,9 @@ static void ipw_rx_queue_replenish(void *data)
3933 list_del(element); 3989 list_del(element);
3934 3990
3935 rxb->rxb = (struct ipw_rx_buffer *)rxb->skb->data; 3991 rxb->rxb = (struct ipw_rx_buffer *)rxb->skb->data;
3936 rxb->dma_addr = pci_map_single( 3992 rxb->dma_addr =
3937 priv->pci_dev, rxb->skb->data, CX2_RX_BUF_SIZE, 3993 pci_map_single(priv->pci_dev, rxb->skb->data,
3938 PCI_DMA_FROMDEVICE); 3994 CX2_RX_BUF_SIZE, PCI_DMA_FROMDEVICE);
3939 3995
3940 list_add_tail(&rxb->list, &rxq->rx_free); 3996 list_add_tail(&rxb->list, &rxq->rx_free);
3941 rxq->free_count++; 3997 rxq->free_count++;
@@ -3950,8 +4006,7 @@ static void ipw_rx_queue_replenish(void *data)
3950 * This free routine walks the list of POOL entries and if SKB is set to 4006 * This free routine walks the list of POOL entries and if SKB is set to
3951 * non NULL it is unmapped and freed 4007 * non NULL it is unmapped and freed
3952 */ 4008 */
3953static void ipw_rx_queue_free(struct ipw_priv *priv, 4009static void ipw_rx_queue_free(struct ipw_priv *priv, struct ipw_rx_queue *rxq)
3954 struct ipw_rx_queue *rxq)
3955{ 4010{
3956 int i; 4011 int i;
3957 4012
@@ -3961,8 +4016,7 @@ static void ipw_rx_queue_free(struct ipw_priv *priv,
3961 for (i = 0; i < RX_QUEUE_SIZE + RX_FREE_BUFFERS; i++) { 4016 for (i = 0; i < RX_QUEUE_SIZE + RX_FREE_BUFFERS; i++) {
3962 if (rxq->pool[i].skb != NULL) { 4017 if (rxq->pool[i].skb != NULL) {
3963 pci_unmap_single(priv->pci_dev, rxq->pool[i].dma_addr, 4018 pci_unmap_single(priv->pci_dev, rxq->pool[i].dma_addr,
3964 CX2_RX_BUF_SIZE, 4019 CX2_RX_BUF_SIZE, PCI_DMA_FROMDEVICE);
3965 PCI_DMA_FROMDEVICE);
3966 dev_kfree_skb(rxq->pool[i].skb); 4020 dev_kfree_skb(rxq->pool[i].skb);
3967 } 4021 }
3968 } 4022 }
@@ -4001,28 +4055,28 @@ static int ipw_is_rate_in_mask(struct ipw_priv *priv, int ieee_mode, u8 rate)
4001 switch (rate) { 4055 switch (rate) {
4002 case IEEE80211_OFDM_RATE_6MB: 4056 case IEEE80211_OFDM_RATE_6MB:
4003 return priv->rates_mask & IEEE80211_OFDM_RATE_6MB_MASK ? 4057 return priv->rates_mask & IEEE80211_OFDM_RATE_6MB_MASK ?
4004 1 : 0; 4058 1 : 0;
4005 case IEEE80211_OFDM_RATE_9MB: 4059 case IEEE80211_OFDM_RATE_9MB:
4006 return priv->rates_mask & IEEE80211_OFDM_RATE_9MB_MASK ? 4060 return priv->rates_mask & IEEE80211_OFDM_RATE_9MB_MASK ?
4007 1 : 0; 4061 1 : 0;
4008 case IEEE80211_OFDM_RATE_12MB: 4062 case IEEE80211_OFDM_RATE_12MB:
4009 return priv->rates_mask & IEEE80211_OFDM_RATE_12MB_MASK ? 4063 return priv->
4010 1 : 0; 4064 rates_mask & IEEE80211_OFDM_RATE_12MB_MASK ? 1 : 0;
4011 case IEEE80211_OFDM_RATE_18MB: 4065 case IEEE80211_OFDM_RATE_18MB:
4012 return priv->rates_mask & IEEE80211_OFDM_RATE_18MB_MASK ? 4066 return priv->
4013 1 : 0; 4067 rates_mask & IEEE80211_OFDM_RATE_18MB_MASK ? 1 : 0;
4014 case IEEE80211_OFDM_RATE_24MB: 4068 case IEEE80211_OFDM_RATE_24MB:
4015 return priv->rates_mask & IEEE80211_OFDM_RATE_24MB_MASK ? 4069 return priv->
4016 1 : 0; 4070 rates_mask & IEEE80211_OFDM_RATE_24MB_MASK ? 1 : 0;
4017 case IEEE80211_OFDM_RATE_36MB: 4071 case IEEE80211_OFDM_RATE_36MB:
4018 return priv->rates_mask & IEEE80211_OFDM_RATE_36MB_MASK ? 4072 return priv->
4019 1 : 0; 4073 rates_mask & IEEE80211_OFDM_RATE_36MB_MASK ? 1 : 0;
4020 case IEEE80211_OFDM_RATE_48MB: 4074 case IEEE80211_OFDM_RATE_48MB:
4021 return priv->rates_mask & IEEE80211_OFDM_RATE_48MB_MASK ? 4075 return priv->
4022 1 : 0; 4076 rates_mask & IEEE80211_OFDM_RATE_48MB_MASK ? 1 : 0;
4023 case IEEE80211_OFDM_RATE_54MB: 4077 case IEEE80211_OFDM_RATE_54MB:
4024 return priv->rates_mask & IEEE80211_OFDM_RATE_54MB_MASK ? 4078 return priv->
4025 1 : 0; 4079 rates_mask & IEEE80211_OFDM_RATE_54MB_MASK ? 1 : 0;
4026 default: 4080 default:
4027 return 0; 4081 return 0;
4028 } 4082 }
@@ -4074,10 +4128,11 @@ static int ipw_compatible_rates(struct ipw_priv *priv,
4074 int num_rates, i; 4128 int num_rates, i;
4075 4129
4076 memset(rates, 0, sizeof(*rates)); 4130 memset(rates, 0, sizeof(*rates));
4077 num_rates = min(network->rates_len, (u8)IPW_MAX_RATES); 4131 num_rates = min(network->rates_len, (u8) IPW_MAX_RATES);
4078 rates->num_rates = 0; 4132 rates->num_rates = 0;
4079 for (i = 0; i < num_rates; i++) { 4133 for (i = 0; i < num_rates; i++) {
4080 if (!ipw_is_rate_in_mask(priv, network->mode, network->rates[i])) { 4134 if (!ipw_is_rate_in_mask
4135 (priv, network->mode, network->rates[i])) {
4081 IPW_DEBUG_SCAN("Rate %02X masked : 0x%08X\n", 4136 IPW_DEBUG_SCAN("Rate %02X masked : 0x%08X\n",
4082 network->rates[i], priv->rates_mask); 4137 network->rates[i], priv->rates_mask);
4083 continue; 4138 continue;
@@ -4086,15 +4141,18 @@ static int ipw_compatible_rates(struct ipw_priv *priv,
4086 rates->supported_rates[rates->num_rates++] = network->rates[i]; 4141 rates->supported_rates[rates->num_rates++] = network->rates[i];
4087 } 4142 }
4088 4143
4089 num_rates = min(network->rates_ex_len, (u8)(IPW_MAX_RATES - num_rates)); 4144 num_rates =
4145 min(network->rates_ex_len, (u8) (IPW_MAX_RATES - num_rates));
4090 for (i = 0; i < num_rates; i++) { 4146 for (i = 0; i < num_rates; i++) {
4091 if (!ipw_is_rate_in_mask(priv, network->mode, network->rates_ex[i])) { 4147 if (!ipw_is_rate_in_mask
4148 (priv, network->mode, network->rates_ex[i])) {
4092 IPW_DEBUG_SCAN("Rate %02X masked : 0x%08X\n", 4149 IPW_DEBUG_SCAN("Rate %02X masked : 0x%08X\n",
4093 network->rates_ex[i], priv->rates_mask); 4150 network->rates_ex[i], priv->rates_mask);
4094 continue; 4151 continue;
4095 } 4152 }
4096 4153
4097 rates->supported_rates[rates->num_rates++] = network->rates_ex[i]; 4154 rates->supported_rates[rates->num_rates++] =
4155 network->rates_ex[i];
4098 } 4156 }
4099 4157
4100 return rates->num_rates; 4158 return rates->num_rates;
@@ -4113,65 +4171,65 @@ static inline void ipw_copy_rates(struct ipw_supported_rates *dest,
4113 * mask should ever be used -- right now all callers to add the scan rates are 4171 * mask should ever be used -- right now all callers to add the scan rates are
4114 * set with the modulation = CCK, so BASIC_RATE_MASK is never set... */ 4172 * set with the modulation = CCK, so BASIC_RATE_MASK is never set... */
4115static void ipw_add_cck_scan_rates(struct ipw_supported_rates *rates, 4173static void ipw_add_cck_scan_rates(struct ipw_supported_rates *rates,
4116 u8 modulation, u32 rate_mask) 4174 u8 modulation, u32 rate_mask)
4117{ 4175{
4118 u8 basic_mask = (IEEE80211_OFDM_MODULATION == modulation) ? 4176 u8 basic_mask = (IEEE80211_OFDM_MODULATION == modulation) ?
4119 IEEE80211_BASIC_RATE_MASK : 0; 4177 IEEE80211_BASIC_RATE_MASK : 0;
4120 4178
4121 if (rate_mask & IEEE80211_CCK_RATE_1MB_MASK) 4179 if (rate_mask & IEEE80211_CCK_RATE_1MB_MASK)
4122 rates->supported_rates[rates->num_rates++] = 4180 rates->supported_rates[rates->num_rates++] =
4123 IEEE80211_BASIC_RATE_MASK | IEEE80211_CCK_RATE_1MB; 4181 IEEE80211_BASIC_RATE_MASK | IEEE80211_CCK_RATE_1MB;
4124 4182
4125 if (rate_mask & IEEE80211_CCK_RATE_2MB_MASK) 4183 if (rate_mask & IEEE80211_CCK_RATE_2MB_MASK)
4126 rates->supported_rates[rates->num_rates++] = 4184 rates->supported_rates[rates->num_rates++] =
4127 IEEE80211_BASIC_RATE_MASK | IEEE80211_CCK_RATE_2MB; 4185 IEEE80211_BASIC_RATE_MASK | IEEE80211_CCK_RATE_2MB;
4128 4186
4129 if (rate_mask & IEEE80211_CCK_RATE_5MB_MASK) 4187 if (rate_mask & IEEE80211_CCK_RATE_5MB_MASK)
4130 rates->supported_rates[rates->num_rates++] = basic_mask | 4188 rates->supported_rates[rates->num_rates++] = basic_mask |
4131 IEEE80211_CCK_RATE_5MB; 4189 IEEE80211_CCK_RATE_5MB;
4132 4190
4133 if (rate_mask & IEEE80211_CCK_RATE_11MB_MASK) 4191 if (rate_mask & IEEE80211_CCK_RATE_11MB_MASK)
4134 rates->supported_rates[rates->num_rates++] = basic_mask | 4192 rates->supported_rates[rates->num_rates++] = basic_mask |
4135 IEEE80211_CCK_RATE_11MB; 4193 IEEE80211_CCK_RATE_11MB;
4136} 4194}
4137 4195
4138static void ipw_add_ofdm_scan_rates(struct ipw_supported_rates *rates, 4196static void ipw_add_ofdm_scan_rates(struct ipw_supported_rates *rates,
4139 u8 modulation, u32 rate_mask) 4197 u8 modulation, u32 rate_mask)
4140{ 4198{
4141 u8 basic_mask = (IEEE80211_OFDM_MODULATION == modulation) ? 4199 u8 basic_mask = (IEEE80211_OFDM_MODULATION == modulation) ?
4142 IEEE80211_BASIC_RATE_MASK : 0; 4200 IEEE80211_BASIC_RATE_MASK : 0;
4143 4201
4144 if (rate_mask & IEEE80211_OFDM_RATE_6MB_MASK) 4202 if (rate_mask & IEEE80211_OFDM_RATE_6MB_MASK)
4145 rates->supported_rates[rates->num_rates++] = basic_mask | 4203 rates->supported_rates[rates->num_rates++] = basic_mask |
4146 IEEE80211_OFDM_RATE_6MB; 4204 IEEE80211_OFDM_RATE_6MB;
4147 4205
4148 if (rate_mask & IEEE80211_OFDM_RATE_9MB_MASK) 4206 if (rate_mask & IEEE80211_OFDM_RATE_9MB_MASK)
4149 rates->supported_rates[rates->num_rates++] = 4207 rates->supported_rates[rates->num_rates++] =
4150 IEEE80211_OFDM_RATE_9MB; 4208 IEEE80211_OFDM_RATE_9MB;
4151 4209
4152 if (rate_mask & IEEE80211_OFDM_RATE_12MB_MASK) 4210 if (rate_mask & IEEE80211_OFDM_RATE_12MB_MASK)
4153 rates->supported_rates[rates->num_rates++] = basic_mask | 4211 rates->supported_rates[rates->num_rates++] = basic_mask |
4154 IEEE80211_OFDM_RATE_12MB; 4212 IEEE80211_OFDM_RATE_12MB;
4155 4213
4156 if (rate_mask & IEEE80211_OFDM_RATE_18MB_MASK) 4214 if (rate_mask & IEEE80211_OFDM_RATE_18MB_MASK)
4157 rates->supported_rates[rates->num_rates++] = 4215 rates->supported_rates[rates->num_rates++] =
4158 IEEE80211_OFDM_RATE_18MB; 4216 IEEE80211_OFDM_RATE_18MB;
4159 4217
4160 if (rate_mask & IEEE80211_OFDM_RATE_24MB_MASK) 4218 if (rate_mask & IEEE80211_OFDM_RATE_24MB_MASK)
4161 rates->supported_rates[rates->num_rates++] = basic_mask | 4219 rates->supported_rates[rates->num_rates++] = basic_mask |
4162 IEEE80211_OFDM_RATE_24MB; 4220 IEEE80211_OFDM_RATE_24MB;
4163 4221
4164 if (rate_mask & IEEE80211_OFDM_RATE_36MB_MASK) 4222 if (rate_mask & IEEE80211_OFDM_RATE_36MB_MASK)
4165 rates->supported_rates[rates->num_rates++] = 4223 rates->supported_rates[rates->num_rates++] =
4166 IEEE80211_OFDM_RATE_36MB; 4224 IEEE80211_OFDM_RATE_36MB;
4167 4225
4168 if (rate_mask & IEEE80211_OFDM_RATE_48MB_MASK) 4226 if (rate_mask & IEEE80211_OFDM_RATE_48MB_MASK)
4169 rates->supported_rates[rates->num_rates++] = 4227 rates->supported_rates[rates->num_rates++] =
4170 IEEE80211_OFDM_RATE_48MB; 4228 IEEE80211_OFDM_RATE_48MB;
4171 4229
4172 if (rate_mask & IEEE80211_OFDM_RATE_54MB_MASK) 4230 if (rate_mask & IEEE80211_OFDM_RATE_54MB_MASK)
4173 rates->supported_rates[rates->num_rates++] = 4231 rates->supported_rates[rates->num_rates++] =
4174 IEEE80211_OFDM_RATE_54MB; 4232 IEEE80211_OFDM_RATE_54MB;
4175} 4233}
4176 4234
4177struct ipw_network_match { 4235struct ipw_network_match {
@@ -4179,11 +4237,9 @@ struct ipw_network_match {
4179 struct ipw_supported_rates rates; 4237 struct ipw_supported_rates rates;
4180}; 4238};
4181 4239
4182static int ipw_best_network( 4240static int ipw_best_network(struct ipw_priv *priv,
4183 struct ipw_priv *priv, 4241 struct ipw_network_match *match,
4184 struct ipw_network_match *match, 4242 struct ieee80211_network *network, int roaming)
4185 struct ieee80211_network *network,
4186 int roaming)
4187{ 4243{
4188 struct ipw_supported_rates rates; 4244 struct ipw_supported_rates rates;
4189 4245
@@ -4231,21 +4287,21 @@ static int ipw_best_network(
4231 memcmp(network->ssid, priv->essid, 4287 memcmp(network->ssid, priv->essid,
4232 min(network->ssid_len, priv->essid_len)))) { 4288 min(network->ssid_len, priv->essid_len)))) {
4233 char escaped[IW_ESSID_MAX_SIZE * 2 + 1]; 4289 char escaped[IW_ESSID_MAX_SIZE * 2 + 1];
4234 strncpy(escaped, escape_essid( 4290 strncpy(escaped,
4235 network->ssid, network->ssid_len), 4291 escape_essid(network->ssid, network->ssid_len),
4236 sizeof(escaped)); 4292 sizeof(escaped));
4237 IPW_DEBUG_ASSOC("Network '%s (" MAC_FMT ")' excluded " 4293 IPW_DEBUG_ASSOC("Network '%s (" MAC_FMT ")' excluded "
4238 "because of ESSID mismatch: '%s'.\n", 4294 "because of ESSID mismatch: '%s'.\n",
4239 escaped, MAC_ARG(network->bssid), 4295 escaped, MAC_ARG(network->bssid),
4240 escape_essid(priv->essid, priv->essid_len)); 4296 escape_essid(priv->essid,
4297 priv->essid_len));
4241 return 0; 4298 return 0;
4242 } 4299 }
4243 } 4300 }
4244 4301
4245 /* If the old network rate is better than this one, don't bother 4302 /* If the old network rate is better than this one, don't bother
4246 * testing everything else. */ 4303 * testing everything else. */
4247 if (match->network && match->network->stats.rssi > 4304 if (match->network && match->network->stats.rssi > network->stats.rssi) {
4248 network->stats.rssi) {
4249 char escaped[IW_ESSID_MAX_SIZE * 2 + 1]; 4305 char escaped[IW_ESSID_MAX_SIZE * 2 + 1];
4250 strncpy(escaped, 4306 strncpy(escaped,
4251 escape_essid(network->ssid, network->ssid_len), 4307 escape_essid(network->ssid, network->ssid_len),
@@ -4303,7 +4359,7 @@ static int ipw_best_network(
4303 priv->capability & CAP_PRIVACY_ON ? "on" : 4359 priv->capability & CAP_PRIVACY_ON ? "on" :
4304 "off", 4360 "off",
4305 network->capability & 4361 network->capability &
4306 WLAN_CAPABILITY_PRIVACY ?"on" : "off"); 4362 WLAN_CAPABILITY_PRIVACY ? "on" : "off");
4307 return 0; 4363 return 0;
4308 } 4364 }
4309 4365
@@ -4312,8 +4368,7 @@ static int ipw_best_network(
4312 IPW_DEBUG_ASSOC("Network '%s (" MAC_FMT ")' excluded " 4368 IPW_DEBUG_ASSOC("Network '%s (" MAC_FMT ")' excluded "
4313 "because of BSSID mismatch: " MAC_FMT ".\n", 4369 "because of BSSID mismatch: " MAC_FMT ".\n",
4314 escape_essid(network->ssid, network->ssid_len), 4370 escape_essid(network->ssid, network->ssid_len),
4315 MAC_ARG(network->bssid), 4371 MAC_ARG(network->bssid), MAC_ARG(priv->bssid));
4316 MAC_ARG(priv->bssid));
4317 return 0; 4372 return 0;
4318 } 4373 }
4319 4374
@@ -4351,9 +4406,8 @@ static int ipw_best_network(
4351 return 1; 4406 return 1;
4352} 4407}
4353 4408
4354
4355static void ipw_adhoc_create(struct ipw_priv *priv, 4409static void ipw_adhoc_create(struct ipw_priv *priv,
4356 struct ieee80211_network *network) 4410 struct ieee80211_network *network)
4357{ 4411{
4358 /* 4412 /*
4359 * For the purposes of scanning, we can set our wireless mode 4413 * For the purposes of scanning, we can set our wireless mode
@@ -4393,8 +4447,7 @@ static void ipw_adhoc_create(struct ipw_priv *priv,
4393 if (priv->capability & CAP_PRIVACY_ON) 4447 if (priv->capability & CAP_PRIVACY_ON)
4394 network->capability |= WLAN_CAPABILITY_PRIVACY; 4448 network->capability |= WLAN_CAPABILITY_PRIVACY;
4395 network->rates_len = min(priv->rates.num_rates, MAX_RATES_LENGTH); 4449 network->rates_len = min(priv->rates.num_rates, MAX_RATES_LENGTH);
4396 memcpy(network->rates, priv->rates.supported_rates, 4450 memcpy(network->rates, priv->rates.supported_rates, network->rates_len);
4397 network->rates_len);
4398 network->rates_ex_len = priv->rates.num_rates - network->rates_len; 4451 network->rates_ex_len = priv->rates.num_rates - network->rates_len;
4399 memcpy(network->rates_ex, 4452 memcpy(network->rates_ex,
4400 &priv->rates.supported_rates[network->rates_len], 4453 &priv->rates.supported_rates[network->rates_len],
@@ -4404,13 +4457,13 @@ static void ipw_adhoc_create(struct ipw_priv *priv,
4404 network->last_associate = 0; 4457 network->last_associate = 0;
4405 network->time_stamp[0] = 0; 4458 network->time_stamp[0] = 0;
4406 network->time_stamp[1] = 0; 4459 network->time_stamp[1] = 0;
4407 network->beacon_interval = 100; /* Default */ 4460 network->beacon_interval = 100; /* Default */
4408 network->listen_interval = 10; /* Default */ 4461 network->listen_interval = 10; /* Default */
4409 network->atim_window = 0; /* Default */ 4462 network->atim_window = 0; /* Default */
4410#ifdef CONFIG_IEEE80211_WPA 4463#ifdef CONFIG_IEEE80211_WPA
4411 network->wpa_ie_len = 0; 4464 network->wpa_ie_len = 0;
4412 network->rsn_ie_len = 0; 4465 network->rsn_ie_len = 0;
4413#endif /* CONFIG_IEEE80211_WPA */ 4466#endif /* CONFIG_IEEE80211_WPA */
4414} 4467}
4415 4468
4416static void ipw_send_wep_keys(struct ipw_priv *priv) 4469static void ipw_send_wep_keys(struct ipw_priv *priv)
@@ -4464,14 +4517,12 @@ static void ipw_debug_config(struct ipw_priv *priv)
4464 IPW_DEBUG_INFO("Scan completed, no valid APs matched " 4517 IPW_DEBUG_INFO("Scan completed, no valid APs matched "
4465 "[CFG 0x%08X]\n", priv->config); 4518 "[CFG 0x%08X]\n", priv->config);
4466 if (priv->config & CFG_STATIC_CHANNEL) 4519 if (priv->config & CFG_STATIC_CHANNEL)
4467 IPW_DEBUG_INFO("Channel locked to %d\n", 4520 IPW_DEBUG_INFO("Channel locked to %d\n", priv->channel);
4468 priv->channel);
4469 else 4521 else
4470 IPW_DEBUG_INFO("Channel unlocked.\n"); 4522 IPW_DEBUG_INFO("Channel unlocked.\n");
4471 if (priv->config & CFG_STATIC_ESSID) 4523 if (priv->config & CFG_STATIC_ESSID)
4472 IPW_DEBUG_INFO("ESSID locked to '%s'\n", 4524 IPW_DEBUG_INFO("ESSID locked to '%s'\n",
4473 escape_essid(priv->essid, 4525 escape_essid(priv->essid, priv->essid_len));
4474 priv->essid_len));
4475 else 4526 else
4476 IPW_DEBUG_INFO("ESSID unlocked.\n"); 4527 IPW_DEBUG_INFO("ESSID unlocked.\n");
4477 if (priv->config & CFG_STATIC_BSSID) 4528 if (priv->config & CFG_STATIC_BSSID)
@@ -4502,7 +4553,7 @@ static inline void ipw_set_fixed_rate(struct ipw_priv *priv,
4502 * Tx rates */ 4553 * Tx rates */
4503 4554
4504 switch (priv->ieee->freq_band) { 4555 switch (priv->ieee->freq_band) {
4505 case IEEE80211_52GHZ_BAND: /* A only */ 4556 case IEEE80211_52GHZ_BAND: /* A only */
4506 /* IEEE_A */ 4557 /* IEEE_A */
4507 if (priv->rates_mask & ~IEEE80211_OFDM_RATES_MASK) { 4558 if (priv->rates_mask & ~IEEE80211_OFDM_RATES_MASK) {
4508 /* Invalid fixed rate mask */ 4559 /* Invalid fixed rate mask */
@@ -4513,7 +4564,7 @@ static inline void ipw_set_fixed_rate(struct ipw_priv *priv,
4513 fr.tx_rates >>= IEEE80211_OFDM_SHIFT_MASK_A; 4564 fr.tx_rates >>= IEEE80211_OFDM_SHIFT_MASK_A;
4514 break; 4565 break;
4515 4566
4516 default: /* 2.4Ghz or Mixed */ 4567 default: /* 2.4Ghz or Mixed */
4517 /* IEEE_B */ 4568 /* IEEE_B */
4518 if (network->mode == IEEE_B) { 4569 if (network->mode == IEEE_B) {
4519 if (fr.tx_rates & ~IEEE80211_CCK_RATES_MASK) { 4570 if (fr.tx_rates & ~IEEE80211_CCK_RATES_MASK) {
@@ -4551,13 +4602,12 @@ static inline void ipw_set_fixed_rate(struct ipw_priv *priv,
4551 } 4602 }
4552 4603
4553 reg = ipw_read32(priv, IPW_MEM_FIXED_OVERRIDE); 4604 reg = ipw_read32(priv, IPW_MEM_FIXED_OVERRIDE);
4554 ipw_write_reg32(priv, reg, *(u32*)&fr); 4605 ipw_write_reg32(priv, reg, *(u32 *) & fr);
4555} 4606}
4556 4607
4557static int ipw_associate_network(struct ipw_priv *priv, 4608static int ipw_associate_network(struct ipw_priv *priv,
4558 struct ieee80211_network *network, 4609 struct ieee80211_network *network,
4559 struct ipw_supported_rates *rates, 4610 struct ipw_supported_rates *rates, int roaming)
4560 int roaming)
4561{ 4611{
4562 int err; 4612 int err;
4563 4613
@@ -4566,7 +4616,7 @@ static int ipw_associate_network(struct ipw_priv *priv,
4566 4616
4567 if (!(priv->config & CFG_STATIC_ESSID)) { 4617 if (!(priv->config & CFG_STATIC_ESSID)) {
4568 priv->essid_len = min(network->ssid_len, 4618 priv->essid_len = min(network->ssid_len,
4569 (u8)IW_ESSID_MAX_SIZE); 4619 (u8) IW_ESSID_MAX_SIZE);
4570 memcpy(priv->essid, network->ssid, priv->essid_len); 4620 memcpy(priv->essid, network->ssid, priv->essid_len);
4571 } 4621 }
4572 4622
@@ -4612,13 +4662,11 @@ static int ipw_associate_network(struct ipw_priv *priv,
4612 priv->capability & CAP_PRIVACY_ON ? " key=" : "", 4662 priv->capability & CAP_PRIVACY_ON ? " key=" : "",
4613 priv->capability & CAP_PRIVACY_ON ? 4663 priv->capability & CAP_PRIVACY_ON ?
4614 '1' + priv->sec.active_key : '.', 4664 '1' + priv->sec.active_key : '.',
4615 priv->capability & CAP_PRIVACY_ON ? 4665 priv->capability & CAP_PRIVACY_ON ? '.' : ' ');
4616 '.' : ' ');
4617 4666
4618 priv->assoc_request.beacon_interval = network->beacon_interval; 4667 priv->assoc_request.beacon_interval = network->beacon_interval;
4619 if ((priv->ieee->iw_mode == IW_MODE_ADHOC) && 4668 if ((priv->ieee->iw_mode == IW_MODE_ADHOC) &&
4620 (network->time_stamp[0] == 0) && 4669 (network->time_stamp[0] == 0) && (network->time_stamp[1] == 0)) {
4621 (network->time_stamp[1] == 0)) {
4622 priv->assoc_request.assoc_type = HC_IBSS_START; 4670 priv->assoc_request.assoc_type = HC_IBSS_START;
4623 priv->assoc_request.assoc_tsf_msw = 0; 4671 priv->assoc_request.assoc_tsf_msw = 0;
4624 priv->assoc_request.assoc_tsf_lsw = 0; 4672 priv->assoc_request.assoc_tsf_lsw = 0;
@@ -4637,8 +4685,7 @@ static int ipw_associate_network(struct ipw_priv *priv,
4637 memset(&priv->assoc_request.dest, 0xFF, ETH_ALEN); 4685 memset(&priv->assoc_request.dest, 0xFF, ETH_ALEN);
4638 priv->assoc_request.atim_window = network->atim_window; 4686 priv->assoc_request.atim_window = network->atim_window;
4639 } else { 4687 } else {
4640 memcpy(&priv->assoc_request.dest, network->bssid, 4688 memcpy(&priv->assoc_request.dest, network->bssid, ETH_ALEN);
4641 ETH_ALEN);
4642 priv->assoc_request.atim_window = 0; 4689 priv->assoc_request.atim_window = 0;
4643 } 4690 }
4644 4691
@@ -4772,14 +4819,13 @@ static void ipw_associate(void *data)
4772 4819
4773 if (!(priv->config & CFG_ASSOCIATE) && 4820 if (!(priv->config & CFG_ASSOCIATE) &&
4774 !(priv->config & (CFG_STATIC_ESSID | 4821 !(priv->config & (CFG_STATIC_ESSID |
4775 CFG_STATIC_CHANNEL | 4822 CFG_STATIC_CHANNEL | CFG_STATIC_BSSID))) {
4776 CFG_STATIC_BSSID))) {
4777 IPW_DEBUG_ASSOC("Not attempting association (associate=0)\n"); 4823 IPW_DEBUG_ASSOC("Not attempting association (associate=0)\n");
4778 return; 4824 return;
4779 } 4825 }
4780 4826
4781 list_for_each_entry(network, &priv->ieee->network_list, list) 4827 list_for_each_entry(network, &priv->ieee->network_list, list)
4782 ipw_best_network(priv, &match, network, 0); 4828 ipw_best_network(priv, &match, network, 0);
4783 4829
4784 network = match.network; 4830 network = match.network;
4785 rates = &match.rates; 4831 rates = &match.rates;
@@ -4790,8 +4836,7 @@ static void ipw_associate(void *data)
4790 priv->config & CFG_STATIC_ESSID && 4836 priv->config & CFG_STATIC_ESSID &&
4791 !list_empty(&priv->ieee->network_free_list)) { 4837 !list_empty(&priv->ieee->network_free_list)) {
4792 element = priv->ieee->network_free_list.next; 4838 element = priv->ieee->network_free_list.next;
4793 network = list_entry(element, struct ieee80211_network, 4839 network = list_entry(element, struct ieee80211_network, list);
4794 list);
4795 ipw_adhoc_create(priv, network); 4840 ipw_adhoc_create(priv, network);
4796 rates = &priv->rates; 4841 rates = &priv->rates;
4797 list_del(element); 4842 list_del(element);
@@ -4813,8 +4858,8 @@ static void ipw_associate(void *data)
4813} 4858}
4814 4859
4815static inline void ipw_handle_data_packet(struct ipw_priv *priv, 4860static inline void ipw_handle_data_packet(struct ipw_priv *priv,
4816 struct ipw_rx_mem_buffer *rxb, 4861 struct ipw_rx_mem_buffer *rxb,
4817 struct ieee80211_rx_stats *stats) 4862 struct ieee80211_rx_stats *stats)
4818{ 4863{
4819 struct ipw_rx_packet *pkt = (struct ipw_rx_packet *)rxb->skb->data; 4864 struct ipw_rx_packet *pkt = (struct ipw_rx_packet *)rxb->skb->data;
4820 4865
@@ -4846,11 +4891,10 @@ static inline void ipw_handle_data_packet(struct ipw_priv *priv,
4846 4891
4847 if (!ieee80211_rx(priv->ieee, rxb->skb, stats)) 4892 if (!ieee80211_rx(priv->ieee, rxb->skb, stats))
4848 priv->ieee->stats.rx_errors++; 4893 priv->ieee->stats.rx_errors++;
4849 else /* ieee80211_rx succeeded, so it now owns the SKB */ 4894 else /* ieee80211_rx succeeded, so it now owns the SKB */
4850 rxb->skb = NULL; 4895 rxb->skb = NULL;
4851} 4896}
4852 4897
4853
4854/* 4898/*
4855 * Main entry function for recieving a packet with 80211 headers. This 4899 * Main entry function for recieving a packet with 80211 headers. This
4856 * should be called when ever the FW has notified us that there is a new 4900 * should be called when ever the FW has notified us that there is a new
@@ -4885,125 +4929,152 @@ static void ipw_rx(struct ipw_priv *priv)
4885 pkt = (struct ipw_rx_packet *)rxb->skb->data; 4929 pkt = (struct ipw_rx_packet *)rxb->skb->data;
4886 IPW_DEBUG_RX("Packet: type=%02X seq=%02X bits=%02X\n", 4930 IPW_DEBUG_RX("Packet: type=%02X seq=%02X bits=%02X\n",
4887 pkt->header.message_type, 4931 pkt->header.message_type,
4888 pkt->header.rx_seq_num, 4932 pkt->header.rx_seq_num, pkt->header.control_bits);
4889 pkt->header.control_bits);
4890 4933
4891 switch (pkt->header.message_type) { 4934 switch (pkt->header.message_type) {
4892 case RX_FRAME_TYPE: /* 802.11 frame */ { 4935 case RX_FRAME_TYPE: /* 802.11 frame */ {
4893 struct ieee80211_rx_stats stats = { 4936 struct ieee80211_rx_stats stats = {
4894 .rssi = pkt->u.frame.rssi_dbm - 4937 .rssi = pkt->u.frame.rssi_dbm -
4895 IPW_RSSI_TO_DBM, 4938 IPW_RSSI_TO_DBM,
4896 .signal = pkt->u.frame.signal, 4939 .signal = pkt->u.frame.signal,
4897 .rate = pkt->u.frame.rate, 4940 .rate = pkt->u.frame.rate,
4898 .mac_time = jiffies, 4941 .mac_time = jiffies,
4899 .received_channel = 4942 .received_channel =
4900 pkt->u.frame.received_channel, 4943 pkt->u.frame.received_channel,
4901 .freq = (pkt->u.frame.control & (1<<0)) ? 4944 .freq =
4902 IEEE80211_24GHZ_BAND : IEEE80211_52GHZ_BAND, 4945 (pkt->u.frame.
4903 .len = pkt->u.frame.length, 4946 control & (1 << 0)) ?
4904 }; 4947 IEEE80211_24GHZ_BAND :
4905 4948 IEEE80211_52GHZ_BAND,
4906 if (stats.rssi != 0) 4949 .len = pkt->u.frame.length,
4907 stats.mask |= IEEE80211_STATMASK_RSSI; 4950 };
4908 if (stats.signal != 0) 4951
4909 stats.mask |= IEEE80211_STATMASK_SIGNAL; 4952 if (stats.rssi != 0)
4910 if (stats.rate != 0) 4953 stats.mask |= IEEE80211_STATMASK_RSSI;
4911 stats.mask |= IEEE80211_STATMASK_RATE; 4954 if (stats.signal != 0)
4912 4955 stats.mask |= IEEE80211_STATMASK_SIGNAL;
4913 priv->rx_packets++; 4956 if (stats.rate != 0)
4957 stats.mask |= IEEE80211_STATMASK_RATE;
4958
4959 priv->rx_packets++;
4914 4960
4915#ifdef CONFIG_IPW_PROMISC 4961#ifdef CONFIG_IPW_PROMISC
4916 if (priv->ieee->iw_mode == IW_MODE_MONITOR) { 4962 if (priv->ieee->iw_mode == IW_MODE_MONITOR) {
4917 ipw_handle_data_packet(priv, rxb, &stats); 4963 ipw_handle_data_packet(priv, rxb,
4918 break; 4964 &stats);
4919 } 4965 break;
4966 }
4920#endif 4967#endif
4921 4968
4922 header = (struct ieee80211_hdr *)(rxb->skb->data + 4969 header =
4923 IPW_RX_FRAME_SIZE); 4970 (struct ieee80211_hdr *)(rxb->skb->data +
4971 IPW_RX_FRAME_SIZE);
4924 /* TODO: Check Ad-Hoc dest/source and make sure 4972 /* TODO: Check Ad-Hoc dest/source and make sure
4925 * that we are actually parsing these packets 4973 * that we are actually parsing these packets
4926 * correctly -- we should probably use the 4974 * correctly -- we should probably use the
4927 * frame control of the packet and disregard 4975 * frame control of the packet and disregard
4928 * the current iw_mode */ 4976 * the current iw_mode */
4929 switch (priv->ieee->iw_mode) { 4977 switch (priv->ieee->iw_mode) {
4930 case IW_MODE_ADHOC: 4978 case IW_MODE_ADHOC:
4931 network_packet = 4979 network_packet =
4932 !memcmp(header->addr1, 4980 !memcmp(header->addr1,
4933 priv->net_dev->dev_addr, 4981 priv->net_dev->dev_addr,
4934 ETH_ALEN) || 4982 ETH_ALEN) ||
4935 !memcmp(header->addr3, 4983 !memcmp(header->addr3,
4936 priv->bssid, ETH_ALEN) || 4984 priv->bssid, ETH_ALEN) ||
4937 is_broadcast_ether_addr(header->addr1) || 4985 is_broadcast_ether_addr(header->
4938 is_multicast_ether_addr(header->addr1); 4986 addr1)
4939 break; 4987 || is_multicast_ether_addr(header->
4940 4988 addr1);
4941 case IW_MODE_INFRA: 4989 break;
4942 default: 4990
4943 network_packet = 4991 case IW_MODE_INFRA:
4944 !memcmp(header->addr3, 4992 default:
4945 priv->bssid, ETH_ALEN) || 4993 network_packet =
4946 !memcmp(header->addr1, 4994 !memcmp(header->addr3,
4947 priv->net_dev->dev_addr, 4995 priv->bssid, ETH_ALEN) ||
4948 ETH_ALEN) || 4996 !memcmp(header->addr1,
4949 is_broadcast_ether_addr(header->addr1) || 4997 priv->net_dev->dev_addr,
4950 is_multicast_ether_addr(header->addr1); 4998 ETH_ALEN) ||
4999 is_broadcast_ether_addr(header->
5000 addr1)
5001 || is_multicast_ether_addr(header->
5002 addr1);
5003 break;
5004 }
5005
5006 if (network_packet && priv->assoc_network) {
5007 priv->assoc_network->stats.rssi =
5008 stats.rssi;
5009 average_add(&priv->average_rssi,
5010 stats.rssi);
5011 priv->last_rx_rssi = stats.rssi;
5012 }
5013
5014 IPW_DEBUG_RX("Frame: len=%u\n",
5015 pkt->u.frame.length);
5016
5017 if (pkt->u.frame.length < frame_hdr_len(header)) {
5018 IPW_DEBUG_DROP
5019 ("Received packet is too small. "
5020 "Dropping.\n");
5021 priv->ieee->stats.rx_errors++;
5022 priv->wstats.discard.misc++;
5023 break;
5024 }
5025
5026 switch (WLAN_FC_GET_TYPE(header->frame_ctl)) {
5027 case IEEE80211_FTYPE_MGMT:
5028 ieee80211_rx_mgt(priv->ieee, header,
5029 &stats);
5030 if (priv->ieee->iw_mode == IW_MODE_ADHOC
5031 &&
5032 ((WLAN_FC_GET_STYPE
5033 (header->frame_ctl) ==
5034 IEEE80211_STYPE_PROBE_RESP)
5035 ||
5036 (WLAN_FC_GET_STYPE
5037 (header->frame_ctl) ==
5038 IEEE80211_STYPE_BEACON))
5039 && !memcmp(header->addr3,
5040 priv->bssid, ETH_ALEN))
5041 ipw_add_station(priv,
5042 header->addr2);
5043 break;
5044
5045 case IEEE80211_FTYPE_CTL:
5046 break;
5047
5048 case IEEE80211_FTYPE_DATA:
5049 if (network_packet)
5050 ipw_handle_data_packet(priv,
5051 rxb,
5052 &stats);
5053 else
5054 IPW_DEBUG_DROP("Dropping: "
5055 MAC_FMT ", "
5056 MAC_FMT ", "
5057 MAC_FMT "\n",
5058 MAC_ARG(header->
5059 addr1),
5060 MAC_ARG(header->
5061 addr2),
5062 MAC_ARG(header->
5063 addr3));
5064 break;
5065 }
4951 break; 5066 break;
4952 } 5067 }
4953 5068
4954 if (network_packet && priv->assoc_network) { 5069 case RX_HOST_NOTIFICATION_TYPE:{
4955 priv->assoc_network->stats.rssi = stats.rssi; 5070 IPW_DEBUG_RX
4956 average_add(&priv->average_rssi, 5071 ("Notification: subtype=%02X flags=%02X size=%d\n",
4957 stats.rssi);
4958 priv->last_rx_rssi = stats.rssi;
4959 }
4960
4961 IPW_DEBUG_RX("Frame: len=%u\n", pkt->u.frame.length);
4962
4963 if (pkt->u.frame.length < frame_hdr_len(header)) {
4964 IPW_DEBUG_DROP("Received packet is too small. "
4965 "Dropping.\n");
4966 priv->ieee->stats.rx_errors++;
4967 priv->wstats.discard.misc++;
4968 break;
4969 }
4970
4971 switch (WLAN_FC_GET_TYPE(header->frame_ctl)) {
4972 case IEEE80211_FTYPE_MGMT:
4973 ieee80211_rx_mgt(priv->ieee, header, &stats);
4974 if (priv->ieee->iw_mode == IW_MODE_ADHOC &&
4975 ((WLAN_FC_GET_STYPE(header->frame_ctl) ==
4976 IEEE80211_STYPE_PROBE_RESP) ||
4977 (WLAN_FC_GET_STYPE(header->frame_ctl) ==
4978 IEEE80211_STYPE_BEACON)) &&
4979 !memcmp(header->addr3, priv->bssid, ETH_ALEN))
4980 ipw_add_station(priv, header->addr2);
4981 break;
4982
4983 case IEEE80211_FTYPE_CTL:
4984 break;
4985
4986 case IEEE80211_FTYPE_DATA:
4987 if (network_packet)
4988 ipw_handle_data_packet(priv, rxb, &stats);
4989 else
4990 IPW_DEBUG_DROP("Dropping: " MAC_FMT
4991 ", " MAC_FMT ", " MAC_FMT "\n",
4992 MAC_ARG(header->addr1), MAC_ARG(header->addr2),
4993 MAC_ARG(header->addr3));
4994 break;
4995 }
4996 break;
4997 }
4998
4999 case RX_HOST_NOTIFICATION_TYPE: {
5000 IPW_DEBUG_RX("Notification: subtype=%02X flags=%02X size=%d\n",
5001 pkt->u.notification.subtype, 5072 pkt->u.notification.subtype,
5002 pkt->u.notification.flags, 5073 pkt->u.notification.flags,
5003 pkt->u.notification.size); 5074 pkt->u.notification.size);
5004 ipw_rx_notification(priv, &pkt->u.notification); 5075 ipw_rx_notification(priv, &pkt->u.notification);
5005 break; 5076 break;
5006 } 5077 }
5007 5078
5008 default: 5079 default:
5009 IPW_DEBUG_RX("Bad Rx packet of type %d\n", 5080 IPW_DEBUG_RX("Bad Rx packet of type %d\n",
@@ -5088,10 +5159,10 @@ static int ipw_request_scan(struct ipw_priv *priv)
5088 /* If we are roaming, then make this a directed scan for the current 5159 /* If we are roaming, then make this a directed scan for the current
5089 * network. Otherwise, ensure that every other scan is a fast 5160 * network. Otherwise, ensure that every other scan is a fast
5090 * channel hop scan */ 5161 * channel hop scan */
5091 if ((priv->status & STATUS_ROAMING) || ( 5162 if ((priv->status & STATUS_ROAMING)
5092 !(priv->status & STATUS_ASSOCIATED) && 5163 || (!(priv->status & STATUS_ASSOCIATED)
5093 (priv->config & CFG_STATIC_ESSID) && 5164 && (priv->config & CFG_STATIC_ESSID)
5094 (scan.full_scan_index % 2))) { 5165 && (scan.full_scan_index % 2))) {
5095 err = ipw_send_ssid(priv, priv->essid, priv->essid_len); 5166 err = ipw_send_ssid(priv, priv->essid, priv->essid_len);
5096 if (err) { 5167 if (err) {
5097 IPW_DEBUG_HC("Attempt to send SSID command failed.\n"); 5168 IPW_DEBUG_HC("Attempt to send SSID command failed.\n");
@@ -5103,7 +5174,7 @@ static int ipw_request_scan(struct ipw_priv *priv)
5103 scan_type = IPW_SCAN_ACTIVE_BROADCAST_SCAN; 5174 scan_type = IPW_SCAN_ACTIVE_BROADCAST_SCAN;
5104 } 5175 }
5105 5176
5106 if (priv->ieee->freq_band & IEEE80211_52GHZ_BAND) { 5177 if (priv->ieee->freq_band & IEEE80211_52GHZ_BAND) {
5107 int start = channel_index; 5178 int start = channel_index;
5108 for (i = 0; i < MAX_A_CHANNELS; i++) { 5179 for (i = 0; i < MAX_A_CHANNELS; i++) {
5109 if (band_a_active_channel[i] == 0) 5180 if (band_a_active_channel[i] == 0)
@@ -5113,18 +5184,18 @@ static int ipw_request_scan(struct ipw_priv *priv)
5113 continue; 5184 continue;
5114 channel_index++; 5185 channel_index++;
5115 scan.channels_list[channel_index] = 5186 scan.channels_list[channel_index] =
5116 band_a_active_channel[i]; 5187 band_a_active_channel[i];
5117 ipw_set_scan_type(&scan, channel_index, scan_type); 5188 ipw_set_scan_type(&scan, channel_index, scan_type);
5118 } 5189 }
5119 5190
5120 if (start != channel_index) { 5191 if (start != channel_index) {
5121 scan.channels_list[start] = (u8)(IPW_A_MODE << 6) | 5192 scan.channels_list[start] = (u8) (IPW_A_MODE << 6) |
5122 (channel_index - start); 5193 (channel_index - start);
5123 channel_index++; 5194 channel_index++;
5124 } 5195 }
5125 } 5196 }
5126 5197
5127 if (priv->ieee->freq_band & IEEE80211_24GHZ_BAND) { 5198 if (priv->ieee->freq_band & IEEE80211_24GHZ_BAND) {
5128 int start = channel_index; 5199 int start = channel_index;
5129 for (i = 0; i < MAX_B_CHANNELS; i++) { 5200 for (i = 0; i < MAX_B_CHANNELS; i++) {
5130 if (band_b_active_channel[i] == 0) 5201 if (band_b_active_channel[i] == 0)
@@ -5134,20 +5205,19 @@ static int ipw_request_scan(struct ipw_priv *priv)
5134 continue; 5205 continue;
5135 channel_index++; 5206 channel_index++;
5136 scan.channels_list[channel_index] = 5207 scan.channels_list[channel_index] =
5137 band_b_active_channel[i]; 5208 band_b_active_channel[i];
5138 ipw_set_scan_type(&scan, channel_index, scan_type); 5209 ipw_set_scan_type(&scan, channel_index, scan_type);
5139 } 5210 }
5140 5211
5141 if (start != channel_index) { 5212 if (start != channel_index) {
5142 scan.channels_list[start] = (u8)(IPW_B_MODE << 6) | 5213 scan.channels_list[start] = (u8) (IPW_B_MODE << 6) |
5143 (channel_index - start); 5214 (channel_index - start);
5144 } 5215 }
5145 } 5216 }
5146 5217
5147 err = ipw_send_scan_request_ext(priv, &scan); 5218 err = ipw_send_scan_request_ext(priv, &scan);
5148 if (err) { 5219 if (err) {
5149 IPW_DEBUG_HC("Sending scan command failed: %08X\n", 5220 IPW_DEBUG_HC("Sending scan command failed: %08X\n", err);
5150 err);
5151 return -EIO; 5221 return -EIO;
5152 } 5222 }
5153 5223
@@ -5199,9 +5269,8 @@ static int ipw_set_channel(struct ipw_priv *priv, u8 channel)
5199 priv->config |= CFG_STATIC_CHANNEL; 5269 priv->config |= CFG_STATIC_CHANNEL;
5200 5270
5201 if (priv->channel == channel) { 5271 if (priv->channel == channel) {
5202 IPW_DEBUG_INFO( 5272 IPW_DEBUG_INFO("Request to set channel to current value (%d)\n",
5203 "Request to set channel to current value (%d)\n", 5273 channel);
5204 channel);
5205 return 0; 5274 return 0;
5206 } 5275 }
5207 5276
@@ -5229,8 +5298,7 @@ static int ipw_wx_set_freq(struct net_device *dev,
5229 5298
5230 /* if setting by freq convert to channel */ 5299 /* if setting by freq convert to channel */
5231 if (fwrq->e == 1) { 5300 if (fwrq->e == 1) {
5232 if ((fwrq->m >= (int) 2.412e8 && 5301 if ((fwrq->m >= (int)2.412e8 && fwrq->m <= (int)2.487e8)) {
5233 fwrq->m <= (int) 2.487e8)) {
5234 int f = fwrq->m / 100000; 5302 int f = fwrq->m / 100000;
5235 int c = 0; 5303 int c = 0;
5236 5304
@@ -5248,12 +5316,11 @@ static int ipw_wx_set_freq(struct net_device *dev,
5248 return -EOPNOTSUPP; 5316 return -EOPNOTSUPP;
5249 5317
5250 IPW_DEBUG_WX("SET Freq/Channel -> %d \n", fwrq->m); 5318 IPW_DEBUG_WX("SET Freq/Channel -> %d \n", fwrq->m);
5251 return ipw_set_channel(priv, (u8)fwrq->m); 5319 return ipw_set_channel(priv, (u8) fwrq->m);
5252 5320
5253 return 0; 5321 return 0;
5254} 5322}
5255 5323
5256
5257static int ipw_wx_get_freq(struct net_device *dev, 5324static int ipw_wx_get_freq(struct net_device *dev,
5258 struct iw_request_info *info, 5325 struct iw_request_info *info,
5259 union iwreq_data *wrqu, char *extra) 5326 union iwreq_data *wrqu, char *extra)
@@ -5306,7 +5373,7 @@ static int ipw_wx_set_mode(struct net_device *dev,
5306 5373
5307 if (wrqu->mode == IW_MODE_MONITOR) 5374 if (wrqu->mode == IW_MODE_MONITOR)
5308 priv->net_dev->type = ARPHRD_IEEE80211; 5375 priv->net_dev->type = ARPHRD_IEEE80211;
5309#endif /* CONFIG_IPW_PROMISC */ 5376#endif /* CONFIG_IPW_PROMISC */
5310 5377
5311#ifdef CONFIG_PM 5378#ifdef CONFIG_PM
5312 /* Free the existing firmware and reset the fw_loaded 5379 /* Free the existing firmware and reset the fw_loaded
@@ -5324,12 +5391,12 @@ static int ipw_wx_set_mode(struct net_device *dev,
5324 priv->ieee->iw_mode = wrqu->mode; 5391 priv->ieee->iw_mode = wrqu->mode;
5325 ipw_adapter_restart(priv); 5392 ipw_adapter_restart(priv);
5326 5393
5327 return err; 5394 return err;
5328} 5395}
5329 5396
5330static int ipw_wx_get_mode(struct net_device *dev, 5397static int ipw_wx_get_mode(struct net_device *dev,
5331 struct iw_request_info *info, 5398 struct iw_request_info *info,
5332 union iwreq_data *wrqu, char *extra) 5399 union iwreq_data *wrqu, char *extra)
5333{ 5400{
5334 struct ipw_priv *priv = ieee80211_priv(dev); 5401 struct ipw_priv *priv = ieee80211_priv(dev);
5335 5402
@@ -5339,7 +5406,6 @@ static int ipw_wx_get_mode(struct net_device *dev,
5339 return 0; 5406 return 0;
5340} 5407}
5341 5408
5342
5343#define DEFAULT_RTS_THRESHOLD 2304U 5409#define DEFAULT_RTS_THRESHOLD 2304U
5344#define MIN_RTS_THRESHOLD 1U 5410#define MIN_RTS_THRESHOLD 1U
5345#define MAX_RTS_THRESHOLD 2304U 5411#define MAX_RTS_THRESHOLD 2304U
@@ -5383,19 +5449,19 @@ static int ipw_wx_get_range(struct net_device *dev,
5383 /* TODO: Find real max RSSI and stick here */ 5449 /* TODO: Find real max RSSI and stick here */
5384 range->max_qual.level = 0; 5450 range->max_qual.level = 0;
5385 range->max_qual.noise = 0; 5451 range->max_qual.noise = 0;
5386 range->max_qual.updated = 7; /* Updated all three */ 5452 range->max_qual.updated = 7; /* Updated all three */
5387 5453
5388 range->avg_qual.qual = 70; 5454 range->avg_qual.qual = 70;
5389 /* TODO: Find real 'good' to 'bad' threshol value for RSSI */ 5455 /* TODO: Find real 'good' to 'bad' threshol value for RSSI */
5390 range->avg_qual.level = 0; /* FIXME to real average level */ 5456 range->avg_qual.level = 0; /* FIXME to real average level */
5391 range->avg_qual.noise = 0; 5457 range->avg_qual.noise = 0;
5392 range->avg_qual.updated = 7; /* Updated all three */ 5458 range->avg_qual.updated = 7; /* Updated all three */
5393 5459
5394 range->num_bitrates = min(priv->rates.num_rates, (u8)IW_MAX_BITRATES); 5460 range->num_bitrates = min(priv->rates.num_rates, (u8) IW_MAX_BITRATES);
5395 5461
5396 for (i = 0; i < range->num_bitrates; i++) 5462 for (i = 0; i < range->num_bitrates; i++)
5397 range->bitrate[i] = (priv->rates.supported_rates[i] & 0x7F) * 5463 range->bitrate[i] = (priv->rates.supported_rates[i] & 0x7F) *
5398 500000; 5464 500000;
5399 5465
5400 range->max_rts = DEFAULT_RTS_THRESHOLD; 5466 range->max_rts = DEFAULT_RTS_THRESHOLD;
5401 range->min_frag = MIN_FRAG_THRESHOLD; 5467 range->min_frag = MIN_FRAG_THRESHOLD;
@@ -5410,7 +5476,7 @@ static int ipw_wx_get_range(struct net_device *dev,
5410 range->we_version_compiled = WIRELESS_EXT; 5476 range->we_version_compiled = WIRELESS_EXT;
5411 range->we_version_source = 16; 5477 range->we_version_source = 16;
5412 5478
5413 range->num_channels = FREQ_COUNT; 5479 range->num_channels = FREQ_COUNT;
5414 5480
5415 val = 0; 5481 val = 0;
5416 for (i = 0; i < FREQ_COUNT; i++) { 5482 for (i = 0; i < FREQ_COUNT; i++) {
@@ -5506,7 +5572,7 @@ static int ipw_wx_set_essid(struct net_device *dev,
5506 union iwreq_data *wrqu, char *extra) 5572 union iwreq_data *wrqu, char *extra)
5507{ 5573{
5508 struct ipw_priv *priv = ieee80211_priv(dev); 5574 struct ipw_priv *priv = ieee80211_priv(dev);
5509 char *essid = ""; /* ANY */ 5575 char *essid = ""; /* ANY */
5510 int length = 0; 5576 int length = 0;
5511 5577
5512 if (wrqu->essid.flags && wrqu->essid.length) { 5578 if (wrqu->essid.flags && wrqu->essid.length) {
@@ -5567,11 +5633,11 @@ static int ipw_wx_get_essid(struct net_device *dev,
5567 escape_essid(priv->essid, priv->essid_len)); 5633 escape_essid(priv->essid, priv->essid_len));
5568 memcpy(extra, priv->essid, priv->essid_len); 5634 memcpy(extra, priv->essid, priv->essid_len);
5569 wrqu->essid.length = priv->essid_len; 5635 wrqu->essid.length = priv->essid_len;
5570 wrqu->essid.flags = 1; /* active */ 5636 wrqu->essid.flags = 1; /* active */
5571 } else { 5637 } else {
5572 IPW_DEBUG_WX("Getting essid: ANY\n"); 5638 IPW_DEBUG_WX("Getting essid: ANY\n");
5573 wrqu->essid.length = 0; 5639 wrqu->essid.length = 0;
5574 wrqu->essid.flags = 0; /* active */ 5640 wrqu->essid.flags = 0; /* active */
5575 } 5641 }
5576 5642
5577 return 0; 5643 return 0;
@@ -5587,15 +5653,14 @@ static int ipw_wx_set_nick(struct net_device *dev,
5587 if (wrqu->data.length > IW_ESSID_MAX_SIZE) 5653 if (wrqu->data.length > IW_ESSID_MAX_SIZE)
5588 return -E2BIG; 5654 return -E2BIG;
5589 5655
5590 wrqu->data.length = min((size_t)wrqu->data.length, sizeof(priv->nick)); 5656 wrqu->data.length = min((size_t) wrqu->data.length, sizeof(priv->nick));
5591 memset(priv->nick, 0, sizeof(priv->nick)); 5657 memset(priv->nick, 0, sizeof(priv->nick));
5592 memcpy(priv->nick, extra, wrqu->data.length); 5658 memcpy(priv->nick, extra, wrqu->data.length);
5593 IPW_DEBUG_TRACE("<<\n"); 5659 IPW_DEBUG_TRACE("<<\n");
5594 return 0; 5660 return 0;
5595 5661
5596} 5662}
5597 5663
5598
5599static int ipw_wx_get_nick(struct net_device *dev, 5664static int ipw_wx_get_nick(struct net_device *dev,
5600 struct iw_request_info *info, 5665 struct iw_request_info *info,
5601 union iwreq_data *wrqu, char *extra) 5666 union iwreq_data *wrqu, char *extra)
@@ -5604,11 +5669,10 @@ static int ipw_wx_get_nick(struct net_device *dev,
5604 IPW_DEBUG_WX("Getting nick\n"); 5669 IPW_DEBUG_WX("Getting nick\n");
5605 wrqu->data.length = strlen(priv->nick) + 1; 5670 wrqu->data.length = strlen(priv->nick) + 1;
5606 memcpy(extra, priv->nick, wrqu->data.length); 5671 memcpy(extra, priv->nick, wrqu->data.length);
5607 wrqu->data.flags = 1; /* active */ 5672 wrqu->data.flags = 1; /* active */
5608 return 0; 5673 return 0;
5609} 5674}
5610 5675
5611
5612static int ipw_wx_set_rate(struct net_device *dev, 5676static int ipw_wx_set_rate(struct net_device *dev,
5613 struct iw_request_info *info, 5677 struct iw_request_info *info,
5614 union iwreq_data *wrqu, char *extra) 5678 union iwreq_data *wrqu, char *extra)
@@ -5621,14 +5685,13 @@ static int ipw_wx_get_rate(struct net_device *dev,
5621 struct iw_request_info *info, 5685 struct iw_request_info *info,
5622 union iwreq_data *wrqu, char *extra) 5686 union iwreq_data *wrqu, char *extra)
5623{ 5687{
5624 struct ipw_priv * priv = ieee80211_priv(dev); 5688 struct ipw_priv *priv = ieee80211_priv(dev);
5625 wrqu->bitrate.value = priv->last_rate; 5689 wrqu->bitrate.value = priv->last_rate;
5626 5690
5627 IPW_DEBUG_WX("GET Rate -> %d \n", wrqu->bitrate.value); 5691 IPW_DEBUG_WX("GET Rate -> %d \n", wrqu->bitrate.value);
5628 return 0; 5692 return 0;
5629} 5693}
5630 5694
5631
5632static int ipw_wx_set_rts(struct net_device *dev, 5695static int ipw_wx_set_rts(struct net_device *dev,
5633 struct iw_request_info *info, 5696 struct iw_request_info *info,
5634 union iwreq_data *wrqu, char *extra) 5697 union iwreq_data *wrqu, char *extra)
@@ -5657,14 +5720,12 @@ static int ipw_wx_get_rts(struct net_device *dev,
5657 struct ipw_priv *priv = ieee80211_priv(dev); 5720 struct ipw_priv *priv = ieee80211_priv(dev);
5658 wrqu->rts.value = priv->rts_threshold; 5721 wrqu->rts.value = priv->rts_threshold;
5659 wrqu->rts.fixed = 0; /* no auto select */ 5722 wrqu->rts.fixed = 0; /* no auto select */
5660 wrqu->rts.disabled = 5723 wrqu->rts.disabled = (wrqu->rts.value == DEFAULT_RTS_THRESHOLD);
5661 (wrqu->rts.value == DEFAULT_RTS_THRESHOLD);
5662 5724
5663 IPW_DEBUG_WX("GET RTS Threshold -> %d \n", wrqu->rts.value); 5725 IPW_DEBUG_WX("GET RTS Threshold -> %d \n", wrqu->rts.value);
5664 return 0; 5726 return 0;
5665} 5727}
5666 5728
5667
5668static int ipw_wx_set_txpow(struct net_device *dev, 5729static int ipw_wx_set_txpow(struct net_device *dev,
5669 struct iw_request_info *info, 5730 struct iw_request_info *info,
5670 union iwreq_data *wrqu, char *extra) 5731 union iwreq_data *wrqu, char *extra)
@@ -5679,8 +5740,7 @@ static int ipw_wx_set_txpow(struct net_device *dev,
5679 if (wrqu->power.flags != IW_TXPOW_DBM) 5740 if (wrqu->power.flags != IW_TXPOW_DBM)
5680 return -EINVAL; 5741 return -EINVAL;
5681 5742
5682 if ((wrqu->power.value > 20) || 5743 if ((wrqu->power.value > 20) || (wrqu->power.value < -12))
5683 (wrqu->power.value < -12))
5684 return -EINVAL; 5744 return -EINVAL;
5685 5745
5686 priv->tx_power = wrqu->power.value; 5746 priv->tx_power = wrqu->power.value;
@@ -5704,11 +5764,10 @@ static int ipw_wx_set_txpow(struct net_device *dev,
5704 5764
5705 return 0; 5765 return 0;
5706 5766
5707 error: 5767 error:
5708 return -EIO; 5768 return -EIO;
5709} 5769}
5710 5770
5711
5712static int ipw_wx_get_txpow(struct net_device *dev, 5771static int ipw_wx_get_txpow(struct net_device *dev,
5713 struct iw_request_info *info, 5772 struct iw_request_info *info,
5714 union iwreq_data *wrqu, char *extra) 5773 union iwreq_data *wrqu, char *extra)
@@ -5721,15 +5780,14 @@ static int ipw_wx_get_txpow(struct net_device *dev,
5721 wrqu->power.disabled = (priv->status & STATUS_RF_KILL_MASK) ? 1 : 0; 5780 wrqu->power.disabled = (priv->status & STATUS_RF_KILL_MASK) ? 1 : 0;
5722 5781
5723 IPW_DEBUG_WX("GET TX Power -> %s %d \n", 5782 IPW_DEBUG_WX("GET TX Power -> %s %d \n",
5724 wrqu->power.disabled ? "ON" : "OFF", 5783 wrqu->power.disabled ? "ON" : "OFF", wrqu->power.value);
5725 wrqu->power.value);
5726 5784
5727 return 0; 5785 return 0;
5728} 5786}
5729 5787
5730static int ipw_wx_set_frag(struct net_device *dev, 5788static int ipw_wx_set_frag(struct net_device *dev,
5731 struct iw_request_info *info, 5789 struct iw_request_info *info,
5732 union iwreq_data *wrqu, char *extra) 5790 union iwreq_data *wrqu, char *extra)
5733{ 5791{
5734 struct ipw_priv *priv = ieee80211_priv(dev); 5792 struct ipw_priv *priv = ieee80211_priv(dev);
5735 5793
@@ -5749,14 +5807,13 @@ static int ipw_wx_set_frag(struct net_device *dev,
5749} 5807}
5750 5808
5751static int ipw_wx_get_frag(struct net_device *dev, 5809static int ipw_wx_get_frag(struct net_device *dev,
5752 struct iw_request_info *info, 5810 struct iw_request_info *info,
5753 union iwreq_data *wrqu, char *extra) 5811 union iwreq_data *wrqu, char *extra)
5754{ 5812{
5755 struct ipw_priv *priv = ieee80211_priv(dev); 5813 struct ipw_priv *priv = ieee80211_priv(dev);
5756 wrqu->frag.value = priv->ieee->fts; 5814 wrqu->frag.value = priv->ieee->fts;
5757 wrqu->frag.fixed = 0; /* no auto select */ 5815 wrqu->frag.fixed = 0; /* no auto select */
5758 wrqu->frag.disabled = 5816 wrqu->frag.disabled = (wrqu->frag.value == DEFAULT_FTS);
5759 (wrqu->frag.value == DEFAULT_FTS);
5760 5817
5761 IPW_DEBUG_WX("GET Frag Threshold -> %d \n", wrqu->frag.value); 5818 IPW_DEBUG_WX("GET Frag Threshold -> %d \n", wrqu->frag.value);
5762 5819
@@ -5771,7 +5828,6 @@ static int ipw_wx_set_retry(struct net_device *dev,
5771 return -EOPNOTSUPP; 5828 return -EOPNOTSUPP;
5772} 5829}
5773 5830
5774
5775static int ipw_wx_get_retry(struct net_device *dev, 5831static int ipw_wx_get_retry(struct net_device *dev,
5776 struct iw_request_info *info, 5832 struct iw_request_info *info,
5777 union iwreq_data *wrqu, char *extra) 5833 union iwreq_data *wrqu, char *extra)
@@ -5780,7 +5836,6 @@ static int ipw_wx_get_retry(struct net_device *dev,
5780 return -EOPNOTSUPP; 5836 return -EOPNOTSUPP;
5781} 5837}
5782 5838
5783
5784static int ipw_wx_set_scan(struct net_device *dev, 5839static int ipw_wx_set_scan(struct net_device *dev,
5785 struct iw_request_info *info, 5840 struct iw_request_info *info,
5786 union iwreq_data *wrqu, char *extra) 5841 union iwreq_data *wrqu, char *extra)
@@ -5801,24 +5856,24 @@ static int ipw_wx_get_scan(struct net_device *dev,
5801} 5856}
5802 5857
5803static int ipw_wx_set_encode(struct net_device *dev, 5858static int ipw_wx_set_encode(struct net_device *dev,
5804 struct iw_request_info *info, 5859 struct iw_request_info *info,
5805 union iwreq_data *wrqu, char *key) 5860 union iwreq_data *wrqu, char *key)
5806{ 5861{
5807 struct ipw_priv *priv = ieee80211_priv(dev); 5862 struct ipw_priv *priv = ieee80211_priv(dev);
5808 return ieee80211_wx_set_encode(priv->ieee, info, wrqu, key); 5863 return ieee80211_wx_set_encode(priv->ieee, info, wrqu, key);
5809} 5864}
5810 5865
5811static int ipw_wx_get_encode(struct net_device *dev, 5866static int ipw_wx_get_encode(struct net_device *dev,
5812 struct iw_request_info *info, 5867 struct iw_request_info *info,
5813 union iwreq_data *wrqu, char *key) 5868 union iwreq_data *wrqu, char *key)
5814{ 5869{
5815 struct ipw_priv *priv = ieee80211_priv(dev); 5870 struct ipw_priv *priv = ieee80211_priv(dev);
5816 return ieee80211_wx_get_encode(priv->ieee, info, wrqu, key); 5871 return ieee80211_wx_get_encode(priv->ieee, info, wrqu, key);
5817} 5872}
5818 5873
5819static int ipw_wx_set_power(struct net_device *dev, 5874static int ipw_wx_set_power(struct net_device *dev,
5820 struct iw_request_info *info, 5875 struct iw_request_info *info,
5821 union iwreq_data *wrqu, char *extra) 5876 union iwreq_data *wrqu, char *extra)
5822{ 5877{
5823 struct ipw_priv *priv = ieee80211_priv(dev); 5878 struct ipw_priv *priv = ieee80211_priv(dev);
5824 int err; 5879 int err;
@@ -5837,11 +5892,11 @@ static int ipw_wx_set_power(struct net_device *dev,
5837 } 5892 }
5838 5893
5839 switch (wrqu->power.flags & IW_POWER_MODE) { 5894 switch (wrqu->power.flags & IW_POWER_MODE) {
5840 case IW_POWER_ON: /* If not specified */ 5895 case IW_POWER_ON: /* If not specified */
5841 case IW_POWER_MODE: /* If set all mask */ 5896 case IW_POWER_MODE: /* If set all mask */
5842 case IW_POWER_ALL_R: /* If explicitely state all */ 5897 case IW_POWER_ALL_R: /* If explicitely state all */
5843 break; 5898 break;
5844 default: /* Otherwise we don't support it */ 5899 default: /* Otherwise we don't support it */
5845 IPW_DEBUG_WX("SET PM Mode: %X not supported.\n", 5900 IPW_DEBUG_WX("SET PM Mode: %X not supported.\n",
5846 wrqu->power.flags); 5901 wrqu->power.flags);
5847 return -EOPNOTSUPP; 5902 return -EOPNOTSUPP;
@@ -5849,7 +5904,7 @@ static int ipw_wx_set_power(struct net_device *dev,
5849 5904
5850 /* If the user hasn't specified a power management mode yet, default 5905 /* If the user hasn't specified a power management mode yet, default
5851 * to BATTERY */ 5906 * to BATTERY */
5852 if (IPW_POWER_LEVEL(priv->power_mode) == IPW_POWER_AC) 5907 if (IPW_POWER_LEVEL(priv->power_mode) == IPW_POWER_AC)
5853 priv->power_mode = IPW_POWER_ENABLED | IPW_POWER_BATTERY; 5908 priv->power_mode = IPW_POWER_ENABLED | IPW_POWER_BATTERY;
5854 else 5909 else
5855 priv->power_mode = IPW_POWER_ENABLED | priv->power_mode; 5910 priv->power_mode = IPW_POWER_ENABLED | priv->power_mode;
@@ -5859,15 +5914,14 @@ static int ipw_wx_set_power(struct net_device *dev,
5859 return err; 5914 return err;
5860 } 5915 }
5861 5916
5862 IPW_DEBUG_WX("SET Power Management Mode -> 0x%02X\n", 5917 IPW_DEBUG_WX("SET Power Management Mode -> 0x%02X\n", priv->power_mode);
5863 priv->power_mode);
5864 5918
5865 return 0; 5919 return 0;
5866} 5920}
5867 5921
5868static int ipw_wx_get_power(struct net_device *dev, 5922static int ipw_wx_get_power(struct net_device *dev,
5869 struct iw_request_info *info, 5923 struct iw_request_info *info,
5870 union iwreq_data *wrqu, char *extra) 5924 union iwreq_data *wrqu, char *extra)
5871{ 5925{
5872 struct ipw_priv *priv = ieee80211_priv(dev); 5926 struct ipw_priv *priv = ieee80211_priv(dev);
5873 5927
@@ -5883,8 +5937,8 @@ static int ipw_wx_get_power(struct net_device *dev,
5883} 5937}
5884 5938
5885static int ipw_wx_set_powermode(struct net_device *dev, 5939static int ipw_wx_set_powermode(struct net_device *dev,
5886 struct iw_request_info *info, 5940 struct iw_request_info *info,
5887 union iwreq_data *wrqu, char *extra) 5941 union iwreq_data *wrqu, char *extra)
5888{ 5942{
5889 struct ipw_priv *priv = ieee80211_priv(dev); 5943 struct ipw_priv *priv = ieee80211_priv(dev);
5890 int mode = *(int *)extra; 5944 int mode = *(int *)extra;
@@ -5911,8 +5965,8 @@ static int ipw_wx_set_powermode(struct net_device *dev,
5911 5965
5912#define MAX_WX_STRING 80 5966#define MAX_WX_STRING 80
5913static int ipw_wx_get_powermode(struct net_device *dev, 5967static int ipw_wx_get_powermode(struct net_device *dev,
5914 struct iw_request_info *info, 5968 struct iw_request_info *info,
5915 union iwreq_data *wrqu, char *extra) 5969 union iwreq_data *wrqu, char *extra)
5916{ 5970{
5917 struct ipw_priv *priv = ieee80211_priv(dev); 5971 struct ipw_priv *priv = ieee80211_priv(dev);
5918 int level = IPW_POWER_LEVEL(priv->power_mode); 5972 int level = IPW_POWER_LEVEL(priv->power_mode);
@@ -5935,7 +5989,7 @@ static int ipw_wx_get_powermode(struct net_device *dev,
5935 } 5989 }
5936 5990
5937 if (!(priv->power_mode & IPW_POWER_ENABLED)) 5991 if (!(priv->power_mode & IPW_POWER_ENABLED))
5938 p += snprintf(p, MAX_WX_STRING - (p - extra)," OFF"); 5992 p += snprintf(p, MAX_WX_STRING - (p - extra), " OFF");
5939 5993
5940 wrqu->data.length = p - extra + 1; 5994 wrqu->data.length = p - extra + 1;
5941 5995
@@ -5943,16 +5997,15 @@ static int ipw_wx_get_powermode(struct net_device *dev,
5943} 5997}
5944 5998
5945static int ipw_wx_set_wireless_mode(struct net_device *dev, 5999static int ipw_wx_set_wireless_mode(struct net_device *dev,
5946 struct iw_request_info *info, 6000 struct iw_request_info *info,
5947 union iwreq_data *wrqu, char *extra) 6001 union iwreq_data *wrqu, char *extra)
5948{ 6002{
5949 struct ipw_priv *priv = ieee80211_priv(dev); 6003 struct ipw_priv *priv = ieee80211_priv(dev);
5950 int mode = *(int *)extra; 6004 int mode = *(int *)extra;
5951 u8 band = 0, modulation = 0; 6005 u8 band = 0, modulation = 0;
5952 6006
5953 if (mode == 0 || mode & ~IEEE_MODE_MASK) { 6007 if (mode == 0 || mode & ~IEEE_MODE_MASK) {
5954 IPW_WARNING("Attempt to set invalid wireless mode: %d\n", 6008 IPW_WARNING("Attempt to set invalid wireless mode: %d\n", mode);
5955 mode);
5956 return -EINVAL; 6009 return -EINVAL;
5957 } 6010 }
5958 6011
@@ -5988,31 +6041,30 @@ static int ipw_wx_set_wireless_mode(struct net_device *dev,
5988 priv->ieee->mode = mode; 6041 priv->ieee->mode = mode;
5989 priv->ieee->freq_band = band; 6042 priv->ieee->freq_band = band;
5990 priv->ieee->modulation = modulation; 6043 priv->ieee->modulation = modulation;
5991 init_supported_rates(priv, &priv->rates); 6044 init_supported_rates(priv, &priv->rates);
5992 6045
5993 /* If we are currently associated, or trying to associate 6046 /* If we are currently associated, or trying to associate
5994 * then see if this is a new configuration (causing us to 6047 * then see if this is a new configuration (causing us to
5995 * disassociate) */ 6048 * disassociate) */
5996 if (priv->status & (STATUS_ASSOCIATED | STATUS_ASSOCIATING)) { 6049 if (priv->status & (STATUS_ASSOCIATED | STATUS_ASSOCIATING)) {
5997 /* The resulting association will trigger 6050 /* The resulting association will trigger
5998 * the new rates to be sent to the device */ 6051 * the new rates to be sent to the device */
5999 IPW_DEBUG_ASSOC("Disassociating due to mode change.\n"); 6052 IPW_DEBUG_ASSOC("Disassociating due to mode change.\n");
6000 ipw_disassociate(priv); 6053 ipw_disassociate(priv);
6001 } else 6054 } else
6002 ipw_send_supported_rates(priv, &priv->rates); 6055 ipw_send_supported_rates(priv, &priv->rates);
6003 6056
6004 IPW_DEBUG_WX("PRIV SET MODE: %c%c%c\n", 6057 IPW_DEBUG_WX("PRIV SET MODE: %c%c%c\n",
6005 mode & IEEE_A ? 'a' : '.', 6058 mode & IEEE_A ? 'a' : '.',
6006 mode & IEEE_B ? 'b' : '.', 6059 mode & IEEE_B ? 'b' : '.', mode & IEEE_G ? 'g' : '.');
6007 mode & IEEE_G ? 'g' : '.');
6008 return 0; 6060 return 0;
6009} 6061}
6010 6062
6011static int ipw_wx_get_wireless_mode(struct net_device *dev, 6063static int ipw_wx_get_wireless_mode(struct net_device *dev,
6012 struct iw_request_info *info, 6064 struct iw_request_info *info,
6013 union iwreq_data *wrqu, char *extra) 6065 union iwreq_data *wrqu, char *extra)
6014{ 6066{
6015 struct ipw_priv *priv = ieee80211_priv(dev); 6067 struct ipw_priv *priv = ieee80211_priv(dev);
6016 6068
6017 switch (priv->ieee->freq_band) { 6069 switch (priv->ieee->freq_band) {
6018 case IEEE80211_24GHZ_BAND: 6070 case IEEE80211_24GHZ_BAND:
@@ -6033,7 +6085,7 @@ static int ipw_wx_get_wireless_mode(struct net_device *dev,
6033 strncpy(extra, "802.11a (1)", MAX_WX_STRING); 6085 strncpy(extra, "802.11a (1)", MAX_WX_STRING);
6034 break; 6086 break;
6035 6087
6036 default: /* Mixed Band */ 6088 default: /* Mixed Band */
6037 switch (priv->ieee->modulation) { 6089 switch (priv->ieee->modulation) {
6038 case IEEE80211_CCK_MODULATION: 6090 case IEEE80211_CCK_MODULATION:
6039 strncpy(extra, "802.11ab (3)", MAX_WX_STRING); 6091 strncpy(extra, "802.11ab (3)", MAX_WX_STRING);
@@ -6050,9 +6102,9 @@ static int ipw_wx_get_wireless_mode(struct net_device *dev,
6050 6102
6051 IPW_DEBUG_WX("PRIV GET MODE: %s\n", extra); 6103 IPW_DEBUG_WX("PRIV GET MODE: %s\n", extra);
6052 6104
6053 wrqu->data.length = strlen(extra) + 1; 6105 wrqu->data.length = strlen(extra) + 1;
6054 6106
6055 return 0; 6107 return 0;
6056} 6108}
6057 6109
6058#ifdef CONFIG_IPW_PROMISC 6110#ifdef CONFIG_IPW_PROMISC
@@ -6081,7 +6133,6 @@ static int ipw_wx_set_promisc(struct net_device *dev,
6081 return 0; 6133 return 0;
6082} 6134}
6083 6135
6084
6085static int ipw_wx_reset(struct net_device *dev, 6136static int ipw_wx_reset(struct net_device *dev,
6086 struct iw_request_info *info, 6137 struct iw_request_info *info,
6087 union iwreq_data *wrqu, char *extra) 6138 union iwreq_data *wrqu, char *extra)
@@ -6091,40 +6142,39 @@ static int ipw_wx_reset(struct net_device *dev,
6091 ipw_adapter_restart(priv); 6142 ipw_adapter_restart(priv);
6092 return 0; 6143 return 0;
6093} 6144}
6094#endif // CONFIG_IPW_PROMISC 6145#endif // CONFIG_IPW_PROMISC
6095 6146
6096/* Rebase the WE IOCTLs to zero for the handler array */ 6147/* Rebase the WE IOCTLs to zero for the handler array */
6097#define IW_IOCTL(x) [(x)-SIOCSIWCOMMIT] 6148#define IW_IOCTL(x) [(x)-SIOCSIWCOMMIT]
6098static iw_handler ipw_wx_handlers[] = 6149static iw_handler ipw_wx_handlers[] = {
6099{ 6150 IW_IOCTL(SIOCGIWNAME) = ipw_wx_get_name,
6100 IW_IOCTL(SIOCGIWNAME) = ipw_wx_get_name, 6151 IW_IOCTL(SIOCSIWFREQ) = ipw_wx_set_freq,
6101 IW_IOCTL(SIOCSIWFREQ) = ipw_wx_set_freq, 6152 IW_IOCTL(SIOCGIWFREQ) = ipw_wx_get_freq,
6102 IW_IOCTL(SIOCGIWFREQ) = ipw_wx_get_freq, 6153 IW_IOCTL(SIOCSIWMODE) = ipw_wx_set_mode,
6103 IW_IOCTL(SIOCSIWMODE) = ipw_wx_set_mode, 6154 IW_IOCTL(SIOCGIWMODE) = ipw_wx_get_mode,
6104 IW_IOCTL(SIOCGIWMODE) = ipw_wx_get_mode, 6155 IW_IOCTL(SIOCGIWRANGE) = ipw_wx_get_range,
6105 IW_IOCTL(SIOCGIWRANGE) = ipw_wx_get_range, 6156 IW_IOCTL(SIOCSIWAP) = ipw_wx_set_wap,
6106 IW_IOCTL(SIOCSIWAP) = ipw_wx_set_wap, 6157 IW_IOCTL(SIOCGIWAP) = ipw_wx_get_wap,
6107 IW_IOCTL(SIOCGIWAP) = ipw_wx_get_wap, 6158 IW_IOCTL(SIOCSIWSCAN) = ipw_wx_set_scan,
6108 IW_IOCTL(SIOCSIWSCAN) = ipw_wx_set_scan, 6159 IW_IOCTL(SIOCGIWSCAN) = ipw_wx_get_scan,
6109 IW_IOCTL(SIOCGIWSCAN) = ipw_wx_get_scan, 6160 IW_IOCTL(SIOCSIWESSID) = ipw_wx_set_essid,
6110 IW_IOCTL(SIOCSIWESSID) = ipw_wx_set_essid, 6161 IW_IOCTL(SIOCGIWESSID) = ipw_wx_get_essid,
6111 IW_IOCTL(SIOCGIWESSID) = ipw_wx_get_essid, 6162 IW_IOCTL(SIOCSIWNICKN) = ipw_wx_set_nick,
6112 IW_IOCTL(SIOCSIWNICKN) = ipw_wx_set_nick, 6163 IW_IOCTL(SIOCGIWNICKN) = ipw_wx_get_nick,
6113 IW_IOCTL(SIOCGIWNICKN) = ipw_wx_get_nick, 6164 IW_IOCTL(SIOCSIWRATE) = ipw_wx_set_rate,
6114 IW_IOCTL(SIOCSIWRATE) = ipw_wx_set_rate, 6165 IW_IOCTL(SIOCGIWRATE) = ipw_wx_get_rate,
6115 IW_IOCTL(SIOCGIWRATE) = ipw_wx_get_rate, 6166 IW_IOCTL(SIOCSIWRTS) = ipw_wx_set_rts,
6116 IW_IOCTL(SIOCSIWRTS) = ipw_wx_set_rts, 6167 IW_IOCTL(SIOCGIWRTS) = ipw_wx_get_rts,
6117 IW_IOCTL(SIOCGIWRTS) = ipw_wx_get_rts, 6168 IW_IOCTL(SIOCSIWFRAG) = ipw_wx_set_frag,
6118 IW_IOCTL(SIOCSIWFRAG) = ipw_wx_set_frag, 6169 IW_IOCTL(SIOCGIWFRAG) = ipw_wx_get_frag,
6119 IW_IOCTL(SIOCGIWFRAG) = ipw_wx_get_frag, 6170 IW_IOCTL(SIOCSIWTXPOW) = ipw_wx_set_txpow,
6120 IW_IOCTL(SIOCSIWTXPOW) = ipw_wx_set_txpow, 6171 IW_IOCTL(SIOCGIWTXPOW) = ipw_wx_get_txpow,
6121 IW_IOCTL(SIOCGIWTXPOW) = ipw_wx_get_txpow, 6172 IW_IOCTL(SIOCSIWRETRY) = ipw_wx_set_retry,
6122 IW_IOCTL(SIOCSIWRETRY) = ipw_wx_set_retry, 6173 IW_IOCTL(SIOCGIWRETRY) = ipw_wx_get_retry,
6123 IW_IOCTL(SIOCGIWRETRY) = ipw_wx_get_retry, 6174 IW_IOCTL(SIOCSIWENCODE) = ipw_wx_set_encode,
6124 IW_IOCTL(SIOCSIWENCODE) = ipw_wx_set_encode, 6175 IW_IOCTL(SIOCGIWENCODE) = ipw_wx_get_encode,
6125 IW_IOCTL(SIOCGIWENCODE) = ipw_wx_get_encode, 6176 IW_IOCTL(SIOCSIWPOWER) = ipw_wx_set_power,
6126 IW_IOCTL(SIOCSIWPOWER) = ipw_wx_set_power, 6177 IW_IOCTL(SIOCGIWPOWER) = ipw_wx_get_power,
6127 IW_IOCTL(SIOCGIWPOWER) = ipw_wx_get_power,
6128}; 6178};
6129 6179
6130#define IPW_PRIV_SET_POWER SIOCIWFIRSTPRIV 6180#define IPW_PRIV_SET_POWER SIOCIWFIRSTPRIV
@@ -6134,38 +6184,31 @@ static iw_handler ipw_wx_handlers[] =
6134#define IPW_PRIV_SET_PROMISC SIOCIWFIRSTPRIV+4 6184#define IPW_PRIV_SET_PROMISC SIOCIWFIRSTPRIV+4
6135#define IPW_PRIV_RESET SIOCIWFIRSTPRIV+5 6185#define IPW_PRIV_RESET SIOCIWFIRSTPRIV+5
6136 6186
6137
6138static struct iw_priv_args ipw_priv_args[] = { 6187static struct iw_priv_args ipw_priv_args[] = {
6139 { 6188 {
6140 .cmd = IPW_PRIV_SET_POWER, 6189 .cmd = IPW_PRIV_SET_POWER,
6141 .set_args = IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1, 6190 .set_args = IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1,
6142 .name = "set_power" 6191 .name = "set_power"},
6143 },
6144 { 6192 {
6145 .cmd = IPW_PRIV_GET_POWER, 6193 .cmd = IPW_PRIV_GET_POWER,
6146 .get_args = IW_PRIV_TYPE_CHAR | IW_PRIV_SIZE_FIXED | MAX_WX_STRING, 6194 .get_args = IW_PRIV_TYPE_CHAR | IW_PRIV_SIZE_FIXED | MAX_WX_STRING,
6147 .name = "get_power" 6195 .name = "get_power"},
6148 },
6149 { 6196 {
6150 .cmd = IPW_PRIV_SET_MODE, 6197 .cmd = IPW_PRIV_SET_MODE,
6151 .set_args = IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1, 6198 .set_args = IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1,
6152 .name = "set_mode" 6199 .name = "set_mode"},
6153 },
6154 { 6200 {
6155 .cmd = IPW_PRIV_GET_MODE, 6201 .cmd = IPW_PRIV_GET_MODE,
6156 .get_args = IW_PRIV_TYPE_CHAR | IW_PRIV_SIZE_FIXED | MAX_WX_STRING, 6202 .get_args = IW_PRIV_TYPE_CHAR | IW_PRIV_SIZE_FIXED | MAX_WX_STRING,
6157 .name = "get_mode" 6203 .name = "get_mode"},
6158 },
6159#ifdef CONFIG_IPW_PROMISC 6204#ifdef CONFIG_IPW_PROMISC
6160 { 6205 {
6161 IPW_PRIV_SET_PROMISC, 6206 IPW_PRIV_SET_PROMISC,
6162 IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 2, 0, "monitor" 6207 IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 2, 0, "monitor"},
6163 },
6164 { 6208 {
6165 IPW_PRIV_RESET, 6209 IPW_PRIV_RESET,
6166 IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 0, 0, "reset" 6210 IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 0, 0, "reset"},
6167 }, 6211#endif /* CONFIG_IPW_PROMISC */
6168#endif /* CONFIG_IPW_PROMISC */
6169}; 6212};
6170 6213
6171static iw_handler ipw_priv_handler[] = { 6214static iw_handler ipw_priv_handler[] = {
@@ -6179,25 +6222,21 @@ static iw_handler ipw_priv_handler[] = {
6179#endif 6222#endif
6180}; 6223};
6181 6224
6182static struct iw_handler_def ipw_wx_handler_def = 6225static struct iw_handler_def ipw_wx_handler_def = {
6183{ 6226 .standard = ipw_wx_handlers,
6184 .standard = ipw_wx_handlers, 6227 .num_standard = ARRAY_SIZE(ipw_wx_handlers),
6185 .num_standard = ARRAY_SIZE(ipw_wx_handlers), 6228 .num_private = ARRAY_SIZE(ipw_priv_handler),
6186 .num_private = ARRAY_SIZE(ipw_priv_handler), 6229 .num_private_args = ARRAY_SIZE(ipw_priv_args),
6187 .num_private_args = ARRAY_SIZE(ipw_priv_args), 6230 .private = ipw_priv_handler,
6188 .private = ipw_priv_handler, 6231 .private_args = ipw_priv_args,
6189 .private_args = ipw_priv_args,
6190}; 6232};
6191 6233
6192
6193
6194
6195/* 6234/*
6196 * Get wireless statistics. 6235 * Get wireless statistics.
6197 * Called by /proc/net/wireless 6236 * Called by /proc/net/wireless
6198 * Also called by SIOCGIWSTATS 6237 * Also called by SIOCGIWSTATS
6199 */ 6238 */
6200static struct iw_statistics *ipw_get_wireless_stats(struct net_device * dev) 6239static struct iw_statistics *ipw_get_wireless_stats(struct net_device *dev)
6201{ 6240{
6202 struct ipw_priv *priv = ieee80211_priv(dev); 6241 struct ipw_priv *priv = ieee80211_priv(dev);
6203 struct iw_statistics *wstats; 6242 struct iw_statistics *wstats;
@@ -6217,7 +6256,7 @@ static struct iw_statistics *ipw_get_wireless_stats(struct net_device * dev)
6217 wstats->qual.noise = 0; 6256 wstats->qual.noise = 0;
6218 wstats->qual.updated = 7; 6257 wstats->qual.updated = 7;
6219 wstats->qual.updated |= IW_QUAL_NOISE_INVALID | 6258 wstats->qual.updated |= IW_QUAL_NOISE_INVALID |
6220 IW_QUAL_QUAL_INVALID | IW_QUAL_LEVEL_INVALID; 6259 IW_QUAL_QUAL_INVALID | IW_QUAL_LEVEL_INVALID;
6221 return wstats; 6260 return wstats;
6222 } 6261 }
6223 6262
@@ -6225,7 +6264,7 @@ static struct iw_statistics *ipw_get_wireless_stats(struct net_device * dev)
6225 wstats->qual.level = average_value(&priv->average_rssi); 6264 wstats->qual.level = average_value(&priv->average_rssi);
6226 wstats->qual.noise = average_value(&priv->average_noise); 6265 wstats->qual.noise = average_value(&priv->average_noise);
6227 wstats->qual.updated = IW_QUAL_QUAL_UPDATED | IW_QUAL_LEVEL_UPDATED | 6266 wstats->qual.updated = IW_QUAL_QUAL_UPDATED | IW_QUAL_LEVEL_UPDATED |
6228 IW_QUAL_NOISE_UPDATED; 6267 IW_QUAL_NOISE_UPDATED;
6229 6268
6230 wstats->miss.beacon = average_value(&priv->average_missed_beacons); 6269 wstats->miss.beacon = average_value(&priv->average_missed_beacons);
6231 wstats->discard.retries = priv->last_tx_failures; 6270 wstats->discard.retries = priv->last_tx_failures;
@@ -6238,13 +6277,12 @@ static struct iw_statistics *ipw_get_wireless_stats(struct net_device * dev)
6238 return wstats; 6277 return wstats;
6239} 6278}
6240 6279
6241
6242/* net device stuff */ 6280/* net device stuff */
6243 6281
6244static inline void init_sys_config(struct ipw_sys_config *sys_config) 6282static inline void init_sys_config(struct ipw_sys_config *sys_config)
6245{ 6283{
6246 memset(sys_config, 0, sizeof(struct ipw_sys_config)); 6284 memset(sys_config, 0, sizeof(struct ipw_sys_config));
6247 sys_config->bt_coexistence = 1; /* We may need to look into prvStaBtConfig */ 6285 sys_config->bt_coexistence = 1; /* We may need to look into prvStaBtConfig */
6248 sys_config->answer_broadcast_ssid_probe = 0; 6286 sys_config->answer_broadcast_ssid_probe = 0;
6249 sys_config->accept_all_data_frames = 0; 6287 sys_config->accept_all_data_frames = 0;
6250 sys_config->accept_non_directed_frames = 1; 6288 sys_config->accept_non_directed_frames = 1;
@@ -6253,7 +6291,7 @@ static inline void init_sys_config(struct ipw_sys_config *sys_config)
6253 sys_config->exclude_multicast_unencrypted = 0; 6291 sys_config->exclude_multicast_unencrypted = 0;
6254 sys_config->disable_multicast_decryption = 1; 6292 sys_config->disable_multicast_decryption = 1;
6255 sys_config->antenna_diversity = CFG_SYS_ANTENNA_BOTH; 6293 sys_config->antenna_diversity = CFG_SYS_ANTENNA_BOTH;
6256 sys_config->pass_crc_to_host = 0; /* TODO: See if 1 gives us FCS */ 6294 sys_config->pass_crc_to_host = 0; /* TODO: See if 1 gives us FCS */
6257 sys_config->dot11g_auto_detection = 0; 6295 sys_config->dot11g_auto_detection = 0;
6258 sys_config->enable_cts_to_self = 0; 6296 sys_config->enable_cts_to_self = 0;
6259 sys_config->bt_coexist_collision_thr = 0; 6297 sys_config->bt_coexist_collision_thr = 0;
@@ -6288,7 +6326,7 @@ we need to heavily modify the ieee80211_skb_to_txb.
6288static inline void ipw_tx_skb(struct ipw_priv *priv, struct ieee80211_txb *txb) 6326static inline void ipw_tx_skb(struct ipw_priv *priv, struct ieee80211_txb *txb)
6289{ 6327{
6290 struct ieee80211_hdr *hdr = (struct ieee80211_hdr *) 6328 struct ieee80211_hdr *hdr = (struct ieee80211_hdr *)
6291 txb->fragments[0]->data; 6329 txb->fragments[0]->data;
6292 int i = 0; 6330 int i = 0;
6293 struct tfd_frame *tfd; 6331 struct tfd_frame *tfd;
6294 struct clx2_tx_queue *txq = &priv->txq[0]; 6332 struct clx2_tx_queue *txq = &priv->txq[0];
@@ -6300,7 +6338,7 @@ static inline void ipw_tx_skb(struct ipw_priv *priv, struct ieee80211_txb *txb)
6300 case IW_MODE_ADHOC: 6338 case IW_MODE_ADHOC:
6301 hdr_len = IEEE80211_3ADDR_LEN; 6339 hdr_len = IEEE80211_3ADDR_LEN;
6302 unicast = !is_broadcast_ether_addr(hdr->addr1) && 6340 unicast = !is_broadcast_ether_addr(hdr->addr1) &&
6303 !is_multicast_ether_addr(hdr->addr1); 6341 !is_multicast_ether_addr(hdr->addr1);
6304 id = ipw_find_station(priv, hdr->addr1); 6342 id = ipw_find_station(priv, hdr->addr1);
6305 if (id == IPW_INVALID_STATION) { 6343 if (id == IPW_INVALID_STATION) {
6306 id = ipw_add_station(priv, hdr->addr1); 6344 id = ipw_add_station(priv, hdr->addr1);
@@ -6316,7 +6354,7 @@ static inline void ipw_tx_skb(struct ipw_priv *priv, struct ieee80211_txb *txb)
6316 case IW_MODE_INFRA: 6354 case IW_MODE_INFRA:
6317 default: 6355 default:
6318 unicast = !is_broadcast_ether_addr(hdr->addr3) && 6356 unicast = !is_broadcast_ether_addr(hdr->addr3) &&
6319 !is_multicast_ether_addr(hdr->addr3); 6357 !is_multicast_ether_addr(hdr->addr3);
6320 hdr_len = IEEE80211_3ADDR_LEN; 6358 hdr_len = IEEE80211_3ADDR_LEN;
6321 id = 0; 6359 id = 0;
6322 break; 6360 break;
@@ -6349,7 +6387,7 @@ static inline void ipw_tx_skb(struct ipw_priv *priv, struct ieee80211_txb *txb)
6349 memcpy(&tfd->u.data.tfd.tfd_24.mchdr, hdr, hdr_len); 6387 memcpy(&tfd->u.data.tfd.tfd_24.mchdr, hdr, hdr_len);
6350 6388
6351 /* payload */ 6389 /* payload */
6352 tfd->u.data.num_chunks = min((u8)(NUM_TFD_CHUNKS - 2), txb->nr_frags); 6390 tfd->u.data.num_chunks = min((u8) (NUM_TFD_CHUNKS - 2), txb->nr_frags);
6353 for (i = 0; i < tfd->u.data.num_chunks; i++) { 6391 for (i = 0; i < tfd->u.data.num_chunks; i++) {
6354 IPW_DEBUG_TX("Dumping TX packet frag %i of %i (%d bytes):\n", 6392 IPW_DEBUG_TX("Dumping TX packet frag %i of %i (%d bytes):\n",
6355 i, tfd->u.data.num_chunks, 6393 i, tfd->u.data.num_chunks,
@@ -6357,9 +6395,11 @@ static inline void ipw_tx_skb(struct ipw_priv *priv, struct ieee80211_txb *txb)
6357 printk_buf(IPW_DL_TX, txb->fragments[i]->data + hdr_len, 6395 printk_buf(IPW_DL_TX, txb->fragments[i]->data + hdr_len,
6358 txb->fragments[i]->len - hdr_len); 6396 txb->fragments[i]->len - hdr_len);
6359 6397
6360 tfd->u.data.chunk_ptr[i] = pci_map_single( 6398 tfd->u.data.chunk_ptr[i] =
6361 priv->pci_dev, txb->fragments[i]->data + hdr_len, 6399 pci_map_single(priv->pci_dev,
6362 txb->fragments[i]->len - hdr_len, PCI_DMA_TODEVICE); 6400 txb->fragments[i]->data + hdr_len,
6401 txb->fragments[i]->len - hdr_len,
6402 PCI_DMA_TODEVICE);
6363 tfd->u.data.chunk_len[i] = txb->fragments[i]->len - hdr_len; 6403 tfd->u.data.chunk_len[i] = txb->fragments[i]->len - hdr_len;
6364 } 6404 }
6365 6405
@@ -6379,16 +6419,16 @@ static inline void ipw_tx_skb(struct ipw_priv *priv, struct ieee80211_txb *txb)
6379 for (j = i; j < txb->nr_frags; j++) { 6419 for (j = i; j < txb->nr_frags; j++) {
6380 int size = txb->fragments[j]->len - hdr_len; 6420 int size = txb->fragments[j]->len - hdr_len;
6381 printk(KERN_INFO "Adding frag %d %d...\n", 6421 printk(KERN_INFO "Adding frag %d %d...\n",
6382 j, size); 6422 j, size);
6383 memcpy(skb_put(skb, size), 6423 memcpy(skb_put(skb, size),
6384 txb->fragments[j]->data + hdr_len, 6424 txb->fragments[j]->data + hdr_len, size);
6385 size);
6386 } 6425 }
6387 dev_kfree_skb_any(txb->fragments[i]); 6426 dev_kfree_skb_any(txb->fragments[i]);
6388 txb->fragments[i] = skb; 6427 txb->fragments[i] = skb;
6389 tfd->u.data.chunk_ptr[i] = pci_map_single( 6428 tfd->u.data.chunk_ptr[i] =
6390 priv->pci_dev, skb->data, 6429 pci_map_single(priv->pci_dev, skb->data,
6391 tfd->u.data.chunk_len[i], PCI_DMA_TODEVICE); 6430 tfd->u.data.chunk_len[i],
6431 PCI_DMA_TODEVICE);
6392 tfd->u.data.num_chunks++; 6432 tfd->u.data.num_chunks++;
6393 } 6433 }
6394 } 6434 }
@@ -6402,7 +6442,7 @@ static inline void ipw_tx_skb(struct ipw_priv *priv, struct ieee80211_txb *txb)
6402 6442
6403 return; 6443 return;
6404 6444
6405 drop: 6445 drop:
6406 IPW_DEBUG_DROP("Silently dropping Tx packet.\n"); 6446 IPW_DEBUG_DROP("Silently dropping Tx packet.\n");
6407 ieee80211_txb_free(txb); 6447 ieee80211_txb_free(txb);
6408} 6448}
@@ -6429,7 +6469,7 @@ static int ipw_net_hard_start_xmit(struct ieee80211_txb *txb,
6429 spin_unlock_irqrestore(&priv->lock, flags); 6469 spin_unlock_irqrestore(&priv->lock, flags);
6430 return 0; 6470 return 0;
6431 6471
6432 fail_unlock: 6472 fail_unlock:
6433 spin_unlock_irqrestore(&priv->lock, flags); 6473 spin_unlock_irqrestore(&priv->lock, flags);
6434 return 1; 6474 return 1;
6435} 6475}
@@ -6478,7 +6518,7 @@ static void ipw_ethtool_get_drvinfo(struct net_device *dev,
6478 len = sizeof(date); 6518 len = sizeof(date);
6479 ipw_get_ordinal(p, IPW_ORD_STAT_FW_DATE, date, &len); 6519 ipw_get_ordinal(p, IPW_ORD_STAT_FW_DATE, date, &len);
6480 6520
6481 snprintf(info->fw_version, sizeof(info->fw_version),"%s (%s)", 6521 snprintf(info->fw_version, sizeof(info->fw_version), "%s (%s)",
6482 vers, date); 6522 vers, date);
6483 strcpy(info->bus_info, pci_name(p->pci_dev)); 6523 strcpy(info->bus_info, pci_name(p->pci_dev));
6484 info->eedump_len = CX2_EEPROM_IMAGE_SIZE; 6524 info->eedump_len = CX2_EEPROM_IMAGE_SIZE;
@@ -6496,19 +6536,19 @@ static int ipw_ethtool_get_eeprom_len(struct net_device *dev)
6496} 6536}
6497 6537
6498static int ipw_ethtool_get_eeprom(struct net_device *dev, 6538static int ipw_ethtool_get_eeprom(struct net_device *dev,
6499 struct ethtool_eeprom *eeprom, u8 *bytes) 6539 struct ethtool_eeprom *eeprom, u8 * bytes)
6500{ 6540{
6501 struct ipw_priv *p = ieee80211_priv(dev); 6541 struct ipw_priv *p = ieee80211_priv(dev);
6502 6542
6503 if (eeprom->offset + eeprom->len > CX2_EEPROM_IMAGE_SIZE) 6543 if (eeprom->offset + eeprom->len > CX2_EEPROM_IMAGE_SIZE)
6504 return -EINVAL; 6544 return -EINVAL;
6505 6545
6506 memcpy(bytes, &((u8 *)p->eeprom)[eeprom->offset], eeprom->len); 6546 memcpy(bytes, &((u8 *) p->eeprom)[eeprom->offset], eeprom->len);
6507 return 0; 6547 return 0;
6508} 6548}
6509 6549
6510static int ipw_ethtool_set_eeprom(struct net_device *dev, 6550static int ipw_ethtool_set_eeprom(struct net_device *dev,
6511 struct ethtool_eeprom *eeprom, u8 *bytes) 6551 struct ethtool_eeprom *eeprom, u8 * bytes)
6512{ 6552{
6513 struct ipw_priv *p = ieee80211_priv(dev); 6553 struct ipw_priv *p = ieee80211_priv(dev);
6514 int i; 6554 int i;
@@ -6516,21 +6556,20 @@ static int ipw_ethtool_set_eeprom(struct net_device *dev,
6516 if (eeprom->offset + eeprom->len > CX2_EEPROM_IMAGE_SIZE) 6556 if (eeprom->offset + eeprom->len > CX2_EEPROM_IMAGE_SIZE)
6517 return -EINVAL; 6557 return -EINVAL;
6518 6558
6519 memcpy(&((u8 *)p->eeprom)[eeprom->offset], bytes, eeprom->len); 6559 memcpy(&((u8 *) p->eeprom)[eeprom->offset], bytes, eeprom->len);
6520 for (i = IPW_EEPROM_DATA; 6560 for (i = IPW_EEPROM_DATA;
6521 i < IPW_EEPROM_DATA + CX2_EEPROM_IMAGE_SIZE; 6561 i < IPW_EEPROM_DATA + CX2_EEPROM_IMAGE_SIZE; i++)
6522 i++)
6523 ipw_write8(p, i, p->eeprom[i]); 6562 ipw_write8(p, i, p->eeprom[i]);
6524 6563
6525 return 0; 6564 return 0;
6526} 6565}
6527 6566
6528static struct ethtool_ops ipw_ethtool_ops = { 6567static struct ethtool_ops ipw_ethtool_ops = {
6529 .get_link = ipw_ethtool_get_link, 6568 .get_link = ipw_ethtool_get_link,
6530 .get_drvinfo = ipw_ethtool_get_drvinfo, 6569 .get_drvinfo = ipw_ethtool_get_drvinfo,
6531 .get_eeprom_len = ipw_ethtool_get_eeprom_len, 6570 .get_eeprom_len = ipw_ethtool_get_eeprom_len,
6532 .get_eeprom = ipw_ethtool_get_eeprom, 6571 .get_eeprom = ipw_ethtool_get_eeprom,
6533 .set_eeprom = ipw_ethtool_set_eeprom, 6572 .set_eeprom = ipw_ethtool_set_eeprom,
6534}; 6573};
6535 6574
6536static irqreturn_t ipw_isr(int irq, void *data, struct pt_regs *regs) 6575static irqreturn_t ipw_isr(int irq, void *data, struct pt_regs *regs)
@@ -6574,10 +6613,10 @@ static irqreturn_t ipw_isr(int irq, void *data, struct pt_regs *regs)
6574 6613
6575 tasklet_schedule(&priv->irq_tasklet); 6614 tasklet_schedule(&priv->irq_tasklet);
6576 6615
6577 spin_unlock(&priv->lock); 6616 spin_unlock(&priv->lock);
6578 6617
6579 return IRQ_HANDLED; 6618 return IRQ_HANDLED;
6580 none: 6619 none:
6581 spin_unlock(&priv->lock); 6620 spin_unlock(&priv->lock);
6582 return IRQ_NONE; 6621 return IRQ_NONE;
6583} 6622}
@@ -6609,7 +6648,7 @@ static void ipw_rf_kill(void *adapter)
6609 IPW_DEBUG_RF_KILL("HW RF Kill deactivated. SW RF Kill still " 6648 IPW_DEBUG_RF_KILL("HW RF Kill deactivated. SW RF Kill still "
6610 "enabled\n"); 6649 "enabled\n");
6611 6650
6612 exit_unlock: 6651 exit_unlock:
6613 spin_unlock_irqrestore(&priv->lock, flags); 6652 spin_unlock_irqrestore(&priv->lock, flags);
6614} 6653}
6615 6654
@@ -6642,7 +6681,6 @@ static int ipw_setup_deferred_work(struct ipw_priv *priv)
6642 return ret; 6681 return ret;
6643} 6682}
6644 6683
6645
6646static void shim__set_security(struct net_device *dev, 6684static void shim__set_security(struct net_device *dev,
6647 struct ieee80211_security *sec) 6685 struct ieee80211_security *sec)
6648{ 6686{
@@ -6683,8 +6721,7 @@ static void shim__set_security(struct net_device *dev,
6683 priv->status |= STATUS_SECURITY_UPDATED; 6721 priv->status |= STATUS_SECURITY_UPDATED;
6684 } 6722 }
6685 6723
6686 if (sec->flags & SEC_ENABLED && 6724 if (sec->flags & SEC_ENABLED && priv->sec.enabled != sec->enabled) {
6687 priv->sec.enabled != sec->enabled) {
6688 priv->sec.flags |= SEC_ENABLED; 6725 priv->sec.flags |= SEC_ENABLED;
6689 priv->sec.enabled = sec->enabled; 6726 priv->sec.enabled = sec->enabled;
6690 priv->status |= STATUS_SECURITY_UPDATED; 6727 priv->status |= STATUS_SECURITY_UPDATED;
@@ -6694,8 +6731,7 @@ static void shim__set_security(struct net_device *dev,
6694 priv->capability &= ~CAP_PRIVACY_ON; 6731 priv->capability &= ~CAP_PRIVACY_ON;
6695 } 6732 }
6696 6733
6697 if (sec->flags & SEC_LEVEL && 6734 if (sec->flags & SEC_LEVEL && priv->sec.level != sec->level) {
6698 priv->sec.level != sec->level) {
6699 priv->sec.level = sec->level; 6735 priv->sec.level = sec->level;
6700 priv->sec.flags |= SEC_LEVEL; 6736 priv->sec.flags |= SEC_LEVEL;
6701 priv->status |= STATUS_SECURITY_UPDATED; 6737 priv->status |= STATUS_SECURITY_UPDATED;
@@ -6709,7 +6745,7 @@ static void shim__set_security(struct net_device *dev,
6709 (((priv->assoc_request.capability & 6745 (((priv->assoc_request.capability &
6710 WLAN_CAPABILITY_PRIVACY) && !sec->enabled) || 6746 WLAN_CAPABILITY_PRIVACY) && !sec->enabled) ||
6711 (!(priv->assoc_request.capability & 6747 (!(priv->assoc_request.capability &
6712 WLAN_CAPABILITY_PRIVACY) && sec->enabled))) { 6748 WLAN_CAPABILITY_PRIVACY) && sec->enabled))) {
6713 IPW_DEBUG_ASSOC("Disassociating due to capability " 6749 IPW_DEBUG_ASSOC("Disassociating due to capability "
6714 "change.\n"); 6750 "change.\n");
6715 ipw_disassociate(priv); 6751 ipw_disassociate(priv);
@@ -6723,7 +6759,7 @@ static int init_supported_rates(struct ipw_priv *priv,
6723 /* TODO: Mask out rates based on priv->rates_mask */ 6759 /* TODO: Mask out rates based on priv->rates_mask */
6724 6760
6725 memset(rates, 0, sizeof(*rates)); 6761 memset(rates, 0, sizeof(*rates));
6726 /* configure supported rates */ 6762 /* configure supported rates */
6727 switch (priv->ieee->freq_band) { 6763 switch (priv->ieee->freq_band) {
6728 case IEEE80211_52GHZ_BAND: 6764 case IEEE80211_52GHZ_BAND:
6729 rates->ieee_mode = IPW_A_MODE; 6765 rates->ieee_mode = IPW_A_MODE;
@@ -6732,7 +6768,7 @@ static int init_supported_rates(struct ipw_priv *priv,
6732 IEEE80211_OFDM_DEFAULT_RATES_MASK); 6768 IEEE80211_OFDM_DEFAULT_RATES_MASK);
6733 break; 6769 break;
6734 6770
6735 default: /* Mixed or 2.4Ghz */ 6771 default: /* Mixed or 2.4Ghz */
6736 rates->ieee_mode = IPW_G_MODE; 6772 rates->ieee_mode = IPW_G_MODE;
6737 rates->purpose = IPW_RATE_CAPABILITIES; 6773 rates->purpose = IPW_RATE_CAPABILITIES;
6738 ipw_add_cck_scan_rates(rates, IEEE80211_CCK_MODULATION, 6774 ipw_add_cck_scan_rates(rates, IEEE80211_CCK_MODULATION,
@@ -6783,8 +6819,8 @@ static int ipw_config(struct ipw_priv *priv)
6783 if (ipw_send_system_config(priv, &priv->sys_config)) 6819 if (ipw_send_system_config(priv, &priv->sys_config))
6784 goto error; 6820 goto error;
6785 6821
6786 init_supported_rates(priv, &priv->rates); 6822 init_supported_rates(priv, &priv->rates);
6787 if (ipw_send_supported_rates(priv, &priv->rates)) 6823 if (ipw_send_supported_rates(priv, &priv->rates))
6788 goto error; 6824 goto error;
6789 6825
6790 /* Set request-to-send threshold */ 6826 /* Set request-to-send threshold */
@@ -6806,7 +6842,7 @@ static int ipw_config(struct ipw_priv *priv)
6806 6842
6807 return 0; 6843 return 0;
6808 6844
6809 error: 6845 error:
6810 return -EIO; 6846 return -EIO;
6811} 6847}
6812 6848
@@ -6818,13 +6854,12 @@ static int ipw_up(struct ipw_priv *priv)
6818 if (priv->status & STATUS_EXIT_PENDING) 6854 if (priv->status & STATUS_EXIT_PENDING)
6819 return -EIO; 6855 return -EIO;
6820 6856
6821 for (i = 0; i < MAX_HW_RESTARTS; i++ ) { 6857 for (i = 0; i < MAX_HW_RESTARTS; i++) {
6822 /* Load the microcode, firmware, and eeprom. 6858 /* Load the microcode, firmware, and eeprom.
6823 * Also start the clocks. */ 6859 * Also start the clocks. */
6824 rc = ipw_load(priv); 6860 rc = ipw_load(priv);
6825 if (rc) { 6861 if (rc) {
6826 IPW_ERROR("Unable to load firmware: 0x%08X\n", 6862 IPW_ERROR("Unable to load firmware: 0x%08X\n", rc);
6827 rc);
6828 return rc; 6863 return rc;
6829 } 6864 }
6830 6865
@@ -6857,8 +6892,7 @@ static int ipw_up(struct ipw_priv *priv)
6857 6892
6858 /* tried to restart and config the device for as long as our 6893 /* tried to restart and config the device for as long as our
6859 * patience could withstand */ 6894 * patience could withstand */
6860 IPW_ERROR("Unable to initialize device after %d attempts.\n", 6895 IPW_ERROR("Unable to initialize device after %d attempts.\n", i);
6861 i);
6862 return -EIO; 6896 return -EIO;
6863} 6897}
6864 6898
@@ -6923,10 +6957,10 @@ static struct pci_device_id card_ids[] = {
6923 {PCI_VENDOR_ID_INTEL, 0x1043, 0x8086, 0x2761, 0, 0, 0}, 6957 {PCI_VENDOR_ID_INTEL, 0x1043, 0x8086, 0x2761, 0, 0, 0},
6924 {PCI_VENDOR_ID_INTEL, 0x1043, 0x8086, 0x2762, 0, 0, 0}, 6958 {PCI_VENDOR_ID_INTEL, 0x1043, 0x8086, 0x2762, 0, 0, 0},
6925 {PCI_VENDOR_ID_INTEL, 0x104f, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0}, 6959 {PCI_VENDOR_ID_INTEL, 0x104f, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0},
6926 {PCI_VENDOR_ID_INTEL, 0x4220, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0}, /* BG */ 6960 {PCI_VENDOR_ID_INTEL, 0x4220, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0}, /* BG */
6927 {PCI_VENDOR_ID_INTEL, 0x4221, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0}, /* 2225BG */ 6961 {PCI_VENDOR_ID_INTEL, 0x4221, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0}, /* 2225BG */
6928 {PCI_VENDOR_ID_INTEL, 0x4223, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0}, /* ABG */ 6962 {PCI_VENDOR_ID_INTEL, 0x4223, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0}, /* ABG */
6929 {PCI_VENDOR_ID_INTEL, 0x4224, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0}, /* ABG */ 6963 {PCI_VENDOR_ID_INTEL, 0x4224, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0}, /* ABG */
6930 6964
6931 /* required last entry */ 6965 /* required last entry */
6932 {0,} 6966 {0,}
@@ -6954,11 +6988,10 @@ static struct attribute *ipw_sysfs_entries[] = {
6954 6988
6955static struct attribute_group ipw_attribute_group = { 6989static struct attribute_group ipw_attribute_group = {
6956 .name = NULL, /* put in device directory */ 6990 .name = NULL, /* put in device directory */
6957 .attrs = ipw_sysfs_entries, 6991 .attrs = ipw_sysfs_entries,
6958}; 6992};
6959 6993
6960static int ipw_pci_probe(struct pci_dev *pdev, 6994static int ipw_pci_probe(struct pci_dev *pdev, const struct pci_device_id *ent)
6961 const struct pci_device_id *ent)
6962{ 6995{
6963 int err = 0; 6996 int err = 0;
6964 struct net_device *net_dev; 6997 struct net_device *net_dev;
@@ -7051,7 +7084,7 @@ static int ipw_pci_probe(struct pci_dev *pdev,
7051 priv->config |= CFG_STATIC_CHANNEL; 7084 priv->config |= CFG_STATIC_CHANNEL;
7052 priv->channel = channel; 7085 priv->channel = channel;
7053 IPW_DEBUG_INFO("Bind to static channel %d\n", channel); 7086 IPW_DEBUG_INFO("Bind to static channel %d\n", channel);
7054 IPW_DEBUG_INFO("Bind to static channel %d\n", channel); 7087 IPW_DEBUG_INFO("Bind to static channel %d\n", channel);
7055 /* TODO: Validate that provided channel is in range */ 7088 /* TODO: Validate that provided channel is in range */
7056 } 7089 }
7057 7090
@@ -7078,9 +7111,9 @@ static int ipw_pci_probe(struct pci_dev *pdev,
7078 priv->ieee->abg_ture = 1; 7111 priv->ieee->abg_ture = 1;
7079 band = IEEE80211_52GHZ_BAND | IEEE80211_24GHZ_BAND; 7112 band = IEEE80211_52GHZ_BAND | IEEE80211_24GHZ_BAND;
7080 modulation = IEEE80211_OFDM_MODULATION | 7113 modulation = IEEE80211_OFDM_MODULATION |
7081 IEEE80211_CCK_MODULATION; 7114 IEEE80211_CCK_MODULATION;
7082 priv->adapter = IPW_2915ABG; 7115 priv->adapter = IPW_2915ABG;
7083 priv->ieee->mode = IEEE_A|IEEE_G|IEEE_B; 7116 priv->ieee->mode = IEEE_A | IEEE_G | IEEE_B;
7084 } else { 7117 } else {
7085 if (priv->pci_dev->device == 0x4221) 7118 if (priv->pci_dev->device == 0x4221)
7086 printk(KERN_INFO DRV_NAME 7119 printk(KERN_INFO DRV_NAME
@@ -7094,9 +7127,9 @@ static int ipw_pci_probe(struct pci_dev *pdev,
7094 priv->ieee->abg_ture = 0; 7127 priv->ieee->abg_ture = 0;
7095 band = IEEE80211_24GHZ_BAND; 7128 band = IEEE80211_24GHZ_BAND;
7096 modulation = IEEE80211_OFDM_MODULATION | 7129 modulation = IEEE80211_OFDM_MODULATION |
7097 IEEE80211_CCK_MODULATION; 7130 IEEE80211_CCK_MODULATION;
7098 priv->adapter = IPW_2200BG; 7131 priv->adapter = IPW_2200BG;
7099 priv->ieee->mode = IEEE_G|IEEE_B; 7132 priv->ieee->mode = IEEE_G | IEEE_B;
7100 } 7133 }
7101 7134
7102 priv->ieee->freq_band = band; 7135 priv->ieee->freq_band = band;
@@ -7110,11 +7143,10 @@ static int ipw_pci_probe(struct pci_dev *pdev,
7110 priv->rts_threshold = DEFAULT_RTS_THRESHOLD; 7143 priv->rts_threshold = DEFAULT_RTS_THRESHOLD;
7111 7144
7112 /* If power management is turned on, default to AC mode */ 7145 /* If power management is turned on, default to AC mode */
7113 priv->power_mode = IPW_POWER_AC; 7146 priv->power_mode = IPW_POWER_AC;
7114 priv->tx_power = IPW_DEFAULT_TX_POWER; 7147 priv->tx_power = IPW_DEFAULT_TX_POWER;
7115 7148
7116 err = request_irq(pdev->irq, ipw_isr, SA_SHIRQ, DRV_NAME, 7149 err = request_irq(pdev->irq, ipw_isr, SA_SHIRQ, DRV_NAME, priv);
7117 priv);
7118 if (err) { 7150 if (err) {
7119 IPW_ERROR("Error allocating IRQ %d\n", pdev->irq); 7151 IPW_ERROR("Error allocating IRQ %d\n", pdev->irq);
7120 goto out_destroy_workqueue; 7152 goto out_destroy_workqueue;
@@ -7136,7 +7168,7 @@ static int ipw_pci_probe(struct pci_dev *pdev,
7136 net_dev->wireless_handlers = &ipw_wx_handler_def; 7168 net_dev->wireless_handlers = &ipw_wx_handler_def;
7137 net_dev->ethtool_ops = &ipw_ethtool_ops; 7169 net_dev->ethtool_ops = &ipw_ethtool_ops;
7138 net_dev->irq = pdev->irq; 7170 net_dev->irq = pdev->irq;
7139 net_dev->base_addr = (unsigned long )priv->hw_base; 7171 net_dev->base_addr = (unsigned long)priv->hw_base;
7140 net_dev->mem_start = pci_resource_start(pdev, 0); 7172 net_dev->mem_start = pci_resource_start(pdev, 0);
7141 net_dev->mem_end = net_dev->mem_start + pci_resource_len(pdev, 0) - 1; 7173 net_dev->mem_end = net_dev->mem_start + pci_resource_len(pdev, 0) - 1;
7142 7174
@@ -7154,23 +7186,23 @@ static int ipw_pci_probe(struct pci_dev *pdev,
7154 7186
7155 return 0; 7187 return 0;
7156 7188
7157 out_remove_group: 7189 out_remove_group:
7158 sysfs_remove_group(&pdev->dev.kobj, &ipw_attribute_group); 7190 sysfs_remove_group(&pdev->dev.kobj, &ipw_attribute_group);
7159 out_release_irq: 7191 out_release_irq:
7160 free_irq(pdev->irq, priv); 7192 free_irq(pdev->irq, priv);
7161 out_destroy_workqueue: 7193 out_destroy_workqueue:
7162 destroy_workqueue(priv->workqueue); 7194 destroy_workqueue(priv->workqueue);
7163 priv->workqueue = NULL; 7195 priv->workqueue = NULL;
7164 out_iounmap: 7196 out_iounmap:
7165 iounmap(priv->hw_base); 7197 iounmap(priv->hw_base);
7166 out_pci_release_regions: 7198 out_pci_release_regions:
7167 pci_release_regions(pdev); 7199 pci_release_regions(pdev);
7168 out_pci_disable_device: 7200 out_pci_disable_device:
7169 pci_disable_device(pdev); 7201 pci_disable_device(pdev);
7170 pci_set_drvdata(pdev, NULL); 7202 pci_set_drvdata(pdev, NULL);
7171 out_free_ieee80211: 7203 out_free_ieee80211:
7172 free_ieee80211(priv->net_dev); 7204 free_ieee80211(priv->net_dev);
7173 out: 7205 out:
7174 return err; 7206 return err;
7175} 7207}
7176 7208
@@ -7223,16 +7255,15 @@ static void ipw_pci_remove(struct pci_dev *pdev)
7223#endif 7255#endif
7224} 7256}
7225 7257
7226
7227#ifdef CONFIG_PM 7258#ifdef CONFIG_PM
7228static int ipw_pci_suspend(struct pci_dev *pdev, u32 state) 7259static int ipw_pci_suspend(struct pci_dev *pdev, pm_message_t state)
7229{ 7260{
7230 struct ipw_priv *priv = pci_get_drvdata(pdev); 7261 struct ipw_priv *priv = pci_get_drvdata(pdev);
7231 struct net_device *dev = priv->net_dev; 7262 struct net_device *dev = priv->net_dev;
7232 7263
7233 printk(KERN_INFO "%s: Going into suspend...\n", dev->name); 7264 printk(KERN_INFO "%s: Going into suspend...\n", dev->name);
7234 7265
7235 /* Take down the device; powers it off, etc. */ 7266 /* Take down the device; powers it off, etc. */
7236 ipw_down(priv); 7267 ipw_down(priv);
7237 7268
7238 /* Remove the PRESENT state of the device */ 7269 /* Remove the PRESENT state of the device */
@@ -7240,7 +7271,7 @@ static int ipw_pci_suspend(struct pci_dev *pdev, u32 state)
7240 7271
7241 pci_save_state(pdev); 7272 pci_save_state(pdev);
7242 pci_disable_device(pdev); 7273 pci_disable_device(pdev);
7243 pci_set_power_state(pdev, state); 7274 pci_set_power_state(pdev, pci_choose_state(pdev, state));
7244 7275
7245 return 0; 7276 return 0;
7246} 7277}
@@ -7306,8 +7337,7 @@ static int __init ipw_init(void)
7306 return ret; 7337 return ret;
7307 } 7338 }
7308 7339
7309 ret = driver_create_file(&ipw_driver.driver, 7340 ret = driver_create_file(&ipw_driver.driver, &driver_attr_debug_level);
7310 &driver_attr_debug_level);
7311 if (ret) { 7341 if (ret) {
7312 IPW_ERROR("Unable to create driver sysfs file\n"); 7342 IPW_ERROR("Unable to create driver sysfs file\n");
7313 pci_unregister_driver(&ipw_driver); 7343 pci_unregister_driver(&ipw_driver);
diff --git a/drivers/net/wireless/ipw2200.h b/drivers/net/wireless/ipw2200.h
index 3bff09d9315..5b00882133f 100644
--- a/drivers/net/wireless/ipw2200.h
+++ b/drivers/net/wireless/ipw2200.h
@@ -42,9 +42,11 @@
42#include <linux/etherdevice.h> 42#include <linux/etherdevice.h>
43#include <linux/delay.h> 43#include <linux/delay.h>
44#include <linux/random.h> 44#include <linux/random.h>
45#include <linux/dma-mapping.h>
45 46
46#include <linux/firmware.h> 47#include <linux/firmware.h>
47#include <linux/wireless.h> 48#include <linux/wireless.h>
49#include <linux/dma-mapping.h>
48#include <asm/io.h> 50#include <asm/io.h>
49 51
50#include <net/ieee80211.h> 52#include <net/ieee80211.h>
@@ -54,8 +56,7 @@
54#include <linux/workqueue.h> 56#include <linux/workqueue.h>
55 57
56/* Authentication and Association States */ 58/* Authentication and Association States */
57enum connection_manager_assoc_states 59enum connection_manager_assoc_states {
58{
59 CMAS_INIT = 0, 60 CMAS_INIT = 0,
60 CMAS_TX_AUTH_SEQ_1, 61 CMAS_TX_AUTH_SEQ_1,
61 CMAS_RX_AUTH_SEQ_2, 62 CMAS_RX_AUTH_SEQ_2,
@@ -72,7 +73,6 @@ enum connection_manager_assoc_states
72 CMAS_LAST 73 CMAS_LAST
73}; 74};
74 75
75
76#define IPW_WAIT (1<<0) 76#define IPW_WAIT (1<<0)
77#define IPW_QUIET (1<<1) 77#define IPW_QUIET (1<<1)
78#define IPW_ROAMING (1<<2) 78#define IPW_ROAMING (1<<2)
@@ -188,7 +188,6 @@ enum connection_manager_assoc_states
188#define DCT_FLAG_EXT_MODE_CCK 0x01 188#define DCT_FLAG_EXT_MODE_CCK 0x01
189#define DCT_FLAG_EXT_MODE_OFDM 0x00 189#define DCT_FLAG_EXT_MODE_OFDM 0x00
190 190
191
192#define TX_RX_TYPE_MASK 0xFF 191#define TX_RX_TYPE_MASK 0xFF
193#define TX_FRAME_TYPE 0x00 192#define TX_FRAME_TYPE 0x00
194#define TX_HOST_COMMAND_TYPE 0x01 193#define TX_HOST_COMMAND_TYPE 0x01
@@ -240,107 +239,97 @@ enum connection_manager_assoc_states
240 * Contains common data for Rx and Tx queues 239 * Contains common data for Rx and Tx queues
241 */ 240 */
242struct clx2_queue { 241struct clx2_queue {
243 int n_bd; /**< number of BDs in this queue */ 242 int n_bd; /**< number of BDs in this queue */
244 int first_empty; /**< 1-st empty entry (index) */ 243 int first_empty; /**< 1-st empty entry (index) */
245 int last_used; /**< last used entry (index) */ 244 int last_used; /**< last used entry (index) */
246 u32 reg_w; /**< 'write' reg (queue head), addr in domain 1 */ 245 u32 reg_w; /**< 'write' reg (queue head), addr in domain 1 */
247 u32 reg_r; /**< 'read' reg (queue tail), addr in domain 1 */ 246 u32 reg_r; /**< 'read' reg (queue tail), addr in domain 1 */
248 dma_addr_t dma_addr; /**< physical addr for BD's */ 247 dma_addr_t dma_addr; /**< physical addr for BD's */
249 int low_mark; /**< low watermark, resume queue if free space more than this */ 248 int low_mark; /**< low watermark, resume queue if free space more than this */
250 int high_mark; /**< high watermark, stop queue if free space less than this */ 249 int high_mark; /**< high watermark, stop queue if free space less than this */
251} __attribute__ ((packed)); 250} __attribute__ ((packed));
252 251
253struct machdr32 252struct machdr32 {
254{
255 u16 frame_ctl; 253 u16 frame_ctl;
256 u16 duration; // watch out for endians! 254 u16 duration; // watch out for endians!
257 u8 addr1[ MACADRR_BYTE_LEN ]; 255 u8 addr1[MACADRR_BYTE_LEN];
258 u8 addr2[ MACADRR_BYTE_LEN ]; 256 u8 addr2[MACADRR_BYTE_LEN];
259 u8 addr3[ MACADRR_BYTE_LEN ]; 257 u8 addr3[MACADRR_BYTE_LEN];
260 u16 seq_ctrl; // more endians! 258 u16 seq_ctrl; // more endians!
261 u8 addr4[ MACADRR_BYTE_LEN ]; 259 u8 addr4[MACADRR_BYTE_LEN];
262 u16 qos_ctrl; 260 u16 qos_ctrl;
263} __attribute__ ((packed)) ; 261} __attribute__ ((packed));
264 262
265struct machdr30 263struct machdr30 {
266{
267 u16 frame_ctl; 264 u16 frame_ctl;
268 u16 duration; // watch out for endians! 265 u16 duration; // watch out for endians!
269 u8 addr1[ MACADRR_BYTE_LEN ]; 266 u8 addr1[MACADRR_BYTE_LEN];
270 u8 addr2[ MACADRR_BYTE_LEN ]; 267 u8 addr2[MACADRR_BYTE_LEN];
271 u8 addr3[ MACADRR_BYTE_LEN ]; 268 u8 addr3[MACADRR_BYTE_LEN];
272 u16 seq_ctrl; // more endians! 269 u16 seq_ctrl; // more endians!
273 u8 addr4[ MACADRR_BYTE_LEN ]; 270 u8 addr4[MACADRR_BYTE_LEN];
274} __attribute__ ((packed)) ; 271} __attribute__ ((packed));
275 272
276struct machdr26 273struct machdr26 {
277{
278 u16 frame_ctl; 274 u16 frame_ctl;
279 u16 duration; // watch out for endians! 275 u16 duration; // watch out for endians!
280 u8 addr1[ MACADRR_BYTE_LEN ]; 276 u8 addr1[MACADRR_BYTE_LEN];
281 u8 addr2[ MACADRR_BYTE_LEN ]; 277 u8 addr2[MACADRR_BYTE_LEN];
282 u8 addr3[ MACADRR_BYTE_LEN ]; 278 u8 addr3[MACADRR_BYTE_LEN];
283 u16 seq_ctrl; // more endians! 279 u16 seq_ctrl; // more endians!
284 u16 qos_ctrl; 280 u16 qos_ctrl;
285} __attribute__ ((packed)) ; 281} __attribute__ ((packed));
286 282
287struct machdr24 283struct machdr24 {
288{
289 u16 frame_ctl; 284 u16 frame_ctl;
290 u16 duration; // watch out for endians! 285 u16 duration; // watch out for endians!
291 u8 addr1[ MACADRR_BYTE_LEN ]; 286 u8 addr1[MACADRR_BYTE_LEN];
292 u8 addr2[ MACADRR_BYTE_LEN ]; 287 u8 addr2[MACADRR_BYTE_LEN];
293 u8 addr3[ MACADRR_BYTE_LEN ]; 288 u8 addr3[MACADRR_BYTE_LEN];
294 u16 seq_ctrl; // more endians! 289 u16 seq_ctrl; // more endians!
295} __attribute__ ((packed)) ; 290} __attribute__ ((packed));
296 291
297// TX TFD with 32 byte MAC Header 292// TX TFD with 32 byte MAC Header
298struct tx_tfd_32 293struct tx_tfd_32 {
299{ 294 struct machdr32 mchdr; // 32
300 struct machdr32 mchdr; // 32 295 u32 uivplaceholder[2]; // 8
301 u32 uivplaceholder[2]; // 8 296} __attribute__ ((packed));
302} __attribute__ ((packed)) ;
303 297
304// TX TFD with 30 byte MAC Header 298// TX TFD with 30 byte MAC Header
305struct tx_tfd_30 299struct tx_tfd_30 {
306{ 300 struct machdr30 mchdr; // 30
307 struct machdr30 mchdr; // 30 301 u8 reserved[2]; // 2
308 u8 reserved[2]; // 2 302 u32 uivplaceholder[2]; // 8
309 u32 uivplaceholder[2]; // 8 303} __attribute__ ((packed));
310} __attribute__ ((packed)) ;
311 304
312// tx tfd with 26 byte mac header 305// tx tfd with 26 byte mac header
313struct tx_tfd_26 306struct tx_tfd_26 {
314{ 307 struct machdr26 mchdr; // 26
315 struct machdr26 mchdr; // 26 308 u8 reserved1[2]; // 2
316 u8 reserved1[2]; // 2 309 u32 uivplaceholder[2]; // 8
317 u32 uivplaceholder[2]; // 8 310 u8 reserved2[4]; // 4
318 u8 reserved2[4]; // 4 311} __attribute__ ((packed));
319} __attribute__ ((packed)) ;
320 312
321// tx tfd with 24 byte mac header 313// tx tfd with 24 byte mac header
322struct tx_tfd_24 314struct tx_tfd_24 {
323{ 315 struct machdr24 mchdr; // 24
324 struct machdr24 mchdr; // 24 316 u32 uivplaceholder[2]; // 8
325 u32 uivplaceholder[2]; // 8 317 u8 reserved[8]; // 8
326 u8 reserved[8]; // 8 318} __attribute__ ((packed));
327} __attribute__ ((packed)) ;
328
329 319
330#define DCT_WEP_KEY_FIELD_LENGTH 16 320#define DCT_WEP_KEY_FIELD_LENGTH 16
331 321
332struct tfd_command 322struct tfd_command {
333{
334 u8 index; 323 u8 index;
335 u8 length; 324 u8 length;
336 u16 reserved; 325 u16 reserved;
337 u8 payload[0]; 326 u8 payload[0];
338} __attribute__ ((packed)) ; 327} __attribute__ ((packed));
339 328
340struct tfd_data { 329struct tfd_data {
341 /* Header */ 330 /* Header */
342 u32 work_area_ptr; 331 u32 work_area_ptr;
343 u8 station_number; /* 0 for BSS */ 332 u8 station_number; /* 0 for BSS */
344 u8 reserved1; 333 u8 reserved1;
345 u16 reserved2; 334 u16 reserved2;
346 335
@@ -357,14 +346,13 @@ struct tfd_data {
357 u8 antenna; 346 u8 antenna;
358 u16 next_packet_duration; 347 u16 next_packet_duration;
359 u16 next_frag_len; 348 u16 next_frag_len;
360 u16 back_off_counter; //////txop; 349 u16 back_off_counter; //////txop;
361 u8 retrylimit; 350 u8 retrylimit;
362 u16 cwcurrent; 351 u16 cwcurrent;
363 u8 reserved3; 352 u8 reserved3;
364 353
365 /* 802.11 MAC Header */ 354 /* 802.11 MAC Header */
366 union 355 union {
367 {
368 struct tx_tfd_24 tfd_24; 356 struct tx_tfd_24 tfd_24;
369 struct tx_tfd_26 tfd_26; 357 struct tx_tfd_26 tfd_26;
370 struct tx_tfd_30 tfd_30; 358 struct tx_tfd_30 tfd_30;
@@ -377,8 +365,7 @@ struct tfd_data {
377 u16 chunk_len[NUM_TFD_CHUNKS]; 365 u16 chunk_len[NUM_TFD_CHUNKS];
378} __attribute__ ((packed)); 366} __attribute__ ((packed));
379 367
380struct txrx_control_flags 368struct txrx_control_flags {
381{
382 u8 message_type; 369 u8 message_type;
383 u8 rx_seq_num; 370 u8 rx_seq_num;
384 u8 control_bits; 371 u8 control_bits;
@@ -388,17 +375,16 @@ struct txrx_control_flags
388#define TFD_SIZE 128 375#define TFD_SIZE 128
389#define TFD_CMD_IMMEDIATE_PAYLOAD_LENGTH (TFD_SIZE - sizeof(struct txrx_control_flags)) 376#define TFD_CMD_IMMEDIATE_PAYLOAD_LENGTH (TFD_SIZE - sizeof(struct txrx_control_flags))
390 377
391struct tfd_frame 378struct tfd_frame {
392{
393 struct txrx_control_flags control_flags; 379 struct txrx_control_flags control_flags;
394 union { 380 union {
395 struct tfd_data data; 381 struct tfd_data data;
396 struct tfd_command cmd; 382 struct tfd_command cmd;
397 u8 raw[TFD_CMD_IMMEDIATE_PAYLOAD_LENGTH]; 383 u8 raw[TFD_CMD_IMMEDIATE_PAYLOAD_LENGTH];
398 } u; 384 } u;
399} __attribute__ ((packed)) ; 385} __attribute__ ((packed));
400 386
401typedef void destructor_func(const void*); 387typedef void destructor_func(const void *);
402 388
403/** 389/**
404 * Tx Queue for DMA. Queue consists of circular buffer of 390 * Tx Queue for DMA. Queue consists of circular buffer of
@@ -406,7 +392,7 @@ typedef void destructor_func(const void*);
406 */ 392 */
407struct clx2_tx_queue { 393struct clx2_tx_queue {
408 struct clx2_queue q; 394 struct clx2_queue q;
409 struct tfd_frame* bd; 395 struct tfd_frame *bd;
410 struct ieee80211_txb **txb; 396 struct ieee80211_txb **txb;
411}; 397};
412 398
@@ -421,8 +407,7 @@ struct clx2_tx_queue {
421#define SUP_RATE_11G_MAX_NUM_CHANNELS (12) 407#define SUP_RATE_11G_MAX_NUM_CHANNELS (12)
422 408
423// Used for passing to driver number of successes and failures per rate 409// Used for passing to driver number of successes and failures per rate
424struct rate_histogram 410struct rate_histogram {
425{
426 union { 411 union {
427 u32 a[SUP_RATE_11A_MAX_NUM_CHANNELS]; 412 u32 a[SUP_RATE_11A_MAX_NUM_CHANNELS];
428 u32 b[SUP_RATE_11B_MAX_NUM_CHANNELS]; 413 u32 b[SUP_RATE_11B_MAX_NUM_CHANNELS];
@@ -473,12 +458,12 @@ struct notif_scan_complete {
473 u8 num_channels; 458 u8 num_channels;
474 u8 status; 459 u8 status;
475 u8 reserved; 460 u8 reserved;
476} __attribute__ ((packed)); 461} __attribute__ ((packed));
477 462
478struct notif_frag_length { 463struct notif_frag_length {
479 u16 frag_length; 464 u16 frag_length;
480 u16 reserved; 465 u16 reserved;
481} __attribute__ ((packed)); 466} __attribute__ ((packed));
482 467
483struct notif_beacon_state { 468struct notif_beacon_state {
484 u32 state; 469 u32 state;
@@ -541,11 +526,11 @@ struct ipw_rx_notification {
541 526
542struct ipw_rx_frame { 527struct ipw_rx_frame {
543 u32 reserved1; 528 u32 reserved1;
544 u8 parent_tsf[4]; // fw_use[0] is boolean for OUR_TSF_IS_GREATER 529 u8 parent_tsf[4]; // fw_use[0] is boolean for OUR_TSF_IS_GREATER
545 u8 received_channel; // The channel that this frame was received on. 530 u8 received_channel; // The channel that this frame was received on.
546 // Note that for .11b this does not have to be 531 // Note that for .11b this does not have to be
547 // the same as the channel that it was sent. 532 // the same as the channel that it was sent.
548 // Filled by LMAC 533 // Filled by LMAC
549 u8 frameStatus; 534 u8 frameStatus;
550 u8 rate; 535 u8 rate;
551 u8 rssi; 536 u8 rssi;
@@ -554,10 +539,10 @@ struct ipw_rx_frame {
554 u16 signal; 539 u16 signal;
555 u16 noise; 540 u16 noise;
556 u8 antennaAndPhy; 541 u8 antennaAndPhy;
557 u8 control; // control bit should be on in bg 542 u8 control; // control bit should be on in bg
558 u8 rtscts_rate; // rate of rts or cts (in rts cts sequence rate 543 u8 rtscts_rate; // rate of rts or cts (in rts cts sequence rate
559 // is identical) 544 // is identical)
560 u8 rtscts_seen; // 0x1 RTS seen ; 0x2 CTS seen 545 u8 rtscts_seen; // 0x1 RTS seen ; 0x2 CTS seen
561 u16 length; 546 u16 length;
562 u8 data[0]; 547 u8 data[0];
563} __attribute__ ((packed)); 548} __attribute__ ((packed));
@@ -569,8 +554,7 @@ struct ipw_rx_header {
569 u8 reserved; 554 u8 reserved;
570} __attribute__ ((packed)); 555} __attribute__ ((packed));
571 556
572struct ipw_rx_packet 557struct ipw_rx_packet {
573{
574 struct ipw_rx_header header; 558 struct ipw_rx_header header;
575 union { 559 union {
576 struct ipw_rx_frame frame; 560 struct ipw_rx_frame frame;
@@ -587,21 +571,20 @@ struct ipw_rx_mem_buffer {
587 struct ipw_rx_buffer *rxb; 571 struct ipw_rx_buffer *rxb;
588 struct sk_buff *skb; 572 struct sk_buff *skb;
589 struct list_head list; 573 struct list_head list;
590}; /* Not transferred over network, so not __attribute__ ((packed)) */ 574}; /* Not transferred over network, so not __attribute__ ((packed)) */
591 575
592struct ipw_rx_queue { 576struct ipw_rx_queue {
593 struct ipw_rx_mem_buffer pool[RX_QUEUE_SIZE + RX_FREE_BUFFERS]; 577 struct ipw_rx_mem_buffer pool[RX_QUEUE_SIZE + RX_FREE_BUFFERS];
594 struct ipw_rx_mem_buffer *queue[RX_QUEUE_SIZE]; 578 struct ipw_rx_mem_buffer *queue[RX_QUEUE_SIZE];
595 u32 processed; /* Internal index to last handled Rx packet */ 579 u32 processed; /* Internal index to last handled Rx packet */
596 u32 read; /* Shared index to newest available Rx buffer */ 580 u32 read; /* Shared index to newest available Rx buffer */
597 u32 write; /* Shared index to oldest written Rx packet */ 581 u32 write; /* Shared index to oldest written Rx packet */
598 u32 free_count;/* Number of pre-allocated buffers in rx_free */ 582 u32 free_count; /* Number of pre-allocated buffers in rx_free */
599 /* Each of these lists is used as a FIFO for ipw_rx_mem_buffers */ 583 /* Each of these lists is used as a FIFO for ipw_rx_mem_buffers */
600 struct list_head rx_free; /* Own an SKBs */ 584 struct list_head rx_free; /* Own an SKBs */
601 struct list_head rx_used; /* No SKB allocated */ 585 struct list_head rx_used; /* No SKB allocated */
602 spinlock_t lock; 586 spinlock_t lock;
603}; /* Not transferred over network, so not __attribute__ ((packed)) */ 587}; /* Not transferred over network, so not __attribute__ ((packed)) */
604
605 588
606struct alive_command_responce { 589struct alive_command_responce {
607 u8 alive_command; 590 u8 alive_command;
@@ -625,8 +608,7 @@ struct ipw_rates {
625 u8 rates[IPW_MAX_RATES]; 608 u8 rates[IPW_MAX_RATES];
626} __attribute__ ((packed)); 609} __attribute__ ((packed));
627 610
628struct command_block 611struct command_block {
629{
630 unsigned int control; 612 unsigned int control;
631 u32 source_addr; 613 u32 source_addr;
632 u32 dest_addr; 614 u32 dest_addr;
@@ -634,18 +616,16 @@ struct command_block
634} __attribute__ ((packed)); 616} __attribute__ ((packed));
635 617
636#define CB_NUMBER_OF_ELEMENTS_SMALL 64 618#define CB_NUMBER_OF_ELEMENTS_SMALL 64
637struct fw_image_desc 619struct fw_image_desc {
638{
639 unsigned long last_cb_index; 620 unsigned long last_cb_index;
640 unsigned long current_cb_index; 621 unsigned long current_cb_index;
641 struct command_block cb_list[CB_NUMBER_OF_ELEMENTS_SMALL]; 622 struct command_block cb_list[CB_NUMBER_OF_ELEMENTS_SMALL];
642 void * v_addr; 623 void *v_addr;
643 unsigned long p_addr; 624 unsigned long p_addr;
644 unsigned long len; 625 unsigned long len;
645}; 626};
646 627
647struct ipw_sys_config 628struct ipw_sys_config {
648{
649 u8 bt_coexistence; 629 u8 bt_coexistence;
650 u8 reserved1; 630 u8 reserved1;
651 u8 answer_broadcast_ssid_probe; 631 u8 answer_broadcast_ssid_probe;
@@ -668,8 +648,7 @@ struct ipw_sys_config
668 u8 reserved3; 648 u8 reserved3;
669} __attribute__ ((packed)); 649} __attribute__ ((packed));
670 650
671struct ipw_multicast_addr 651struct ipw_multicast_addr {
672{
673 u8 num_of_multicast_addresses; 652 u8 num_of_multicast_addresses;
674 u8 reserved[3]; 653 u8 reserved[3];
675 u8 mac1[6]; 654 u8 mac1[6];
@@ -678,8 +657,7 @@ struct ipw_multicast_addr
678 u8 mac4[6]; 657 u8 mac4[6];
679} __attribute__ ((packed)); 658} __attribute__ ((packed));
680 659
681struct ipw_wep_key 660struct ipw_wep_key {
682{
683 u8 cmd_id; 661 u8 cmd_id;
684 u8 seq_num; 662 u8 seq_num;
685 u8 key_index; 663 u8 key_index;
@@ -687,8 +665,7 @@ struct ipw_wep_key
687 u8 key[16]; 665 u8 key[16];
688} __attribute__ ((packed)); 666} __attribute__ ((packed));
689 667
690struct ipw_tgi_tx_key 668struct ipw_tgi_tx_key {
691{
692 u8 key_id; 669 u8 key_id;
693 u8 security_type; 670 u8 security_type;
694 u8 station_index; 671 u8 station_index;
@@ -699,8 +676,7 @@ struct ipw_tgi_tx_key
699 676
700#define IPW_SCAN_CHANNELS 54 677#define IPW_SCAN_CHANNELS 54
701 678
702struct ipw_scan_request 679struct ipw_scan_request {
703{
704 u8 scan_type; 680 u8 scan_type;
705 u16 dwell_time; 681 u16 dwell_time;
706 u8 channels_list[IPW_SCAN_CHANNELS]; 682 u8 channels_list[IPW_SCAN_CHANNELS];
@@ -716,8 +692,7 @@ enum {
716 IPW_SCAN_TYPES 692 IPW_SCAN_TYPES
717}; 693};
718 694
719struct ipw_scan_request_ext 695struct ipw_scan_request_ext {
720{
721 u32 full_scan_index; 696 u32 full_scan_index;
722 u8 channels_list[IPW_SCAN_CHANNELS]; 697 u8 channels_list[IPW_SCAN_CHANNELS];
723 u8 scan_type[IPW_SCAN_CHANNELS / 2]; 698 u8 scan_type[IPW_SCAN_CHANNELS / 2];
@@ -738,19 +713,16 @@ extern inline void ipw_set_scan_type(struct ipw_scan_request_ext *scan,
738{ 713{
739 if (index % 2) 714 if (index % 2)
740 scan->scan_type[index / 2] = 715 scan->scan_type[index / 2] =
741 (scan->scan_type[index / 2] & 0xF0) | 716 (scan->scan_type[index / 2] & 0xF0) | (scan_type & 0x0F);
742 (scan_type & 0x0F);
743 else 717 else
744 scan->scan_type[index / 2] = 718 scan->scan_type[index / 2] =
745 (scan->scan_type[index / 2] & 0x0F) | 719 (scan->scan_type[index / 2] & 0x0F) |
746 ((scan_type & 0x0F) << 4); 720 ((scan_type & 0x0F) << 4);
747} 721}
748 722
749struct ipw_associate 723struct ipw_associate {
750{
751 u8 channel; 724 u8 channel;
752 u8 auth_type:4, 725 u8 auth_type:4, auth_key:4;
753 auth_key:4;
754 u8 assoc_type; 726 u8 assoc_type;
755 u8 reserved; 727 u8 reserved;
756 u16 policy_support; 728 u16 policy_support;
@@ -769,8 +741,7 @@ struct ipw_associate
769 u16 reserved2; 741 u16 reserved2;
770} __attribute__ ((packed)); 742} __attribute__ ((packed));
771 743
772struct ipw_supported_rates 744struct ipw_supported_rates {
773{
774 u8 ieee_mode; 745 u8 ieee_mode;
775 u8 num_rates; 746 u8 num_rates;
776 u8 purpose; 747 u8 purpose;
@@ -778,42 +749,36 @@ struct ipw_supported_rates
778 u8 supported_rates[IPW_MAX_RATES]; 749 u8 supported_rates[IPW_MAX_RATES];
779} __attribute__ ((packed)); 750} __attribute__ ((packed));
780 751
781struct ipw_rts_threshold 752struct ipw_rts_threshold {
782{
783 u16 rts_threshold; 753 u16 rts_threshold;
784 u16 reserved; 754 u16 reserved;
785} __attribute__ ((packed)); 755} __attribute__ ((packed));
786 756
787struct ipw_frag_threshold 757struct ipw_frag_threshold {
788{
789 u16 frag_threshold; 758 u16 frag_threshold;
790 u16 reserved; 759 u16 reserved;
791} __attribute__ ((packed)); 760} __attribute__ ((packed));
792 761
793struct ipw_retry_limit 762struct ipw_retry_limit {
794{
795 u8 short_retry_limit; 763 u8 short_retry_limit;
796 u8 long_retry_limit; 764 u8 long_retry_limit;
797 u16 reserved; 765 u16 reserved;
798} __attribute__ ((packed)); 766} __attribute__ ((packed));
799 767
800struct ipw_dino_config 768struct ipw_dino_config {
801{
802 u32 dino_config_addr; 769 u32 dino_config_addr;
803 u16 dino_config_size; 770 u16 dino_config_size;
804 u8 dino_response; 771 u8 dino_response;
805 u8 reserved; 772 u8 reserved;
806} __attribute__ ((packed)); 773} __attribute__ ((packed));
807 774
808struct ipw_aironet_info 775struct ipw_aironet_info {
809{
810 u8 id; 776 u8 id;
811 u8 length; 777 u8 length;
812 u16 reserved; 778 u16 reserved;
813} __attribute__ ((packed)); 779} __attribute__ ((packed));
814 780
815struct ipw_rx_key 781struct ipw_rx_key {
816{
817 u8 station_index; 782 u8 station_index;
818 u8 key_type; 783 u8 key_type;
819 u8 key_id; 784 u8 key_id;
@@ -824,23 +789,20 @@ struct ipw_rx_key
824 u8 reserved; 789 u8 reserved;
825} __attribute__ ((packed)); 790} __attribute__ ((packed));
826 791
827struct ipw_country_channel_info 792struct ipw_country_channel_info {
828{
829 u8 first_channel; 793 u8 first_channel;
830 u8 no_channels; 794 u8 no_channels;
831 s8 max_tx_power; 795 s8 max_tx_power;
832} __attribute__ ((packed)); 796} __attribute__ ((packed));
833 797
834struct ipw_country_info 798struct ipw_country_info {
835{
836 u8 id; 799 u8 id;
837 u8 length; 800 u8 length;
838 u8 country_str[3]; 801 u8 country_str[3];
839 struct ipw_country_channel_info groups[7]; 802 struct ipw_country_channel_info groups[7];
840} __attribute__ ((packed)); 803} __attribute__ ((packed));
841 804
842struct ipw_channel_tx_power 805struct ipw_channel_tx_power {
843{
844 u8 channel_number; 806 u8 channel_number;
845 s8 tx_power; 807 s8 tx_power;
846} __attribute__ ((packed)); 808} __attribute__ ((packed));
@@ -850,15 +812,13 @@ struct ipw_channel_tx_power
850#define MAX_A_CHANNELS 37 812#define MAX_A_CHANNELS 37
851#define MAX_B_CHANNELS 14 813#define MAX_B_CHANNELS 14
852 814
853struct ipw_tx_power 815struct ipw_tx_power {
854{
855 u8 num_channels; 816 u8 num_channels;
856 u8 ieee_mode; 817 u8 ieee_mode;
857 struct ipw_channel_tx_power channels_tx_power[MAX_A_CHANNELS]; 818 struct ipw_channel_tx_power channels_tx_power[MAX_A_CHANNELS];
858} __attribute__ ((packed)); 819} __attribute__ ((packed));
859 820
860struct ipw_qos_parameters 821struct ipw_qos_parameters {
861{
862 u16 cw_min[4]; 822 u16 cw_min[4];
863 u16 cw_max[4]; 823 u16 cw_max[4];
864 u8 aifs[4]; 824 u8 aifs[4];
@@ -866,15 +826,13 @@ struct ipw_qos_parameters
866 u16 tx_op_limit[4]; 826 u16 tx_op_limit[4];
867} __attribute__ ((packed)); 827} __attribute__ ((packed));
868 828
869struct ipw_rsn_capabilities 829struct ipw_rsn_capabilities {
870{
871 u8 id; 830 u8 id;
872 u8 length; 831 u8 length;
873 u16 version; 832 u16 version;
874} __attribute__ ((packed)); 833} __attribute__ ((packed));
875 834
876struct ipw_sensitivity_calib 835struct ipw_sensitivity_calib {
877{
878 u16 beacon_rssi_raw; 836 u16 beacon_rssi_raw;
879 u16 reserved; 837 u16 reserved;
880} __attribute__ ((packed)); 838} __attribute__ ((packed));
@@ -893,10 +851,11 @@ struct ipw_sensitivity_calib
893 * - \a param filled with status parameters. 851 * - \a param filled with status parameters.
894 */ 852 */
895struct ipw_cmd { 853struct ipw_cmd {
896 u32 cmd; /**< Host command */ 854 u32 cmd; /**< Host command */
897 u32 status; /**< Status */ 855 u32 status;/**< Status */
898 u32 status_len; /**< How many 32 bit parameters in the status */ 856 u32 status_len;
899 u32 len; /**< incoming parameters length, bytes */ 857 /**< How many 32 bit parameters in the status */
858 u32 len; /**< incoming parameters length, bytes */
900 /** 859 /**
901 * command parameters. 860 * command parameters.
902 * There should be enough space for incoming and 861 * There should be enough space for incoming and
@@ -904,10 +863,10 @@ struct ipw_cmd {
904 * Incoming parameters listed 1-st, followed by outcoming params. 863 * Incoming parameters listed 1-st, followed by outcoming params.
905 * nParams=(len+3)/4+status_len 864 * nParams=(len+3)/4+status_len
906 */ 865 */
907 u32 param[0]; 866 u32 param[0];
908} __attribute__ ((packed)); 867} __attribute__ ((packed));
909 868
910#define STATUS_HCMD_ACTIVE (1<<0) /**< host command in progress */ 869#define STATUS_HCMD_ACTIVE (1<<0) /**< host command in progress */
911 870
912#define STATUS_INT_ENABLED (1<<1) 871#define STATUS_INT_ENABLED (1<<1)
913#define STATUS_RF_KILL_HW (1<<2) 872#define STATUS_RF_KILL_HW (1<<2)
@@ -930,15 +889,15 @@ struct ipw_cmd {
930#define STATUS_SCANNING (1<<21) 889#define STATUS_SCANNING (1<<21)
931#define STATUS_SCAN_ABORTING (1<<22) 890#define STATUS_SCAN_ABORTING (1<<22)
932 891
933#define STATUS_INDIRECT_BYTE (1<<28) /* sysfs entry configured for access */ 892#define STATUS_INDIRECT_BYTE (1<<28) /* sysfs entry configured for access */
934#define STATUS_INDIRECT_DWORD (1<<29) /* sysfs entry configured for access */ 893#define STATUS_INDIRECT_DWORD (1<<29) /* sysfs entry configured for access */
935#define STATUS_DIRECT_DWORD (1<<30) /* sysfs entry configured for access */ 894#define STATUS_DIRECT_DWORD (1<<30) /* sysfs entry configured for access */
936 895
937#define STATUS_SECURITY_UPDATED (1<<31) /* Security sync needed */ 896#define STATUS_SECURITY_UPDATED (1<<31) /* Security sync needed */
938 897
939#define CFG_STATIC_CHANNEL (1<<0) /* Restrict assoc. to single channel */ 898#define CFG_STATIC_CHANNEL (1<<0) /* Restrict assoc. to single channel */
940#define CFG_STATIC_ESSID (1<<1) /* Restrict assoc. to single SSID */ 899#define CFG_STATIC_ESSID (1<<1) /* Restrict assoc. to single SSID */
941#define CFG_STATIC_BSSID (1<<2) /* Restrict assoc. to single BSSID */ 900#define CFG_STATIC_BSSID (1<<2) /* Restrict assoc. to single BSSID */
942#define CFG_CUSTOM_MAC (1<<3) 901#define CFG_CUSTOM_MAC (1<<3)
943#define CFG_PREAMBLE (1<<4) 902#define CFG_PREAMBLE (1<<4)
944#define CFG_ADHOC_PERSIST (1<<5) 903#define CFG_ADHOC_PERSIST (1<<5)
@@ -946,8 +905,8 @@ struct ipw_cmd {
946#define CFG_FIXED_RATE (1<<7) 905#define CFG_FIXED_RATE (1<<7)
947#define CFG_ADHOC_CREATE (1<<8) 906#define CFG_ADHOC_CREATE (1<<8)
948 907
949#define CAP_SHARED_KEY (1<<0) /* Off = OPEN */ 908#define CAP_SHARED_KEY (1<<0) /* Off = OPEN */
950#define CAP_PRIVACY_ON (1<<1) /* Off = No privacy */ 909#define CAP_PRIVACY_ON (1<<1) /* Off = No privacy */
951 910
952#define MAX_STATIONS 32 911#define MAX_STATIONS 32
953#define IPW_INVALID_STATION (0xff) 912#define IPW_INVALID_STATION (0xff)
@@ -987,8 +946,8 @@ struct ipw_priv {
987 /* result of ucode download */ 946 /* result of ucode download */
988 struct alive_command_responce dino_alive; 947 struct alive_command_responce dino_alive;
989 948
990 wait_queue_head_t wait_command_queue; 949 wait_queue_head_t wait_command_queue;
991 wait_queue_head_t wait_state; 950 wait_queue_head_t wait_state;
992 951
993 /* Rx and Tx DMA processing queues */ 952 /* Rx and Tx DMA processing queues */
994 struct ipw_rx_queue *rxq; 953 struct ipw_rx_queue *rxq;
@@ -1004,9 +963,9 @@ struct ipw_priv {
1004 struct average average_rssi; 963 struct average average_rssi;
1005 struct average average_noise; 964 struct average average_noise;
1006 u32 port_type; 965 u32 port_type;
1007 int rx_bufs_min; /**< minimum number of bufs in Rx queue */ 966 int rx_bufs_min; /**< minimum number of bufs in Rx queue */
1008 int rx_pend_max; /**< maximum pending buffers for one IRQ */ 967 int rx_pend_max; /**< maximum pending buffers for one IRQ */
1009 u32 hcmd_seq; /**< sequence number for hcmd */ 968 u32 hcmd_seq; /**< sequence number for hcmd */
1010 u32 missed_beacon_threshold; 969 u32 missed_beacon_threshold;
1011 u32 roaming_threshold; 970 u32 roaming_threshold;
1012 971
@@ -1015,17 +974,17 @@ struct ipw_priv {
1015 974
1016 unsigned long ts_scan_abort; 975 unsigned long ts_scan_abort;
1017 struct ipw_supported_rates rates; 976 struct ipw_supported_rates rates;
1018 struct ipw_rates phy[3]; /**< PHY restrictions, per band */ 977 struct ipw_rates phy[3]; /**< PHY restrictions, per band */
1019 struct ipw_rates supp; /**< software defined */ 978 struct ipw_rates supp; /**< software defined */
1020 struct ipw_rates extended; /**< use for corresp. IE, AP only */ 979 struct ipw_rates extended; /**< use for corresp. IE, AP only */
1021 980
1022 struct notif_link_deterioration last_link_deterioration; /** for statistics */ 981 struct notif_link_deterioration last_link_deterioration; /** for statistics */
1023 struct ipw_cmd* hcmd; /**< host command currently executed */ 982 struct ipw_cmd *hcmd; /**< host command currently executed */
1024 983
1025 wait_queue_head_t hcmd_wq; /**< host command waits for execution */ 984 wait_queue_head_t hcmd_wq; /**< host command waits for execution */
1026 u32 tsf_bcn[2]; /**< TSF from latest beacon */ 985 u32 tsf_bcn[2]; /**< TSF from latest beacon */
1027 986
1028 struct notif_calibration calib; /**< last calibration */ 987 struct notif_calibration calib; /**< last calibration */
1029 988
1030 /* ordinal interface with firmware */ 989 /* ordinal interface with firmware */
1031 u32 table0_addr; 990 u32 table0_addr;
@@ -1065,8 +1024,8 @@ struct ipw_priv {
1065 u32 tx_packets; 1024 u32 tx_packets;
1066 u32 quality; 1025 u32 quality;
1067 1026
1068 /* eeprom */ 1027 /* eeprom */
1069 u8 eeprom[0x100]; /* 256 bytes of eeprom */ 1028 u8 eeprom[0x100]; /* 256 bytes of eeprom */
1070 int eeprom_delay; 1029 int eeprom_delay;
1071 1030
1072 struct iw_statistics wstats; 1031 struct iw_statistics wstats;
@@ -1089,7 +1048,6 @@ struct ipw_priv {
1089 1048
1090 struct tasklet_struct irq_tasklet; 1049 struct tasklet_struct irq_tasklet;
1091 1050
1092
1093#define IPW_2200BG 1 1051#define IPW_2200BG 1
1094#define IPW_2915ABG 2 1052#define IPW_2915ABG 2
1095 u8 adapter; 1053 u8 adapter;
@@ -1112,7 +1070,6 @@ struct ipw_priv {
1112 u32 indirect_byte; 1070 u32 indirect_byte;
1113}; /*ipw_priv */ 1071}; /*ipw_priv */
1114 1072
1115
1116/* debug macros */ 1073/* debug macros */
1117 1074
1118#ifdef CONFIG_IPW_DEBUG 1075#ifdef CONFIG_IPW_DEBUG
@@ -1168,7 +1125,6 @@ do { if (ipw_debug_level & (level)) \
1168#define IPW_DL_RF_KILL (1<<17) 1125#define IPW_DL_RF_KILL (1<<17)
1169#define IPW_DL_FW_ERRORS (1<<18) 1126#define IPW_DL_FW_ERRORS (1<<18)
1170 1127
1171
1172#define IPW_DL_ORD (1<<20) 1128#define IPW_DL_ORD (1<<20)
1173 1129
1174#define IPW_DL_FRAG (1<<21) 1130#define IPW_DL_FRAG (1<<21)
@@ -1182,7 +1138,6 @@ do { if (ipw_debug_level & (level)) \
1182 1138
1183#define IPW_DL_STATS (1<<29) 1139#define IPW_DL_STATS (1<<29)
1184 1140
1185
1186#define IPW_ERROR(f, a...) printk(KERN_ERR DRV_NAME ": " f, ## a) 1141#define IPW_ERROR(f, a...) printk(KERN_ERR DRV_NAME ": " f, ## a)
1187#define IPW_WARNING(f, a...) printk(KERN_WARNING DRV_NAME ": " f, ## a) 1142#define IPW_WARNING(f, a...) printk(KERN_WARNING DRV_NAME ": " f, ## a)
1188#define IPW_DEBUG_INFO(f, a...) IPW_DEBUG(IPW_DL_INFO, f, ## a) 1143#define IPW_DEBUG_INFO(f, a...) IPW_DEBUG(IPW_DL_INFO, f, ## a)
@@ -1251,12 +1206,12 @@ do { if (ipw_debug_level & (level)) \
1251/* 1206/*
1252 * RESET Register Bit Indexes 1207 * RESET Register Bit Indexes
1253 */ 1208 */
1254#define CBD_RESET_REG_PRINCETON_RESET 0x00000001 /* Bit 0 (LSB) */ 1209#define CBD_RESET_REG_PRINCETON_RESET 0x00000001 /* Bit 0 (LSB) */
1255#define CX2_RESET_REG_SW_RESET 0x00000080 /* Bit 7 */ 1210#define CX2_RESET_REG_SW_RESET 0x00000080 /* Bit 7 */
1256#define CX2_RESET_REG_MASTER_DISABLED 0x00000100 /* Bit 8 */ 1211#define CX2_RESET_REG_MASTER_DISABLED 0x00000100 /* Bit 8 */
1257#define CX2_RESET_REG_STOP_MASTER 0x00000200 /* Bit 9 */ 1212#define CX2_RESET_REG_STOP_MASTER 0x00000200 /* Bit 9 */
1258#define CX2_ARC_KESHET_CONFIG 0x08000000 /* Bit 27 */ 1213#define CX2_ARC_KESHET_CONFIG 0x08000000 /* Bit 27 */
1259#define CX2_START_STANDBY 0x00000004 /* Bit 2 */ 1214#define CX2_START_STANDBY 0x00000004 /* Bit 2 */
1260 1215
1261#define CX2_CSR_CIS_UPPER_BOUND 0x00000200 1216#define CX2_CSR_CIS_UPPER_BOUND 0x00000200
1262#define CX2_DOMAIN_0_END 0x1000 1217#define CX2_DOMAIN_0_END 0x1000
@@ -1287,14 +1242,12 @@ do { if (ipw_debug_level & (level)) \
1287#define CB_SRC_SIZE_LONG 0x00200000 1242#define CB_SRC_SIZE_LONG 0x00200000
1288#define CB_DEST_SIZE_LONG 0x00020000 1243#define CB_DEST_SIZE_LONG 0x00020000
1289 1244
1290
1291/* DMA DEFINES */ 1245/* DMA DEFINES */
1292 1246
1293#define DMA_CONTROL_SMALL_CB_CONST_VALUE 0x00540000 1247#define DMA_CONTROL_SMALL_CB_CONST_VALUE 0x00540000
1294#define DMA_CB_STOP_AND_ABORT 0x00000C00 1248#define DMA_CB_STOP_AND_ABORT 0x00000C00
1295#define DMA_CB_START 0x00000100 1249#define DMA_CB_START 0x00000100
1296 1250
1297
1298#define CX2_SHARED_SRAM_SIZE 0x00030000 1251#define CX2_SHARED_SRAM_SIZE 0x00030000
1299#define CX2_SHARED_SRAM_DMA_CONTROL 0x00027000 1252#define CX2_SHARED_SRAM_DMA_CONTROL 0x00027000
1300#define CB_MAX_LENGTH 0x1FFF 1253#define CB_MAX_LENGTH 0x1FFF
@@ -1302,7 +1255,6 @@ do { if (ipw_debug_level & (level)) \
1302#define CX2_HOST_EEPROM_DATA_SRAM_SIZE 0xA18 1255#define CX2_HOST_EEPROM_DATA_SRAM_SIZE 0xA18
1303#define CX2_EEPROM_IMAGE_SIZE 0x100 1256#define CX2_EEPROM_IMAGE_SIZE 0x100
1304 1257
1305
1306/* DMA defs */ 1258/* DMA defs */
1307#define CX2_DMA_I_CURRENT_CB 0x003000D0 1259#define CX2_DMA_I_CURRENT_CB 0x003000D0
1308#define CX2_DMA_O_CURRENT_CB 0x003000D4 1260#define CX2_DMA_O_CURRENT_CB 0x003000D4
@@ -1354,7 +1306,6 @@ do { if (ipw_debug_level & (level)) \
1354#define IPW_WHO_IS_AWAKE (CX2_SHARED_LOWER_BOUND + 0xB14) 1306#define IPW_WHO_IS_AWAKE (CX2_SHARED_LOWER_BOUND + 0xB14)
1355#define IPW_DURING_ATIM_WINDOW (CX2_SHARED_LOWER_BOUND + 0xB18) 1307#define IPW_DURING_ATIM_WINDOW (CX2_SHARED_LOWER_BOUND + 0xB18)
1356 1308
1357
1358#define MSB 1 1309#define MSB 1
1359#define LSB 0 1310#define LSB 0
1360#define WORD_TO_BYTE(_word) ((_word) * sizeof(u16)) 1311#define WORD_TO_BYTE(_word) ((_word) * sizeof(u16))
@@ -1363,16 +1314,16 @@ do { if (ipw_debug_level & (level)) \
1363 ( WORD_TO_BYTE(_wordoffset) + (_byteoffset) ) 1314 ( WORD_TO_BYTE(_wordoffset) + (_byteoffset) )
1364 1315
1365/* EEPROM access by BYTE */ 1316/* EEPROM access by BYTE */
1366#define EEPROM_PME_CAPABILITY (GET_EEPROM_ADDR(0x09,MSB)) /* 1 byte */ 1317#define EEPROM_PME_CAPABILITY (GET_EEPROM_ADDR(0x09,MSB)) /* 1 byte */
1367#define EEPROM_MAC_ADDRESS (GET_EEPROM_ADDR(0x21,LSB)) /* 6 byte */ 1318#define EEPROM_MAC_ADDRESS (GET_EEPROM_ADDR(0x21,LSB)) /* 6 byte */
1368#define EEPROM_VERSION (GET_EEPROM_ADDR(0x24,MSB)) /* 1 byte */ 1319#define EEPROM_VERSION (GET_EEPROM_ADDR(0x24,MSB)) /* 1 byte */
1369#define EEPROM_NIC_TYPE (GET_EEPROM_ADDR(0x25,LSB)) /* 1 byte */ 1320#define EEPROM_NIC_TYPE (GET_EEPROM_ADDR(0x25,LSB)) /* 1 byte */
1370#define EEPROM_SKU_CAPABILITY (GET_EEPROM_ADDR(0x25,MSB)) /* 1 byte */ 1321#define EEPROM_SKU_CAPABILITY (GET_EEPROM_ADDR(0x25,MSB)) /* 1 byte */
1371#define EEPROM_COUNTRY_CODE (GET_EEPROM_ADDR(0x26,LSB)) /* 3 bytes */ 1322#define EEPROM_COUNTRY_CODE (GET_EEPROM_ADDR(0x26,LSB)) /* 3 bytes */
1372#define EEPROM_IBSS_CHANNELS_BG (GET_EEPROM_ADDR(0x28,LSB)) /* 2 bytes */ 1323#define EEPROM_IBSS_CHANNELS_BG (GET_EEPROM_ADDR(0x28,LSB)) /* 2 bytes */
1373#define EEPROM_IBSS_CHANNELS_A (GET_EEPROM_ADDR(0x29,MSB)) /* 5 bytes */ 1324#define EEPROM_IBSS_CHANNELS_A (GET_EEPROM_ADDR(0x29,MSB)) /* 5 bytes */
1374#define EEPROM_BSS_CHANNELS_BG (GET_EEPROM_ADDR(0x2c,LSB)) /* 2 bytes */ 1325#define EEPROM_BSS_CHANNELS_BG (GET_EEPROM_ADDR(0x2c,LSB)) /* 2 bytes */
1375#define EEPROM_HW_VERSION (GET_EEPROM_ADDR(0x72,LSB)) /* 2 bytes */ 1326#define EEPROM_HW_VERSION (GET_EEPROM_ADDR(0x72,LSB)) /* 2 bytes */
1376 1327
1377/* NIC type as found in the one byte EEPROM_NIC_TYPE offset*/ 1328/* NIC type as found in the one byte EEPROM_NIC_TYPE offset*/
1378#define EEPROM_NIC_TYPE_STANDARD 0 1329#define EEPROM_NIC_TYPE_STANDARD 0
@@ -1477,7 +1428,6 @@ enum {
1477#define IPW_RATE_CAPABILITIES 1 1428#define IPW_RATE_CAPABILITIES 1
1478#define IPW_RATE_CONNECT 0 1429#define IPW_RATE_CONNECT 0
1479 1430
1480
1481/* 1431/*
1482 * Rate values and masks 1432 * Rate values and masks
1483 */ 1433 */
@@ -1522,12 +1472,6 @@ enum {
1522 IPW_ORD_STAT_TX_DIR_DATA_B_11, 1472 IPW_ORD_STAT_TX_DIR_DATA_B_11,
1523 /* Hole */ 1473 /* Hole */
1524 1474
1525
1526
1527
1528
1529
1530
1531 IPW_ORD_STAT_TX_DIR_DATA_G_1 = IPW_ORD_TABLE_0_MASK + 19, 1475 IPW_ORD_STAT_TX_DIR_DATA_G_1 = IPW_ORD_TABLE_0_MASK + 19,
1532 IPW_ORD_STAT_TX_DIR_DATA_G_2, 1476 IPW_ORD_STAT_TX_DIR_DATA_G_2,
1533 IPW_ORD_STAT_TX_DIR_DATA_G_5_5, 1477 IPW_ORD_STAT_TX_DIR_DATA_G_5_5,
@@ -1547,12 +1491,6 @@ enum {
1547 IPW_ORD_STAT_TX_NON_DIR_DATA_B_11, 1491 IPW_ORD_STAT_TX_NON_DIR_DATA_B_11,
1548 /* Hole */ 1492 /* Hole */
1549 1493
1550
1551
1552
1553
1554
1555
1556 IPW_ORD_STAT_TX_NON_DIR_DATA_G_1 = IPW_ORD_TABLE_0_MASK + 44, 1494 IPW_ORD_STAT_TX_NON_DIR_DATA_G_1 = IPW_ORD_TABLE_0_MASK + 44,
1557 IPW_ORD_STAT_TX_NON_DIR_DATA_G_2, 1495 IPW_ORD_STAT_TX_NON_DIR_DATA_G_2,
1558 IPW_ORD_STAT_TX_NON_DIR_DATA_G_5_5, 1496 IPW_ORD_STAT_TX_NON_DIR_DATA_G_5_5,
@@ -1683,7 +1621,7 @@ struct host_cmd {
1683#define CFG_BT_COEXISTENCE_WME_OVER_BT 0x08 1621#define CFG_BT_COEXISTENCE_WME_OVER_BT 0x08
1684#define CFG_BT_COEXISTENCE_OOB 0x10 1622#define CFG_BT_COEXISTENCE_OOB 0x10
1685#define CFG_BT_COEXISTENCE_MAX 0xFF 1623#define CFG_BT_COEXISTENCE_MAX 0xFF
1686#define CFG_BT_COEXISTENCE_DEF 0x80 /* read Bt from EEPROM*/ 1624#define CFG_BT_COEXISTENCE_DEF 0x80 /* read Bt from EEPROM */
1687 1625
1688#define CFG_CTS_TO_ITSELF_ENABLED_MIN 0x0 1626#define CFG_CTS_TO_ITSELF_ENABLED_MIN 0x0
1689#define CFG_CTS_TO_ITSELF_ENABLED_MAX 0x1 1627#define CFG_CTS_TO_ITSELF_ENABLED_MAX 0x1
@@ -1725,11 +1663,11 @@ static inline u32 frame_hdr_len(struct ieee80211_hdr *hdr)
1725 fc = le16_to_cpu(hdr->frame_ctl); 1663 fc = le16_to_cpu(hdr->frame_ctl);
1726 1664
1727 /* 1665 /*
1728 * Function ToDS FromDS 1666 * Function ToDS FromDS
1729 * IBSS 0 0 1667 * IBSS 0 0
1730 * To AP 1 0 1668 * To AP 1 0
1731 * From AP 0 1 1669 * From AP 0 1
1732 * WDS (bridge) 1 1 1670 * WDS (bridge) 1 1
1733 * 1671 *
1734 * Only WDS frames use Address4 among them. --YZ 1672 * Only WDS frames use Address4 among them. --YZ
1735 */ 1673 */
@@ -1739,4 +1677,4 @@ static inline u32 frame_hdr_len(struct ieee80211_hdr *hdr)
1739 return retval; 1677 return retval;
1740} 1678}
1741 1679
1742#endif /* __ipw2200_h__ */ 1680#endif /* __ipw2200_h__ */
diff --git a/drivers/net/wireless/netwave_cs.c b/drivers/net/wireless/netwave_cs.c
index 5f507c49907..ca6c03c8992 100644
--- a/drivers/net/wireless/netwave_cs.c
+++ b/drivers/net/wireless/netwave_cs.c
@@ -471,12 +471,12 @@ static dev_link_t *netwave_attach(void)
471 dev->get_stats = &netwave_get_stats; 471 dev->get_stats = &netwave_get_stats;
472 dev->set_multicast_list = &set_multicast_list; 472 dev->set_multicast_list = &set_multicast_list;
473 /* wireless extensions */ 473 /* wireless extensions */
474#ifdef WIRELESS_EXT 474#if WIRELESS_EXT <= 16
475 dev->get_wireless_stats = &netwave_get_wireless_stats; 475 dev->get_wireless_stats = &netwave_get_wireless_stats;
476#endif /* WIRELESS_EXT <= 16 */
476#if WIRELESS_EXT > 12 477#if WIRELESS_EXT > 12
477 dev->wireless_handlers = (struct iw_handler_def *)&netwave_handler_def; 478 dev->wireless_handlers = (struct iw_handler_def *)&netwave_handler_def;
478#endif /* WIRELESS_EXT > 12 */ 479#endif /* WIRELESS_EXT > 12 */
479#endif /* WIRELESS_EXT */
480 dev->do_ioctl = &netwave_ioctl; 480 dev->do_ioctl = &netwave_ioctl;
481 481
482 dev->tx_timeout = &netwave_watchdog; 482 dev->tx_timeout = &netwave_watchdog;
@@ -839,6 +839,9 @@ static const struct iw_handler_def netwave_handler_def =
839 .standard = (iw_handler *) netwave_handler, 839 .standard = (iw_handler *) netwave_handler,
840 .private = (iw_handler *) netwave_private_handler, 840 .private = (iw_handler *) netwave_private_handler,
841 .private_args = (struct iw_priv_args *) netwave_private_args, 841 .private_args = (struct iw_priv_args *) netwave_private_args,
842#if WIRELESS_EXT > 16
843 .get_wireless_stats = netwave_get_wireless_stats,
844#endif /* WIRELESS_EXT > 16 */
842}; 845};
843#endif /* WIRELESS_EXT > 12 */ 846#endif /* WIRELESS_EXT > 12 */
844 847
diff --git a/drivers/net/wireless/orinoco.c b/drivers/net/wireless/orinoco.c
index d7947358e49..8de49fe5723 100644
--- a/drivers/net/wireless/orinoco.c
+++ b/drivers/net/wireless/orinoco.c
@@ -1053,8 +1053,9 @@ static void orinoco_join_ap(struct net_device *dev)
1053 u16 channel; 1053 u16 channel;
1054 } __attribute__ ((packed)) req; 1054 } __attribute__ ((packed)) req;
1055 const int atom_len = offsetof(struct prism2_scan_apinfo, atim); 1055 const int atom_len = offsetof(struct prism2_scan_apinfo, atim);
1056 struct prism2_scan_apinfo *atom; 1056 struct prism2_scan_apinfo *atom = NULL;
1057 int offset = 4; 1057 int offset = 4;
1058 int found = 0;
1058 u8 *buf; 1059 u8 *buf;
1059 u16 len; 1060 u16 len;
1060 1061
@@ -1089,15 +1090,18 @@ static void orinoco_join_ap(struct net_device *dev)
1089 * we were requested to join */ 1090 * we were requested to join */
1090 for (; offset + atom_len <= len; offset += atom_len) { 1091 for (; offset + atom_len <= len; offset += atom_len) {
1091 atom = (struct prism2_scan_apinfo *) (buf + offset); 1092 atom = (struct prism2_scan_apinfo *) (buf + offset);
1092 if (memcmp(&atom->bssid, priv->desired_bssid, ETH_ALEN) == 0) 1093 if (memcmp(&atom->bssid, priv->desired_bssid, ETH_ALEN) == 0) {
1093 goto found; 1094 found = 1;
1095 break;
1096 }
1094 } 1097 }
1095 1098
1096 DEBUG(1, "%s: Requested AP not found in scan results\n", 1099 if (! found) {
1097 dev->name); 1100 DEBUG(1, "%s: Requested AP not found in scan results\n",
1098 goto out; 1101 dev->name);
1102 goto out;
1103 }
1099 1104
1100 found:
1101 memcpy(req.bssid, priv->desired_bssid, ETH_ALEN); 1105 memcpy(req.bssid, priv->desired_bssid, ETH_ALEN);
1102 req.channel = atom->channel; /* both are little-endian */ 1106 req.channel = atom->channel; /* both are little-endian */
1103 err = HERMES_WRITE_RECORD(hw, USER_BAP, HERMES_RID_CNFJOINREQUEST, 1107 err = HERMES_WRITE_RECORD(hw, USER_BAP, HERMES_RID_CNFJOINREQUEST,
@@ -1284,8 +1288,10 @@ static void __orinoco_ev_info(struct net_device *dev, hermes_t *hw)
1284 /* Read scan data */ 1288 /* Read scan data */
1285 err = hermes_bap_pread(hw, IRQ_BAP, (void *) buf, len, 1289 err = hermes_bap_pread(hw, IRQ_BAP, (void *) buf, len,
1286 infofid, sizeof(info)); 1290 infofid, sizeof(info));
1287 if (err) 1291 if (err) {
1292 kfree(buf);
1288 break; 1293 break;
1294 }
1289 1295
1290#ifdef ORINOCO_DEBUG 1296#ifdef ORINOCO_DEBUG
1291 { 1297 {
@@ -4021,7 +4027,8 @@ static int orinoco_ioctl_setscan(struct net_device *dev,
4021} 4027}
4022 4028
4023/* Translate scan data returned from the card to a card independant 4029/* Translate scan data returned from the card to a card independant
4024 * format that the Wireless Tools will understand - Jean II */ 4030 * format that the Wireless Tools will understand - Jean II
4031 * Return message length or -errno for fatal errors */
4025static inline int orinoco_translate_scan(struct net_device *dev, 4032static inline int orinoco_translate_scan(struct net_device *dev,
4026 char *buffer, 4033 char *buffer,
4027 char *scan, 4034 char *scan,
@@ -4061,13 +4068,19 @@ static inline int orinoco_translate_scan(struct net_device *dev,
4061 break; 4068 break;
4062 case FIRMWARE_TYPE_INTERSIL: 4069 case FIRMWARE_TYPE_INTERSIL:
4063 offset = 4; 4070 offset = 4;
4064 if (priv->has_hostscan) 4071 if (priv->has_hostscan) {
4065 atom_len = scan[0] + (scan[1] << 8); 4072 atom_len = le16_to_cpup((u16 *)scan);
4066 else 4073 /* Sanity check for atom_len */
4074 if (atom_len < sizeof(struct prism2_scan_apinfo)) {
4075 printk(KERN_ERR "%s: Invalid atom_len in scan data: %d\n",
4076 dev->name, atom_len);
4077 return -EIO;
4078 }
4079 } else
4067 atom_len = offsetof(struct prism2_scan_apinfo, atim); 4080 atom_len = offsetof(struct prism2_scan_apinfo, atim);
4068 break; 4081 break;
4069 default: 4082 default:
4070 return 0; 4083 return -EOPNOTSUPP;
4071 } 4084 }
4072 4085
4073 /* Check that we got an whole number of atoms */ 4086 /* Check that we got an whole number of atoms */
@@ -4075,7 +4088,7 @@ static inline int orinoco_translate_scan(struct net_device *dev,
4075 printk(KERN_ERR "%s: Unexpected scan data length %d, " 4088 printk(KERN_ERR "%s: Unexpected scan data length %d, "
4076 "atom_len %d, offset %d\n", dev->name, scan_len, 4089 "atom_len %d, offset %d\n", dev->name, scan_len,
4077 atom_len, offset); 4090 atom_len, offset);
4078 return 0; 4091 return -EIO;
4079 } 4092 }
4080 4093
4081 /* Read the entries one by one */ 4094 /* Read the entries one by one */
@@ -4210,33 +4223,41 @@ static int orinoco_ioctl_getscan(struct net_device *dev,
4210 /* We have some results to push back to user space */ 4223 /* We have some results to push back to user space */
4211 4224
4212 /* Translate to WE format */ 4225 /* Translate to WE format */
4213 srq->length = orinoco_translate_scan(dev, extra, 4226 int ret = orinoco_translate_scan(dev, extra,
4214 priv->scan_result, 4227 priv->scan_result,
4215 priv->scan_len); 4228 priv->scan_len);
4216 4229
4217 /* Return flags */ 4230 if (ret < 0) {
4218 srq->flags = (__u16) priv->scan_mode; 4231 err = ret;
4232 kfree(priv->scan_result);
4233 priv->scan_result = NULL;
4234 } else {
4235 srq->length = ret;
4219 4236
4220 /* Results are here, so scan no longer in progress */ 4237 /* Return flags */
4221 priv->scan_inprogress = 0; 4238 srq->flags = (__u16) priv->scan_mode;
4222 4239
4223 /* In any case, Scan results will be cleaned up in the 4240 /* In any case, Scan results will be cleaned up in the
4224 * reset function and when exiting the driver. 4241 * reset function and when exiting the driver.
4225 * The person triggering the scanning may never come to 4242 * The person triggering the scanning may never come to
4226 * pick the results, so we need to do it in those places. 4243 * pick the results, so we need to do it in those places.
4227 * Jean II */ 4244 * Jean II */
4228 4245
4229#ifdef SCAN_SINGLE_READ 4246#ifdef SCAN_SINGLE_READ
4230 /* If you enable this option, only one client (the first 4247 /* If you enable this option, only one client (the first
4231 * one) will be able to read the result (and only one 4248 * one) will be able to read the result (and only one
4232 * time). If there is multiple concurent clients that 4249 * time). If there is multiple concurent clients that
4233 * want to read scan results, this behavior is not 4250 * want to read scan results, this behavior is not
4234 * advisable - Jean II */ 4251 * advisable - Jean II */
4235 kfree(priv->scan_result); 4252 kfree(priv->scan_result);
4236 priv->scan_result = NULL; 4253 priv->scan_result = NULL;
4237#endif /* SCAN_SINGLE_READ */ 4254#endif /* SCAN_SINGLE_READ */
4238 /* Here, if too much time has elapsed since last scan, 4255 /* Here, if too much time has elapsed since last scan,
4239 * we may want to clean up scan results... - Jean II */ 4256 * we may want to clean up scan results... - Jean II */
4257 }
4258
4259 /* Scan is no longer in progress */
4260 priv->scan_inprogress = 0;
4240 } 4261 }
4241 4262
4242 orinoco_unlock(priv, &flags); 4263 orinoco_unlock(priv, &flags);
diff --git a/drivers/net/wireless/orinoco_cs.c b/drivers/net/wireless/orinoco_cs.c
index 1cc1492083c..d1fb1bab8aa 100644
--- a/drivers/net/wireless/orinoco_cs.c
+++ b/drivers/net/wireless/orinoco_cs.c
@@ -604,7 +604,6 @@ static char version[] __initdata = DRIVER_NAME " " DRIVER_VERSION
604 604
605static struct pcmcia_device_id orinoco_cs_ids[] = { 605static struct pcmcia_device_id orinoco_cs_ids[] = {
606 PCMCIA_DEVICE_MANF_CARD(0x000b, 0x7300), 606 PCMCIA_DEVICE_MANF_CARD(0x000b, 0x7300),
607 PCMCIA_DEVICE_MANF_CARD(0x0089, 0x0001),
608 PCMCIA_DEVICE_MANF_CARD(0x0138, 0x0002), 607 PCMCIA_DEVICE_MANF_CARD(0x0138, 0x0002),
609 PCMCIA_DEVICE_MANF_CARD(0x0156, 0x0002), 608 PCMCIA_DEVICE_MANF_CARD(0x0156, 0x0002),
610 PCMCIA_DEVICE_MANF_CARD(0x01eb, 0x080a), 609 PCMCIA_DEVICE_MANF_CARD(0x01eb, 0x080a),
diff --git a/drivers/net/wireless/orinoco_nortel.c b/drivers/net/wireless/orinoco_nortel.c
new file mode 100644
index 00000000000..86fa58e5cfa
--- /dev/null
+++ b/drivers/net/wireless/orinoco_nortel.c
@@ -0,0 +1,324 @@
1/* orinoco_nortel.c
2 *
3 * Driver for Prism II devices which would usually be driven by orinoco_cs,
4 * but are connected to the PCI bus by a Nortel PCI-PCMCIA-Adapter.
5 *
6 * Copyright (C) 2002 Tobias Hoffmann
7 * (C) 2003 Christoph Jungegger <disdos@traum404.de>
8 *
9 * Some of this code is borrowed from orinoco_plx.c
10 * Copyright (C) 2001 Daniel Barlow
11 * Some of this code is borrowed from orinoco_pci.c
12 * Copyright (C) 2001 Jean Tourrilhes
13 * Some of this code is "inspired" by linux-wlan-ng-0.1.10, but nothing
14 * has been copied from it. linux-wlan-ng-0.1.10 is originally :
15 * Copyright (C) 1999 AbsoluteValue Systems, Inc. All Rights Reserved.
16 *
17 * The contents of this file are subject to the Mozilla Public License
18 * Version 1.1 (the "License"); you may not use this file except in
19 * compliance with the License. You may obtain a copy of the License
20 * at http://www.mozilla.org/MPL/
21 *
22 * Software distributed under the License is distributed on an "AS IS"
23 * basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See
24 * the License for the specific language governing rights and
25 * limitations under the License.
26 *
27 * Alternatively, the contents of this file may be used under the
28 * terms of the GNU General Public License version 2 (the "GPL"), in
29 * which case the provisions of the GPL are applicable instead of the
30 * above. If you wish to allow the use of your version of this file
31 * only under the terms of the GPL and not to allow others to use your
32 * version of this file under the MPL, indicate your decision by
33 * deleting the provisions above and replace them with the notice and
34 * other provisions required by the GPL. If you do not delete the
35 * provisions above, a recipient may use your version of this file
36 * under either the MPL or the GPL.
37 */
38
39#define DRIVER_NAME "orinoco_nortel"
40#define PFX DRIVER_NAME ": "
41
42#include <linux/config.h>
43
44#include <linux/module.h>
45#include <linux/kernel.h>
46#include <linux/init.h>
47#include <linux/sched.h>
48#include <linux/ptrace.h>
49#include <linux/slab.h>
50#include <linux/string.h>
51#include <linux/timer.h>
52#include <linux/ioport.h>
53#include <asm/uaccess.h>
54#include <asm/io.h>
55#include <asm/system.h>
56#include <linux/netdevice.h>
57#include <linux/if_arp.h>
58#include <linux/etherdevice.h>
59#include <linux/list.h>
60#include <linux/pci.h>
61#include <linux/fcntl.h>
62
63#include <pcmcia/cisreg.h>
64
65#include "hermes.h"
66#include "orinoco.h"
67
68#define COR_OFFSET (0xe0) /* COR attribute offset of Prism2 PC card */
69#define COR_VALUE (COR_LEVEL_REQ | COR_FUNC_ENA) /* Enable PC card with interrupt in level trigger */
70
71
72/* Nortel specific data */
73struct nortel_pci_card {
74 unsigned long iobase1;
75 unsigned long iobase2;
76};
77
78/*
79 * Do a soft reset of the PCI card using the Configuration Option Register
80 * We need this to get going...
81 * This is the part of the code that is strongly inspired from wlan-ng
82 *
83 * Note bis : Don't try to access HERMES_CMD during the reset phase.
84 * It just won't work !
85 */
86static int nortel_pci_cor_reset(struct orinoco_private *priv)
87{
88 struct nortel_pci_card *card = priv->card;
89
90 /* Assert the reset until the card notice */
91 outw_p(8, card->iobase1 + 2);
92 inw(card->iobase2 + COR_OFFSET);
93 outw_p(0x80, card->iobase2 + COR_OFFSET);
94 mdelay(1);
95
96 /* Give time for the card to recover from this hard effort */
97 outw_p(0, card->iobase2 + COR_OFFSET);
98 outw_p(0, card->iobase2 + COR_OFFSET);
99 mdelay(1);
100
101 /* set COR as usual */
102 outw_p(COR_VALUE, card->iobase2 + COR_OFFSET);
103 outw_p(COR_VALUE, card->iobase2 + COR_OFFSET);
104 mdelay(1);
105
106 outw_p(0x228, card->iobase1 + 2);
107
108 return 0;
109}
110
111int nortel_pci_hw_init(struct nortel_pci_card *card)
112{
113 int i;
114 u32 reg;
115
116 /* setup bridge */
117 if (inw(card->iobase1) & 1) {
118 printk(KERN_ERR PFX "brg1 answer1 wrong\n");
119 return -EBUSY;
120 }
121 outw_p(0x118, card->iobase1 + 2);
122 outw_p(0x108, card->iobase1 + 2);
123 mdelay(30);
124 outw_p(0x8, card->iobase1 + 2);
125 for (i = 0; i < 30; i++) {
126 mdelay(30);
127 if (inw(card->iobase1) & 0x10) {
128 break;
129 }
130 }
131 if (i == 30) {
132 printk(KERN_ERR PFX "brg1 timed out\n");
133 return -EBUSY;
134 }
135 if (inw(card->iobase2 + 0xe0) & 1) {
136 printk(KERN_ERR PFX "brg2 answer1 wrong\n");
137 return -EBUSY;
138 }
139 if (inw(card->iobase2 + 0xe2) & 1) {
140 printk(KERN_ERR PFX "brg2 answer2 wrong\n");
141 return -EBUSY;
142 }
143 if (inw(card->iobase2 + 0xe4) & 1) {
144 printk(KERN_ERR PFX "brg2 answer3 wrong\n");
145 return -EBUSY;
146 }
147
148 /* set the PCMCIA COR-Register */
149 outw_p(COR_VALUE, card->iobase2 + COR_OFFSET);
150 mdelay(1);
151 reg = inw(card->iobase2 + COR_OFFSET);
152 if (reg != COR_VALUE) {
153 printk(KERN_ERR PFX "Error setting COR value (reg=%x)\n",
154 reg);
155 return -EBUSY;
156 }
157
158 /* set leds */
159 outw_p(1, card->iobase1 + 10);
160 return 0;
161}
162
163static int nortel_pci_init_one(struct pci_dev *pdev,
164 const struct pci_device_id *ent)
165{
166 int err;
167 struct orinoco_private *priv;
168 struct nortel_pci_card *card;
169 struct net_device *dev;
170 void __iomem *iomem;
171
172 err = pci_enable_device(pdev);
173 if (err) {
174 printk(KERN_ERR PFX "Cannot enable PCI device\n");
175 return err;
176 }
177
178 err = pci_request_regions(pdev, DRIVER_NAME);
179 if (err != 0) {
180 printk(KERN_ERR PFX "Cannot obtain PCI resources\n");
181 goto fail_resources;
182 }
183
184 iomem = pci_iomap(pdev, 3, 0);
185 if (!iomem) {
186 err = -ENOMEM;
187 goto fail_map_io;
188 }
189
190 /* Allocate network device */
191 dev = alloc_orinocodev(sizeof(*card), nortel_pci_cor_reset);
192 if (!dev) {
193 printk(KERN_ERR PFX "Cannot allocate network device\n");
194 err = -ENOMEM;
195 goto fail_alloc;
196 }
197
198 priv = netdev_priv(dev);
199 card = priv->card;
200 card->iobase1 = pci_resource_start(pdev, 0);
201 card->iobase2 = pci_resource_start(pdev, 1);
202 dev->base_addr = pci_resource_start(pdev, 2);
203 SET_MODULE_OWNER(dev);
204 SET_NETDEV_DEV(dev, &pdev->dev);
205
206 hermes_struct_init(&priv->hw, iomem, HERMES_16BIT_REGSPACING);
207
208 printk(KERN_DEBUG PFX "Detected Nortel PCI device at %s irq:%d, "
209 "io addr:0x%lx\n", pci_name(pdev), pdev->irq, dev->base_addr);
210
211 err = request_irq(pdev->irq, orinoco_interrupt, SA_SHIRQ,
212 dev->name, dev);
213 if (err) {
214 printk(KERN_ERR PFX "Cannot allocate IRQ %d\n", pdev->irq);
215 err = -EBUSY;
216 goto fail_irq;
217 }
218 dev->irq = pdev->irq;
219
220 err = nortel_pci_hw_init(card);
221 if (err) {
222 printk(KERN_ERR PFX "Hardware initialization failed\n");
223 goto fail;
224 }
225
226 err = nortel_pci_cor_reset(priv);
227 if (err) {
228 printk(KERN_ERR PFX "Initial reset failed\n");
229 goto fail;
230 }
231
232
233 err = register_netdev(dev);
234 if (err) {
235 printk(KERN_ERR PFX "Cannot register network device\n");
236 goto fail;
237 }
238
239 pci_set_drvdata(pdev, dev);
240
241 return 0;
242
243 fail:
244 free_irq(pdev->irq, dev);
245
246 fail_irq:
247 pci_set_drvdata(pdev, NULL);
248 free_orinocodev(dev);
249
250 fail_alloc:
251 pci_iounmap(pdev, iomem);
252
253 fail_map_io:
254 pci_release_regions(pdev);
255
256 fail_resources:
257 pci_disable_device(pdev);
258
259 return err;
260}
261
262static void __devexit nortel_pci_remove_one(struct pci_dev *pdev)
263{
264 struct net_device *dev = pci_get_drvdata(pdev);
265 struct orinoco_private *priv = netdev_priv(dev);
266 struct nortel_pci_card *card = priv->card;
267
268 /* clear leds */
269 outw_p(0, card->iobase1 + 10);
270
271 unregister_netdev(dev);
272 free_irq(dev->irq, dev);
273 pci_set_drvdata(pdev, NULL);
274 free_orinocodev(dev);
275 pci_iounmap(pdev, priv->hw.iobase);
276 pci_release_regions(pdev);
277 pci_disable_device(pdev);
278}
279
280
281static struct pci_device_id nortel_pci_id_table[] = {
282 /* Nortel emobility PCI */
283 {0x126c, 0x8030, PCI_ANY_ID, PCI_ANY_ID,},
284 {0,},
285};
286
287MODULE_DEVICE_TABLE(pci, nortel_pci_id_table);
288
289static struct pci_driver nortel_pci_driver = {
290 .name = DRIVER_NAME,
291 .id_table = nortel_pci_id_table,
292 .probe = nortel_pci_init_one,
293 .remove = __devexit_p(nortel_pci_remove_one),
294};
295
296static char version[] __initdata = DRIVER_NAME " " DRIVER_VERSION
297 " (Tobias Hoffmann & Christoph Jungegger <disdos@traum404.de>)";
298MODULE_AUTHOR("Christoph Jungegger <disdos@traum404.de>");
299MODULE_DESCRIPTION
300 ("Driver for wireless LAN cards using the Nortel PCI bridge");
301MODULE_LICENSE("Dual MPL/GPL");
302
303static int __init nortel_pci_init(void)
304{
305 printk(KERN_DEBUG "%s\n", version);
306 return pci_module_init(&nortel_pci_driver);
307}
308
309static void __exit nortel_pci_exit(void)
310{
311 pci_unregister_driver(&nortel_pci_driver);
312 ssleep(1);
313}
314
315module_init(nortel_pci_init);
316module_exit(nortel_pci_exit);
317
318/*
319 * Local variables:
320 * c-indent-level: 8
321 * c-basic-offset: 8
322 * tab-width: 8
323 * End:
324 */
diff --git a/drivers/net/wireless/orinoco_pci.c b/drivers/net/wireless/orinoco_pci.c
index 7a6f52ea7fa..42e03438291 100644
--- a/drivers/net/wireless/orinoco_pci.c
+++ b/drivers/net/wireless/orinoco_pci.c
@@ -301,8 +301,6 @@ static int orinoco_pci_suspend(struct pci_dev *pdev, pm_message_t state)
301 unsigned long flags; 301 unsigned long flags;
302 int err; 302 int err;
303 303
304 printk(KERN_DEBUG "%s: Orinoco-PCI entering sleep mode (state=%d)\n",
305 dev->name, state);
306 304
307 err = orinoco_lock(priv, &flags); 305 err = orinoco_lock(priv, &flags);
308 if (err) { 306 if (err) {
diff --git a/drivers/net/wireless/prism54/isl_ioctl.c b/drivers/net/wireless/prism54/isl_ioctl.c
index 0f29a9c7bc2..9a8790e3580 100644
--- a/drivers/net/wireless/prism54/isl_ioctl.c
+++ b/drivers/net/wireless/prism54/isl_ioctl.c
@@ -2727,6 +2727,9 @@ const struct iw_handler_def prism54_handler_def = {
2727 .standard = (iw_handler *) prism54_handler, 2727 .standard = (iw_handler *) prism54_handler,
2728 .private = (iw_handler *) prism54_private_handler, 2728 .private = (iw_handler *) prism54_private_handler,
2729 .private_args = (struct iw_priv_args *) prism54_private_args, 2729 .private_args = (struct iw_priv_args *) prism54_private_args,
2730#if WIRELESS_EXT > 16
2731 .get_wireless_stats = prism54_get_wireless_stats,
2732#endif /* WIRELESS_EXT > 16 */
2730#if WIRELESS_EXT == 16 2733#if WIRELESS_EXT == 16
2731 .spy_offset = offsetof(islpci_private, spy_data), 2734 .spy_offset = offsetof(islpci_private, spy_data),
2732#endif /* WIRELESS_EXT == 16 */ 2735#endif /* WIRELESS_EXT == 16 */
diff --git a/drivers/net/wireless/prism54/islpci_dev.c b/drivers/net/wireless/prism54/islpci_dev.c
index efab07e9e24..6f13d4a8e2d 100644
--- a/drivers/net/wireless/prism54/islpci_dev.c
+++ b/drivers/net/wireless/prism54/islpci_dev.c
@@ -815,7 +815,6 @@ islpci_setup(struct pci_dev *pdev)
815 ndev->open = &islpci_open; 815 ndev->open = &islpci_open;
816 ndev->stop = &islpci_close; 816 ndev->stop = &islpci_close;
817 ndev->get_stats = &islpci_statistics; 817 ndev->get_stats = &islpci_statistics;
818 ndev->get_wireless_stats = &prism54_get_wireless_stats;
819 ndev->do_ioctl = &prism54_ioctl; 818 ndev->do_ioctl = &prism54_ioctl;
820 ndev->wireless_handlers = 819 ndev->wireless_handlers =
821 (struct iw_handler_def *) &prism54_handler_def; 820 (struct iw_handler_def *) &prism54_handler_def;
@@ -844,6 +843,8 @@ islpci_setup(struct pci_dev *pdev)
844 /* Add pointers to enable iwspy support. */ 843 /* Add pointers to enable iwspy support. */
845 priv->wireless_data.spy_data = &priv->spy_data; 844 priv->wireless_data.spy_data = &priv->spy_data;
846 ndev->wireless_data = &priv->wireless_data; 845 ndev->wireless_data = &priv->wireless_data;
846#else /* WIRELESS_EXT > 16 */
847 ndev->get_wireless_stats = &prism54_get_wireless_stats;
847#endif /* WIRELESS_EXT > 16 */ 848#endif /* WIRELESS_EXT > 16 */
848 849
849 /* save the start and end address of the PCI memory area */ 850 /* save the start and end address of the PCI memory area */
diff --git a/drivers/net/wireless/prism54/islpci_hotplug.c b/drivers/net/wireless/prism54/islpci_hotplug.c
index c17391d947f..dc040caab7d 100644
--- a/drivers/net/wireless/prism54/islpci_hotplug.c
+++ b/drivers/net/wireless/prism54/islpci_hotplug.c
@@ -267,8 +267,6 @@ prism54_suspend(struct pci_dev *pdev, pm_message_t state)
267 islpci_private *priv = ndev ? netdev_priv(ndev) : NULL; 267 islpci_private *priv = ndev ? netdev_priv(ndev) : NULL;
268 BUG_ON(!priv); 268 BUG_ON(!priv);
269 269
270 printk(KERN_NOTICE "%s: got suspend request (state %d)\n",
271 ndev->name, state);
272 270
273 pci_save_state(pdev); 271 pci_save_state(pdev);
274 272
diff --git a/drivers/net/wireless/ray_cs.c b/drivers/net/wireless/ray_cs.c
index 0e0ba614259..e9c5ea0f553 100644
--- a/drivers/net/wireless/ray_cs.c
+++ b/drivers/net/wireless/ray_cs.c
@@ -53,6 +53,7 @@
53#include <pcmcia/ds.h> 53#include <pcmcia/ds.h>
54#include <pcmcia/mem_op.h> 54#include <pcmcia/mem_op.h>
55 55
56#include <net/ieee80211.h>
56#include <linux/wireless.h> 57#include <linux/wireless.h>
57 58
58#include <asm/io.h> 59#include <asm/io.h>
@@ -64,7 +65,6 @@
64#define WIRELESS_SPY /* Enable spying addresses */ 65#define WIRELESS_SPY /* Enable spying addresses */
65/* Definitions we need for spy */ 66/* Definitions we need for spy */
66typedef struct iw_statistics iw_stats; 67typedef struct iw_statistics iw_stats;
67typedef struct iw_quality iw_qual;
68typedef u_char mac_addr[ETH_ALEN]; /* Hardware address */ 68typedef u_char mac_addr[ETH_ALEN]; /* Hardware address */
69 69
70#include "rayctl.h" 70#include "rayctl.h"
@@ -101,7 +101,6 @@ static int ray_dev_close(struct net_device *dev);
101static int ray_dev_config(struct net_device *dev, struct ifmap *map); 101static int ray_dev_config(struct net_device *dev, struct ifmap *map);
102static struct net_device_stats *ray_get_stats(struct net_device *dev); 102static struct net_device_stats *ray_get_stats(struct net_device *dev);
103static int ray_dev_init(struct net_device *dev); 103static int ray_dev_init(struct net_device *dev);
104static int ray_dev_ioctl(struct net_device *dev, struct ifreq *ifr, int cmd);
105 104
106static struct ethtool_ops netdev_ethtool_ops; 105static struct ethtool_ops netdev_ethtool_ops;
107 106
@@ -114,9 +113,8 @@ static int translate_frame(ray_dev_t *local, struct tx_msg __iomem *ptx,
114static void ray_build_header(ray_dev_t *local, struct tx_msg __iomem *ptx, UCHAR msg_type, 113static void ray_build_header(ray_dev_t *local, struct tx_msg __iomem *ptx, UCHAR msg_type,
115 unsigned char *data); 114 unsigned char *data);
116static void untranslate(ray_dev_t *local, struct sk_buff *skb, int len); 115static void untranslate(ray_dev_t *local, struct sk_buff *skb, int len);
117#if WIRELESS_EXT > 7 /* If wireless extension exist in the kernel */
118static iw_stats * ray_get_wireless_stats(struct net_device * dev); 116static iw_stats * ray_get_wireless_stats(struct net_device * dev);
119#endif /* WIRELESS_EXT > 7 */ 117static const struct iw_handler_def ray_handler_def;
120 118
121/***** Prototypes for raylink functions **************************************/ 119/***** Prototypes for raylink functions **************************************/
122static int asc_to_int(char a); 120static int asc_to_int(char a);
@@ -373,11 +371,12 @@ static dev_link_t *ray_attach(void)
373 dev->hard_start_xmit = &ray_dev_start_xmit; 371 dev->hard_start_xmit = &ray_dev_start_xmit;
374 dev->set_config = &ray_dev_config; 372 dev->set_config = &ray_dev_config;
375 dev->get_stats = &ray_get_stats; 373 dev->get_stats = &ray_get_stats;
376 dev->do_ioctl = &ray_dev_ioctl;
377 SET_ETHTOOL_OPS(dev, &netdev_ethtool_ops); 374 SET_ETHTOOL_OPS(dev, &netdev_ethtool_ops);
378#if WIRELESS_EXT > 7 /* If wireless extension exist in the kernel */ 375 dev->wireless_handlers = &ray_handler_def;
379 dev->get_wireless_stats = ray_get_wireless_stats; 376#ifdef WIRELESS_SPY
380#endif 377 local->wireless_data.spy_data = &local->spy_data;
378 dev->wireless_data = &local->wireless_data;
379#endif /* WIRELESS_SPY */
381 380
382 dev->set_multicast_list = &set_multicast_list; 381 dev->set_multicast_list = &set_multicast_list;
383 382
@@ -1201,436 +1200,420 @@ static struct ethtool_ops netdev_ethtool_ops = {
1201 1200
1202/*====================================================================*/ 1201/*====================================================================*/
1203 1202
1204static int ray_dev_ioctl(struct net_device *dev, struct ifreq *ifr, int cmd) 1203/*------------------------------------------------------------------*/
1204/*
1205 * Wireless Handler : get protocol name
1206 */
1207static int ray_get_name(struct net_device *dev,
1208 struct iw_request_info *info,
1209 char *cwrq,
1210 char *extra)
1205{ 1211{
1206 ray_dev_t *local = (ray_dev_t *)dev->priv; 1212 strcpy(cwrq, "IEEE 802.11-FH");
1207 dev_link_t *link = local->finder; 1213 return 0;
1208 int err = 0; 1214}
1209#if WIRELESS_EXT > 7
1210 struct iwreq *wrq = (struct iwreq *) ifr;
1211#endif /* WIRELESS_EXT > 7 */
1212#ifdef WIRELESS_SPY
1213 struct sockaddr address[IW_MAX_SPY];
1214#endif /* WIRELESS_SPY */
1215 1215
1216 if (!(link->state & DEV_PRESENT)) { 1216/*------------------------------------------------------------------*/
1217 DEBUG(2,"ray_dev_ioctl - device not present\n"); 1217/*
1218 return -1; 1218 * Wireless Handler : set frequency
1219 } 1219 */
1220 DEBUG(2,"ray_cs IOCTL dev=%p, ifr=%p, cmd = 0x%x\n",dev,ifr,cmd); 1220static int ray_set_freq(struct net_device *dev,
1221 /* Validate the command */ 1221 struct iw_request_info *info,
1222 switch (cmd) 1222 struct iw_freq *fwrq,
1223 { 1223 char *extra)
1224#if WIRELESS_EXT > 7 1224{
1225 /* --------------- WIRELESS EXTENSIONS --------------- */ 1225 ray_dev_t *local = (ray_dev_t *)dev->priv;
1226 /* Get name */ 1226 int err = -EINPROGRESS; /* Call commit handler */
1227 case SIOCGIWNAME:
1228 strcpy(wrq->u.name, "IEEE 802.11-FH");
1229 break;
1230
1231 /* Get frequency/channel */
1232 case SIOCGIWFREQ:
1233 wrq->u.freq.m = local->sparm.b5.a_hop_pattern;
1234 wrq->u.freq.e = 0;
1235 break;
1236
1237 /* Set frequency/channel */
1238 case SIOCSIWFREQ:
1239 /* Reject if card is already initialised */
1240 if(local->card_status != CARD_AWAITING_PARAM)
1241 {
1242 err = -EBUSY;
1243 break;
1244 }
1245 1227
1246 /* Setting by channel number */ 1228 /* Reject if card is already initialised */
1247 if ((wrq->u.freq.m > USA_HOP_MOD) || (wrq->u.freq.e > 0)) 1229 if(local->card_status != CARD_AWAITING_PARAM)
1248 err = -EOPNOTSUPP; 1230 return -EBUSY;
1249 else
1250 local->sparm.b5.a_hop_pattern = wrq->u.freq.m;
1251 break;
1252 1231
1253 /* Get current network name (ESSID) */ 1232 /* Setting by channel number */
1254 case SIOCGIWESSID: 1233 if ((fwrq->m > USA_HOP_MOD) || (fwrq->e > 0))
1255 if (wrq->u.data.pointer) 1234 err = -EOPNOTSUPP;
1256 { 1235 else
1257 char essid[IW_ESSID_MAX_SIZE + 1]; 1236 local->sparm.b5.a_hop_pattern = fwrq->m;
1258 /* Get the essid that was set */
1259 memcpy(essid, local->sparm.b5.a_current_ess_id,
1260 IW_ESSID_MAX_SIZE);
1261 essid[IW_ESSID_MAX_SIZE] = '\0';
1262
1263 /* Push it out ! */
1264 wrq->u.data.length = strlen(essid) + 1;
1265 wrq->u.data.flags = 1; /* active */
1266 if (copy_to_user(wrq->u.data.pointer, essid, sizeof(essid)))
1267 err = -EFAULT;
1268 }
1269 break;
1270 1237
1271 /* Set desired network name (ESSID) */ 1238 return err;
1272 case SIOCSIWESSID: 1239}
1273 /* Reject if card is already initialised */ 1240
1274 if(local->card_status != CARD_AWAITING_PARAM) 1241/*------------------------------------------------------------------*/
1275 { 1242/*
1276 err = -EBUSY; 1243 * Wireless Handler : get frequency
1277 break; 1244 */
1278 } 1245static int ray_get_freq(struct net_device *dev,
1246 struct iw_request_info *info,
1247 struct iw_freq *fwrq,
1248 char *extra)
1249{
1250 ray_dev_t *local = (ray_dev_t *)dev->priv;
1279 1251
1280 if (wrq->u.data.pointer) 1252 fwrq->m = local->sparm.b5.a_hop_pattern;
1281 { 1253 fwrq->e = 0;
1282 char card_essid[IW_ESSID_MAX_SIZE + 1]; 1254 return 0;
1283 1255}
1284 /* Check if we asked for `any' */ 1256
1285 if(wrq->u.data.flags == 0) 1257/*------------------------------------------------------------------*/
1286 { 1258/*
1259 * Wireless Handler : set ESSID
1260 */
1261static int ray_set_essid(struct net_device *dev,
1262 struct iw_request_info *info,
1263 struct iw_point *dwrq,
1264 char *extra)
1265{
1266 ray_dev_t *local = (ray_dev_t *)dev->priv;
1267
1268 /* Reject if card is already initialised */
1269 if(local->card_status != CARD_AWAITING_PARAM)
1270 return -EBUSY;
1271
1272 /* Check if we asked for `any' */
1273 if(dwrq->flags == 0) {
1287 /* Corey : can you do that ? */ 1274 /* Corey : can you do that ? */
1288 err = -EOPNOTSUPP; 1275 return -EOPNOTSUPP;
1289 } 1276 } else {
1290 else
1291 {
1292 /* Check the size of the string */ 1277 /* Check the size of the string */
1293 if(wrq->u.data.length > 1278 if(dwrq->length > IW_ESSID_MAX_SIZE + 1) {
1294 IW_ESSID_MAX_SIZE + 1) 1279 return -E2BIG;
1295 {
1296 err = -E2BIG;
1297 break;
1298 }
1299 if (copy_from_user(card_essid,
1300 wrq->u.data.pointer,
1301 wrq->u.data.length)) {
1302 err = -EFAULT;
1303 break;
1304 } 1280 }
1305 card_essid[IW_ESSID_MAX_SIZE] = '\0';
1306 1281
1307 /* Set the ESSID in the card */ 1282 /* Set the ESSID in the card */
1308 memcpy(local->sparm.b5.a_current_ess_id, card_essid, 1283 memset(local->sparm.b5.a_current_ess_id, 0, IW_ESSID_MAX_SIZE);
1309 IW_ESSID_MAX_SIZE); 1284 memcpy(local->sparm.b5.a_current_ess_id, extra, dwrq->length);
1310 }
1311 } 1285 }
1312 break;
1313
1314 /* Get current Access Point (BSSID in our case) */
1315 case SIOCGIWAP:
1316 memcpy(wrq->u.ap_addr.sa_data, local->bss_id, ETH_ALEN);
1317 wrq->u.ap_addr.sa_family = ARPHRD_ETHER;
1318 break;
1319
1320 /* Get the current bit-rate */
1321 case SIOCGIWRATE:
1322 if(local->net_default_tx_rate == 3)
1323 wrq->u.bitrate.value = 2000000; /* Hum... */
1324 else
1325 wrq->u.bitrate.value = local->net_default_tx_rate * 500000;
1326 wrq->u.bitrate.fixed = 0; /* We are in auto mode */
1327 break;
1328
1329 /* Set the desired bit-rate */
1330 case SIOCSIWRATE:
1331 /* Check if rate is in range */
1332 if((wrq->u.bitrate.value != 1000000) &&
1333 (wrq->u.bitrate.value != 2000000))
1334 {
1335 err = -EINVAL;
1336 break;
1337 }
1338 /* Hack for 1.5 Mb/s instead of 2 Mb/s */
1339 if((local->fw_ver == 0x55) && /* Please check */
1340 (wrq->u.bitrate.value == 2000000))
1341 local->net_default_tx_rate = 3;
1342 else
1343 local->net_default_tx_rate = wrq->u.bitrate.value/500000;
1344 break;
1345
1346 /* Get the current RTS threshold */
1347 case SIOCGIWRTS:
1348 wrq->u.rts.value = (local->sparm.b5.a_rts_threshold[0] << 8)
1349 + local->sparm.b5.a_rts_threshold[1];
1350#if WIRELESS_EXT > 8
1351 wrq->u.rts.disabled = (wrq->u.rts.value == 32767);
1352#endif /* WIRELESS_EXT > 8 */
1353 wrq->u.rts.fixed = 1;
1354 break;
1355
1356 /* Set the desired RTS threshold */
1357 case SIOCSIWRTS:
1358 {
1359 int rthr = wrq->u.rts.value;
1360 1286
1361 /* Reject if card is already initialised */ 1287 return -EINPROGRESS; /* Call commit handler */
1362 if(local->card_status != CARD_AWAITING_PARAM) 1288}
1363 {
1364 err = -EBUSY;
1365 break;
1366 }
1367 1289
1368 /* if(wrq->u.rts.fixed == 0) we should complain */ 1290/*------------------------------------------------------------------*/
1369#if WIRELESS_EXT > 8 1291/*
1370 if(wrq->u.rts.disabled) 1292 * Wireless Handler : get ESSID
1371 rthr = 32767; 1293 */
1294static int ray_get_essid(struct net_device *dev,
1295 struct iw_request_info *info,
1296 struct iw_point *dwrq,
1297 char *extra)
1298{
1299 ray_dev_t *local = (ray_dev_t *)dev->priv;
1300
1301 /* Get the essid that was set */
1302 memcpy(extra, local->sparm.b5.a_current_ess_id, IW_ESSID_MAX_SIZE);
1303 extra[IW_ESSID_MAX_SIZE] = '\0';
1304
1305 /* Push it out ! */
1306 dwrq->length = strlen(extra) + 1;
1307 dwrq->flags = 1; /* active */
1308
1309 return 0;
1310}
1311
1312/*------------------------------------------------------------------*/
1313/*
1314 * Wireless Handler : get AP address
1315 */
1316static int ray_get_wap(struct net_device *dev,
1317 struct iw_request_info *info,
1318 struct sockaddr *awrq,
1319 char *extra)
1320{
1321 ray_dev_t *local = (ray_dev_t *)dev->priv;
1322
1323 memcpy(awrq->sa_data, local->bss_id, ETH_ALEN);
1324 awrq->sa_family = ARPHRD_ETHER;
1325
1326 return 0;
1327}
1328
1329/*------------------------------------------------------------------*/
1330/*
1331 * Wireless Handler : set Bit-Rate
1332 */
1333static int ray_set_rate(struct net_device *dev,
1334 struct iw_request_info *info,
1335 struct iw_param *vwrq,
1336 char *extra)
1337{
1338 ray_dev_t *local = (ray_dev_t *)dev->priv;
1339
1340 /* Reject if card is already initialised */
1341 if(local->card_status != CARD_AWAITING_PARAM)
1342 return -EBUSY;
1343
1344 /* Check if rate is in range */
1345 if((vwrq->value != 1000000) && (vwrq->value != 2000000))
1346 return -EINVAL;
1347
1348 /* Hack for 1.5 Mb/s instead of 2 Mb/s */
1349 if((local->fw_ver == 0x55) && /* Please check */
1350 (vwrq->value == 2000000))
1351 local->net_default_tx_rate = 3;
1372 else 1352 else
1373#endif /* WIRELESS_EXT > 8 */ 1353 local->net_default_tx_rate = vwrq->value/500000;
1374 if((rthr < 0) || (rthr > 2347)) /* What's the max packet size ??? */ 1354
1375 { 1355 return 0;
1376 err = -EINVAL; 1356}
1377 break; 1357
1378 } 1358/*------------------------------------------------------------------*/
1359/*
1360 * Wireless Handler : get Bit-Rate
1361 */
1362static int ray_get_rate(struct net_device *dev,
1363 struct iw_request_info *info,
1364 struct iw_param *vwrq,
1365 char *extra)
1366{
1367 ray_dev_t *local = (ray_dev_t *)dev->priv;
1368
1369 if(local->net_default_tx_rate == 3)
1370 vwrq->value = 2000000; /* Hum... */
1371 else
1372 vwrq->value = local->net_default_tx_rate * 500000;
1373 vwrq->fixed = 0; /* We are in auto mode */
1374
1375 return 0;
1376}
1377
1378/*------------------------------------------------------------------*/
1379/*
1380 * Wireless Handler : set RTS threshold
1381 */
1382static int ray_set_rts(struct net_device *dev,
1383 struct iw_request_info *info,
1384 struct iw_param *vwrq,
1385 char *extra)
1386{
1387 ray_dev_t *local = (ray_dev_t *)dev->priv;
1388 int rthr = vwrq->value;
1389
1390 /* Reject if card is already initialised */
1391 if(local->card_status != CARD_AWAITING_PARAM)
1392 return -EBUSY;
1393
1394 /* if(wrq->u.rts.fixed == 0) we should complain */
1395 if(vwrq->disabled)
1396 rthr = 32767;
1397 else {
1398 if((rthr < 0) || (rthr > 2347)) /* What's the max packet size ??? */
1399 return -EINVAL;
1400 }
1379 local->sparm.b5.a_rts_threshold[0] = (rthr >> 8) & 0xFF; 1401 local->sparm.b5.a_rts_threshold[0] = (rthr >> 8) & 0xFF;
1380 local->sparm.b5.a_rts_threshold[1] = rthr & 0xFF; 1402 local->sparm.b5.a_rts_threshold[1] = rthr & 0xFF;
1381 }
1382 break;
1383 1403
1384 /* Get the current fragmentation threshold */ 1404 return -EINPROGRESS; /* Call commit handler */
1385 case SIOCGIWFRAG: 1405}
1386 wrq->u.frag.value = (local->sparm.b5.a_frag_threshold[0] << 8)
1387 + local->sparm.b5.a_frag_threshold[1];
1388#if WIRELESS_EXT > 8
1389 wrq->u.frag.disabled = (wrq->u.frag.value == 32767);
1390#endif /* WIRELESS_EXT > 8 */
1391 wrq->u.frag.fixed = 1;
1392 break;
1393 1406
1394 /* Set the desired fragmentation threshold */
1395 case SIOCSIWFRAG:
1396 {
1397 int fthr = wrq->u.frag.value;
1398 1407
1399 /* Reject if card is already initialised */ 1408/*------------------------------------------------------------------*/
1400 if(local->card_status != CARD_AWAITING_PARAM) 1409/*
1401 { 1410 * Wireless Handler : get RTS threshold
1402 err = -EBUSY; 1411 */
1403 break; 1412static int ray_get_rts(struct net_device *dev,
1404 } 1413 struct iw_request_info *info,
1414 struct iw_param *vwrq,
1415 char *extra)
1416{
1417 ray_dev_t *local = (ray_dev_t *)dev->priv;
1418
1419 vwrq->value = (local->sparm.b5.a_rts_threshold[0] << 8)
1420 + local->sparm.b5.a_rts_threshold[1];
1421 vwrq->disabled = (vwrq->value == 32767);
1422 vwrq->fixed = 1;
1423
1424 return 0;
1425}
1426
1427/*------------------------------------------------------------------*/
1428/*
1429 * Wireless Handler : set Fragmentation threshold
1430 */
1431static int ray_set_frag(struct net_device *dev,
1432 struct iw_request_info *info,
1433 struct iw_param *vwrq,
1434 char *extra)
1435{
1436 ray_dev_t *local = (ray_dev_t *)dev->priv;
1437 int fthr = vwrq->value;
1438
1439 /* Reject if card is already initialised */
1440 if(local->card_status != CARD_AWAITING_PARAM)
1441 return -EBUSY;
1405 1442
1406 /* if(wrq->u.frag.fixed == 0) should complain */ 1443 /* if(wrq->u.frag.fixed == 0) should complain */
1407#if WIRELESS_EXT > 8 1444 if(vwrq->disabled)
1408 if(wrq->u.frag.disabled) 1445 fthr = 32767;
1409 fthr = 32767; 1446 else {
1410 else 1447 if((fthr < 256) || (fthr > 2347)) /* To check out ! */
1411#endif /* WIRELESS_EXT > 8 */ 1448 return -EINVAL;
1412 if((fthr < 256) || (fthr > 2347)) /* To check out ! */ 1449 }
1413 {
1414 err = -EINVAL;
1415 break;
1416 }
1417 local->sparm.b5.a_frag_threshold[0] = (fthr >> 8) & 0xFF; 1450 local->sparm.b5.a_frag_threshold[0] = (fthr >> 8) & 0xFF;
1418 local->sparm.b5.a_frag_threshold[1] = fthr & 0xFF; 1451 local->sparm.b5.a_frag_threshold[1] = fthr & 0xFF;
1419 }
1420 break;
1421 1452
1422#endif /* WIRELESS_EXT > 7 */ 1453 return -EINPROGRESS; /* Call commit handler */
1423#if WIRELESS_EXT > 8 1454}
1424 1455
1425 /* Get the current mode of operation */ 1456/*------------------------------------------------------------------*/
1426 case SIOCGIWMODE: 1457/*
1427 if(local->sparm.b5.a_network_type) 1458 * Wireless Handler : get Fragmentation threshold
1428 wrq->u.mode = IW_MODE_INFRA; 1459 */
1429 else 1460static int ray_get_frag(struct net_device *dev,
1430 wrq->u.mode = IW_MODE_ADHOC; 1461 struct iw_request_info *info,
1431 break; 1462 struct iw_param *vwrq,
1463 char *extra)
1464{
1465 ray_dev_t *local = (ray_dev_t *)dev->priv;
1432 1466
1433 /* Set the current mode of operation */ 1467 vwrq->value = (local->sparm.b5.a_frag_threshold[0] << 8)
1434 case SIOCSIWMODE: 1468 + local->sparm.b5.a_frag_threshold[1];
1435 { 1469 vwrq->disabled = (vwrq->value == 32767);
1470 vwrq->fixed = 1;
1471
1472 return 0;
1473}
1474
1475/*------------------------------------------------------------------*/
1476/*
1477 * Wireless Handler : set Mode of Operation
1478 */
1479static int ray_set_mode(struct net_device *dev,
1480 struct iw_request_info *info,
1481 __u32 *uwrq,
1482 char *extra)
1483{
1484 ray_dev_t *local = (ray_dev_t *)dev->priv;
1485 int err = -EINPROGRESS; /* Call commit handler */
1436 char card_mode = 1; 1486 char card_mode = 1;
1437
1438 /* Reject if card is already initialised */
1439 if(local->card_status != CARD_AWAITING_PARAM)
1440 {
1441 err = -EBUSY;
1442 break;
1443 }
1444 1487
1445 switch (wrq->u.mode) 1488 /* Reject if card is already initialised */
1489 if(local->card_status != CARD_AWAITING_PARAM)
1490 return -EBUSY;
1491
1492 switch (*uwrq)
1446 { 1493 {
1447 case IW_MODE_ADHOC: 1494 case IW_MODE_ADHOC:
1448 card_mode = 0; 1495 card_mode = 0;
1449 // Fall through 1496 // Fall through
1450 case IW_MODE_INFRA: 1497 case IW_MODE_INFRA:
1451 local->sparm.b5.a_network_type = card_mode; 1498 local->sparm.b5.a_network_type = card_mode;
1452 break; 1499 break;
1453 default: 1500 default:
1454 err = -EINVAL; 1501 err = -EINVAL;
1455 } 1502 }
1456 }
1457 break;
1458 1503
1459#endif /* WIRELESS_EXT > 8 */ 1504 return err;
1460#if WIRELESS_EXT > 7 1505}
1461 /* ------------------ IWSPY SUPPORT ------------------ */
1462 /* Define the range (variations) of above parameters */
1463 case SIOCGIWRANGE:
1464 /* Basic checking... */
1465 if(wrq->u.data.pointer != (caddr_t) 0)
1466 {
1467 struct iw_range range;
1468 memset((char *) &range, 0, sizeof(struct iw_range));
1469
1470 /* Set the length (very important for backward compatibility) */
1471 wrq->u.data.length = sizeof(struct iw_range);
1472
1473#if WIRELESS_EXT > 10
1474 /* Set the Wireless Extension versions */
1475 range.we_version_compiled = WIRELESS_EXT;
1476 range.we_version_source = 9;
1477#endif /* WIRELESS_EXT > 10 */
1478
1479 /* Set information in the range struct */
1480 range.throughput = 1.1 * 1000 * 1000; /* Put the right number here */
1481 range.num_channels = hop_pattern_length[(int)country];
1482 range.num_frequency = 0;
1483 range.max_qual.qual = 0;
1484 range.max_qual.level = 255; /* What's the correct value ? */
1485 range.max_qual.noise = 255; /* Idem */
1486 range.num_bitrates = 2;
1487 range.bitrate[0] = 1000000; /* 1 Mb/s */
1488 range.bitrate[1] = 2000000; /* 2 Mb/s */
1489
1490 /* Copy structure to the user buffer */
1491 if(copy_to_user(wrq->u.data.pointer, &range,
1492 sizeof(struct iw_range)))
1493 err = -EFAULT;
1494 }
1495 break;
1496 1506
1497#ifdef WIRELESS_SPY 1507/*------------------------------------------------------------------*/
1498 /* Set addresses to spy */ 1508/*
1499 case SIOCSIWSPY: 1509 * Wireless Handler : get Mode of Operation
1500 /* Check the number of addresses */ 1510 */
1501 if(wrq->u.data.length > IW_MAX_SPY) 1511static int ray_get_mode(struct net_device *dev,
1502 { 1512 struct iw_request_info *info,
1503 err = -E2BIG; 1513 __u32 *uwrq,
1504 break; 1514 char *extra)
1505 } 1515{
1506 local->spy_number = wrq->u.data.length; 1516 ray_dev_t *local = (ray_dev_t *)dev->priv;
1507 1517
1508 /* If there is some addresses to copy */ 1518 if(local->sparm.b5.a_network_type)
1509 if(local->spy_number > 0) 1519 *uwrq = IW_MODE_INFRA;
1510 { 1520 else
1511 int i; 1521 *uwrq = IW_MODE_ADHOC;
1512
1513 /* Copy addresses to the driver */
1514 if(copy_from_user(address, wrq->u.data.pointer,
1515 sizeof(struct sockaddr) * local->spy_number))
1516 {
1517 err = -EFAULT;
1518 break;
1519 }
1520
1521 /* Copy addresses to the lp structure */
1522 for(i = 0; i < local->spy_number; i++)
1523 memcpy(local->spy_address[i], address[i].sa_data, ETH_ALEN);
1524
1525 /* Reset structure... */
1526 memset(local->spy_stat, 0x00, sizeof(iw_qual) * IW_MAX_SPY);
1527
1528#ifdef DEBUG_IOCTL_INFO
1529 printk(KERN_DEBUG "SetSpy - Set of new addresses is :\n");
1530 for(i = 0; i < local->spy_number; i++)
1531 printk(KERN_DEBUG "%02X:%02X:%02X:%02X:%02X:%02X\n",
1532 local->spy_address[i][0],
1533 local->spy_address[i][1],
1534 local->spy_address[i][2],
1535 local->spy_address[i][3],
1536 local->spy_address[i][4],
1537 local->spy_address[i][5]);
1538#endif /* DEBUG_IOCTL_INFO */
1539 }
1540 break;
1541 1522
1542 /* Get the spy list and spy stats */ 1523 return 0;
1543 case SIOCGIWSPY: 1524}
1544 /* Set the number of addresses */
1545 wrq->u.data.length = local->spy_number;
1546 1525
1547 /* If the user want to have the addresses back... */ 1526/*------------------------------------------------------------------*/
1548 if((local->spy_number > 0) && (wrq->u.data.pointer != (caddr_t) 0)) 1527/*
1549 { 1528 * Wireless Handler : get range info
1550 int i; 1529 */
1551 1530static int ray_get_range(struct net_device *dev,
1552 /* Copy addresses from the lp structure */ 1531 struct iw_request_info *info,
1553 for(i = 0; i < local->spy_number; i++) 1532 struct iw_point *dwrq,
1554 { 1533 char *extra)
1555 memcpy(address[i].sa_data, local->spy_address[i], ETH_ALEN); 1534{
1556 address[i].sa_family = ARPHRD_ETHER; 1535 struct iw_range *range = (struct iw_range *) extra;
1557 } 1536
1558 1537 memset((char *) range, 0, sizeof(struct iw_range));
1559 /* Copy addresses to the user buffer */ 1538
1560 if(copy_to_user(wrq->u.data.pointer, address, 1539 /* Set the length (very important for backward compatibility) */
1561 sizeof(struct sockaddr) * local->spy_number)) 1540 dwrq->length = sizeof(struct iw_range);
1562 { 1541
1563 err = -EFAULT; 1542 /* Set the Wireless Extension versions */
1564 break; 1543 range->we_version_compiled = WIRELESS_EXT;
1565 } 1544 range->we_version_source = 9;
1566 1545
1567 /* Copy stats to the user buffer (just after) */ 1546 /* Set information in the range struct */
1568 if(copy_to_user(wrq->u.data.pointer + 1547 range->throughput = 1.1 * 1000 * 1000; /* Put the right number here */
1569 (sizeof(struct sockaddr) * local->spy_number), 1548 range->num_channels = hop_pattern_length[(int)country];
1570 local->spy_stat, sizeof(iw_qual) * local->spy_number)) 1549 range->num_frequency = 0;
1571 { 1550 range->max_qual.qual = 0;
1572 err = -EFAULT; 1551 range->max_qual.level = 255; /* What's the correct value ? */
1573 break; 1552 range->max_qual.noise = 255; /* Idem */
1574 } 1553 range->num_bitrates = 2;
1575 1554 range->bitrate[0] = 1000000; /* 1 Mb/s */
1576 /* Reset updated flags */ 1555 range->bitrate[1] = 2000000; /* 2 Mb/s */
1577 for(i = 0; i < local->spy_number; i++) 1556 return 0;
1578 local->spy_stat[i].updated = 0x0; 1557}
1579 } /* if(pointer != NULL) */
1580
1581 break;
1582#endif /* WIRELESS_SPY */
1583 1558
1584 /* ------------------ PRIVATE IOCTL ------------------ */ 1559/*------------------------------------------------------------------*/
1585#ifndef SIOCIWFIRSTPRIV 1560/*
1586#define SIOCIWFIRSTPRIV SIOCDEVPRIVATE 1561 * Wireless Private Handler : set framing mode
1587#endif /* SIOCIWFIRSTPRIV */ 1562 */
1588#define SIOCSIPFRAMING SIOCIWFIRSTPRIV /* Set framing mode */ 1563static int ray_set_framing(struct net_device *dev,
1589#define SIOCGIPFRAMING SIOCIWFIRSTPRIV + 1 /* Get framing mode */ 1564 struct iw_request_info *info,
1590#define SIOCGIPCOUNTRY SIOCIWFIRSTPRIV + 3 /* Get country code */ 1565 union iwreq_data *wrqu,
1591 case SIOCSIPFRAMING: 1566 char *extra)
1592 if(!capable(CAP_NET_ADMIN)) /* For private IOCTLs, we need to check permissions */ 1567{
1593 { 1568 translate = *(extra); /* Set framing mode */
1594 err = -EPERM;
1595 break;
1596 }
1597 translate = *(wrq->u.name); /* Set framing mode */
1598 break;
1599 case SIOCGIPFRAMING:
1600 *(wrq->u.name) = translate;
1601 break;
1602 case SIOCGIPCOUNTRY:
1603 *(wrq->u.name) = country;
1604 break;
1605 case SIOCGIWPRIV:
1606 /* Export our "private" intercace */
1607 if(wrq->u.data.pointer != (caddr_t) 0)
1608 {
1609 struct iw_priv_args priv[] =
1610 { /* cmd, set_args, get_args, name */
1611 { SIOCSIPFRAMING, IW_PRIV_TYPE_BYTE | IW_PRIV_SIZE_FIXED | 1, 0, "set_framing" },
1612 { SIOCGIPFRAMING, 0, IW_PRIV_TYPE_BYTE | IW_PRIV_SIZE_FIXED | 1, "get_framing" },
1613 { SIOCGIPCOUNTRY, 0, IW_PRIV_TYPE_BYTE | IW_PRIV_SIZE_FIXED | 1, "get_country" },
1614 };
1615 /* Set the number of ioctl available */
1616 wrq->u.data.length = 3;
1617 /* Copy structure to the user buffer */
1618 if(copy_to_user(wrq->u.data.pointer, (u_char *) priv,
1619 sizeof(priv)))
1620 err = -EFAULT;
1621 }
1622 break;
1623#endif /* WIRELESS_EXT > 7 */
1624 1569
1570 return 0;
1571}
1625 1572
1626 default: 1573/*------------------------------------------------------------------*/
1627 DEBUG(0,"ray_dev_ioctl cmd = 0x%x\n", cmd); 1574/*
1628 err = -EOPNOTSUPP; 1575 * Wireless Private Handler : get framing mode
1629 } 1576 */
1630 return err; 1577static int ray_get_framing(struct net_device *dev,
1631} /* end ray_dev_ioctl */ 1578 struct iw_request_info *info,
1632/*===========================================================================*/ 1579 union iwreq_data *wrqu,
1633#if WIRELESS_EXT > 7 /* If wireless extension exist in the kernel */ 1580 char *extra)
1581{
1582 *(extra) = translate;
1583
1584 return 0;
1585}
1586
1587/*------------------------------------------------------------------*/
1588/*
1589 * Wireless Private Handler : get country
1590 */
1591static int ray_get_country(struct net_device *dev,
1592 struct iw_request_info *info,
1593 union iwreq_data *wrqu,
1594 char *extra)
1595{
1596 *(extra) = country;
1597
1598 return 0;
1599}
1600
1601/*------------------------------------------------------------------*/
1602/*
1603 * Commit handler : called after a bunch of SET operations
1604 */
1605static int ray_commit(struct net_device *dev,
1606 struct iw_request_info *info, /* NULL */
1607 void *zwrq, /* NULL */
1608 char *extra) /* NULL */
1609{
1610 return 0;
1611}
1612
1613/*------------------------------------------------------------------*/
1614/*
1615 * Stats handler : return Wireless Stats
1616 */
1634static iw_stats * ray_get_wireless_stats(struct net_device * dev) 1617static iw_stats * ray_get_wireless_stats(struct net_device * dev)
1635{ 1618{
1636 ray_dev_t * local = (ray_dev_t *) dev->priv; 1619 ray_dev_t * local = (ray_dev_t *) dev->priv;
@@ -1642,13 +1625,13 @@ static iw_stats * ray_get_wireless_stats(struct net_device * dev)
1642 1625
1643 local->wstats.status = local->card_status; 1626 local->wstats.status = local->card_status;
1644#ifdef WIRELESS_SPY 1627#ifdef WIRELESS_SPY
1645 if((local->spy_number > 0) && (local->sparm.b5.a_network_type == 0)) 1628 if((local->spy_data.spy_number > 0) && (local->sparm.b5.a_network_type == 0))
1646 { 1629 {
1647 /* Get it from the first node in spy list */ 1630 /* Get it from the first node in spy list */
1648 local->wstats.qual.qual = local->spy_stat[0].qual; 1631 local->wstats.qual.qual = local->spy_data.spy_stat[0].qual;
1649 local->wstats.qual.level = local->spy_stat[0].level; 1632 local->wstats.qual.level = local->spy_data.spy_stat[0].level;
1650 local->wstats.qual.noise = local->spy_stat[0].noise; 1633 local->wstats.qual.noise = local->spy_data.spy_stat[0].noise;
1651 local->wstats.qual.updated = local->spy_stat[0].updated; 1634 local->wstats.qual.updated = local->spy_data.spy_stat[0].updated;
1652 } 1635 }
1653#endif /* WIRELESS_SPY */ 1636#endif /* WIRELESS_SPY */
1654 1637
@@ -1659,7 +1642,65 @@ static iw_stats * ray_get_wireless_stats(struct net_device * dev)
1659 1642
1660 return &local->wstats; 1643 return &local->wstats;
1661} /* end ray_get_wireless_stats */ 1644} /* end ray_get_wireless_stats */
1662#endif /* WIRELESS_EXT > 7 */ 1645
1646/*------------------------------------------------------------------*/
1647/*
1648 * Structures to export the Wireless Handlers
1649 */
1650
1651static const iw_handler ray_handler[] = {
1652 [SIOCSIWCOMMIT-SIOCIWFIRST] (iw_handler) ray_commit,
1653 [SIOCGIWNAME -SIOCIWFIRST] (iw_handler) ray_get_name,
1654 [SIOCSIWFREQ -SIOCIWFIRST] (iw_handler) ray_set_freq,
1655 [SIOCGIWFREQ -SIOCIWFIRST] (iw_handler) ray_get_freq,
1656 [SIOCSIWMODE -SIOCIWFIRST] (iw_handler) ray_set_mode,
1657 [SIOCGIWMODE -SIOCIWFIRST] (iw_handler) ray_get_mode,
1658 [SIOCGIWRANGE -SIOCIWFIRST] (iw_handler) ray_get_range,
1659#ifdef WIRELESS_SPY
1660 [SIOCSIWSPY -SIOCIWFIRST] (iw_handler) iw_handler_set_spy,
1661 [SIOCGIWSPY -SIOCIWFIRST] (iw_handler) iw_handler_get_spy,
1662 [SIOCSIWTHRSPY-SIOCIWFIRST] (iw_handler) iw_handler_set_thrspy,
1663 [SIOCGIWTHRSPY-SIOCIWFIRST] (iw_handler) iw_handler_get_thrspy,
1664#endif /* WIRELESS_SPY */
1665 [SIOCGIWAP -SIOCIWFIRST] (iw_handler) ray_get_wap,
1666 [SIOCSIWESSID -SIOCIWFIRST] (iw_handler) ray_set_essid,
1667 [SIOCGIWESSID -SIOCIWFIRST] (iw_handler) ray_get_essid,
1668 [SIOCSIWRATE -SIOCIWFIRST] (iw_handler) ray_set_rate,
1669 [SIOCGIWRATE -SIOCIWFIRST] (iw_handler) ray_get_rate,
1670 [SIOCSIWRTS -SIOCIWFIRST] (iw_handler) ray_set_rts,
1671 [SIOCGIWRTS -SIOCIWFIRST] (iw_handler) ray_get_rts,
1672 [SIOCSIWFRAG -SIOCIWFIRST] (iw_handler) ray_set_frag,
1673 [SIOCGIWFRAG -SIOCIWFIRST] (iw_handler) ray_get_frag,
1674};
1675
1676#define SIOCSIPFRAMING SIOCIWFIRSTPRIV /* Set framing mode */
1677#define SIOCGIPFRAMING SIOCIWFIRSTPRIV + 1 /* Get framing mode */
1678#define SIOCGIPCOUNTRY SIOCIWFIRSTPRIV + 3 /* Get country code */
1679
1680static const iw_handler ray_private_handler[] = {
1681 [0] (iw_handler) ray_set_framing,
1682 [1] (iw_handler) ray_get_framing,
1683 [3] (iw_handler) ray_get_country,
1684};
1685
1686static const struct iw_priv_args ray_private_args[] = {
1687/* cmd, set_args, get_args, name */
1688{ SIOCSIPFRAMING, IW_PRIV_TYPE_BYTE | IW_PRIV_SIZE_FIXED | 1, 0, "set_framing" },
1689{ SIOCGIPFRAMING, 0, IW_PRIV_TYPE_BYTE | IW_PRIV_SIZE_FIXED | 1, "get_framing" },
1690{ SIOCGIPCOUNTRY, 0, IW_PRIV_TYPE_BYTE | IW_PRIV_SIZE_FIXED | 1, "get_country" },
1691};
1692
1693static const struct iw_handler_def ray_handler_def =
1694{
1695 .num_standard = sizeof(ray_handler)/sizeof(iw_handler),
1696 .num_private = sizeof(ray_private_handler)/sizeof(iw_handler),
1697 .num_private_args = sizeof(ray_private_args)/sizeof(struct iw_priv_args),
1698 .standard = ray_handler,
1699 .private = ray_private_handler,
1700 .private_args = ray_private_args,
1701 .get_wireless_stats = ray_get_wireless_stats,
1702};
1703
1663/*===========================================================================*/ 1704/*===========================================================================*/
1664static int ray_open(struct net_device *dev) 1705static int ray_open(struct net_device *dev)
1665{ 1706{
@@ -2392,20 +2433,15 @@ static void rx_data(struct net_device *dev, struct rcs __iomem *prcs, unsigned i
2392 /*local->wstats.qual.noise = none ? */ 2433 /*local->wstats.qual.noise = none ? */
2393 local->wstats.qual.updated = 0x2; 2434 local->wstats.qual.updated = 0x2;
2394 } 2435 }
2395 /* Now, for the addresses in the spy list */ 2436 /* Now, update the spy stuff */
2396 { 2437 {
2397 int i; 2438 struct iw_quality wstats;
2398 /* Look all addresses */ 2439 wstats.level = siglev;
2399 for(i = 0; i < local->spy_number; i++) 2440 /* wstats.noise = none ? */
2400 /* If match */ 2441 /* wstats.qual = none ? */
2401 if(!memcmp(linksrcaddr, local->spy_address[i], ETH_ALEN)) 2442 wstats.updated = 0x2;
2402 { 2443 /* Update spy records */
2403 /* Update statistics */ 2444 wireless_spy_update(dev, linksrcaddr, &wstats);
2404 /*local->spy_stat[i].qual = none ? */
2405 local->spy_stat[i].level = siglev;
2406 /*local->spy_stat[i].noise = none ? */
2407 local->spy_stat[i].updated = 0x2;
2408 }
2409 } 2445 }
2410#endif /* WIRELESS_SPY */ 2446#endif /* WIRELESS_SPY */
2411} /* end rx_data */ 2447} /* end rx_data */
diff --git a/drivers/net/wireless/ray_cs.h b/drivers/net/wireless/ray_cs.h
index c77afa14fa8..42660fe64bf 100644
--- a/drivers/net/wireless/ray_cs.h
+++ b/drivers/net/wireless/ray_cs.h
@@ -63,13 +63,10 @@ typedef struct ray_dev_t {
63 UCHAR last_rsl; 63 UCHAR last_rsl;
64 int beacon_rxed; 64 int beacon_rxed;
65 struct beacon_rx last_bcn; 65 struct beacon_rx last_bcn;
66#ifdef WIRELESS_EXT
67 iw_stats wstats; /* Wireless specific stats */ 66 iw_stats wstats; /* Wireless specific stats */
68#endif
69#ifdef WIRELESS_SPY 67#ifdef WIRELESS_SPY
70 int spy_number; /* Number of addresses to spy */ 68 struct iw_spy_data spy_data;
71 mac_addr spy_address[IW_MAX_SPY + 1]; /* The addresses to spy */ 69 struct iw_public_data wireless_data;
72 iw_qual spy_stat[IW_MAX_SPY + 1]; /* Statistics gathered */
73#endif /* WIRELESS_SPY */ 70#endif /* WIRELESS_SPY */
74 71
75} ray_dev_t; 72} ray_dev_t;
diff --git a/drivers/net/wireless/spectrum_cs.c b/drivers/net/wireless/spectrum_cs.c
new file mode 100644
index 00000000000..39c6cdf7f3f
--- /dev/null
+++ b/drivers/net/wireless/spectrum_cs.c
@@ -0,0 +1,1120 @@
1/*
2 * Driver for 802.11b cards using RAM-loadable Symbol firmware, such as
3 * Symbol Wireless Networker LA4100, CompactFlash cards by Socket
4 * Communications and Intel PRO/Wireless 2011B.
5 *
6 * The driver implements Symbol firmware download. The rest is handled
7 * in hermes.c and orinoco.c.
8 *
9 * Utilities for downloading the Symbol firmware are available at
10 * http://sourceforge.net/projects/orinoco/
11 *
12 * Copyright (C) 2002-2005 Pavel Roskin <proski@gnu.org>
13 * Portions based on orinoco_cs.c:
14 * Copyright (C) David Gibson, Linuxcare Australia
15 * Portions based on Spectrum24tDnld.c from original spectrum24 driver:
16 * Copyright (C) Symbol Technologies.
17 *
18 * See copyright notice in file orinoco.c.
19 */
20
21#define DRIVER_NAME "spectrum_cs"
22#define PFX DRIVER_NAME ": "
23
24#include <linux/config.h>
25#ifdef __IN_PCMCIA_PACKAGE__
26#include <pcmcia/k_compat.h>
27#endif /* __IN_PCMCIA_PACKAGE__ */
28
29#include <linux/module.h>
30#include <linux/kernel.h>
31#include <linux/init.h>
32#include <linux/sched.h>
33#include <linux/ptrace.h>
34#include <linux/slab.h>
35#include <linux/string.h>
36#include <linux/ioport.h>
37#include <linux/netdevice.h>
38#include <linux/if_arp.h>
39#include <linux/etherdevice.h>
40#include <linux/wireless.h>
41
42#include <pcmcia/cs_types.h>
43#include <pcmcia/cs.h>
44#include <pcmcia/cistpl.h>
45#include <pcmcia/cisreg.h>
46#include <pcmcia/ds.h>
47
48#include <asm/uaccess.h>
49#include <asm/io.h>
50#include <asm/system.h>
51
52#include "orinoco.h"
53
54/*
55 * If SPECTRUM_FW_INCLUDED is defined, the firmware is hardcoded into
56 * the driver. Use get_symbol_fw script to generate spectrum_fw.h and
57 * copy it to the same directory as spectrum_cs.c.
58 *
59 * If SPECTRUM_FW_INCLUDED is not defined, the firmware is loaded at the
60 * runtime using hotplug. Use the same get_symbol_fw script to generate
61 * files symbol_sp24t_prim_fw symbol_sp24t_sec_fw, copy them to the
62 * hotplug firmware directory (typically /usr/lib/hotplug/firmware) and
63 * make sure that you have hotplug installed and enabled in the kernel.
64 */
65/* #define SPECTRUM_FW_INCLUDED 1 */
66
67#ifdef SPECTRUM_FW_INCLUDED
68/* Header with the firmware */
69#include "spectrum_fw.h"
70#else /* !SPECTRUM_FW_INCLUDED */
71#include <linux/firmware.h>
72static unsigned char *primsym;
73static unsigned char *secsym;
74static const char primary_fw_name[] = "symbol_sp24t_prim_fw";
75static const char secondary_fw_name[] = "symbol_sp24t_sec_fw";
76#endif /* !SPECTRUM_FW_INCLUDED */
77
78/********************************************************************/
79/* Module stuff */
80/********************************************************************/
81
82MODULE_AUTHOR("Pavel Roskin <proski@gnu.org>");
83MODULE_DESCRIPTION("Driver for Symbol Spectrum24 Trilogy cards with firmware downloader");
84MODULE_LICENSE("Dual MPL/GPL");
85
86/* Module parameters */
87
88/* Some D-Link cards have buggy CIS. They do work at 5v properly, but
89 * don't have any CIS entry for it. This workaround it... */
90static int ignore_cis_vcc; /* = 0 */
91module_param(ignore_cis_vcc, int, 0);
92MODULE_PARM_DESC(ignore_cis_vcc, "Allow voltage mismatch between card and socket");
93
94/********************************************************************/
95/* Magic constants */
96/********************************************************************/
97
98/*
99 * The dev_info variable is the "key" that is used to match up this
100 * device driver with appropriate cards, through the card
101 * configuration database.
102 */
103static dev_info_t dev_info = DRIVER_NAME;
104
105/********************************************************************/
106/* Data structures */
107/********************************************************************/
108
109/* PCMCIA specific device information (goes in the card field of
110 * struct orinoco_private */
111struct orinoco_pccard {
112 dev_link_t link;
113 dev_node_t node;
114};
115
116/*
117 * A linked list of "instances" of the device. Each actual PCMCIA
118 * card corresponds to one device instance, and is described by one
119 * dev_link_t structure (defined in ds.h).
120 */
121static dev_link_t *dev_list; /* = NULL */
122
123/********************************************************************/
124/* Function prototypes */
125/********************************************************************/
126
127/* device methods */
128static int spectrum_cs_hard_reset(struct orinoco_private *priv);
129
130/* PCMCIA gumpf */
131static void spectrum_cs_config(dev_link_t * link);
132static void spectrum_cs_release(dev_link_t * link);
133static int spectrum_cs_event(event_t event, int priority,
134 event_callback_args_t * args);
135
136static dev_link_t *spectrum_cs_attach(void);
137static void spectrum_cs_detach(dev_link_t *);
138
139/********************************************************************/
140/* Firmware downloader */
141/********************************************************************/
142
143/* Position of PDA in the adapter memory */
144#define EEPROM_ADDR 0x3000
145#define EEPROM_LEN 0x200
146#define PDA_OFFSET 0x100
147
148#define PDA_ADDR (EEPROM_ADDR + PDA_OFFSET)
149#define PDA_WORDS ((EEPROM_LEN - PDA_OFFSET) / 2)
150
151/* Constants for the CISREG_CCSR register */
152#define HCR_RUN 0x07 /* run firmware after reset */
153#define HCR_IDLE 0x0E /* don't run firmware after reset */
154#define HCR_MEM16 0x10 /* memory width bit, should be preserved */
155
156/*
157 * AUX port access. To unlock the AUX port write the access keys to the
158 * PARAM0-2 registers, then write HERMES_AUX_ENABLE to the HERMES_CONTROL
159 * register. Then read it and make sure it's HERMES_AUX_ENABLED.
160 */
161#define HERMES_AUX_ENABLE 0x8000 /* Enable auxiliary port access */
162#define HERMES_AUX_DISABLE 0x4000 /* Disable to auxiliary port access */
163#define HERMES_AUX_ENABLED 0xC000 /* Auxiliary port is open */
164
165#define HERMES_AUX_PW0 0xFE01
166#define HERMES_AUX_PW1 0xDC23
167#define HERMES_AUX_PW2 0xBA45
168
169/* End markers */
170#define PDI_END 0x00000000 /* End of PDA */
171#define BLOCK_END 0xFFFFFFFF /* Last image block */
172#define TEXT_END 0x1A /* End of text header */
173
174/*
175 * The following structures have little-endian fields denoted by
176 * the leading underscore. Don't access them directly - use inline
177 * functions defined below.
178 */
179
180/*
181 * The binary image to be downloaded consists of series of data blocks.
182 * Each block has the following structure.
183 */
184struct dblock {
185 u32 _addr; /* adapter address where to write the block */
186 u16 _len; /* length of the data only, in bytes */
187 char data[0]; /* data to be written */
188} __attribute__ ((packed));
189
190/*
191 * Plug Data References are located in in the image after the last data
192 * block. They refer to areas in the adapter memory where the plug data
193 * items with matching ID should be written.
194 */
195struct pdr {
196 u32 _id; /* record ID */
197 u32 _addr; /* adapter address where to write the data */
198 u32 _len; /* expected length of the data, in bytes */
199 char next[0]; /* next PDR starts here */
200} __attribute__ ((packed));
201
202
203/*
204 * Plug Data Items are located in the EEPROM read from the adapter by
205 * primary firmware. They refer to the device-specific data that should
206 * be plugged into the secondary firmware.
207 */
208struct pdi {
209 u16 _len; /* length of ID and data, in words */
210 u16 _id; /* record ID */
211 char data[0]; /* plug data */
212} __attribute__ ((packed));;
213
214
215/* Functions for access to little-endian data */
216static inline u32
217dblock_addr(const struct dblock *blk)
218{
219 return le32_to_cpu(blk->_addr);
220}
221
222static inline u32
223dblock_len(const struct dblock *blk)
224{
225 return le16_to_cpu(blk->_len);
226}
227
228static inline u32
229pdr_id(const struct pdr *pdr)
230{
231 return le32_to_cpu(pdr->_id);
232}
233
234static inline u32
235pdr_addr(const struct pdr *pdr)
236{
237 return le32_to_cpu(pdr->_addr);
238}
239
240static inline u32
241pdr_len(const struct pdr *pdr)
242{
243 return le32_to_cpu(pdr->_len);
244}
245
246static inline u32
247pdi_id(const struct pdi *pdi)
248{
249 return le16_to_cpu(pdi->_id);
250}
251
252/* Return length of the data only, in bytes */
253static inline u32
254pdi_len(const struct pdi *pdi)
255{
256 return 2 * (le16_to_cpu(pdi->_len) - 1);
257}
258
259
260/* Set address of the auxiliary port */
261static inline void
262spectrum_aux_setaddr(hermes_t *hw, u32 addr)
263{
264 hermes_write_reg(hw, HERMES_AUXPAGE, (u16) (addr >> 7));
265 hermes_write_reg(hw, HERMES_AUXOFFSET, (u16) (addr & 0x7F));
266}
267
268
269/* Open access to the auxiliary port */
270static int
271spectrum_aux_open(hermes_t *hw)
272{
273 int i;
274
275 /* Already open? */
276 if (hermes_read_reg(hw, HERMES_CONTROL) == HERMES_AUX_ENABLED)
277 return 0;
278
279 hermes_write_reg(hw, HERMES_PARAM0, HERMES_AUX_PW0);
280 hermes_write_reg(hw, HERMES_PARAM1, HERMES_AUX_PW1);
281 hermes_write_reg(hw, HERMES_PARAM2, HERMES_AUX_PW2);
282 hermes_write_reg(hw, HERMES_CONTROL, HERMES_AUX_ENABLE);
283
284 for (i = 0; i < 20; i++) {
285 udelay(10);
286 if (hermes_read_reg(hw, HERMES_CONTROL) ==
287 HERMES_AUX_ENABLED)
288 return 0;
289 }
290
291 return -EBUSY;
292}
293
294
295#define CS_CHECK(fn, ret) \
296 do { last_fn = (fn); if ((last_ret = (ret)) != 0) goto cs_failed; } while (0)
297
298/*
299 * Reset the card using configuration registers COR and CCSR.
300 * If IDLE is 1, stop the firmware, so that it can be safely rewritten.
301 */
302static int
303spectrum_reset(dev_link_t *link, int idle)
304{
305 int last_ret, last_fn;
306 conf_reg_t reg;
307 u_int save_cor;
308
309 /* Doing it if hardware is gone is guaranteed crash */
310 if (!(link->state & DEV_CONFIG))
311 return -ENODEV;
312
313 /* Save original COR value */
314 reg.Function = 0;
315 reg.Action = CS_READ;
316 reg.Offset = CISREG_COR;
317 CS_CHECK(AccessConfigurationRegister,
318 pcmcia_access_configuration_register(link->handle, &reg));
319 save_cor = reg.Value;
320
321 /* Soft-Reset card */
322 reg.Action = CS_WRITE;
323 reg.Offset = CISREG_COR;
324 reg.Value = (save_cor | COR_SOFT_RESET);
325 CS_CHECK(AccessConfigurationRegister,
326 pcmcia_access_configuration_register(link->handle, &reg));
327 udelay(1000);
328
329 /* Read CCSR */
330 reg.Action = CS_READ;
331 reg.Offset = CISREG_CCSR;
332 CS_CHECK(AccessConfigurationRegister,
333 pcmcia_access_configuration_register(link->handle, &reg));
334
335 /*
336 * Start or stop the firmware. Memory width bit should be
337 * preserved from the value we've just read.
338 */
339 reg.Action = CS_WRITE;
340 reg.Offset = CISREG_CCSR;
341 reg.Value = (idle ? HCR_IDLE : HCR_RUN) | (reg.Value & HCR_MEM16);
342 CS_CHECK(AccessConfigurationRegister,
343 pcmcia_access_configuration_register(link->handle, &reg));
344 udelay(1000);
345
346 /* Restore original COR configuration index */
347 reg.Action = CS_WRITE;
348 reg.Offset = CISREG_COR;
349 reg.Value = (save_cor & ~COR_SOFT_RESET);
350 CS_CHECK(AccessConfigurationRegister,
351 pcmcia_access_configuration_register(link->handle, &reg));
352 udelay(1000);
353 return 0;
354
355 cs_failed:
356 cs_error(link->handle, last_fn, last_ret);
357 return -ENODEV;
358}
359
360
361/*
362 * Scan PDR for the record with the specified RECORD_ID.
363 * If it's not found, return NULL.
364 */
365static struct pdr *
366spectrum_find_pdr(struct pdr *first_pdr, u32 record_id)
367{
368 struct pdr *pdr = first_pdr;
369
370 while (pdr_id(pdr) != PDI_END) {
371 /*
372 * PDR area is currently not terminated by PDI_END.
373 * It's followed by CRC records, which have the type
374 * field where PDR has length. The type can be 0 or 1.
375 */
376 if (pdr_len(pdr) < 2)
377 return NULL;
378
379 /* If the record ID matches, we are done */
380 if (pdr_id(pdr) == record_id)
381 return pdr;
382
383 pdr = (struct pdr *) pdr->next;
384 }
385 return NULL;
386}
387
388
389/* Process one Plug Data Item - find corresponding PDR and plug it */
390static int
391spectrum_plug_pdi(hermes_t *hw, struct pdr *first_pdr, struct pdi *pdi)
392{
393 struct pdr *pdr;
394
395 /* Find the PDI corresponding to this PDR */
396 pdr = spectrum_find_pdr(first_pdr, pdi_id(pdi));
397
398 /* No match is found, safe to ignore */
399 if (!pdr)
400 return 0;
401
402 /* Lengths of the data in PDI and PDR must match */
403 if (pdi_len(pdi) != pdr_len(pdr))
404 return -EINVAL;
405
406 /* do the actual plugging */
407 spectrum_aux_setaddr(hw, pdr_addr(pdr));
408 hermes_write_words(hw, HERMES_AUXDATA, pdi->data,
409 pdi_len(pdi) / 2);
410
411 return 0;
412}
413
414
415/* Read PDA from the adapter */
416static int
417spectrum_read_pda(hermes_t *hw, u16 *pda, int pda_len)
418{
419 int ret;
420 int pda_size;
421
422 /* Issue command to read EEPROM */
423 ret = hermes_docmd_wait(hw, HERMES_CMD_READMIF, 0, NULL);
424 if (ret)
425 return ret;
426
427 /* Open auxiliary port */
428 ret = spectrum_aux_open(hw);
429 if (ret)
430 return ret;
431
432 /* read PDA from EEPROM */
433 spectrum_aux_setaddr(hw, PDA_ADDR);
434 hermes_read_words(hw, HERMES_AUXDATA, pda, pda_len / 2);
435
436 /* Check PDA length */
437 pda_size = le16_to_cpu(pda[0]);
438 if (pda_size > pda_len)
439 return -EINVAL;
440
441 return 0;
442}
443
444
445/* Parse PDA and write the records into the adapter */
446static int
447spectrum_apply_pda(hermes_t *hw, const struct dblock *first_block,
448 u16 *pda)
449{
450 int ret;
451 struct pdi *pdi;
452 struct pdr *first_pdr;
453 const struct dblock *blk = first_block;
454
455 /* Skip all blocks to locate Plug Data References */
456 while (dblock_addr(blk) != BLOCK_END)
457 blk = (struct dblock *) &blk->data[dblock_len(blk)];
458
459 first_pdr = (struct pdr *) blk;
460
461 /* Go through every PDI and plug them into the adapter */
462 pdi = (struct pdi *) (pda + 2);
463 while (pdi_id(pdi) != PDI_END) {
464 ret = spectrum_plug_pdi(hw, first_pdr, pdi);
465 if (ret)
466 return ret;
467
468 /* Increment to the next PDI */
469 pdi = (struct pdi *) &pdi->data[pdi_len(pdi)];
470 }
471 return 0;
472}
473
474
475/* Load firmware blocks into the adapter */
476static int
477spectrum_load_blocks(hermes_t *hw, const struct dblock *first_block)
478{
479 const struct dblock *blk;
480 u32 blkaddr;
481 u32 blklen;
482
483 blk = first_block;
484 blkaddr = dblock_addr(blk);
485 blklen = dblock_len(blk);
486
487 while (dblock_addr(blk) != BLOCK_END) {
488 spectrum_aux_setaddr(hw, blkaddr);
489 hermes_write_words(hw, HERMES_AUXDATA, blk->data,
490 blklen / 2);
491
492 blk = (struct dblock *) &blk->data[blklen];
493 blkaddr = dblock_addr(blk);
494 blklen = dblock_len(blk);
495 }
496 return 0;
497}
498
499
500/*
501 * Process a firmware image - stop the card, load the firmware, reset
502 * the card and make sure it responds. For the secondary firmware take
503 * care of the PDA - read it and then write it on top of the firmware.
504 */
505static int
506spectrum_dl_image(hermes_t *hw, dev_link_t *link,
507 const unsigned char *image)
508{
509 int ret;
510 const unsigned char *ptr;
511 const struct dblock *first_block;
512
513 /* Plug Data Area (PDA) */
514 u16 pda[PDA_WORDS];
515
516 /* Binary block begins after the 0x1A marker */
517 ptr = image;
518 while (*ptr++ != TEXT_END);
519 first_block = (const struct dblock *) ptr;
520
521 /* Read the PDA */
522 if (image != primsym) {
523 ret = spectrum_read_pda(hw, pda, sizeof(pda));
524 if (ret)
525 return ret;
526 }
527
528 /* Stop the firmware, so that it can be safely rewritten */
529 ret = spectrum_reset(link, 1);
530 if (ret)
531 return ret;
532
533 /* Program the adapter with new firmware */
534 ret = spectrum_load_blocks(hw, first_block);
535 if (ret)
536 return ret;
537
538 /* Write the PDA to the adapter */
539 if (image != primsym) {
540 ret = spectrum_apply_pda(hw, first_block, pda);
541 if (ret)
542 return ret;
543 }
544
545 /* Run the firmware */
546 ret = spectrum_reset(link, 0);
547 if (ret)
548 return ret;
549
550 /* Reset hermes chip and make sure it responds */
551 ret = hermes_init(hw);
552
553 /* hermes_reset() should return 0 with the secondary firmware */
554 if (image != primsym && ret != 0)
555 return -ENODEV;
556
557 /* And this should work with any firmware */
558 if (!hermes_present(hw))
559 return -ENODEV;
560
561 return 0;
562}
563
564
565/*
566 * Download the firmware into the card, this also does a PCMCIA soft
567 * reset on the card, to make sure it's in a sane state.
568 */
569static int
570spectrum_dl_firmware(hermes_t *hw, dev_link_t *link)
571{
572 int ret;
573 client_handle_t handle = link->handle;
574
575#ifndef SPECTRUM_FW_INCLUDED
576 const struct firmware *fw_entry;
577
578 if (request_firmware(&fw_entry, primary_fw_name,
579 &handle_to_dev(handle)) == 0) {
580 primsym = fw_entry->data;
581 } else {
582 printk(KERN_ERR PFX "Cannot find firmware: %s\n",
583 primary_fw_name);
584 return -ENOENT;
585 }
586
587 if (request_firmware(&fw_entry, secondary_fw_name,
588 &handle_to_dev(handle)) == 0) {
589 secsym = fw_entry->data;
590 } else {
591 printk(KERN_ERR PFX "Cannot find firmware: %s\n",
592 secondary_fw_name);
593 return -ENOENT;
594 }
595#endif
596
597 /* Load primary firmware */
598 ret = spectrum_dl_image(hw, link, primsym);
599 if (ret) {
600 printk(KERN_ERR PFX "Primary firmware download failed\n");
601 return ret;
602 }
603
604 /* Load secondary firmware */
605 ret = spectrum_dl_image(hw, link, secsym);
606
607 if (ret) {
608 printk(KERN_ERR PFX "Secondary firmware download failed\n");
609 }
610
611 return ret;
612}
613
614/********************************************************************/
615/* Device methods */
616/********************************************************************/
617
618static int
619spectrum_cs_hard_reset(struct orinoco_private *priv)
620{
621 struct orinoco_pccard *card = priv->card;
622 dev_link_t *link = &card->link;
623 int err;
624
625 if (!hermes_present(&priv->hw)) {
626 /* The firmware needs to be reloaded */
627 if (spectrum_dl_firmware(&priv->hw, &card->link) != 0) {
628 printk(KERN_ERR PFX "Firmware download failed\n");
629 err = -ENODEV;
630 }
631 } else {
632 /* Soft reset using COR and HCR */
633 spectrum_reset(link, 0);
634 }
635
636 return 0;
637}
638
639/********************************************************************/
640/* PCMCIA stuff */
641/********************************************************************/
642
643/*
644 * This creates an "instance" of the driver, allocating local data
645 * structures for one device. The device is registered with Card
646 * Services.
647 *
648 * The dev_link structure is initialized, but we don't actually
649 * configure the card at this point -- we wait until we receive a card
650 * insertion event. */
651static dev_link_t *
652spectrum_cs_attach(void)
653{
654 struct net_device *dev;
655 struct orinoco_private *priv;
656 struct orinoco_pccard *card;
657 dev_link_t *link;
658 client_reg_t client_reg;
659 int ret;
660
661 dev = alloc_orinocodev(sizeof(*card), spectrum_cs_hard_reset);
662 if (! dev)
663 return NULL;
664 priv = netdev_priv(dev);
665 card = priv->card;
666
667 /* Link both structures together */
668 link = &card->link;
669 link->priv = dev;
670
671 /* Interrupt setup */
672 link->irq.Attributes = IRQ_TYPE_EXCLUSIVE | IRQ_HANDLE_PRESENT;
673 link->irq.IRQInfo1 = IRQ_LEVEL_ID;
674 link->irq.Handler = orinoco_interrupt;
675 link->irq.Instance = dev;
676
677 /* General socket configuration defaults can go here. In this
678 * client, we assume very little, and rely on the CIS for
679 * almost everything. In most clients, many details (i.e.,
680 * number, sizes, and attributes of IO windows) are fixed by
681 * the nature of the device, and can be hard-wired here. */
682 link->conf.Attributes = 0;
683 link->conf.IntType = INT_MEMORY_AND_IO;
684
685 /* Register with Card Services */
686 /* FIXME: need a lock? */
687 link->next = dev_list;
688 dev_list = link;
689
690 client_reg.dev_info = &dev_info;
691 client_reg.Version = 0x0210; /* FIXME: what does this mean? */
692 client_reg.event_callback_args.client_data = link;
693
694 ret = pcmcia_register_client(&link->handle, &client_reg);
695 if (ret != CS_SUCCESS) {
696 cs_error(link->handle, RegisterClient, ret);
697 spectrum_cs_detach(link);
698 return NULL;
699 }
700
701 return link;
702} /* spectrum_cs_attach */
703
704/*
705 * This deletes a driver "instance". The device is de-registered with
706 * Card Services. If it has been released, all local data structures
707 * are freed. Otherwise, the structures will be freed when the device
708 * is released.
709 */
710static void spectrum_cs_detach(dev_link_t *link)
711{
712 dev_link_t **linkp;
713 struct net_device *dev = link->priv;
714
715 /* Locate device structure */
716 for (linkp = &dev_list; *linkp; linkp = &(*linkp)->next)
717 if (*linkp == link)
718 break;
719
720 BUG_ON(*linkp == NULL);
721
722 if (link->state & DEV_CONFIG)
723 spectrum_cs_release(link);
724
725 /* Break the link with Card Services */
726 if (link->handle)
727 pcmcia_deregister_client(link->handle);
728
729 /* Unlink device structure, and free it */
730 *linkp = link->next;
731 DEBUG(0, PFX "detach: link=%p link->dev=%p\n", link, link->dev);
732 if (link->dev) {
733 DEBUG(0, PFX "About to unregister net device %p\n",
734 dev);
735 unregister_netdev(dev);
736 }
737 free_orinocodev(dev);
738} /* spectrum_cs_detach */
739
740/*
741 * spectrum_cs_config() is scheduled to run after a CARD_INSERTION
742 * event is received, to configure the PCMCIA socket, and to make the
743 * device available to the system.
744 */
745
746static void
747spectrum_cs_config(dev_link_t *link)
748{
749 struct net_device *dev = link->priv;
750 client_handle_t handle = link->handle;
751 struct orinoco_private *priv = netdev_priv(dev);
752 struct orinoco_pccard *card = priv->card;
753 hermes_t *hw = &priv->hw;
754 int last_fn, last_ret;
755 u_char buf[64];
756 config_info_t conf;
757 cisinfo_t info;
758 tuple_t tuple;
759 cisparse_t parse;
760 void __iomem *mem;
761
762 CS_CHECK(ValidateCIS, pcmcia_validate_cis(handle, &info));
763
764 /*
765 * This reads the card's CONFIG tuple to find its
766 * configuration registers.
767 */
768 tuple.DesiredTuple = CISTPL_CONFIG;
769 tuple.Attributes = 0;
770 tuple.TupleData = buf;
771 tuple.TupleDataMax = sizeof(buf);
772 tuple.TupleOffset = 0;
773 CS_CHECK(GetFirstTuple, pcmcia_get_first_tuple(handle, &tuple));
774 CS_CHECK(GetTupleData, pcmcia_get_tuple_data(handle, &tuple));
775 CS_CHECK(ParseTuple, pcmcia_parse_tuple(handle, &tuple, &parse));
776 link->conf.ConfigBase = parse.config.base;
777 link->conf.Present = parse.config.rmask[0];
778
779 /* Configure card */
780 link->state |= DEV_CONFIG;
781
782 /* Look up the current Vcc */
783 CS_CHECK(GetConfigurationInfo,
784 pcmcia_get_configuration_info(handle, &conf));
785 link->conf.Vcc = conf.Vcc;
786
787 /*
788 * In this loop, we scan the CIS for configuration table
789 * entries, each of which describes a valid card
790 * configuration, including voltage, IO window, memory window,
791 * and interrupt settings.
792 *
793 * We make no assumptions about the card to be configured: we
794 * use just the information available in the CIS. In an ideal
795 * world, this would work for any PCMCIA card, but it requires
796 * a complete and accurate CIS. In practice, a driver usually
797 * "knows" most of these things without consulting the CIS,
798 * and most client drivers will only use the CIS to fill in
799 * implementation-defined details.
800 */
801 tuple.DesiredTuple = CISTPL_CFTABLE_ENTRY;
802 CS_CHECK(GetFirstTuple, pcmcia_get_first_tuple(handle, &tuple));
803 while (1) {
804 cistpl_cftable_entry_t *cfg = &(parse.cftable_entry);
805 cistpl_cftable_entry_t dflt = { .index = 0 };
806
807 if ( (pcmcia_get_tuple_data(handle, &tuple) != 0)
808 || (pcmcia_parse_tuple(handle, &tuple, &parse) != 0))
809 goto next_entry;
810
811 if (cfg->flags & CISTPL_CFTABLE_DEFAULT)
812 dflt = *cfg;
813 if (cfg->index == 0)
814 goto next_entry;
815 link->conf.ConfigIndex = cfg->index;
816
817 /* Does this card need audio output? */
818 if (cfg->flags & CISTPL_CFTABLE_AUDIO) {
819 link->conf.Attributes |= CONF_ENABLE_SPKR;
820 link->conf.Status = CCSR_AUDIO_ENA;
821 }
822
823 /* Use power settings for Vcc and Vpp if present */
824 /* Note that the CIS values need to be rescaled */
825 if (cfg->vcc.present & (1 << CISTPL_POWER_VNOM)) {
826 if (conf.Vcc != cfg->vcc.param[CISTPL_POWER_VNOM] / 10000) {
827 DEBUG(2, "spectrum_cs_config: Vcc mismatch (conf.Vcc = %d, CIS = %d)\n", conf.Vcc, cfg->vcc.param[CISTPL_POWER_VNOM] / 10000);
828 if (!ignore_cis_vcc)
829 goto next_entry;
830 }
831 } else if (dflt.vcc.present & (1 << CISTPL_POWER_VNOM)) {
832 if (conf.Vcc != dflt.vcc.param[CISTPL_POWER_VNOM] / 10000) {
833 DEBUG(2, "spectrum_cs_config: Vcc mismatch (conf.Vcc = %d, CIS = %d)\n", conf.Vcc, dflt.vcc.param[CISTPL_POWER_VNOM] / 10000);
834 if(!ignore_cis_vcc)
835 goto next_entry;
836 }
837 }
838
839 if (cfg->vpp1.present & (1 << CISTPL_POWER_VNOM))
840 link->conf.Vpp1 = link->conf.Vpp2 =
841 cfg->vpp1.param[CISTPL_POWER_VNOM] / 10000;
842 else if (dflt.vpp1.present & (1 << CISTPL_POWER_VNOM))
843 link->conf.Vpp1 = link->conf.Vpp2 =
844 dflt.vpp1.param[CISTPL_POWER_VNOM] / 10000;
845
846 /* Do we need to allocate an interrupt? */
847 link->conf.Attributes |= CONF_ENABLE_IRQ;
848
849 /* IO window settings */
850 link->io.NumPorts1 = link->io.NumPorts2 = 0;
851 if ((cfg->io.nwin > 0) || (dflt.io.nwin > 0)) {
852 cistpl_io_t *io =
853 (cfg->io.nwin) ? &cfg->io : &dflt.io;
854 link->io.Attributes1 = IO_DATA_PATH_WIDTH_AUTO;
855 if (!(io->flags & CISTPL_IO_8BIT))
856 link->io.Attributes1 =
857 IO_DATA_PATH_WIDTH_16;
858 if (!(io->flags & CISTPL_IO_16BIT))
859 link->io.Attributes1 =
860 IO_DATA_PATH_WIDTH_8;
861 link->io.IOAddrLines =
862 io->flags & CISTPL_IO_LINES_MASK;
863 link->io.BasePort1 = io->win[0].base;
864 link->io.NumPorts1 = io->win[0].len;
865 if (io->nwin > 1) {
866 link->io.Attributes2 =
867 link->io.Attributes1;
868 link->io.BasePort2 = io->win[1].base;
869 link->io.NumPorts2 = io->win[1].len;
870 }
871
872 /* This reserves IO space but doesn't actually enable it */
873 if (pcmcia_request_io(link->handle, &link->io) != 0)
874 goto next_entry;
875 }
876
877
878 /* If we got this far, we're cool! */
879
880 break;
881
882 next_entry:
883 if (link->io.NumPorts1)
884 pcmcia_release_io(link->handle, &link->io);
885 last_ret = pcmcia_get_next_tuple(handle, &tuple);
886 if (last_ret == CS_NO_MORE_ITEMS) {
887 printk(KERN_ERR PFX "GetNextTuple(): No matching "
888 "CIS configuration. Maybe you need the "
889 "ignore_cis_vcc=1 parameter.\n");
890 goto cs_failed;
891 }
892 }
893
894 /*
895 * Allocate an interrupt line. Note that this does not assign
896 * a handler to the interrupt, unless the 'Handler' member of
897 * the irq structure is initialized.
898 */
899 CS_CHECK(RequestIRQ, pcmcia_request_irq(link->handle, &link->irq));
900
901 /* We initialize the hermes structure before completing PCMCIA
902 * configuration just in case the interrupt handler gets
903 * called. */
904 mem = ioport_map(link->io.BasePort1, link->io.NumPorts1);
905 if (!mem)
906 goto cs_failed;
907
908 hermes_struct_init(hw, mem, HERMES_16BIT_REGSPACING);
909
910 /*
911 * This actually configures the PCMCIA socket -- setting up
912 * the I/O windows and the interrupt mapping, and putting the
913 * card and host interface into "Memory and IO" mode.
914 */
915 CS_CHECK(RequestConfiguration,
916 pcmcia_request_configuration(link->handle, &link->conf));
917
918 /* Ok, we have the configuration, prepare to register the netdev */
919 dev->base_addr = link->io.BasePort1;
920 dev->irq = link->irq.AssignedIRQ;
921 SET_MODULE_OWNER(dev);
922 card->node.major = card->node.minor = 0;
923
924 /* Reset card and download firmware */
925 if (spectrum_cs_hard_reset(priv) != 0) {
926 goto failed;
927 }
928
929 SET_NETDEV_DEV(dev, &handle_to_dev(handle));
930 /* Tell the stack we exist */
931 if (register_netdev(dev) != 0) {
932 printk(KERN_ERR PFX "register_netdev() failed\n");
933 goto failed;
934 }
935
936 /* At this point, the dev_node_t structure(s) needs to be
937 * initialized and arranged in a linked list at link->dev. */
938 strcpy(card->node.dev_name, dev->name);
939 link->dev = &card->node; /* link->dev being non-NULL is also
940 used to indicate that the
941 net_device has been registered */
942 link->state &= ~DEV_CONFIG_PENDING;
943
944 /* Finally, report what we've done */
945 printk(KERN_DEBUG "%s: index 0x%02x: Vcc %d.%d",
946 dev->name, link->conf.ConfigIndex,
947 link->conf.Vcc / 10, link->conf.Vcc % 10);
948 if (link->conf.Vpp1)
949 printk(", Vpp %d.%d", link->conf.Vpp1 / 10,
950 link->conf.Vpp1 % 10);
951 printk(", irq %d", link->irq.AssignedIRQ);
952 if (link->io.NumPorts1)
953 printk(", io 0x%04x-0x%04x", link->io.BasePort1,
954 link->io.BasePort1 + link->io.NumPorts1 - 1);
955 if (link->io.NumPorts2)
956 printk(" & 0x%04x-0x%04x", link->io.BasePort2,
957 link->io.BasePort2 + link->io.NumPorts2 - 1);
958 printk("\n");
959
960 return;
961
962 cs_failed:
963 cs_error(link->handle, last_fn, last_ret);
964
965 failed:
966 spectrum_cs_release(link);
967} /* spectrum_cs_config */
968
969/*
970 * After a card is removed, spectrum_cs_release() will unregister the
971 * device, and release the PCMCIA configuration. If the device is
972 * still open, this will be postponed until it is closed.
973 */
974static void
975spectrum_cs_release(dev_link_t *link)
976{
977 struct net_device *dev = link->priv;
978 struct orinoco_private *priv = netdev_priv(dev);
979 unsigned long flags;
980
981 /* We're committed to taking the device away now, so mark the
982 * hardware as unavailable */
983 spin_lock_irqsave(&priv->lock, flags);
984 priv->hw_unavailable++;
985 spin_unlock_irqrestore(&priv->lock, flags);
986
987 /* Don't bother checking to see if these succeed or not */
988 pcmcia_release_configuration(link->handle);
989 if (link->io.NumPorts1)
990 pcmcia_release_io(link->handle, &link->io);
991 if (link->irq.AssignedIRQ)
992 pcmcia_release_irq(link->handle, &link->irq);
993 link->state &= ~DEV_CONFIG;
994 if (priv->hw.iobase)
995 ioport_unmap(priv->hw.iobase);
996} /* spectrum_cs_release */
997
998/*
999 * The card status event handler. Mostly, this schedules other stuff
1000 * to run after an event is received.
1001 */
1002static int
1003spectrum_cs_event(event_t event, int priority,
1004 event_callback_args_t * args)
1005{
1006 dev_link_t *link = args->client_data;
1007 struct net_device *dev = link->priv;
1008 struct orinoco_private *priv = netdev_priv(dev);
1009 int err = 0;
1010 unsigned long flags;
1011
1012 switch (event) {
1013 case CS_EVENT_CARD_REMOVAL:
1014 link->state &= ~DEV_PRESENT;
1015 if (link->state & DEV_CONFIG) {
1016 unsigned long flags;
1017
1018 spin_lock_irqsave(&priv->lock, flags);
1019 netif_device_detach(dev);
1020 priv->hw_unavailable++;
1021 spin_unlock_irqrestore(&priv->lock, flags);
1022 }
1023 break;
1024
1025 case CS_EVENT_CARD_INSERTION:
1026 link->state |= DEV_PRESENT | DEV_CONFIG_PENDING;
1027 spectrum_cs_config(link);
1028 break;
1029
1030 case CS_EVENT_PM_SUSPEND:
1031 link->state |= DEV_SUSPEND;
1032 /* Fall through... */
1033 case CS_EVENT_RESET_PHYSICAL:
1034 /* Mark the device as stopped, to block IO until later */
1035 if (link->state & DEV_CONFIG) {
1036 /* This is probably racy, but I can't think of
1037 a better way, short of rewriting the PCMCIA
1038 layer to not suck :-( */
1039 spin_lock_irqsave(&priv->lock, flags);
1040
1041 err = __orinoco_down(dev);
1042 if (err)
1043 printk(KERN_WARNING "%s: %s: Error %d downing interface\n",
1044 dev->name,
1045 event == CS_EVENT_PM_SUSPEND ? "SUSPEND" : "RESET_PHYSICAL",
1046 err);
1047
1048 netif_device_detach(dev);
1049 priv->hw_unavailable++;
1050
1051 spin_unlock_irqrestore(&priv->lock, flags);
1052
1053 pcmcia_release_configuration(link->handle);
1054 }
1055 break;
1056
1057 case CS_EVENT_PM_RESUME:
1058 link->state &= ~DEV_SUSPEND;
1059 /* Fall through... */
1060 case CS_EVENT_CARD_RESET:
1061 if (link->state & DEV_CONFIG) {
1062 /* FIXME: should we double check that this is
1063 * the same card as we had before */
1064 pcmcia_request_configuration(link->handle, &link->conf);
1065 netif_device_attach(dev);
1066 priv->hw_unavailable--;
1067 schedule_work(&priv->reset_work);
1068 }
1069 break;
1070 }
1071
1072 return err;
1073} /* spectrum_cs_event */
1074
1075/********************************************************************/
1076/* Module initialization */
1077/********************************************************************/
1078
1079/* Can't be declared "const" or the whole __initdata section will
1080 * become const */
1081static char version[] __initdata = DRIVER_NAME " " DRIVER_VERSION
1082 " (Pavel Roskin <proski@gnu.org>,"
1083 " David Gibson <hermes@gibson.dropbear.id.au>, et al)";
1084
1085static struct pcmcia_device_id spectrum_cs_ids[] = {
1086 PCMCIA_DEVICE_MANF_CARD(0x026c, 0x0001), /* Symbol Spectrum24 LA4100 */
1087 PCMCIA_DEVICE_MANF_CARD(0x0104, 0x0001), /* Socket Communications CF */
1088 PCMCIA_DEVICE_MANF_CARD(0x0089, 0x0001), /* Intel PRO/Wireless 2011B */
1089 PCMCIA_DEVICE_NULL,
1090};
1091MODULE_DEVICE_TABLE(pcmcia, spectrum_cs_ids);
1092
1093static struct pcmcia_driver orinoco_driver = {
1094 .owner = THIS_MODULE,
1095 .drv = {
1096 .name = DRIVER_NAME,
1097 },
1098 .attach = spectrum_cs_attach,
1099 .event = spectrum_cs_event,
1100 .detach = spectrum_cs_detach,
1101 .id_table = spectrum_cs_ids,
1102};
1103
1104static int __init
1105init_spectrum_cs(void)
1106{
1107 printk(KERN_DEBUG "%s\n", version);
1108
1109 return pcmcia_register_driver(&orinoco_driver);
1110}
1111
1112static void __exit
1113exit_spectrum_cs(void)
1114{
1115 pcmcia_unregister_driver(&orinoco_driver);
1116 BUG_ON(dev_list != NULL);
1117}
1118
1119module_init(init_spectrum_cs);
1120module_exit(exit_spectrum_cs);
diff --git a/drivers/net/wireless/wl3501.h b/drivers/net/wireless/wl3501.h
index b5719437e98..7fcbe589c3f 100644
--- a/drivers/net/wireless/wl3501.h
+++ b/drivers/net/wireless/wl3501.h
@@ -609,6 +609,7 @@ struct wl3501_card {
609 struct net_device_stats stats; 609 struct net_device_stats stats;
610 struct iw_statistics wstats; 610 struct iw_statistics wstats;
611 struct iw_spy_data spy_data; 611 struct iw_spy_data spy_data;
612 struct iw_public_data wireless_data;
612 struct dev_node_t node; 613 struct dev_node_t node;
613}; 614};
614#endif 615#endif
diff --git a/drivers/net/wireless/wl3501_cs.c b/drivers/net/wireless/wl3501_cs.c
index 7cc5edbf6ed..3f8c27f0871 100644
--- a/drivers/net/wireless/wl3501_cs.c
+++ b/drivers/net/wireless/wl3501_cs.c
@@ -1944,7 +1944,7 @@ static const iw_handler wl3501_handler[] = {
1944static const struct iw_handler_def wl3501_handler_def = { 1944static const struct iw_handler_def wl3501_handler_def = {
1945 .num_standard = sizeof(wl3501_handler) / sizeof(iw_handler), 1945 .num_standard = sizeof(wl3501_handler) / sizeof(iw_handler),
1946 .standard = (iw_handler *)wl3501_handler, 1946 .standard = (iw_handler *)wl3501_handler,
1947 .spy_offset = offsetof(struct wl3501_card, spy_data), 1947 .get_wireless_stats = wl3501_get_wireless_stats,
1948}; 1948};
1949 1949
1950/** 1950/**
@@ -1961,6 +1961,7 @@ static dev_link_t *wl3501_attach(void)
1961 client_reg_t client_reg; 1961 client_reg_t client_reg;
1962 dev_link_t *link; 1962 dev_link_t *link;
1963 struct net_device *dev; 1963 struct net_device *dev;
1964 struct wl3501_card *this;
1964 int ret; 1965 int ret;
1965 1966
1966 /* Initialize the dev_link_t structure */ 1967 /* Initialize the dev_link_t structure */
@@ -1995,7 +1996,9 @@ static dev_link_t *wl3501_attach(void)
1995 dev->tx_timeout = wl3501_tx_timeout; 1996 dev->tx_timeout = wl3501_tx_timeout;
1996 dev->watchdog_timeo = 5 * HZ; 1997 dev->watchdog_timeo = 5 * HZ;
1997 dev->get_stats = wl3501_get_stats; 1998 dev->get_stats = wl3501_get_stats;
1998 dev->get_wireless_stats = wl3501_get_wireless_stats; 1999 this = dev->priv;
2000 this->wireless_data.spy_data = &this->spy_data;
2001 dev->wireless_data = &this->wireless_data;
1999 dev->wireless_handlers = (struct iw_handler_def *)&wl3501_handler_def; 2002 dev->wireless_handlers = (struct iw_handler_def *)&wl3501_handler_def;
2000 SET_ETHTOOL_OPS(dev, &ops); 2003 SET_ETHTOOL_OPS(dev, &ops);
2001 netif_stop_queue(dev); 2004 netif_stop_queue(dev);
diff --git a/drivers/parport/parport_pc.c b/drivers/parport/parport_pc.c
index 4598c6a9212..97f723179f6 100644
--- a/drivers/parport/parport_pc.c
+++ b/drivers/parport/parport_pc.c
@@ -2739,6 +2739,7 @@ enum parport_pc_pci_cards {
2739 syba_2p_epp, 2739 syba_2p_epp,
2740 syba_1p_ecp, 2740 syba_1p_ecp,
2741 titan_010l, 2741 titan_010l,
2742 titan_1284p1,
2742 titan_1284p2, 2743 titan_1284p2,
2743 avlab_1p, 2744 avlab_1p,
2744 avlab_2p, 2745 avlab_2p,
@@ -2811,6 +2812,7 @@ static struct parport_pc_pci {
2811 /* syba_2p_epp AP138B */ { 2, { { 0, 0x078 }, { 0, 0x178 }, } }, 2812 /* syba_2p_epp AP138B */ { 2, { { 0, 0x078 }, { 0, 0x178 }, } },
2812 /* syba_1p_ecp W83787 */ { 1, { { 0, 0x078 }, } }, 2813 /* syba_1p_ecp W83787 */ { 1, { { 0, 0x078 }, } },
2813 /* titan_010l */ { 1, { { 3, -1 }, } }, 2814 /* titan_010l */ { 1, { { 3, -1 }, } },
2815 /* titan_1284p1 */ { 1, { { 0, 1 }, } },
2814 /* titan_1284p2 */ { 2, { { 0, 1 }, { 2, 3 }, } }, 2816 /* titan_1284p2 */ { 2, { { 0, 1 }, { 2, 3 }, } },
2815 /* avlab_1p */ { 1, { { 0, 1}, } }, 2817 /* avlab_1p */ { 1, { { 0, 1}, } },
2816 /* avlab_2p */ { 2, { { 0, 1}, { 2, 3 },} }, 2818 /* avlab_2p */ { 2, { { 0, 1}, { 2, 3 },} },
@@ -2884,6 +2886,7 @@ static struct pci_device_id parport_pc_pci_tbl[] = {
2884 PCI_ANY_ID, PCI_ANY_ID, 0, 0, syba_1p_ecp }, 2886 PCI_ANY_ID, PCI_ANY_ID, 0, 0, syba_1p_ecp },
2885 { PCI_VENDOR_ID_TITAN, PCI_DEVICE_ID_TITAN_010L, 2887 { PCI_VENDOR_ID_TITAN, PCI_DEVICE_ID_TITAN_010L,
2886 PCI_ANY_ID, PCI_ANY_ID, 0, 0, titan_010l }, 2888 PCI_ANY_ID, PCI_ANY_ID, 0, 0, titan_010l },
2889 { 0x9710, 0x9805, 0x1000, 0x0010, 0, 0, titan_1284p1 },
2887 { 0x9710, 0x9815, 0x1000, 0x0020, 0, 0, titan_1284p2 }, 2890 { 0x9710, 0x9815, 0x1000, 0x0020, 0, 0, titan_1284p2 },
2888 /* PCI_VENDOR_ID_AVLAB/Intek21 has another bunch of cards ...*/ 2891 /* PCI_VENDOR_ID_AVLAB/Intek21 has another bunch of cards ...*/
2889 { 0x14db, 0x2120, PCI_ANY_ID, PCI_ANY_ID, 0, 0, avlab_1p}, /* AFAVLAB_TK9902 */ 2892 { 0x14db, 0x2120, PCI_ANY_ID, PCI_ANY_ID, 0, 0, avlab_1p}, /* AFAVLAB_TK9902 */
diff --git a/drivers/pci/msi.c b/drivers/pci/msi.c
index 2b85aa39f95..532f73bb222 100644
--- a/drivers/pci/msi.c
+++ b/drivers/pci/msi.c
@@ -91,6 +91,7 @@ static void set_msi_affinity(unsigned int vector, cpumask_t cpu_mask)
91{ 91{
92 struct msi_desc *entry; 92 struct msi_desc *entry;
93 struct msg_address address; 93 struct msg_address address;
94 unsigned int irq = vector;
94 95
95 entry = (struct msi_desc *)msi_desc[vector]; 96 entry = (struct msi_desc *)msi_desc[vector];
96 if (!entry || !entry->dev) 97 if (!entry || !entry->dev)
@@ -112,6 +113,7 @@ static void set_msi_affinity(unsigned int vector, cpumask_t cpu_mask)
112 entry->msi_attrib.current_cpu = cpu_mask_to_apicid(cpu_mask); 113 entry->msi_attrib.current_cpu = cpu_mask_to_apicid(cpu_mask);
113 pci_write_config_dword(entry->dev, msi_lower_address_reg(pos), 114 pci_write_config_dword(entry->dev, msi_lower_address_reg(pos),
114 address.lo_address.value); 115 address.lo_address.value);
116 set_native_irq_info(irq, cpu_mask);
115 break; 117 break;
116 } 118 }
117 case PCI_CAP_ID_MSIX: 119 case PCI_CAP_ID_MSIX:
@@ -125,22 +127,13 @@ static void set_msi_affinity(unsigned int vector, cpumask_t cpu_mask)
125 MSI_TARGET_CPU_SHIFT); 127 MSI_TARGET_CPU_SHIFT);
126 entry->msi_attrib.current_cpu = cpu_mask_to_apicid(cpu_mask); 128 entry->msi_attrib.current_cpu = cpu_mask_to_apicid(cpu_mask);
127 writel(address.lo_address.value, entry->mask_base + offset); 129 writel(address.lo_address.value, entry->mask_base + offset);
130 set_native_irq_info(irq, cpu_mask);
128 break; 131 break;
129 } 132 }
130 default: 133 default:
131 break; 134 break;
132 } 135 }
133} 136}
134
135#ifdef CONFIG_IRQBALANCE
136static inline void move_msi(int vector)
137{
138 if (!cpus_empty(pending_irq_balance_cpumask[vector])) {
139 set_msi_affinity(vector, pending_irq_balance_cpumask[vector]);
140 cpus_clear(pending_irq_balance_cpumask[vector]);
141 }
142}
143#endif /* CONFIG_IRQBALANCE */
144#endif /* CONFIG_SMP */ 137#endif /* CONFIG_SMP */
145 138
146static void mask_MSI_irq(unsigned int vector) 139static void mask_MSI_irq(unsigned int vector)
@@ -191,13 +184,13 @@ static void shutdown_msi_irq(unsigned int vector)
191 184
192static void end_msi_irq_wo_maskbit(unsigned int vector) 185static void end_msi_irq_wo_maskbit(unsigned int vector)
193{ 186{
194 move_msi(vector); 187 move_native_irq(vector);
195 ack_APIC_irq(); 188 ack_APIC_irq();
196} 189}
197 190
198static void end_msi_irq_w_maskbit(unsigned int vector) 191static void end_msi_irq_w_maskbit(unsigned int vector)
199{ 192{
200 move_msi(vector); 193 move_native_irq(vector);
201 unmask_MSI_irq(vector); 194 unmask_MSI_irq(vector);
202 ack_APIC_irq(); 195 ack_APIC_irq();
203} 196}
diff --git a/drivers/pci/msi.h b/drivers/pci/msi.h
index 390f1851c0f..402136a5c9e 100644
--- a/drivers/pci/msi.h
+++ b/drivers/pci/msi.h
@@ -19,7 +19,6 @@
19#define NR_HP_RESERVED_VECTORS 20 19#define NR_HP_RESERVED_VECTORS 20
20 20
21extern int vector_irq[NR_VECTORS]; 21extern int vector_irq[NR_VECTORS];
22extern cpumask_t pending_irq_balance_cpumask[NR_IRQS];
23extern void (*interrupt[NR_IRQS])(void); 22extern void (*interrupt[NR_IRQS])(void);
24extern int pci_vector_resources(int last, int nr_released); 23extern int pci_vector_resources(int last, int nr_released);
25 24
@@ -29,10 +28,6 @@ extern int pci_vector_resources(int last, int nr_released);
29#define set_msi_irq_affinity NULL 28#define set_msi_irq_affinity NULL
30#endif 29#endif
31 30
32#ifndef CONFIG_IRQBALANCE
33static inline void move_msi(int vector) {}
34#endif
35
36/* 31/*
37 * MSI-X Address Register 32 * MSI-X Address Register
38 */ 33 */
diff --git a/drivers/pci/pci.c b/drivers/pci/pci.c
index 1b34fc56067..c62d2f04339 100644
--- a/drivers/pci/pci.c
+++ b/drivers/pci/pci.c
@@ -333,13 +333,17 @@ pci_power_t pci_choose_state(struct pci_dev *dev, pm_message_t state)
333 if (platform_pci_choose_state) { 333 if (platform_pci_choose_state) {
334 ret = platform_pci_choose_state(dev, state); 334 ret = platform_pci_choose_state(dev, state);
335 if (ret >= 0) 335 if (ret >= 0)
336 state = ret; 336 state.event = ret;
337 } 337 }
338 switch (state) { 338
339 case 0: return PCI_D0; 339 switch (state.event) {
340 case 3: return PCI_D3hot; 340 case PM_EVENT_ON:
341 return PCI_D0;
342 case PM_EVENT_FREEZE:
343 case PM_EVENT_SUSPEND:
344 return PCI_D3hot;
341 default: 345 default:
342 printk("They asked me for state %d\n", state); 346 printk("They asked me for state %d\n", state.event);
343 BUG(); 347 BUG();
344 } 348 }
345 return PCI_D0; 349 return PCI_D0;
diff --git a/drivers/pci/quirks.c b/drivers/pci/quirks.c
index bb36bb69803..140354a2aa7 100644
--- a/drivers/pci/quirks.c
+++ b/drivers/pci/quirks.c
@@ -422,6 +422,25 @@ static void __devinit quirk_via_ioapic(struct pci_dev *dev)
422DECLARE_PCI_FIXUP_FINAL(PCI_VENDOR_ID_VIA, PCI_DEVICE_ID_VIA_82C686, quirk_via_ioapic ); 422DECLARE_PCI_FIXUP_FINAL(PCI_VENDOR_ID_VIA, PCI_DEVICE_ID_VIA_82C686, quirk_via_ioapic );
423 423
424/* 424/*
425 * VIA 8237: Some BIOSs don't set the 'Bypass APIC De-Assert Message' Bit.
426 * This leads to doubled level interrupt rates.
427 * Set this bit to get rid of cycle wastage.
428 * Otherwise uncritical.
429 */
430static void __devinit quirk_via_vt8237_bypass_apic_deassert(struct pci_dev *dev)
431{
432 u8 misc_control2;
433#define BYPASS_APIC_DEASSERT 8
434
435 pci_read_config_byte(dev, 0x5B, &misc_control2);
436 if (!(misc_control2 & BYPASS_APIC_DEASSERT)) {
437 printk(KERN_INFO "PCI: Bypassing VIA 8237 APIC De-Assert Message\n");
438 pci_write_config_byte(dev, 0x5B, misc_control2|BYPASS_APIC_DEASSERT);
439 }
440}
441DECLARE_PCI_FIXUP_FINAL(PCI_VENDOR_ID_VIA, PCI_DEVICE_ID_VIA_8237, quirk_via_vt8237_bypass_apic_deassert);
442
443/*
425 * The AMD io apic can hang the box when an apic irq is masked. 444 * The AMD io apic can hang the box when an apic irq is masked.
426 * We check all revs >= B0 (yet not in the pre production!) as the bug 445 * We check all revs >= B0 (yet not in the pre production!) as the bug
427 * is currently marked NoFix 446 * is currently marked NoFix
diff --git a/drivers/pcmcia/pxa2xx_base.c b/drivers/pcmcia/pxa2xx_base.c
index 3e23cd461fb..325c992f7d8 100644
--- a/drivers/pcmcia/pxa2xx_base.c
+++ b/drivers/pcmcia/pxa2xx_base.c
@@ -246,7 +246,7 @@ static void __exit pxa2xx_pcmcia_exit(void)
246 driver_unregister(&pxa2xx_pcmcia_driver); 246 driver_unregister(&pxa2xx_pcmcia_driver);
247} 247}
248 248
249module_init(pxa2xx_pcmcia_init); 249fs_initcall(pxa2xx_pcmcia_init);
250module_exit(pxa2xx_pcmcia_exit); 250module_exit(pxa2xx_pcmcia_exit);
251 251
252MODULE_AUTHOR("Stefan Eletzhofer <stefan.eletzhofer@inquant.de> and Ian Molton <spyro@f2s.com>"); 252MODULE_AUTHOR("Stefan Eletzhofer <stefan.eletzhofer@inquant.de> and Ian Molton <spyro@f2s.com>");
diff --git a/drivers/pcmcia/pxa2xx_mainstone.c b/drivers/pcmcia/pxa2xx_mainstone.c
index 5309734e168..bbe69b07ce5 100644
--- a/drivers/pcmcia/pxa2xx_mainstone.c
+++ b/drivers/pcmcia/pxa2xx_mainstone.c
@@ -196,7 +196,7 @@ static void __exit mst_pcmcia_exit(void)
196 platform_device_unregister(mst_pcmcia_device); 196 platform_device_unregister(mst_pcmcia_device);
197} 197}
198 198
199module_init(mst_pcmcia_init); 199fs_initcall(mst_pcmcia_init);
200module_exit(mst_pcmcia_exit); 200module_exit(mst_pcmcia_exit);
201 201
202MODULE_LICENSE("GPL"); 202MODULE_LICENSE("GPL");
diff --git a/drivers/pcmcia/pxa2xx_sharpsl.c b/drivers/pcmcia/pxa2xx_sharpsl.c
index 42efe218867..a1178a600e3 100644
--- a/drivers/pcmcia/pxa2xx_sharpsl.c
+++ b/drivers/pcmcia/pxa2xx_sharpsl.c
@@ -20,27 +20,18 @@
20 20
21#include <asm/hardware.h> 21#include <asm/hardware.h>
22#include <asm/irq.h> 22#include <asm/irq.h>
23
24#include <asm/hardware/scoop.h> 23#include <asm/hardware/scoop.h>
25#include <asm/arch/corgi.h>
26#include <asm/arch/pxa-regs.h> 24#include <asm/arch/pxa-regs.h>
27 25
28#include "soc_common.h" 26#include "soc_common.h"
29 27
30#define NO_KEEP_VS 0x0001 28#define NO_KEEP_VS 0x0001
31 29
32static unsigned char keep_vs; 30static void sharpsl_pcmcia_init_reset(struct scoop_pcmcia_dev *scoopdev)
33static unsigned char keep_rd;
34
35static struct pcmcia_irqs irqs[] = {
36 { 0, CORGI_IRQ_GPIO_CF_CD, "PCMCIA0 CD"},
37};
38
39static void sharpsl_pcmcia_init_reset(void)
40{ 31{
41 reset_scoop(&corgiscoop_device.dev); 32 reset_scoop(scoopdev->dev);
42 keep_vs = NO_KEEP_VS; 33 scoopdev->keep_vs = NO_KEEP_VS;
43 keep_rd = 0; 34 scoopdev->keep_rd = 0;
44} 35}
45 36
46static int sharpsl_pcmcia_hw_init(struct soc_pcmcia_socket *skt) 37static int sharpsl_pcmcia_hw_init(struct soc_pcmcia_socket *skt)
@@ -71,29 +62,35 @@ static int sharpsl_pcmcia_hw_init(struct soc_pcmcia_socket *skt)
71 pxa_gpio_mode(GPIO57_nIOIS16_MD); 62 pxa_gpio_mode(GPIO57_nIOIS16_MD);
72 63
73 /* Register interrupts */ 64 /* Register interrupts */
74 ret = soc_pcmcia_request_irqs(skt, irqs, ARRAY_SIZE(irqs)); 65 if (scoop_devs[skt->nr].cd_irq >= 0) {
75 66 struct pcmcia_irqs cd_irq;
76 if (ret) { 67
77 printk(KERN_ERR "Request for Compact Flash IRQ failed\n"); 68 cd_irq.sock = skt->nr;
78 return ret; 69 cd_irq.irq = scoop_devs[skt->nr].cd_irq;
70 cd_irq.str = scoop_devs[skt->nr].cd_irq_str;
71 ret = soc_pcmcia_request_irqs(skt, &cd_irq, 1);
72
73 if (ret) {
74 printk(KERN_ERR "Request for Compact Flash IRQ failed\n");
75 return ret;
76 }
79 } 77 }
80 78
81 /* Enable interrupt */ 79 skt->irq = scoop_devs[skt->nr].irq;
82 write_scoop_reg(&corgiscoop_device.dev, SCOOP_IMR, 0x00C0);
83 write_scoop_reg(&corgiscoop_device.dev, SCOOP_MCR, 0x0101);
84 keep_vs = NO_KEEP_VS;
85
86 skt->irq = CORGI_IRQ_GPIO_CF_IRQ;
87 80
88 return 0; 81 return 0;
89} 82}
90 83
91static void sharpsl_pcmcia_hw_shutdown(struct soc_pcmcia_socket *skt) 84static void sharpsl_pcmcia_hw_shutdown(struct soc_pcmcia_socket *skt)
92{ 85{
93 soc_pcmcia_free_irqs(skt, irqs, ARRAY_SIZE(irqs)); 86 if (scoop_devs[skt->nr].cd_irq >= 0) {
87 struct pcmcia_irqs cd_irq;
94 88
95 /* CF_BUS_OFF */ 89 cd_irq.sock = skt->nr;
96 sharpsl_pcmcia_init_reset(); 90 cd_irq.irq = scoop_devs[skt->nr].cd_irq;
91 cd_irq.str = scoop_devs[skt->nr].cd_irq_str;
92 soc_pcmcia_free_irqs(skt, &cd_irq, 1);
93 }
97} 94}
98 95
99 96
@@ -101,31 +98,32 @@ static void sharpsl_pcmcia_socket_state(struct soc_pcmcia_socket *skt,
101 struct pcmcia_state *state) 98 struct pcmcia_state *state)
102{ 99{
103 unsigned short cpr, csr; 100 unsigned short cpr, csr;
101 struct device *scoop = scoop_devs[skt->nr].dev;
104 102
105 cpr = read_scoop_reg(&corgiscoop_device.dev, SCOOP_CPR); 103 cpr = read_scoop_reg(scoop_devs[skt->nr].dev, SCOOP_CPR);
106 104
107 write_scoop_reg(&corgiscoop_device.dev, SCOOP_IRM, 0x00FF); 105 write_scoop_reg(scoop, SCOOP_IRM, 0x00FF);
108 write_scoop_reg(&corgiscoop_device.dev, SCOOP_ISR, 0x0000); 106 write_scoop_reg(scoop, SCOOP_ISR, 0x0000);
109 write_scoop_reg(&corgiscoop_device.dev, SCOOP_IRM, 0x0000); 107 write_scoop_reg(scoop, SCOOP_IRM, 0x0000);
110 csr = read_scoop_reg(&corgiscoop_device.dev, SCOOP_CSR); 108 csr = read_scoop_reg(scoop, SCOOP_CSR);
111 if (csr & 0x0004) { 109 if (csr & 0x0004) {
112 /* card eject */ 110 /* card eject */
113 write_scoop_reg(&corgiscoop_device.dev, SCOOP_CDR, 0x0000); 111 write_scoop_reg(scoop, SCOOP_CDR, 0x0000);
114 keep_vs = NO_KEEP_VS; 112 scoop_devs[skt->nr].keep_vs = NO_KEEP_VS;
115 } 113 }
116 else if (!(keep_vs & NO_KEEP_VS)) { 114 else if (!(scoop_devs[skt->nr].keep_vs & NO_KEEP_VS)) {
117 /* keep vs1,vs2 */ 115 /* keep vs1,vs2 */
118 write_scoop_reg(&corgiscoop_device.dev, SCOOP_CDR, 0x0000); 116 write_scoop_reg(scoop, SCOOP_CDR, 0x0000);
119 csr |= keep_vs; 117 csr |= scoop_devs[skt->nr].keep_vs;
120 } 118 }
121 else if (cpr & 0x0003) { 119 else if (cpr & 0x0003) {
122 /* power on */ 120 /* power on */
123 write_scoop_reg(&corgiscoop_device.dev, SCOOP_CDR, 0x0000); 121 write_scoop_reg(scoop, SCOOP_CDR, 0x0000);
124 keep_vs = (csr & 0x00C0); 122 scoop_devs[skt->nr].keep_vs = (csr & 0x00C0);
125 } 123 }
126 else { 124 else {
127 /* card detect */ 125 /* card detect */
128 write_scoop_reg(&corgiscoop_device.dev, SCOOP_CDR, 0x0002); 126 write_scoop_reg(scoop, SCOOP_CDR, 0x0002);
129 } 127 }
130 128
131 state->detect = (csr & 0x0004) ? 0 : 1; 129 state->detect = (csr & 0x0004) ? 0 : 1;
@@ -147,6 +145,7 @@ static int sharpsl_pcmcia_configure_socket(struct soc_pcmcia_socket *skt,
147 const socket_state_t *state) 145 const socket_state_t *state)
148{ 146{
149 unsigned long flags; 147 unsigned long flags;
148 struct device *scoop = scoop_devs[skt->nr].dev;
150 149
151 unsigned short cpr, ncpr, ccr, nccr, mcr, nmcr, imr, nimr; 150 unsigned short cpr, ncpr, ccr, nccr, mcr, nmcr, imr, nimr;
152 151
@@ -166,10 +165,10 @@ static int sharpsl_pcmcia_configure_socket(struct soc_pcmcia_socket *skt,
166 165
167 local_irq_save(flags); 166 local_irq_save(flags);
168 167
169 nmcr = (mcr = read_scoop_reg(&corgiscoop_device.dev, SCOOP_MCR)) & ~0x0010; 168 nmcr = (mcr = read_scoop_reg(scoop, SCOOP_MCR)) & ~0x0010;
170 ncpr = (cpr = read_scoop_reg(&corgiscoop_device.dev, SCOOP_CPR)) & ~0x0083; 169 ncpr = (cpr = read_scoop_reg(scoop, SCOOP_CPR)) & ~0x0083;
171 nccr = (ccr = read_scoop_reg(&corgiscoop_device.dev, SCOOP_CCR)) & ~0x0080; 170 nccr = (ccr = read_scoop_reg(scoop, SCOOP_CCR)) & ~0x0080;
172 nimr = (imr = read_scoop_reg(&corgiscoop_device.dev, SCOOP_IMR)) & ~0x003E; 171 nimr = (imr = read_scoop_reg(scoop, SCOOP_IMR)) & ~0x003E;
173 172
174 ncpr |= (state->Vcc == 33) ? 0x0001 : 173 ncpr |= (state->Vcc == 33) ? 0x0001 :
175 (state->Vcc == 50) ? 0x0002 : 0; 174 (state->Vcc == 50) ? 0x0002 : 0;
@@ -184,22 +183,22 @@ static int sharpsl_pcmcia_configure_socket(struct soc_pcmcia_socket *skt,
184 ((skt->status&SS_WRPROT) ? 0x0008 : 0); 183 ((skt->status&SS_WRPROT) ? 0x0008 : 0);
185 184
186 if (!(ncpr & 0x0003)) { 185 if (!(ncpr & 0x0003)) {
187 keep_rd = 0; 186 scoop_devs[skt->nr].keep_rd = 0;
188 } else if (!keep_rd) { 187 } else if (!scoop_devs[skt->nr].keep_rd) {
189 if (nccr & 0x0080) 188 if (nccr & 0x0080)
190 keep_rd = 1; 189 scoop_devs[skt->nr].keep_rd = 1;
191 else 190 else
192 nccr |= 0x0080; 191 nccr |= 0x0080;
193 } 192 }
194 193
195 if (mcr != nmcr) 194 if (mcr != nmcr)
196 write_scoop_reg(&corgiscoop_device.dev, SCOOP_MCR, nmcr); 195 write_scoop_reg(scoop, SCOOP_MCR, nmcr);
197 if (cpr != ncpr) 196 if (cpr != ncpr)
198 write_scoop_reg(&corgiscoop_device.dev, SCOOP_CPR, ncpr); 197 write_scoop_reg(scoop, SCOOP_CPR, ncpr);
199 if (ccr != nccr) 198 if (ccr != nccr)
200 write_scoop_reg(&corgiscoop_device.dev, SCOOP_CCR, nccr); 199 write_scoop_reg(scoop, SCOOP_CCR, nccr);
201 if (imr != nimr) 200 if (imr != nimr)
202 write_scoop_reg(&corgiscoop_device.dev, SCOOP_IMR, nimr); 201 write_scoop_reg(scoop, SCOOP_IMR, nimr);
203 202
204 local_irq_restore(flags); 203 local_irq_restore(flags);
205 204
@@ -208,10 +207,18 @@ static int sharpsl_pcmcia_configure_socket(struct soc_pcmcia_socket *skt,
208 207
209static void sharpsl_pcmcia_socket_init(struct soc_pcmcia_socket *skt) 208static void sharpsl_pcmcia_socket_init(struct soc_pcmcia_socket *skt)
210{ 209{
210 sharpsl_pcmcia_init_reset(&scoop_devs[skt->nr]);
211
212 /* Enable interrupt */
213 write_scoop_reg(scoop_devs[skt->nr].dev, SCOOP_IMR, 0x00C0);
214 write_scoop_reg(scoop_devs[skt->nr].dev, SCOOP_MCR, 0x0101);
215 scoop_devs[skt->nr].keep_vs = NO_KEEP_VS;
211} 216}
212 217
213static void sharpsl_pcmcia_socket_suspend(struct soc_pcmcia_socket *skt) 218static void sharpsl_pcmcia_socket_suspend(struct soc_pcmcia_socket *skt)
214{ 219{
220 /* CF_BUS_OFF */
221 sharpsl_pcmcia_init_reset(&scoop_devs[skt->nr]);
215} 222}
216 223
217static struct pcmcia_low_level sharpsl_pcmcia_ops = { 224static struct pcmcia_low_level sharpsl_pcmcia_ops = {
@@ -223,7 +230,7 @@ static struct pcmcia_low_level sharpsl_pcmcia_ops = {
223 .socket_init = sharpsl_pcmcia_socket_init, 230 .socket_init = sharpsl_pcmcia_socket_init,
224 .socket_suspend = sharpsl_pcmcia_socket_suspend, 231 .socket_suspend = sharpsl_pcmcia_socket_suspend,
225 .first = 0, 232 .first = 0,
226 .nr = 1, 233 .nr = 0,
227}; 234};
228 235
229static struct platform_device *sharpsl_pcmcia_device; 236static struct platform_device *sharpsl_pcmcia_device;
@@ -232,12 +239,15 @@ static int __init sharpsl_pcmcia_init(void)
232{ 239{
233 int ret; 240 int ret;
234 241
242 sharpsl_pcmcia_ops.nr=scoop_num;
235 sharpsl_pcmcia_device = kmalloc(sizeof(*sharpsl_pcmcia_device), GFP_KERNEL); 243 sharpsl_pcmcia_device = kmalloc(sizeof(*sharpsl_pcmcia_device), GFP_KERNEL);
236 if (!sharpsl_pcmcia_device) 244 if (!sharpsl_pcmcia_device)
237 return -ENOMEM; 245 return -ENOMEM;
246
238 memset(sharpsl_pcmcia_device, 0, sizeof(*sharpsl_pcmcia_device)); 247 memset(sharpsl_pcmcia_device, 0, sizeof(*sharpsl_pcmcia_device));
239 sharpsl_pcmcia_device->name = "pxa2xx-pcmcia"; 248 sharpsl_pcmcia_device->name = "pxa2xx-pcmcia";
240 sharpsl_pcmcia_device->dev.platform_data = &sharpsl_pcmcia_ops; 249 sharpsl_pcmcia_device->dev.platform_data = &sharpsl_pcmcia_ops;
250 sharpsl_pcmcia_device->dev.parent=scoop_devs[0].dev;
241 251
242 ret = platform_device_register(sharpsl_pcmcia_device); 252 ret = platform_device_register(sharpsl_pcmcia_device);
243 if (ret) 253 if (ret)
@@ -257,7 +267,7 @@ static void __exit sharpsl_pcmcia_exit(void)
257 platform_device_unregister(sharpsl_pcmcia_device); 267 platform_device_unregister(sharpsl_pcmcia_device);
258} 268}
259 269
260module_init(sharpsl_pcmcia_init); 270fs_initcall(sharpsl_pcmcia_init);
261module_exit(sharpsl_pcmcia_exit); 271module_exit(sharpsl_pcmcia_exit);
262 272
263MODULE_DESCRIPTION("Sharp SL Series PCMCIA Support"); 273MODULE_DESCRIPTION("Sharp SL Series PCMCIA Support");
diff --git a/drivers/pcmcia/sa1100_generic.c b/drivers/pcmcia/sa1100_generic.c
index e98bb3d80e7..d4ed508b38b 100644
--- a/drivers/pcmcia/sa1100_generic.c
+++ b/drivers/pcmcia/sa1100_generic.c
@@ -126,5 +126,5 @@ MODULE_AUTHOR("John Dorsey <john+@cs.cmu.edu>");
126MODULE_DESCRIPTION("Linux PCMCIA Card Services: SA-11x0 Socket Controller"); 126MODULE_DESCRIPTION("Linux PCMCIA Card Services: SA-11x0 Socket Controller");
127MODULE_LICENSE("Dual MPL/GPL"); 127MODULE_LICENSE("Dual MPL/GPL");
128 128
129module_init(sa11x0_pcmcia_init); 129fs_initcall(sa11x0_pcmcia_init);
130module_exit(sa11x0_pcmcia_exit); 130module_exit(sa11x0_pcmcia_exit);
diff --git a/drivers/pcmcia/sa1111_generic.c b/drivers/pcmcia/sa1111_generic.c
index b441f43a6a5..bb90a1448a5 100644
--- a/drivers/pcmcia/sa1111_generic.c
+++ b/drivers/pcmcia/sa1111_generic.c
@@ -189,7 +189,7 @@ static void __exit sa1111_drv_pcmcia_exit(void)
189 sa1111_driver_unregister(&pcmcia_driver); 189 sa1111_driver_unregister(&pcmcia_driver);
190} 190}
191 191
192module_init(sa1111_drv_pcmcia_init); 192fs_initcall(sa1111_drv_pcmcia_init);
193module_exit(sa1111_drv_pcmcia_exit); 193module_exit(sa1111_drv_pcmcia_exit);
194 194
195MODULE_DESCRIPTION("SA1111 PCMCIA card socket driver"); 195MODULE_DESCRIPTION("SA1111 PCMCIA card socket driver");
diff --git a/drivers/pcmcia/sa11xx_base.c b/drivers/pcmcia/sa11xx_base.c
index db04ffb6f68..59c5d968e9f 100644
--- a/drivers/pcmcia/sa11xx_base.c
+++ b/drivers/pcmcia/sa11xx_base.c
@@ -189,7 +189,7 @@ static int __init sa11xx_pcmcia_init(void)
189{ 189{
190 return 0; 190 return 0;
191} 191}
192module_init(sa11xx_pcmcia_init); 192fs_initcall(sa11xx_pcmcia_init);
193 193
194static void __exit sa11xx_pcmcia_exit(void) {} 194static void __exit sa11xx_pcmcia_exit(void) {}
195 195
diff --git a/drivers/pcmcia/topic.h b/drivers/pcmcia/topic.h
index be420bb2911..edccfa5bb40 100644
--- a/drivers/pcmcia/topic.h
+++ b/drivers/pcmcia/topic.h
@@ -101,6 +101,8 @@
101#define TOPIC97_AVS_AUDIO_CONTROL 0x02 101#define TOPIC97_AVS_AUDIO_CONTROL 0x02
102#define TOPIC97_AVS_VIDEO_CONTROL 0x01 102#define TOPIC97_AVS_VIDEO_CONTROL 0x01
103 103
104#define TOPIC_EXCA_IF_CONTROL 0x3e /* 8 bit */
105#define TOPIC_EXCA_IFC_33V_ENA 0x01
104 106
105static void topic97_zoom_video(struct pcmcia_socket *sock, int onoff) 107static void topic97_zoom_video(struct pcmcia_socket *sock, int onoff)
106{ 108{
@@ -137,4 +139,19 @@ static int topic97_override(struct yenta_socket *socket)
137 return 0; 139 return 0;
138} 140}
139 141
142
143static int topic95_override(struct yenta_socket *socket)
144{
145 u8 fctrl;
146
147 /* enable 3.3V support for 16bit cards */
148 fctrl = exca_readb(socket, TOPIC_EXCA_IF_CONTROL);
149 exca_writeb(socket, TOPIC_EXCA_IF_CONTROL, fctrl | TOPIC_EXCA_IFC_33V_ENA);
150
151 /* tell yenta to use exca registers to power 16bit cards */
152 socket->flags |= YENTA_16BIT_POWER_EXCA | YENTA_16BIT_POWER_DF;
153
154 return 0;
155}
156
140#endif /* _LINUX_TOPIC_H */ 157#endif /* _LINUX_TOPIC_H */
diff --git a/drivers/pcmcia/yenta_socket.c b/drivers/pcmcia/yenta_socket.c
index 62fd705203f..0347a29f297 100644
--- a/drivers/pcmcia/yenta_socket.c
+++ b/drivers/pcmcia/yenta_socket.c
@@ -184,22 +184,52 @@ static int yenta_get_status(struct pcmcia_socket *sock, unsigned int *value)
184 return 0; 184 return 0;
185} 185}
186 186
187static int yenta_Vcc_power(u32 control) 187static void yenta_get_power(struct yenta_socket *socket, socket_state_t *state)
188{ 188{
189 switch (control & CB_SC_VCC_MASK) { 189 if (!(cb_readl(socket, CB_SOCKET_STATE) & CB_CBCARD) &&
190 case CB_SC_VCC_5V: return 50; 190 (socket->flags & YENTA_16BIT_POWER_EXCA)) {
191 case CB_SC_VCC_3V: return 33; 191 u8 reg, vcc, vpp;
192 default: return 0; 192
193 } 193 reg = exca_readb(socket, I365_POWER);
194} 194 vcc = reg & I365_VCC_MASK;
195 vpp = reg & I365_VPP1_MASK;
196 state->Vcc = state->Vpp = 0;
197
198 if (socket->flags & YENTA_16BIT_POWER_DF) {
199 if (vcc == I365_VCC_3V)
200 state->Vcc = 33;
201 if (vcc == I365_VCC_5V)
202 state->Vcc = 50;
203 if (vpp == I365_VPP1_5V)
204 state->Vpp = state->Vcc;
205 if (vpp == I365_VPP1_12V)
206 state->Vpp = 120;
207 } else {
208 if (reg & I365_VCC_5V) {
209 state->Vcc = 50;
210 if (vpp == I365_VPP1_5V)
211 state->Vpp = 50;
212 if (vpp == I365_VPP1_12V)
213 state->Vpp = 120;
214 }
215 }
216 } else {
217 u32 control;
195 218
196static int yenta_Vpp_power(u32 control) 219 control = cb_readl(socket, CB_SOCKET_CONTROL);
197{ 220
198 switch (control & CB_SC_VPP_MASK) { 221 switch (control & CB_SC_VCC_MASK) {
199 case CB_SC_VPP_12V: return 120; 222 case CB_SC_VCC_5V: state->Vcc = 50; break;
200 case CB_SC_VPP_5V: return 50; 223 case CB_SC_VCC_3V: state->Vcc = 33; break;
201 case CB_SC_VPP_3V: return 33; 224 default: state->Vcc = 0;
202 default: return 0; 225 }
226
227 switch (control & CB_SC_VPP_MASK) {
228 case CB_SC_VPP_12V: state->Vpp = 120; break;
229 case CB_SC_VPP_5V: state->Vpp = 50; break;
230 case CB_SC_VPP_3V: state->Vpp = 33; break;
231 default: state->Vpp = 0;
232 }
203 } 233 }
204} 234}
205 235
@@ -211,8 +241,7 @@ static int yenta_get_socket(struct pcmcia_socket *sock, socket_state_t *state)
211 241
212 control = cb_readl(socket, CB_SOCKET_CONTROL); 242 control = cb_readl(socket, CB_SOCKET_CONTROL);
213 243
214 state->Vcc = yenta_Vcc_power(control); 244 yenta_get_power(socket, state);
215 state->Vpp = yenta_Vpp_power(control);
216 state->io_irq = socket->io_irq; 245 state->io_irq = socket->io_irq;
217 246
218 if (cb_readl(socket, CB_SOCKET_STATE) & CB_CBCARD) { 247 if (cb_readl(socket, CB_SOCKET_STATE) & CB_CBCARD) {
@@ -246,19 +275,54 @@ static int yenta_get_socket(struct pcmcia_socket *sock, socket_state_t *state)
246 275
247static void yenta_set_power(struct yenta_socket *socket, socket_state_t *state) 276static void yenta_set_power(struct yenta_socket *socket, socket_state_t *state)
248{ 277{
249 u32 reg = 0; /* CB_SC_STPCLK? */ 278 /* some birdges require to use the ExCA registers to power 16bit cards */
250 switch (state->Vcc) { 279 if (!(cb_readl(socket, CB_SOCKET_STATE) & CB_CBCARD) &&
251 case 33: reg = CB_SC_VCC_3V; break; 280 (socket->flags & YENTA_16BIT_POWER_EXCA)) {
252 case 50: reg = CB_SC_VCC_5V; break; 281 u8 reg, old;
253 default: reg = 0; break; 282 reg = old = exca_readb(socket, I365_POWER);
254 } 283 reg &= ~(I365_VCC_MASK | I365_VPP1_MASK | I365_VPP2_MASK);
255 switch (state->Vpp) { 284
256 case 33: reg |= CB_SC_VPP_3V; break; 285 /* i82365SL-DF style */
257 case 50: reg |= CB_SC_VPP_5V; break; 286 if (socket->flags & YENTA_16BIT_POWER_DF) {
258 case 120: reg |= CB_SC_VPP_12V; break; 287 switch (state->Vcc) {
288 case 33: reg |= I365_VCC_3V; break;
289 case 50: reg |= I365_VCC_5V; break;
290 default: reg = 0; break;
291 }
292 switch (state->Vpp) {
293 case 33:
294 case 50: reg |= I365_VPP1_5V; break;
295 case 120: reg |= I365_VPP1_12V; break;
296 }
297 } else {
298 /* i82365SL-B style */
299 switch (state->Vcc) {
300 case 50: reg |= I365_VCC_5V; break;
301 default: reg = 0; break;
302 }
303 switch (state->Vpp) {
304 case 50: reg |= I365_VPP1_5V | I365_VPP2_5V; break;
305 case 120: reg |= I365_VPP1_12V | I365_VPP2_12V; break;
306 }
307 }
308
309 if (reg != old)
310 exca_writeb(socket, I365_POWER, reg);
311 } else {
312 u32 reg = 0; /* CB_SC_STPCLK? */
313 switch (state->Vcc) {
314 case 33: reg = CB_SC_VCC_3V; break;
315 case 50: reg = CB_SC_VCC_5V; break;
316 default: reg = 0; break;
317 }
318 switch (state->Vpp) {
319 case 33: reg |= CB_SC_VPP_3V; break;
320 case 50: reg |= CB_SC_VPP_5V; break;
321 case 120: reg |= CB_SC_VPP_12V; break;
322 }
323 if (reg != cb_readl(socket, CB_SOCKET_CONTROL))
324 cb_writel(socket, CB_SOCKET_CONTROL, reg);
259 } 325 }
260 if (reg != cb_readl(socket, CB_SOCKET_CONTROL))
261 cb_writel(socket, CB_SOCKET_CONTROL, reg);
262} 326}
263 327
264static int yenta_set_socket(struct pcmcia_socket *sock, socket_state_t *state) 328static int yenta_set_socket(struct pcmcia_socket *sock, socket_state_t *state)
@@ -751,6 +815,7 @@ enum {
751 CARDBUS_TYPE_TI12XX, 815 CARDBUS_TYPE_TI12XX,
752 CARDBUS_TYPE_TI1250, 816 CARDBUS_TYPE_TI1250,
753 CARDBUS_TYPE_RICOH, 817 CARDBUS_TYPE_RICOH,
818 CARDBUS_TYPE_TOPIC95,
754 CARDBUS_TYPE_TOPIC97, 819 CARDBUS_TYPE_TOPIC97,
755 CARDBUS_TYPE_O2MICRO, 820 CARDBUS_TYPE_O2MICRO,
756}; 821};
@@ -789,6 +854,9 @@ static struct cardbus_type cardbus_type[] = {
789 .save_state = ricoh_save_state, 854 .save_state = ricoh_save_state,
790 .restore_state = ricoh_restore_state, 855 .restore_state = ricoh_restore_state,
791 }, 856 },
857 [CARDBUS_TYPE_TOPIC95] = {
858 .override = topic95_override,
859 },
792 [CARDBUS_TYPE_TOPIC97] = { 860 [CARDBUS_TYPE_TOPIC97] = {
793 .override = topic97_override, 861 .override = topic97_override,
794 }, 862 },
@@ -1196,6 +1264,7 @@ static struct pci_device_id yenta_table [] = {
1196 CB_ID(PCI_VENDOR_ID_RICOH, PCI_DEVICE_ID_RICOH_RL5C476, RICOH), 1264 CB_ID(PCI_VENDOR_ID_RICOH, PCI_DEVICE_ID_RICOH_RL5C476, RICOH),
1197 CB_ID(PCI_VENDOR_ID_RICOH, PCI_DEVICE_ID_RICOH_RL5C478, RICOH), 1265 CB_ID(PCI_VENDOR_ID_RICOH, PCI_DEVICE_ID_RICOH_RL5C478, RICOH),
1198 1266
1267 CB_ID(PCI_VENDOR_ID_TOSHIBA, PCI_DEVICE_ID_TOSHIBA_TOPIC95, TOPIC95),
1199 CB_ID(PCI_VENDOR_ID_TOSHIBA, PCI_DEVICE_ID_TOSHIBA_TOPIC97, TOPIC97), 1268 CB_ID(PCI_VENDOR_ID_TOSHIBA, PCI_DEVICE_ID_TOSHIBA_TOPIC97, TOPIC97),
1200 CB_ID(PCI_VENDOR_ID_TOSHIBA, PCI_DEVICE_ID_TOSHIBA_TOPIC100, TOPIC97), 1269 CB_ID(PCI_VENDOR_ID_TOSHIBA, PCI_DEVICE_ID_TOSHIBA_TOPIC100, TOPIC97),
1201 1270
diff --git a/drivers/pcmcia/yenta_socket.h b/drivers/pcmcia/yenta_socket.h
index 4e637eef207..4e75e9e258c 100644
--- a/drivers/pcmcia/yenta_socket.h
+++ b/drivers/pcmcia/yenta_socket.h
@@ -95,6 +95,12 @@
95 */ 95 */
96#define CB_MEM_PAGE(map) (0x40 + (map)) 96#define CB_MEM_PAGE(map) (0x40 + (map))
97 97
98
99/* control how 16bit cards are powered */
100#define YENTA_16BIT_POWER_EXCA 0x00000001
101#define YENTA_16BIT_POWER_DF 0x00000002
102
103
98struct yenta_socket; 104struct yenta_socket;
99 105
100struct cardbus_type { 106struct cardbus_type {
@@ -113,6 +119,8 @@ struct yenta_socket {
113 struct pcmcia_socket socket; 119 struct pcmcia_socket socket;
114 struct cardbus_type *type; 120 struct cardbus_type *type;
115 121
122 u32 flags;
123
116 /* for PCI interrupt probing */ 124 /* for PCI interrupt probing */
117 unsigned int probe_status; 125 unsigned int probe_status;
118 126
diff --git a/drivers/pnp/card.c b/drivers/pnp/card.c
index 6e5229e92fb..e95ed67d4f0 100644
--- a/drivers/pnp/card.c
+++ b/drivers/pnp/card.c
@@ -8,13 +8,6 @@
8#include <linux/config.h> 8#include <linux/config.h>
9#include <linux/module.h> 9#include <linux/module.h>
10#include <linux/slab.h> 10#include <linux/slab.h>
11
12#ifdef CONFIG_PNP_DEBUG
13 #define DEBUG
14#else
15 #undef DEBUG
16#endif
17
18#include <linux/pnp.h> 11#include <linux/pnp.h>
19#include "base.h" 12#include "base.h"
20 13
diff --git a/drivers/pnp/driver.c b/drivers/pnp/driver.c
index 1d037c2a82a..33da25f3213 100644
--- a/drivers/pnp/driver.c
+++ b/drivers/pnp/driver.c
@@ -11,13 +11,6 @@
11#include <linux/module.h> 11#include <linux/module.h>
12#include <linux/ctype.h> 12#include <linux/ctype.h>
13#include <linux/slab.h> 13#include <linux/slab.h>
14
15#ifdef CONFIG_PNP_DEBUG
16 #define DEBUG
17#else
18 #undef DEBUG
19#endif
20
21#include <linux/pnp.h> 14#include <linux/pnp.h>
22#include "base.h" 15#include "base.h"
23 16
diff --git a/drivers/pnp/isapnp/core.c b/drivers/pnp/isapnp/core.c
index 82c5edd5b9e..beedd86800f 100644
--- a/drivers/pnp/isapnp/core.c
+++ b/drivers/pnp/isapnp/core.c
@@ -142,17 +142,6 @@ static void isapnp_write_word(unsigned char idx, unsigned short val)
142 isapnp_write_byte(idx+1, val); 142 isapnp_write_byte(idx+1, val);
143} 143}
144 144
145static void *isapnp_alloc(long size)
146{
147 void *result;
148
149 result = kmalloc(size, GFP_KERNEL);
150 if (!result)
151 return NULL;
152 memset(result, 0, size);
153 return result;
154}
155
156static void isapnp_key(void) 145static void isapnp_key(void)
157{ 146{
158 unsigned char code = 0x6a, msb; 147 unsigned char code = 0x6a, msb;
@@ -406,7 +395,7 @@ static void isapnp_parse_id(struct pnp_dev * dev, unsigned short vendor, unsigne
406 struct pnp_id * id; 395 struct pnp_id * id;
407 if (!dev) 396 if (!dev)
408 return; 397 return;
409 id = isapnp_alloc(sizeof(struct pnp_id)); 398 id = kcalloc(1, sizeof(struct pnp_id), GFP_KERNEL);
410 if (!id) 399 if (!id)
411 return; 400 return;
412 sprintf(id->id, "%c%c%c%x%x%x%x", 401 sprintf(id->id, "%c%c%c%x%x%x%x",
@@ -430,7 +419,7 @@ static struct pnp_dev * __init isapnp_parse_device(struct pnp_card *card, int si
430 struct pnp_dev *dev; 419 struct pnp_dev *dev;
431 420
432 isapnp_peek(tmp, size); 421 isapnp_peek(tmp, size);
433 dev = isapnp_alloc(sizeof(struct pnp_dev)); 422 dev = kcalloc(1, sizeof(struct pnp_dev), GFP_KERNEL);
434 if (!dev) 423 if (!dev)
435 return NULL; 424 return NULL;
436 dev->number = number; 425 dev->number = number;
@@ -461,7 +450,7 @@ static void __init isapnp_parse_irq_resource(struct pnp_option *option,
461 unsigned long bits; 450 unsigned long bits;
462 451
463 isapnp_peek(tmp, size); 452 isapnp_peek(tmp, size);
464 irq = isapnp_alloc(sizeof(struct pnp_irq)); 453 irq = kcalloc(1, sizeof(struct pnp_irq), GFP_KERNEL);
465 if (!irq) 454 if (!irq)
466 return; 455 return;
467 bits = (tmp[1] << 8) | tmp[0]; 456 bits = (tmp[1] << 8) | tmp[0];
@@ -485,7 +474,7 @@ static void __init isapnp_parse_dma_resource(struct pnp_option *option,
485 struct pnp_dma *dma; 474 struct pnp_dma *dma;
486 475
487 isapnp_peek(tmp, size); 476 isapnp_peek(tmp, size);
488 dma = isapnp_alloc(sizeof(struct pnp_dma)); 477 dma = kcalloc(1, sizeof(struct pnp_dma), GFP_KERNEL);
489 if (!dma) 478 if (!dma)
490 return; 479 return;
491 dma->map = tmp[0]; 480 dma->map = tmp[0];
@@ -505,7 +494,7 @@ static void __init isapnp_parse_port_resource(struct pnp_option *option,
505 struct pnp_port *port; 494 struct pnp_port *port;
506 495
507 isapnp_peek(tmp, size); 496 isapnp_peek(tmp, size);
508 port = isapnp_alloc(sizeof(struct pnp_port)); 497 port = kcalloc(1, sizeof(struct pnp_port), GFP_KERNEL);
509 if (!port) 498 if (!port)
510 return; 499 return;
511 port->min = (tmp[2] << 8) | tmp[1]; 500 port->min = (tmp[2] << 8) | tmp[1];
@@ -528,7 +517,7 @@ static void __init isapnp_parse_fixed_port_resource(struct pnp_option *option,
528 struct pnp_port *port; 517 struct pnp_port *port;
529 518
530 isapnp_peek(tmp, size); 519 isapnp_peek(tmp, size);
531 port = isapnp_alloc(sizeof(struct pnp_port)); 520 port = kcalloc(1, sizeof(struct pnp_port), GFP_KERNEL);
532 if (!port) 521 if (!port)
533 return; 522 return;
534 port->min = port->max = (tmp[1] << 8) | tmp[0]; 523 port->min = port->max = (tmp[1] << 8) | tmp[0];
@@ -550,7 +539,7 @@ static void __init isapnp_parse_mem_resource(struct pnp_option *option,
550 struct pnp_mem *mem; 539 struct pnp_mem *mem;
551 540
552 isapnp_peek(tmp, size); 541 isapnp_peek(tmp, size);
553 mem = isapnp_alloc(sizeof(struct pnp_mem)); 542 mem = kcalloc(1, sizeof(struct pnp_mem), GFP_KERNEL);
554 if (!mem) 543 if (!mem)
555 return; 544 return;
556 mem->min = ((tmp[2] << 8) | tmp[1]) << 8; 545 mem->min = ((tmp[2] << 8) | tmp[1]) << 8;
@@ -573,7 +562,7 @@ static void __init isapnp_parse_mem32_resource(struct pnp_option *option,
573 struct pnp_mem *mem; 562 struct pnp_mem *mem;
574 563
575 isapnp_peek(tmp, size); 564 isapnp_peek(tmp, size);
576 mem = isapnp_alloc(sizeof(struct pnp_mem)); 565 mem = kcalloc(1, sizeof(struct pnp_mem), GFP_KERNEL);
577 if (!mem) 566 if (!mem)
578 return; 567 return;
579 mem->min = (tmp[4] << 24) | (tmp[3] << 16) | (tmp[2] << 8) | tmp[1]; 568 mem->min = (tmp[4] << 24) | (tmp[3] << 16) | (tmp[2] << 8) | tmp[1];
@@ -595,7 +584,7 @@ static void __init isapnp_parse_fixed_mem32_resource(struct pnp_option *option,
595 struct pnp_mem *mem; 584 struct pnp_mem *mem;
596 585
597 isapnp_peek(tmp, size); 586 isapnp_peek(tmp, size);
598 mem = isapnp_alloc(sizeof(struct pnp_mem)); 587 mem = kcalloc(1, sizeof(struct pnp_mem), GFP_KERNEL);
599 if (!mem) 588 if (!mem)
600 return; 589 return;
601 mem->min = mem->max = (tmp[4] << 24) | (tmp[3] << 16) | (tmp[2] << 8) | tmp[1]; 590 mem->min = mem->max = (tmp[4] << 24) | (tmp[3] << 16) | (tmp[2] << 8) | tmp[1];
@@ -838,7 +827,7 @@ static unsigned char __init isapnp_checksum(unsigned char *data)
838 827
839static void isapnp_parse_card_id(struct pnp_card * card, unsigned short vendor, unsigned short device) 828static void isapnp_parse_card_id(struct pnp_card * card, unsigned short vendor, unsigned short device)
840{ 829{
841 struct pnp_id * id = isapnp_alloc(sizeof(struct pnp_id)); 830 struct pnp_id * id = kcalloc(1, sizeof(struct pnp_id), GFP_KERNEL);
842 if (!id) 831 if (!id)
843 return; 832 return;
844 sprintf(id->id, "%c%c%c%x%x%x%x", 833 sprintf(id->id, "%c%c%c%x%x%x%x",
@@ -874,7 +863,7 @@ static int __init isapnp_build_device_list(void)
874 header[4], header[5], header[6], header[7], header[8]); 863 header[4], header[5], header[6], header[7], header[8]);
875 printk(KERN_DEBUG "checksum = 0x%x\n", checksum); 864 printk(KERN_DEBUG "checksum = 0x%x\n", checksum);
876#endif 865#endif
877 if ((card = isapnp_alloc(sizeof(struct pnp_card))) == NULL) 866 if ((card = kcalloc(1, sizeof(struct pnp_card), GFP_KERNEL)) == NULL)
878 continue; 867 continue;
879 868
880 card->number = csn; 869 card->number = csn;
diff --git a/drivers/pnp/manager.c b/drivers/pnp/manager.c
index 6c510c19ad7..94442ffd4ae 100644
--- a/drivers/pnp/manager.c
+++ b/drivers/pnp/manager.c
@@ -11,13 +11,6 @@
11#include <linux/module.h> 11#include <linux/module.h>
12#include <linux/init.h> 12#include <linux/init.h>
13#include <linux/kernel.h> 13#include <linux/kernel.h>
14
15#ifdef CONFIG_PNP_DEBUG
16 #define DEBUG
17#else
18 #undef DEBUG
19#endif
20
21#include <linux/pnp.h> 14#include <linux/pnp.h>
22#include "base.h" 15#include "base.h"
23 16
diff --git a/drivers/pnp/pnpacpi/core.c b/drivers/pnp/pnpacpi/core.c
index 8655dd2e5b8..1a8915e7416 100644
--- a/drivers/pnp/pnpacpi/core.c
+++ b/drivers/pnp/pnpacpi/core.c
@@ -19,6 +19,7 @@
19 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 19 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
20 */ 20 */
21 21
22#include <linux/config.h>
22#include <linux/acpi.h> 23#include <linux/acpi.h>
23#include <linux/pnp.h> 24#include <linux/pnp.h>
24#include <acpi/acpi_bus.h> 25#include <acpi/acpi_bus.h>
@@ -41,14 +42,6 @@ static inline int is_exclusive_device(struct acpi_device *dev)
41 return (!acpi_match_ids(dev, excluded_id_list)); 42 return (!acpi_match_ids(dev, excluded_id_list));
42} 43}
43 44
44void *pnpacpi_kmalloc(size_t size, int f)
45{
46 void *p = kmalloc(size, f);
47 if (p)
48 memset(p, 0, size);
49 return p;
50}
51
52/* 45/*
53 * Compatible Device IDs 46 * Compatible Device IDs
54 */ 47 */
@@ -143,7 +136,7 @@ static int __init pnpacpi_add_device(struct acpi_device *device)
143 return 0; 136 return 0;
144 137
145 pnp_dbg("ACPI device : hid %s", acpi_device_hid(device)); 138 pnp_dbg("ACPI device : hid %s", acpi_device_hid(device));
146 dev = pnpacpi_kmalloc(sizeof(struct pnp_dev), GFP_KERNEL); 139 dev = kcalloc(1, sizeof(struct pnp_dev), GFP_KERNEL);
147 if (!dev) { 140 if (!dev) {
148 pnp_err("Out of memory"); 141 pnp_err("Out of memory");
149 return -ENOMEM; 142 return -ENOMEM;
@@ -173,7 +166,7 @@ static int __init pnpacpi_add_device(struct acpi_device *device)
173 dev->number = num; 166 dev->number = num;
174 167
175 /* set the initial values for the PnP device */ 168 /* set the initial values for the PnP device */
176 dev_id = pnpacpi_kmalloc(sizeof(struct pnp_id), GFP_KERNEL); 169 dev_id = kcalloc(1, sizeof(struct pnp_id), GFP_KERNEL);
177 if (!dev_id) 170 if (!dev_id)
178 goto err; 171 goto err;
179 pnpidacpi_to_pnpid(acpi_device_hid(device), dev_id->id); 172 pnpidacpi_to_pnpid(acpi_device_hid(device), dev_id->id);
@@ -205,8 +198,7 @@ static int __init pnpacpi_add_device(struct acpi_device *device)
205 for (i = 0; i < cid_list->count; i++) { 198 for (i = 0; i < cid_list->count; i++) {
206 if (!ispnpidacpi(cid_list->id[i].value)) 199 if (!ispnpidacpi(cid_list->id[i].value))
207 continue; 200 continue;
208 dev_id = pnpacpi_kmalloc(sizeof(struct pnp_id), 201 dev_id = kcalloc(1, sizeof(struct pnp_id), GFP_KERNEL);
209 GFP_KERNEL);
210 if (!dev_id) 202 if (!dev_id)
211 continue; 203 continue;
212 204
diff --git a/drivers/pnp/pnpacpi/pnpacpi.h b/drivers/pnp/pnpacpi/pnpacpi.h
index 76f907e09ee..f28e2ed66fa 100644
--- a/drivers/pnp/pnpacpi/pnpacpi.h
+++ b/drivers/pnp/pnpacpi/pnpacpi.h
@@ -5,7 +5,6 @@
5#include <linux/acpi.h> 5#include <linux/acpi.h>
6#include <linux/pnp.h> 6#include <linux/pnp.h>
7 7
8void *pnpacpi_kmalloc(size_t size, int f);
9acpi_status pnpacpi_parse_allocated_resource(acpi_handle, struct pnp_resource_table*); 8acpi_status pnpacpi_parse_allocated_resource(acpi_handle, struct pnp_resource_table*);
10acpi_status pnpacpi_parse_resource_option_data(acpi_handle, struct pnp_dev*); 9acpi_status pnpacpi_parse_resource_option_data(acpi_handle, struct pnp_dev*);
11int pnpacpi_encode_resources(struct pnp_resource_table *, struct acpi_buffer *); 10int pnpacpi_encode_resources(struct pnp_resource_table *, struct acpi_buffer *);
diff --git a/drivers/pnp/pnpacpi/rsparser.c b/drivers/pnp/pnpacpi/rsparser.c
index 6db549c9480..416d30debe6 100644
--- a/drivers/pnp/pnpacpi/rsparser.c
+++ b/drivers/pnp/pnpacpi/rsparser.c
@@ -255,7 +255,7 @@ static void pnpacpi_parse_dma_option(struct pnp_option *option, struct acpi_reso
255 255
256 if (p->number_of_channels == 0) 256 if (p->number_of_channels == 0)
257 return; 257 return;
258 dma = pnpacpi_kmalloc(sizeof(struct pnp_dma), GFP_KERNEL); 258 dma = kcalloc(1, sizeof(struct pnp_dma), GFP_KERNEL);
259 if (!dma) 259 if (!dma)
260 return; 260 return;
261 261
@@ -311,7 +311,7 @@ static void pnpacpi_parse_irq_option(struct pnp_option *option,
311 311
312 if (p->number_of_interrupts == 0) 312 if (p->number_of_interrupts == 0)
313 return; 313 return;
314 irq = pnpacpi_kmalloc(sizeof(struct pnp_irq), GFP_KERNEL); 314 irq = kcalloc(1, sizeof(struct pnp_irq), GFP_KERNEL);
315 if (!irq) 315 if (!irq)
316 return; 316 return;
317 317
@@ -332,7 +332,7 @@ static void pnpacpi_parse_ext_irq_option(struct pnp_option *option,
332 332
333 if (p->number_of_interrupts == 0) 333 if (p->number_of_interrupts == 0)
334 return; 334 return;
335 irq = pnpacpi_kmalloc(sizeof(struct pnp_irq), GFP_KERNEL); 335 irq = kcalloc(1, sizeof(struct pnp_irq), GFP_KERNEL);
336 if (!irq) 336 if (!irq)
337 return; 337 return;
338 338
@@ -353,7 +353,7 @@ pnpacpi_parse_port_option(struct pnp_option *option,
353 353
354 if (io->range_length == 0) 354 if (io->range_length == 0)
355 return; 355 return;
356 port = pnpacpi_kmalloc(sizeof(struct pnp_port), GFP_KERNEL); 356 port = kcalloc(1, sizeof(struct pnp_port), GFP_KERNEL);
357 if (!port) 357 if (!port)
358 return; 358 return;
359 port->min = io->min_base_address; 359 port->min = io->min_base_address;
@@ -374,7 +374,7 @@ pnpacpi_parse_fixed_port_option(struct pnp_option *option,
374 374
375 if (io->range_length == 0) 375 if (io->range_length == 0)
376 return; 376 return;
377 port = pnpacpi_kmalloc(sizeof(struct pnp_port), GFP_KERNEL); 377 port = kcalloc(1, sizeof(struct pnp_port), GFP_KERNEL);
378 if (!port) 378 if (!port)
379 return; 379 return;
380 port->min = port->max = io->base_address; 380 port->min = port->max = io->base_address;
@@ -393,7 +393,7 @@ pnpacpi_parse_mem24_option(struct pnp_option *option,
393 393
394 if (p->range_length == 0) 394 if (p->range_length == 0)
395 return; 395 return;
396 mem = pnpacpi_kmalloc(sizeof(struct pnp_mem), GFP_KERNEL); 396 mem = kcalloc(1, sizeof(struct pnp_mem), GFP_KERNEL);
397 if (!mem) 397 if (!mem)
398 return; 398 return;
399 mem->min = p->min_base_address; 399 mem->min = p->min_base_address;
@@ -416,7 +416,7 @@ pnpacpi_parse_mem32_option(struct pnp_option *option,
416 416
417 if (p->range_length == 0) 417 if (p->range_length == 0)
418 return; 418 return;
419 mem = pnpacpi_kmalloc(sizeof(struct pnp_mem), GFP_KERNEL); 419 mem = kcalloc(1, sizeof(struct pnp_mem), GFP_KERNEL);
420 if (!mem) 420 if (!mem)
421 return; 421 return;
422 mem->min = p->min_base_address; 422 mem->min = p->min_base_address;
@@ -439,7 +439,7 @@ pnpacpi_parse_fixed_mem32_option(struct pnp_option *option,
439 439
440 if (p->range_length == 0) 440 if (p->range_length == 0)
441 return; 441 return;
442 mem = pnpacpi_kmalloc(sizeof(struct pnp_mem), GFP_KERNEL); 442 mem = kcalloc(1, sizeof(struct pnp_mem), GFP_KERNEL);
443 if (!mem) 443 if (!mem)
444 return; 444 return;
445 mem->min = mem->max = p->range_base_address; 445 mem->min = mem->max = p->range_base_address;
@@ -623,7 +623,7 @@ int pnpacpi_build_resource_template(acpi_handle handle,
623 if (!res_cnt) 623 if (!res_cnt)
624 return -EINVAL; 624 return -EINVAL;
625 buffer->length = sizeof(struct acpi_resource) * (res_cnt + 1) + 1; 625 buffer->length = sizeof(struct acpi_resource) * (res_cnt + 1) + 1;
626 buffer->pointer = pnpacpi_kmalloc(buffer->length - 1, GFP_KERNEL); 626 buffer->pointer = kcalloc(1, buffer->length - 1, GFP_KERNEL);
627 if (!buffer->pointer) 627 if (!buffer->pointer)
628 return -ENOMEM; 628 return -ENOMEM;
629 pnp_dbg("Res cnt %d", res_cnt); 629 pnp_dbg("Res cnt %d", res_cnt);
diff --git a/drivers/pnp/pnpbios/core.c b/drivers/pnp/pnpbios/core.c
index 778a324028f..f49674f0794 100644
--- a/drivers/pnp/pnpbios/core.c
+++ b/drivers/pnp/pnpbios/core.c
@@ -86,16 +86,6 @@ int pnp_bios_present(void)
86 86
87struct pnp_dev_node_info node_info; 87struct pnp_dev_node_info node_info;
88 88
89void *pnpbios_kmalloc(size_t size, int f)
90{
91 void *p = kmalloc( size, f );
92 if ( p == NULL )
93 printk(KERN_ERR "PnPBIOS: kmalloc() failed\n");
94 else
95 memset(p, 0, size);
96 return p;
97}
98
99/* 89/*
100 * 90 *
101 * DOCKING FUNCTIONS 91 * DOCKING FUNCTIONS
@@ -121,10 +111,10 @@ static int pnp_dock_event(int dock, struct pnp_docking_station_info *info)
121 if (!current->fs->root) { 111 if (!current->fs->root) {
122 return -EAGAIN; 112 return -EAGAIN;
123 } 113 }
124 if (!(envp = (char **) pnpbios_kmalloc (20 * sizeof (char *), GFP_KERNEL))) { 114 if (!(envp = (char **) kcalloc (20, sizeof (char *), GFP_KERNEL))) {
125 return -ENOMEM; 115 return -ENOMEM;
126 } 116 }
127 if (!(buf = pnpbios_kmalloc (256, GFP_KERNEL))) { 117 if (!(buf = kcalloc (1, 256, GFP_KERNEL))) {
128 kfree (envp); 118 kfree (envp);
129 return -ENOMEM; 119 return -ENOMEM;
130 } 120 }
@@ -231,7 +221,7 @@ static int pnpbios_get_resources(struct pnp_dev * dev, struct pnp_resource_table
231 if(!pnpbios_is_dynamic(dev)) 221 if(!pnpbios_is_dynamic(dev))
232 return -EPERM; 222 return -EPERM;
233 223
234 node = pnpbios_kmalloc(node_info.max_node_size, GFP_KERNEL); 224 node = kcalloc(1, node_info.max_node_size, GFP_KERNEL);
235 if (!node) 225 if (!node)
236 return -1; 226 return -1;
237 if (pnp_bios_get_dev_node(&nodenum, (char )PNPMODE_DYNAMIC, node)) { 227 if (pnp_bios_get_dev_node(&nodenum, (char )PNPMODE_DYNAMIC, node)) {
@@ -254,7 +244,7 @@ static int pnpbios_set_resources(struct pnp_dev * dev, struct pnp_resource_table
254 if (!pnpbios_is_dynamic(dev)) 244 if (!pnpbios_is_dynamic(dev))
255 return -EPERM; 245 return -EPERM;
256 246
257 node = pnpbios_kmalloc(node_info.max_node_size, GFP_KERNEL); 247 node = kcalloc(1, node_info.max_node_size, GFP_KERNEL);
258 if (!node) 248 if (!node)
259 return -1; 249 return -1;
260 if (pnp_bios_get_dev_node(&nodenum, (char )PNPMODE_DYNAMIC, node)) { 250 if (pnp_bios_get_dev_node(&nodenum, (char )PNPMODE_DYNAMIC, node)) {
@@ -305,7 +295,7 @@ static int pnpbios_disable_resources(struct pnp_dev *dev)
305 if(dev->flags & PNPBIOS_NO_DISABLE || !pnpbios_is_dynamic(dev)) 295 if(dev->flags & PNPBIOS_NO_DISABLE || !pnpbios_is_dynamic(dev))
306 return -EPERM; 296 return -EPERM;
307 297
308 node = pnpbios_kmalloc(node_info.max_node_size, GFP_KERNEL); 298 node = kcalloc(1, node_info.max_node_size, GFP_KERNEL);
309 if (!node) 299 if (!node)
310 return -ENOMEM; 300 return -ENOMEM;
311 301
@@ -347,7 +337,7 @@ static int insert_device(struct pnp_dev *dev, struct pnp_bios_node * node)
347 } 337 }
348 338
349 /* set the initial values for the PnP device */ 339 /* set the initial values for the PnP device */
350 dev_id = pnpbios_kmalloc(sizeof(struct pnp_id), GFP_KERNEL); 340 dev_id = kcalloc(1, sizeof(struct pnp_id), GFP_KERNEL);
351 if (!dev_id) 341 if (!dev_id)
352 return -1; 342 return -1;
353 pnpid32_to_pnpid(node->eisa_id,id); 343 pnpid32_to_pnpid(node->eisa_id,id);
@@ -385,7 +375,7 @@ static void __init build_devlist(void)
385 struct pnp_bios_node *node; 375 struct pnp_bios_node *node;
386 struct pnp_dev *dev; 376 struct pnp_dev *dev;
387 377
388 node = pnpbios_kmalloc(node_info.max_node_size, GFP_KERNEL); 378 node = kcalloc(1, node_info.max_node_size, GFP_KERNEL);
389 if (!node) 379 if (!node)
390 return; 380 return;
391 381
@@ -402,7 +392,7 @@ static void __init build_devlist(void)
402 break; 392 break;
403 } 393 }
404 nodes_got++; 394 nodes_got++;
405 dev = pnpbios_kmalloc(sizeof (struct pnp_dev), GFP_KERNEL); 395 dev = kcalloc(1, sizeof (struct pnp_dev), GFP_KERNEL);
406 if (!dev) 396 if (!dev)
407 break; 397 break;
408 if(insert_device(dev,node)<0) 398 if(insert_device(dev,node)<0)
diff --git a/drivers/pnp/pnpbios/pnpbios.h b/drivers/pnp/pnpbios/pnpbios.h
index 01896e705ed..d8cb2fd1f12 100644
--- a/drivers/pnp/pnpbios/pnpbios.h
+++ b/drivers/pnp/pnpbios/pnpbios.h
@@ -26,7 +26,6 @@ union pnp_bios_install_struct {
26 26
27extern int pnp_bios_present(void); 27extern int pnp_bios_present(void);
28extern int pnpbios_dont_use_current_config; 28extern int pnpbios_dont_use_current_config;
29extern void *pnpbios_kmalloc(size_t size, int f);
30 29
31extern int pnpbios_parse_data_stream(struct pnp_dev *dev, struct pnp_bios_node * node); 30extern int pnpbios_parse_data_stream(struct pnp_dev *dev, struct pnp_bios_node * node);
32extern int pnpbios_read_resources_from_node(struct pnp_resource_table *res, struct pnp_bios_node * node); 31extern int pnpbios_read_resources_from_node(struct pnp_resource_table *res, struct pnp_bios_node * node);
diff --git a/drivers/pnp/pnpbios/proc.c b/drivers/pnp/pnpbios/proc.c
index 6bb8e1973fd..5a3dfc97f5e 100644
--- a/drivers/pnp/pnpbios/proc.c
+++ b/drivers/pnp/pnpbios/proc.c
@@ -87,7 +87,7 @@ static int proc_read_escd(char *buf, char **start, off_t pos,
87 return -EFBIG; 87 return -EFBIG;
88 } 88 }
89 89
90 tmpbuf = pnpbios_kmalloc(escd.escd_size, GFP_KERNEL); 90 tmpbuf = kcalloc(1, escd.escd_size, GFP_KERNEL);
91 if (!tmpbuf) return -ENOMEM; 91 if (!tmpbuf) return -ENOMEM;
92 92
93 if (pnp_bios_read_escd(tmpbuf, escd.nv_storage_base)) { 93 if (pnp_bios_read_escd(tmpbuf, escd.nv_storage_base)) {
@@ -133,7 +133,7 @@ static int proc_read_devices(char *buf, char **start, off_t pos,
133 if (pos >= 0xff) 133 if (pos >= 0xff)
134 return 0; 134 return 0;
135 135
136 node = pnpbios_kmalloc(node_info.max_node_size, GFP_KERNEL); 136 node = kcalloc(1, node_info.max_node_size, GFP_KERNEL);
137 if (!node) return -ENOMEM; 137 if (!node) return -ENOMEM;
138 138
139 for (nodenum=pos; nodenum<0xff; ) { 139 for (nodenum=pos; nodenum<0xff; ) {
@@ -168,7 +168,7 @@ static int proc_read_node(char *buf, char **start, off_t pos,
168 u8 nodenum = (long)data; 168 u8 nodenum = (long)data;
169 int len; 169 int len;
170 170
171 node = pnpbios_kmalloc(node_info.max_node_size, GFP_KERNEL); 171 node = kcalloc(1, node_info.max_node_size, GFP_KERNEL);
172 if (!node) return -ENOMEM; 172 if (!node) return -ENOMEM;
173 if (pnp_bios_get_dev_node(&nodenum, boot, node)) { 173 if (pnp_bios_get_dev_node(&nodenum, boot, node)) {
174 kfree(node); 174 kfree(node);
@@ -188,7 +188,7 @@ static int proc_write_node(struct file *file, const char __user *buf,
188 u8 nodenum = (long)data; 188 u8 nodenum = (long)data;
189 int ret = count; 189 int ret = count;
190 190
191 node = pnpbios_kmalloc(node_info.max_node_size, GFP_KERNEL); 191 node = kcalloc(1, node_info.max_node_size, GFP_KERNEL);
192 if (!node) 192 if (!node)
193 return -ENOMEM; 193 return -ENOMEM;
194 if (pnp_bios_get_dev_node(&nodenum, boot, node)) { 194 if (pnp_bios_get_dev_node(&nodenum, boot, node)) {
diff --git a/drivers/pnp/pnpbios/rsparser.c b/drivers/pnp/pnpbios/rsparser.c
index e305bb132c2..b0ca65b6864 100644
--- a/drivers/pnp/pnpbios/rsparser.c
+++ b/drivers/pnp/pnpbios/rsparser.c
@@ -247,7 +247,7 @@ static void
247pnpbios_parse_mem_option(unsigned char *p, int size, struct pnp_option *option) 247pnpbios_parse_mem_option(unsigned char *p, int size, struct pnp_option *option)
248{ 248{
249 struct pnp_mem * mem; 249 struct pnp_mem * mem;
250 mem = pnpbios_kmalloc(sizeof(struct pnp_mem), GFP_KERNEL); 250 mem = kcalloc(1, sizeof(struct pnp_mem), GFP_KERNEL);
251 if (!mem) 251 if (!mem)
252 return; 252 return;
253 mem->min = ((p[5] << 8) | p[4]) << 8; 253 mem->min = ((p[5] << 8) | p[4]) << 8;
@@ -263,7 +263,7 @@ static void
263pnpbios_parse_mem32_option(unsigned char *p, int size, struct pnp_option *option) 263pnpbios_parse_mem32_option(unsigned char *p, int size, struct pnp_option *option)
264{ 264{
265 struct pnp_mem * mem; 265 struct pnp_mem * mem;
266 mem = pnpbios_kmalloc(sizeof(struct pnp_mem), GFP_KERNEL); 266 mem = kcalloc(1, sizeof(struct pnp_mem), GFP_KERNEL);
267 if (!mem) 267 if (!mem)
268 return; 268 return;
269 mem->min = (p[7] << 24) | (p[6] << 16) | (p[5] << 8) | p[4]; 269 mem->min = (p[7] << 24) | (p[6] << 16) | (p[5] << 8) | p[4];
@@ -279,7 +279,7 @@ static void
279pnpbios_parse_fixed_mem32_option(unsigned char *p, int size, struct pnp_option *option) 279pnpbios_parse_fixed_mem32_option(unsigned char *p, int size, struct pnp_option *option)
280{ 280{
281 struct pnp_mem * mem; 281 struct pnp_mem * mem;
282 mem = pnpbios_kmalloc(sizeof(struct pnp_mem), GFP_KERNEL); 282 mem = kcalloc(1, sizeof(struct pnp_mem), GFP_KERNEL);
283 if (!mem) 283 if (!mem)
284 return; 284 return;
285 mem->min = mem->max = (p[7] << 24) | (p[6] << 16) | (p[5] << 8) | p[4]; 285 mem->min = mem->max = (p[7] << 24) | (p[6] << 16) | (p[5] << 8) | p[4];
@@ -296,7 +296,7 @@ pnpbios_parse_irq_option(unsigned char *p, int size, struct pnp_option *option)
296 struct pnp_irq * irq; 296 struct pnp_irq * irq;
297 unsigned long bits; 297 unsigned long bits;
298 298
299 irq = pnpbios_kmalloc(sizeof(struct pnp_irq), GFP_KERNEL); 299 irq = kcalloc(1, sizeof(struct pnp_irq), GFP_KERNEL);
300 if (!irq) 300 if (!irq)
301 return; 301 return;
302 bits = (p[2] << 8) | p[1]; 302 bits = (p[2] << 8) | p[1];
@@ -313,7 +313,7 @@ static void
313pnpbios_parse_dma_option(unsigned char *p, int size, struct pnp_option *option) 313pnpbios_parse_dma_option(unsigned char *p, int size, struct pnp_option *option)
314{ 314{
315 struct pnp_dma * dma; 315 struct pnp_dma * dma;
316 dma = pnpbios_kmalloc(sizeof(struct pnp_dma), GFP_KERNEL); 316 dma = kcalloc(1, sizeof(struct pnp_dma), GFP_KERNEL);
317 if (!dma) 317 if (!dma)
318 return; 318 return;
319 dma->map = p[1]; 319 dma->map = p[1];
@@ -326,7 +326,7 @@ static void
326pnpbios_parse_port_option(unsigned char *p, int size, struct pnp_option *option) 326pnpbios_parse_port_option(unsigned char *p, int size, struct pnp_option *option)
327{ 327{
328 struct pnp_port * port; 328 struct pnp_port * port;
329 port = pnpbios_kmalloc(sizeof(struct pnp_port), GFP_KERNEL); 329 port = kcalloc(1, sizeof(struct pnp_port), GFP_KERNEL);
330 if (!port) 330 if (!port)
331 return; 331 return;
332 port->min = (p[3] << 8) | p[2]; 332 port->min = (p[3] << 8) | p[2];
@@ -342,7 +342,7 @@ static void
342pnpbios_parse_fixed_port_option(unsigned char *p, int size, struct pnp_option *option) 342pnpbios_parse_fixed_port_option(unsigned char *p, int size, struct pnp_option *option)
343{ 343{
344 struct pnp_port * port; 344 struct pnp_port * port;
345 port = pnpbios_kmalloc(sizeof(struct pnp_port), GFP_KERNEL); 345 port = kcalloc(1, sizeof(struct pnp_port), GFP_KERNEL);
346 if (!port) 346 if (!port)
347 return; 347 return;
348 port->min = port->max = (p[2] << 8) | p[1]; 348 port->min = port->max = (p[2] << 8) | p[1];
@@ -530,7 +530,7 @@ pnpbios_parse_compatible_ids(unsigned char *p, unsigned char *end, struct pnp_de
530 case SMALL_TAG_COMPATDEVID: /* compatible ID */ 530 case SMALL_TAG_COMPATDEVID: /* compatible ID */
531 if (len != 4) 531 if (len != 4)
532 goto len_err; 532 goto len_err;
533 dev_id = pnpbios_kmalloc(sizeof (struct pnp_id), GFP_KERNEL); 533 dev_id = kcalloc(1, sizeof (struct pnp_id), GFP_KERNEL);
534 if (!dev_id) 534 if (!dev_id)
535 return NULL; 535 return NULL;
536 memset(dev_id, 0, sizeof(struct pnp_id)); 536 memset(dev_id, 0, sizeof(struct pnp_id));
diff --git a/drivers/pnp/quirks.c b/drivers/pnp/quirks.c
index 596a02d7e03..8936b0cb2ec 100644
--- a/drivers/pnp/quirks.c
+++ b/drivers/pnp/quirks.c
@@ -16,13 +16,6 @@
16#include <linux/kernel.h> 16#include <linux/kernel.h>
17#include <linux/string.h> 17#include <linux/string.h>
18#include <linux/slab.h> 18#include <linux/slab.h>
19
20#ifdef CONFIG_PNP_DEBUG
21 #define DEBUG
22#else
23 #undef DEBUG
24#endif
25
26#include <linux/pnp.h> 19#include <linux/pnp.h>
27#include "base.h" 20#include "base.h"
28 21
diff --git a/drivers/pnp/support.c b/drivers/pnp/support.c
index b952aec4918..61fe998944b 100644
--- a/drivers/pnp/support.c
+++ b/drivers/pnp/support.c
@@ -8,13 +8,6 @@
8#include <linux/config.h> 8#include <linux/config.h>
9#include <linux/module.h> 9#include <linux/module.h>
10#include <linux/ctype.h> 10#include <linux/ctype.h>
11
12#ifdef CONFIG_PNP_DEBUG
13 #define DEBUG
14#else
15 #undef DEBUG
16#endif
17
18#include <linux/pnp.h> 11#include <linux/pnp.h>
19#include "base.h" 12#include "base.h"
20 13
diff --git a/drivers/s390/block/Kconfig b/drivers/s390/block/Kconfig
index dc1c89dbdb8..6e7d7b06421 100644
--- a/drivers/s390/block/Kconfig
+++ b/drivers/s390/block/Kconfig
@@ -49,7 +49,7 @@ config DASD_FBA
49 49
50config DASD_DIAG 50config DASD_DIAG
51 tristate "Support for DIAG access to Disks" 51 tristate "Support for DIAG access to Disks"
52 depends on DASD && ARCH_S390X = 'n' 52 depends on DASD && ( ARCH_S390X = 'n' || EXPERIMENTAL)
53 help 53 help
54 Select this option if you want to use Diagnose250 command to access 54 Select this option if you want to use Diagnose250 command to access
55 Disks under VM. If you are not running under VM or unsure what it is, 55 Disks under VM. If you are not running under VM or unsure what it is,
diff --git a/drivers/s390/block/dasd.c b/drivers/s390/block/dasd.c
index d5f53980749..8fc891a9d47 100644
--- a/drivers/s390/block/dasd.c
+++ b/drivers/s390/block/dasd.c
@@ -7,7 +7,7 @@
7 * Bugreports.to..: <Linux390@de.ibm.com> 7 * Bugreports.to..: <Linux390@de.ibm.com>
8 * (C) IBM Corporation, IBM Deutschland Entwicklung GmbH, 1999-2001 8 * (C) IBM Corporation, IBM Deutschland Entwicklung GmbH, 1999-2001
9 * 9 *
10 * $Revision: 1.165 $ 10 * $Revision: 1.167 $
11 */ 11 */
12 12
13#include <linux/config.h> 13#include <linux/config.h>
@@ -1131,17 +1131,13 @@ __dasd_process_blk_queue(struct dasd_device * device)
1131 request_queue_t *queue; 1131 request_queue_t *queue;
1132 struct request *req; 1132 struct request *req;
1133 struct dasd_ccw_req *cqr; 1133 struct dasd_ccw_req *cqr;
1134 int nr_queued, feature_ro; 1134 int nr_queued;
1135 1135
1136 queue = device->request_queue; 1136 queue = device->request_queue;
1137 /* No queue ? Then there is nothing to do. */ 1137 /* No queue ? Then there is nothing to do. */
1138 if (queue == NULL) 1138 if (queue == NULL)
1139 return; 1139 return;
1140 1140
1141 feature_ro = dasd_get_feature(device->cdev, DASD_FEATURE_READONLY);
1142 if (feature_ro < 0) /* no devmap */
1143 return;
1144
1145 /* 1141 /*
1146 * We requeue request from the block device queue to the ccw 1142 * We requeue request from the block device queue to the ccw
1147 * queue only in two states. In state DASD_STATE_READY the 1143 * queue only in two states. In state DASD_STATE_READY the
@@ -1162,7 +1158,8 @@ __dasd_process_blk_queue(struct dasd_device * device)
1162 nr_queued < DASD_CHANQ_MAX_SIZE) { 1158 nr_queued < DASD_CHANQ_MAX_SIZE) {
1163 req = elv_next_request(queue); 1159 req = elv_next_request(queue);
1164 1160
1165 if (feature_ro && rq_data_dir(req) == WRITE) { 1161 if (device->features & DASD_FEATURE_READONLY &&
1162 rq_data_dir(req) == WRITE) {
1166 DBF_DEV_EVENT(DBF_ERR, device, 1163 DBF_DEV_EVENT(DBF_ERR, device,
1167 "Rejecting write request %p", 1164 "Rejecting write request %p",
1168 req); 1165 req);
@@ -1814,17 +1811,13 @@ dasd_generic_set_online (struct ccw_device *cdev,
1814 1811
1815{ 1812{
1816 struct dasd_device *device; 1813 struct dasd_device *device;
1817 int feature_diag, rc; 1814 int rc;
1818 1815
1819 device = dasd_create_device(cdev); 1816 device = dasd_create_device(cdev);
1820 if (IS_ERR(device)) 1817 if (IS_ERR(device))
1821 return PTR_ERR(device); 1818 return PTR_ERR(device);
1822 1819
1823 feature_diag = dasd_get_feature(cdev, DASD_FEATURE_USEDIAG); 1820 if (device->features & DASD_FEATURE_USEDIAG) {
1824 if (feature_diag < 0)
1825 return feature_diag;
1826
1827 if (feature_diag) {
1828 if (!dasd_diag_discipline_pointer) { 1821 if (!dasd_diag_discipline_pointer) {
1829 printk (KERN_WARNING 1822 printk (KERN_WARNING
1830 "dasd_generic couldn't online device %s " 1823 "dasd_generic couldn't online device %s "
diff --git a/drivers/s390/block/dasd_devmap.c b/drivers/s390/block/dasd_devmap.c
index d948566bb24..bda896d9d78 100644
--- a/drivers/s390/block/dasd_devmap.c
+++ b/drivers/s390/block/dasd_devmap.c
@@ -11,7 +11,7 @@
11 * functions may not be called from interrupt context. In particular 11 * functions may not be called from interrupt context. In particular
12 * dasd_get_device is a no-no from interrupt context. 12 * dasd_get_device is a no-no from interrupt context.
13 * 13 *
14 * $Revision: 1.40 $ 14 * $Revision: 1.43 $
15 */ 15 */
16 16
17#include <linux/config.h> 17#include <linux/config.h>
@@ -513,6 +513,7 @@ dasd_create_device(struct ccw_device *cdev)
513 if (!devmap->device) { 513 if (!devmap->device) {
514 devmap->device = device; 514 devmap->device = device;
515 device->devindex = devmap->devindex; 515 device->devindex = devmap->devindex;
516 device->features = devmap->features;
516 get_device(&cdev->dev); 517 get_device(&cdev->dev);
517 device->cdev = cdev; 518 device->cdev = cdev;
518 rc = 0; 519 rc = 0;
@@ -643,6 +644,8 @@ dasd_ro_store(struct device *dev, struct device_attribute *attr, const char *buf
643 devmap->features |= DASD_FEATURE_READONLY; 644 devmap->features |= DASD_FEATURE_READONLY;
644 else 645 else
645 devmap->features &= ~DASD_FEATURE_READONLY; 646 devmap->features &= ~DASD_FEATURE_READONLY;
647 if (devmap->device)
648 devmap->device->features = devmap->features;
646 if (devmap->device && devmap->device->gdp) 649 if (devmap->device && devmap->device->gdp)
647 set_disk_ro(devmap->device->gdp, ro_flag); 650 set_disk_ro(devmap->device->gdp, ro_flag);
648 spin_unlock(&dasd_devmap_lock); 651 spin_unlock(&dasd_devmap_lock);
@@ -758,7 +761,8 @@ dasd_set_feature(struct ccw_device *cdev, int feature, int flag)
758 devmap->features |= feature; 761 devmap->features |= feature;
759 else 762 else
760 devmap->features &= ~feature; 763 devmap->features &= ~feature;
761 764 if (devmap->device)
765 devmap->device->features = devmap->features;
762 spin_unlock(&dasd_devmap_lock); 766 spin_unlock(&dasd_devmap_lock);
763 return 0; 767 return 0;
764} 768}
diff --git a/drivers/s390/block/dasd_diag.c b/drivers/s390/block/dasd_diag.c
index 127699830fa..7478423b53b 100644
--- a/drivers/s390/block/dasd_diag.c
+++ b/drivers/s390/block/dasd_diag.c
@@ -6,17 +6,18 @@
6 * Bugreports.to..: <Linux390@de.ibm.com> 6 * Bugreports.to..: <Linux390@de.ibm.com>
7 * (C) IBM Corporation, IBM Deutschland Entwicklung GmbH, 1999,2000 7 * (C) IBM Corporation, IBM Deutschland Entwicklung GmbH, 1999,2000
8 * 8 *
9 * $Revision: 1.42 $ 9 * $Revision: 1.49 $
10 */ 10 */
11 11
12#include <linux/config.h> 12#include <linux/config.h>
13#include <linux/stddef.h> 13#include <linux/stddef.h>
14#include <linux/kernel.h> 14#include <linux/kernel.h>
15#include <linux/slab.h> 15#include <linux/slab.h>
16#include <linux/hdreg.h> /* HDIO_GETGEO */ 16#include <linux/hdreg.h>
17#include <linux/bio.h> 17#include <linux/bio.h>
18#include <linux/module.h> 18#include <linux/module.h>
19#include <linux/init.h> 19#include <linux/init.h>
20#include <linux/jiffies.h>
20 21
21#include <asm/dasd.h> 22#include <asm/dasd.h>
22#include <asm/debug.h> 23#include <asm/debug.h>
@@ -28,58 +29,89 @@
28#include "dasd_int.h" 29#include "dasd_int.h"
29#include "dasd_diag.h" 30#include "dasd_diag.h"
30 31
31#ifdef PRINTK_HEADER
32#undef PRINTK_HEADER
33#endif /* PRINTK_HEADER */
34#define PRINTK_HEADER "dasd(diag):" 32#define PRINTK_HEADER "dasd(diag):"
35 33
36MODULE_LICENSE("GPL"); 34MODULE_LICENSE("GPL");
37 35
36/* The maximum number of blocks per request (max_blocks) is dependent on the
37 * amount of storage that is available in the static I/O buffer for each
38 * device. Currently each device gets 2 pages. We want to fit two requests
39 * into the available memory so that we can immediately start the next if one
40 * finishes. */
41#define DIAG_MAX_BLOCKS (((2 * PAGE_SIZE - sizeof(struct dasd_ccw_req) - \
42 sizeof(struct dasd_diag_req)) / \
43 sizeof(struct dasd_diag_bio)) / 2)
44#define DIAG_MAX_RETRIES 32
45#define DIAG_TIMEOUT 50 * HZ
46
38struct dasd_discipline dasd_diag_discipline; 47struct dasd_discipline dasd_diag_discipline;
39 48
40struct dasd_diag_private { 49struct dasd_diag_private {
41 struct dasd_diag_characteristics rdc_data; 50 struct dasd_diag_characteristics rdc_data;
42 struct dasd_diag_rw_io iob; 51 struct dasd_diag_rw_io iob;
43 struct dasd_diag_init_io iib; 52 struct dasd_diag_init_io iib;
44 unsigned int pt_block; 53 blocknum_t pt_block;
45}; 54};
46 55
47struct dasd_diag_req { 56struct dasd_diag_req {
48 int block_count; 57 unsigned int block_count;
49 struct dasd_diag_bio bio[0]; 58 struct dasd_diag_bio bio[0];
50}; 59};
51 60
61static const u8 DASD_DIAG_CMS1[] = { 0xc3, 0xd4, 0xe2, 0xf1 };/* EBCDIC CMS1 */
62
63/* Perform DIAG250 call with block I/O parameter list iob (input and output)
64 * and function code cmd.
65 * In case of an exception return 3. Otherwise return result of bitwise OR of
66 * resulting condition code and DIAG return code. */
52static __inline__ int 67static __inline__ int
53dia250(void *iob, int cmd) 68dia250(void *iob, int cmd)
54{ 69{
70 typedef struct {
71 char _[max(sizeof (struct dasd_diag_init_io),
72 sizeof (struct dasd_diag_rw_io))];
73 } addr_type;
55 int rc; 74 int rc;
56 75
57 __asm__ __volatile__(" lhi %0,3\n" 76 __asm__ __volatile__(
58 " lr 0,%2\n" 77#ifdef CONFIG_ARCH_S390X
59 " diag 0,%1,0x250\n" 78 " lghi %0,3\n"
60 "0: ipm %0\n" 79 " lgr 0,%3\n"
61 " srl %0,28\n" 80 " diag 0,%2,0x250\n"
62 " or %0,1\n" 81 "0: ipm %0\n"
63 "1:\n" 82 " srl %0,28\n"
64#ifndef CONFIG_ARCH_S390X 83 " or %0,1\n"
65 ".section __ex_table,\"a\"\n" 84 "1:\n"
66 " .align 4\n" 85 ".section __ex_table,\"a\"\n"
67 " .long 0b,1b\n" 86 " .align 8\n"
68 ".previous\n" 87 " .quad 0b,1b\n"
88 ".previous\n"
69#else 89#else
70 ".section __ex_table,\"a\"\n" 90 " lhi %0,3\n"
71 " .align 8\n" 91 " lr 0,%3\n"
72 " .quad 0b,1b\n" 92 " diag 0,%2,0x250\n"
73 ".previous\n" 93 "0: ipm %0\n"
94 " srl %0,28\n"
95 " or %0,1\n"
96 "1:\n"
97 ".section __ex_table,\"a\"\n"
98 " .align 4\n"
99 " .long 0b,1b\n"
100 ".previous\n"
74#endif 101#endif
75 : "=&d" (rc) 102 : "=&d" (rc), "=m" (*(addr_type *) iob)
76 : "d" (cmd), "d" ((void *) __pa(iob)) 103 : "d" (cmd), "d" (iob), "m" (*(addr_type *) iob)
77 : "0", "1", "cc"); 104 : "0", "1", "cc");
78 return rc; 105 return rc;
79} 106}
80 107
108/* Initialize block I/O to DIAG device using the specified blocksize and
109 * block offset. On success, return zero and set end_block to contain the
110 * number of blocks on the device minus the specified offset. Return non-zero
111 * otherwise. */
81static __inline__ int 112static __inline__ int
82mdsk_init_io(struct dasd_device * device, int blocksize, int offset, int size) 113mdsk_init_io(struct dasd_device *device, unsigned int blocksize,
114 blocknum_t offset, blocknum_t *end_block)
83{ 115{
84 struct dasd_diag_private *private; 116 struct dasd_diag_private *private;
85 struct dasd_diag_init_io *iib; 117 struct dasd_diag_init_io *iib;
@@ -92,14 +124,18 @@ mdsk_init_io(struct dasd_device * device, int blocksize, int offset, int size)
92 iib->dev_nr = _ccw_device_get_device_number(device->cdev); 124 iib->dev_nr = _ccw_device_get_device_number(device->cdev);
93 iib->block_size = blocksize; 125 iib->block_size = blocksize;
94 iib->offset = offset; 126 iib->offset = offset;
95 iib->start_block = 0; 127 iib->flaga = DASD_DIAG_FLAGA_DEFAULT;
96 iib->end_block = size;
97 128
98 rc = dia250(iib, INIT_BIO); 129 rc = dia250(iib, INIT_BIO);
99 130
100 return rc & 3; 131 if ((rc & 3) == 0 && end_block)
132 *end_block = iib->end_block;
133
134 return rc;
101} 135}
102 136
137/* Remove block I/O environment for device. Return zero on success, non-zero
138 * otherwise. */
103static __inline__ int 139static __inline__ int
104mdsk_term_io(struct dasd_device * device) 140mdsk_term_io(struct dasd_device * device)
105{ 141{
@@ -112,9 +148,25 @@ mdsk_term_io(struct dasd_device * device)
112 memset(iib, 0, sizeof (struct dasd_diag_init_io)); 148 memset(iib, 0, sizeof (struct dasd_diag_init_io));
113 iib->dev_nr = _ccw_device_get_device_number(device->cdev); 149 iib->dev_nr = _ccw_device_get_device_number(device->cdev);
114 rc = dia250(iib, TERM_BIO); 150 rc = dia250(iib, TERM_BIO);
115 return rc & 3; 151 return rc;
152}
153
154/* Error recovery for failed DIAG requests - try to reestablish the DIAG
155 * environment. */
156static void
157dasd_diag_erp(struct dasd_device *device)
158{
159 int rc;
160
161 mdsk_term_io(device);
162 rc = mdsk_init_io(device, device->bp_block, 0, NULL);
163 if (rc)
164 DEV_MESSAGE(KERN_WARNING, device, "DIAG ERP unsuccessful, "
165 "rc=%d", rc);
116} 166}
117 167
168/* Start a given request at the device. Return zero on success, non-zero
169 * otherwise. */
118static int 170static int
119dasd_start_diag(struct dasd_ccw_req * cqr) 171dasd_start_diag(struct dasd_ccw_req * cqr)
120{ 172{
@@ -124,32 +176,66 @@ dasd_start_diag(struct dasd_ccw_req * cqr)
124 int rc; 176 int rc;
125 177
126 device = cqr->device; 178 device = cqr->device;
179 if (cqr->retries < 0) {
180 DEV_MESSAGE(KERN_WARNING, device, "DIAG start_IO: request %p "
181 "- no retry left)", cqr);
182 cqr->status = DASD_CQR_FAILED;
183 return -EIO;
184 }
127 private = (struct dasd_diag_private *) device->private; 185 private = (struct dasd_diag_private *) device->private;
128 dreq = (struct dasd_diag_req *) cqr->data; 186 dreq = (struct dasd_diag_req *) cqr->data;
129 187
130 private->iob.dev_nr = _ccw_device_get_device_number(device->cdev); 188 private->iob.dev_nr = _ccw_device_get_device_number(device->cdev);
131 private->iob.key = 0; 189 private->iob.key = 0;
132 private->iob.flags = 2; /* do asynchronous io */ 190 private->iob.flags = DASD_DIAG_RWFLAG_ASYNC;
133 private->iob.block_count = dreq->block_count; 191 private->iob.block_count = dreq->block_count;
134 private->iob.interrupt_params = (u32)(addr_t) cqr; 192 private->iob.interrupt_params = (addr_t) cqr;
135 private->iob.bio_list = __pa(dreq->bio); 193 private->iob.bio_list = __pa(dreq->bio);
194 private->iob.flaga = DASD_DIAG_FLAGA_DEFAULT;
136 195
137 cqr->startclk = get_clock(); 196 cqr->startclk = get_clock();
197 cqr->starttime = jiffies;
198 cqr->retries--;
138 199
139 rc = dia250(&private->iob, RW_BIO); 200 rc = dia250(&private->iob, RW_BIO);
140 if (rc > 8) { 201 switch (rc) {
141 DEV_MESSAGE(KERN_WARNING, device, "dia250 returned CC %d", rc); 202 case 0: /* Synchronous I/O finished successfully */
142 cqr->status = DASD_CQR_ERROR; 203 cqr->stopclk = get_clock();
143 } else if (rc == 0) {
144 cqr->status = DASD_CQR_DONE; 204 cqr->status = DASD_CQR_DONE;
145 dasd_schedule_bh(device); 205 /* Indicate to calling function that only a dasd_schedule_bh()
146 } else { 206 and no timer is needed */
207 rc = -EACCES;
208 break;
209 case 8: /* Asynchronous I/O was started */
147 cqr->status = DASD_CQR_IN_IO; 210 cqr->status = DASD_CQR_IN_IO;
148 rc = 0; 211 rc = 0;
212 break;
213 default: /* Error condition */
214 cqr->status = DASD_CQR_QUEUED;
215 DEV_MESSAGE(KERN_WARNING, device, "dia250 returned rc=%d", rc);
216 dasd_diag_erp(device);
217 rc = -EIO;
218 break;
149 } 219 }
150 return rc; 220 return rc;
151} 221}
152 222
223/* Terminate given request at the device. */
224static int
225dasd_diag_term_IO(struct dasd_ccw_req * cqr)
226{
227 struct dasd_device *device;
228
229 device = cqr->device;
230 mdsk_term_io(device);
231 mdsk_init_io(device, device->bp_block, 0, NULL);
232 cqr->status = DASD_CQR_CLEAR;
233 cqr->stopclk = get_clock();
234 dasd_schedule_bh(device);
235 return 0;
236}
237
238/* Handle external interruption. */
153static void 239static void
154dasd_ext_handler(struct pt_regs *regs, __u16 code) 240dasd_ext_handler(struct pt_regs *regs, __u16 code)
155{ 241{
@@ -157,25 +243,27 @@ dasd_ext_handler(struct pt_regs *regs, __u16 code)
157 struct dasd_device *device; 243 struct dasd_device *device;
158 unsigned long long expires; 244 unsigned long long expires;
159 unsigned long flags; 245 unsigned long flags;
160 char status; 246 u8 int_code, status;
161 int ip; 247 addr_t ip;
162 248 int rc;
163 /*
164 * Get the external interruption subcode. VM stores
165 * this in the 'cpu address' field associated with
166 * the external interrupt. For diag 250 the subcode
167 * needs to be 3.
168 */
169 if ((S390_lowcore.cpu_addr & 0xff00) != 0x0300)
170 return;
171 status = *((char *) &S390_lowcore.ext_params + 5);
172 ip = S390_lowcore.ext_params;
173 249
250 int_code = *((u8 *) DASD_DIAG_LC_INT_CODE);
251 status = *((u8 *) DASD_DIAG_LC_INT_STATUS);
252 switch (int_code) {
253 case DASD_DIAG_CODE_31BIT:
254 ip = (addr_t) *((u32 *) DASD_DIAG_LC_INT_PARM_31BIT);
255 break;
256 case DASD_DIAG_CODE_64BIT:
257 ip = (addr_t) *((u64 *) DASD_DIAG_LC_INT_PARM_64BIT);
258 break;
259 default:
260 return;
261 }
174 if (!ip) { /* no intparm: unsolicited interrupt */ 262 if (!ip) { /* no intparm: unsolicited interrupt */
175 MESSAGE(KERN_DEBUG, "%s", "caught unsolicited interrupt"); 263 MESSAGE(KERN_DEBUG, "%s", "caught unsolicited interrupt");
176 return; 264 return;
177 } 265 }
178 cqr = (struct dasd_ccw_req *)(addr_t) ip; 266 cqr = (struct dasd_ccw_req *) ip;
179 device = (struct dasd_device *) cqr->device; 267 device = (struct dasd_device *) cqr->device;
180 if (strncmp(device->discipline->ebcname, (char *) &cqr->magic, 4)) { 268 if (strncmp(device->discipline->ebcname, (char *) &cqr->magic, 4)) {
181 DEV_MESSAGE(KERN_WARNING, device, 269 DEV_MESSAGE(KERN_WARNING, device,
@@ -188,6 +276,15 @@ dasd_ext_handler(struct pt_regs *regs, __u16 code)
188 /* get irq lock to modify request queue */ 276 /* get irq lock to modify request queue */
189 spin_lock_irqsave(get_ccwdev_lock(device->cdev), flags); 277 spin_lock_irqsave(get_ccwdev_lock(device->cdev), flags);
190 278
279 /* Check for a pending clear operation */
280 if (cqr->status == DASD_CQR_CLEAR) {
281 cqr->status = DASD_CQR_QUEUED;
282 dasd_clear_timer(device);
283 dasd_schedule_bh(device);
284 spin_unlock_irqrestore(get_ccwdev_lock(device->cdev), flags);
285 return;
286 }
287
191 cqr->stopclk = get_clock(); 288 cqr->stopclk = get_clock();
192 289
193 expires = 0; 290 expires = 0;
@@ -198,16 +295,22 @@ dasd_ext_handler(struct pt_regs *regs, __u16 code)
198 next = list_entry(device->ccw_queue.next, 295 next = list_entry(device->ccw_queue.next,
199 struct dasd_ccw_req, list); 296 struct dasd_ccw_req, list);
200 if (next->status == DASD_CQR_QUEUED) { 297 if (next->status == DASD_CQR_QUEUED) {
201 if (dasd_start_diag(next) == 0) 298 rc = dasd_start_diag(next);
299 if (rc == 0)
202 expires = next->expires; 300 expires = next->expires;
203 else 301 else if (rc != -EACCES)
204 DEV_MESSAGE(KERN_WARNING, device, "%s", 302 DEV_MESSAGE(KERN_WARNING, device, "%s",
205 "Interrupt fastpath " 303 "Interrupt fastpath "
206 "failed!"); 304 "failed!");
207 } 305 }
208 } 306 }
209 } else 307 } else {
210 cqr->status = DASD_CQR_FAILED; 308 cqr->status = DASD_CQR_QUEUED;
309 DEV_MESSAGE(KERN_WARNING, device, "interrupt status for "
310 "request %p was %d (%d retries left)", cqr, status,
311 cqr->retries);
312 dasd_diag_erp(device);
313 }
211 314
212 if (expires != 0) 315 if (expires != 0)
213 dasd_set_timer(device, expires); 316 dasd_set_timer(device, expires);
@@ -218,14 +321,17 @@ dasd_ext_handler(struct pt_regs *regs, __u16 code)
218 spin_unlock_irqrestore(get_ccwdev_lock(device->cdev), flags); 321 spin_unlock_irqrestore(get_ccwdev_lock(device->cdev), flags);
219} 322}
220 323
324/* Check whether device can be controlled by DIAG discipline. Return zero on
325 * success, non-zero otherwise. */
221static int 326static int
222dasd_diag_check_device(struct dasd_device *device) 327dasd_diag_check_device(struct dasd_device *device)
223{ 328{
224 struct dasd_diag_private *private; 329 struct dasd_diag_private *private;
225 struct dasd_diag_characteristics *rdc_data; 330 struct dasd_diag_characteristics *rdc_data;
226 struct dasd_diag_bio bio; 331 struct dasd_diag_bio bio;
227 long *label; 332 struct dasd_diag_cms_label *label;
228 int sb, bsize; 333 blocknum_t end_block;
334 unsigned int sb, bsize;
229 int rc; 335 int rc;
230 336
231 private = (struct dasd_diag_private *) device->private; 337 private = (struct dasd_diag_private *) device->private;
@@ -244,8 +350,11 @@ dasd_diag_check_device(struct dasd_device *device)
244 rdc_data->rdc_len = sizeof (struct dasd_diag_characteristics); 350 rdc_data->rdc_len = sizeof (struct dasd_diag_characteristics);
245 351
246 rc = diag210((struct diag210 *) rdc_data); 352 rc = diag210((struct diag210 *) rdc_data);
247 if (rc) 353 if (rc) {
354 DEV_MESSAGE(KERN_WARNING, device, "failed to retrieve device "
355 "information (rc=%d)", rc);
248 return -ENOTSUPP; 356 return -ENOTSUPP;
357 }
249 358
250 /* Figure out position of label block */ 359 /* Figure out position of label block */
251 switch (private->rdc_data.vdev_class) { 360 switch (private->rdc_data.vdev_class) {
@@ -256,6 +365,8 @@ dasd_diag_check_device(struct dasd_device *device)
256 private->pt_block = 2; 365 private->pt_block = 2;
257 break; 366 break;
258 default: 367 default:
368 DEV_MESSAGE(KERN_WARNING, device, "unsupported device class "
369 "(class=%d)", private->rdc_data.vdev_class);
259 return -ENOTSUPP; 370 return -ENOTSUPP;
260 } 371 }
261 372
@@ -269,15 +380,17 @@ dasd_diag_check_device(struct dasd_device *device)
269 mdsk_term_io(device); 380 mdsk_term_io(device);
270 381
271 /* figure out blocksize of device */ 382 /* figure out blocksize of device */
272 label = (long *) get_zeroed_page(GFP_KERNEL); 383 label = (struct dasd_diag_cms_label *) get_zeroed_page(GFP_KERNEL);
273 if (label == NULL) { 384 if (label == NULL) {
274 DEV_MESSAGE(KERN_WARNING, device, "%s", 385 DEV_MESSAGE(KERN_WARNING, device, "%s",
275 "No memory to allocate initialization request"); 386 "No memory to allocate initialization request");
276 return -ENOMEM; 387 return -ENOMEM;
277 } 388 }
389 rc = 0;
390 end_block = 0;
278 /* try all sizes - needed for ECKD devices */ 391 /* try all sizes - needed for ECKD devices */
279 for (bsize = 512; bsize <= PAGE_SIZE; bsize <<= 1) { 392 for (bsize = 512; bsize <= PAGE_SIZE; bsize <<= 1) {
280 mdsk_init_io(device, bsize, 0, 64); 393 mdsk_init_io(device, bsize, 0, &end_block);
281 memset(&bio, 0, sizeof (struct dasd_diag_bio)); 394 memset(&bio, 0, sizeof (struct dasd_diag_bio));
282 bio.type = MDSK_READ_REQ; 395 bio.type = MDSK_READ_REQ;
283 bio.block_number = private->pt_block + 1; 396 bio.block_number = private->pt_block + 1;
@@ -289,37 +402,45 @@ dasd_diag_check_device(struct dasd_device *device)
289 private->iob.block_count = 1; 402 private->iob.block_count = 1;
290 private->iob.interrupt_params = 0; 403 private->iob.interrupt_params = 0;
291 private->iob.bio_list = __pa(&bio); 404 private->iob.bio_list = __pa(&bio);
292 if (dia250(&private->iob, RW_BIO) == 0) 405 private->iob.flaga = DASD_DIAG_FLAGA_DEFAULT;
406 rc = dia250(&private->iob, RW_BIO);
407 if (rc == 0 || rc == 3)
293 break; 408 break;
294 mdsk_term_io(device); 409 mdsk_term_io(device);
295 } 410 }
296 if (bsize <= PAGE_SIZE && label[0] == 0xc3d4e2f1) { 411 if (rc == 3) {
297 /* get formatted blocksize from label block */ 412 DEV_MESSAGE(KERN_WARNING, device, "%s", "DIAG call failed");
298 bsize = (int) label[3]; 413 rc = -EOPNOTSUPP;
299 device->blocks = label[7]; 414 } else if (rc != 0) {
415 DEV_MESSAGE(KERN_WARNING, device, "device access failed "
416 "(rc=%d)", rc);
417 rc = -EIO;
418 } else {
419 if (memcmp(label->label_id, DASD_DIAG_CMS1,
420 sizeof(DASD_DIAG_CMS1)) == 0) {
421 /* get formatted blocksize from label block */
422 bsize = (unsigned int) label->block_size;
423 device->blocks = (unsigned long) label->block_count;
424 } else
425 device->blocks = end_block;
300 device->bp_block = bsize; 426 device->bp_block = bsize;
301 device->s2b_shift = 0; /* bits to shift 512 to get a block */ 427 device->s2b_shift = 0; /* bits to shift 512 to get a block */
302 for (sb = 512; sb < bsize; sb = sb << 1) 428 for (sb = 512; sb < bsize; sb = sb << 1)
303 device->s2b_shift++; 429 device->s2b_shift++;
304 430
305 DEV_MESSAGE(KERN_INFO, device, 431 DEV_MESSAGE(KERN_INFO, device,
306 "capacity (%dkB blks): %ldkB", 432 "(%ld B/blk): %ldkB",
307 (device->bp_block >> 10), 433 (unsigned long) device->bp_block,
308 (device->blocks << device->s2b_shift) >> 1); 434 (unsigned long) (device->blocks <<
435 device->s2b_shift) >> 1);
309 rc = 0; 436 rc = 0;
310 } else {
311 if (bsize > PAGE_SIZE)
312 DEV_MESSAGE(KERN_WARNING, device, "%s",
313 "DIAG access failed");
314 else
315 DEV_MESSAGE(KERN_WARNING, device, "%s",
316 "volume is not CMS formatted");
317 rc = -EMEDIUMTYPE;
318 } 437 }
319 free_page((long) label); 438 free_page((long) label);
320 return rc; 439 return rc;
321} 440}
322 441
442/* Fill in virtual disk geometry for device. Return zero on success, non-zero
443 * otherwise. */
323static int 444static int
324dasd_diag_fill_geometry(struct dasd_device *device, struct hd_geometry *geo) 445dasd_diag_fill_geometry(struct dasd_device *device, struct hd_geometry *geo)
325{ 446{
@@ -349,6 +470,8 @@ dasd_diag_erp_postaction(struct dasd_ccw_req * cqr)
349 return dasd_default_erp_postaction; 470 return dasd_default_erp_postaction;
350} 471}
351 472
473/* Create DASD request from block device request. Return pointer to new
474 * request on success, ERR_PTR otherwise. */
352static struct dasd_ccw_req * 475static struct dasd_ccw_req *
353dasd_diag_build_cp(struct dasd_device * device, struct request *req) 476dasd_diag_build_cp(struct dasd_device * device, struct request *req)
354{ 477{
@@ -358,9 +481,9 @@ dasd_diag_build_cp(struct dasd_device * device, struct request *req)
358 struct bio *bio; 481 struct bio *bio;
359 struct bio_vec *bv; 482 struct bio_vec *bv;
360 char *dst; 483 char *dst;
361 int count, datasize; 484 unsigned int count, datasize;
362 sector_t recid, first_rec, last_rec; 485 sector_t recid, first_rec, last_rec;
363 unsigned blksize, off; 486 unsigned int blksize, off;
364 unsigned char rw_cmd; 487 unsigned char rw_cmd;
365 int i; 488 int i;
366 489
@@ -413,13 +536,16 @@ dasd_diag_build_cp(struct dasd_device * device, struct request *req)
413 } 536 }
414 } 537 }
415 } 538 }
539 cqr->retries = DIAG_MAX_RETRIES;
416 cqr->buildclk = get_clock(); 540 cqr->buildclk = get_clock();
417 cqr->device = device; 541 cqr->device = device;
418 cqr->expires = 50 * HZ; /* 50 seconds */ 542 cqr->expires = DIAG_TIMEOUT;
419 cqr->status = DASD_CQR_FILLED; 543 cqr->status = DASD_CQR_FILLED;
420 return cqr; 544 return cqr;
421} 545}
422 546
547/* Release DASD request. Return non-zero if request was successful, zero
548 * otherwise. */
423static int 549static int
424dasd_diag_free_cp(struct dasd_ccw_req *cqr, struct request *req) 550dasd_diag_free_cp(struct dasd_ccw_req *cqr, struct request *req)
425{ 551{
@@ -430,6 +556,7 @@ dasd_diag_free_cp(struct dasd_ccw_req *cqr, struct request *req)
430 return status; 556 return status;
431} 557}
432 558
559/* Fill in IOCTL data for device. */
433static int 560static int
434dasd_diag_fill_info(struct dasd_device * device, 561dasd_diag_fill_info(struct dasd_device * device,
435 struct dasd_information2_t * info) 562 struct dasd_information2_t * info)
@@ -437,7 +564,7 @@ dasd_diag_fill_info(struct dasd_device * device,
437 struct dasd_diag_private *private; 564 struct dasd_diag_private *private;
438 565
439 private = (struct dasd_diag_private *) device->private; 566 private = (struct dasd_diag_private *) device->private;
440 info->label_block = private->pt_block; 567 info->label_block = (unsigned int) private->pt_block;
441 info->FBA_layout = 1; 568 info->FBA_layout = 1;
442 info->format = DASD_FORMAT_LDL; 569 info->format = DASD_FORMAT_LDL;
443 info->characteristics_size = sizeof (struct dasd_diag_characteristics); 570 info->characteristics_size = sizeof (struct dasd_diag_characteristics);
@@ -456,26 +583,15 @@ dasd_diag_dump_sense(struct dasd_device *device, struct dasd_ccw_req * req,
456 "dump sense not available for DIAG data"); 583 "dump sense not available for DIAG data");
457} 584}
458 585
459/*
460 * max_blocks is dependent on the amount of storage that is available
461 * in the static io buffer for each device. Currently each device has
462 * 8192 bytes (=2 pages). dasd diag is only relevant for 31 bit.
463 * The struct dasd_ccw_req has 96 bytes, the struct dasd_diag_req has
464 * 8 bytes and the struct dasd_diag_bio for each block has 16 bytes.
465 * That makes:
466 * (8192 - 96 - 8) / 16 = 505.5 blocks at maximum.
467 * We want to fit two into the available memory so that we can immediately
468 * start the next request if one finishes off. That makes 252.75 blocks
469 * for one request. Give a little safety and the result is 240.
470 */
471struct dasd_discipline dasd_diag_discipline = { 586struct dasd_discipline dasd_diag_discipline = {
472 .owner = THIS_MODULE, 587 .owner = THIS_MODULE,
473 .name = "DIAG", 588 .name = "DIAG",
474 .ebcname = "DIAG", 589 .ebcname = "DIAG",
475 .max_blocks = 240, 590 .max_blocks = DIAG_MAX_BLOCKS,
476 .check_device = dasd_diag_check_device, 591 .check_device = dasd_diag_check_device,
477 .fill_geometry = dasd_diag_fill_geometry, 592 .fill_geometry = dasd_diag_fill_geometry,
478 .start_IO = dasd_start_diag, 593 .start_IO = dasd_start_diag,
594 .term_IO = dasd_diag_term_IO,
479 .examine_error = dasd_diag_examine_error, 595 .examine_error = dasd_diag_examine_error,
480 .erp_action = dasd_diag_erp_action, 596 .erp_action = dasd_diag_erp_action,
481 .erp_postaction = dasd_diag_erp_postaction, 597 .erp_postaction = dasd_diag_erp_postaction,
@@ -493,7 +609,7 @@ dasd_diag_init(void)
493 "Machine is not VM: %s " 609 "Machine is not VM: %s "
494 "discipline not initializing", 610 "discipline not initializing",
495 dasd_diag_discipline.name); 611 dasd_diag_discipline.name);
496 return -EINVAL; 612 return -ENODEV;
497 } 613 }
498 ASCEBC(dasd_diag_discipline.ebcname, 4); 614 ASCEBC(dasd_diag_discipline.ebcname, 4);
499 615
@@ -506,13 +622,6 @@ dasd_diag_init(void)
506static void __exit 622static void __exit
507dasd_diag_cleanup(void) 623dasd_diag_cleanup(void)
508{ 624{
509 if (!MACHINE_IS_VM) {
510 MESSAGE_LOG(KERN_INFO,
511 "Machine is not VM: %s "
512 "discipline not cleaned",
513 dasd_diag_discipline.name);
514 return;
515 }
516 unregister_external_interrupt(0x2603, dasd_ext_handler); 625 unregister_external_interrupt(0x2603, dasd_ext_handler);
517 ctl_clear_bit(0, 9); 626 ctl_clear_bit(0, 9);
518 dasd_diag_discipline_pointer = NULL; 627 dasd_diag_discipline_pointer = NULL;
@@ -520,22 +629,3 @@ dasd_diag_cleanup(void)
520 629
521module_init(dasd_diag_init); 630module_init(dasd_diag_init);
522module_exit(dasd_diag_cleanup); 631module_exit(dasd_diag_cleanup);
523
524/*
525 * Overrides for Emacs so that we follow Linus's tabbing style.
526 * Emacs will notice this stuff at the end of the file and automatically
527 * adjust the settings for this buffer only. This must remain at the end
528 * of the file.
529 * ---------------------------------------------------------------------------
530 * Local variables:
531 * c-indent-level: 4
532 * c-brace-imaginary-offset: 0
533 * c-brace-offset: -4
534 * c-argdecl-indent: 4
535 * c-label-offset: -4
536 * c-continued-statement-offset: 4
537 * c-continued-brace-offset: 0
538 * indent-tabs-mode: 1
539 * tab-width: 8
540 * End:
541 */
diff --git a/drivers/s390/block/dasd_diag.h b/drivers/s390/block/dasd_diag.h
index a0c38e30397..b26eb28df4b 100644
--- a/drivers/s390/block/dasd_diag.h
+++ b/drivers/s390/block/dasd_diag.h
@@ -6,7 +6,7 @@
6 * Bugreports.to..: <Linux390@de.ibm.com> 6 * Bugreports.to..: <Linux390@de.ibm.com>
7 * (C) IBM Corporation, IBM Deutschland Entwicklung GmbH, 1999,2000 7 * (C) IBM Corporation, IBM Deutschland Entwicklung GmbH, 1999,2000
8 * 8 *
9 * $Revision: 1.6 $ 9 * $Revision: 1.7 $
10 */ 10 */
11 11
12#define MDSK_WRITE_REQ 0x01 12#define MDSK_WRITE_REQ 0x01
@@ -19,6 +19,18 @@
19#define DEV_CLASS_FBA 0x01 19#define DEV_CLASS_FBA 0x01
20#define DEV_CLASS_ECKD 0x04 20#define DEV_CLASS_ECKD 0x04
21 21
22#define DASD_DIAG_LC_INT_CODE 132
23#define DASD_DIAG_LC_INT_STATUS 133
24#define DASD_DIAG_LC_INT_PARM_31BIT 128
25#define DASD_DIAG_LC_INT_PARM_64BIT 4536
26#define DASD_DIAG_CODE_31BIT 0x03
27#define DASD_DIAG_CODE_64BIT 0x07
28
29#define DASD_DIAG_RWFLAG_ASYNC 0x02
30#define DASD_DIAG_RWFLAG_NOCACHE 0x01
31
32#define DASD_DIAG_FLAGA_FORMAT_64BIT 0x80
33
22struct dasd_diag_characteristics { 34struct dasd_diag_characteristics {
23 u16 dev_nr; 35 u16 dev_nr;
24 u16 rdc_len; 36 u16 rdc_len;
@@ -32,35 +44,106 @@ struct dasd_diag_characteristics {
32 u8 rdev_features; 44 u8 rdev_features;
33} __attribute__ ((packed, aligned(4))); 45} __attribute__ ((packed, aligned(4)));
34 46
47struct dasd_diag_cms_label {
48 u8 label_id[4];
49 u8 vol_id[6];
50 u16 version_id;
51 u32 block_size;
52 u32 origin_ptr;
53 u32 usable_count;
54 u32 formatted_count;
55 u32 block_count;
56 u32 used_count;
57 u32 fst_size;
58 u32 fst_count;
59 u8 format_date[6];
60 u8 reserved1[2];
61 u32 disk_offset;
62 u32 map_block;
63 u32 hblk_disp;
64 u32 user_disp;
65 u8 reserved2[4];
66 u8 segment_name[8];
67} __attribute__ ((packed));
68
69#ifdef CONFIG_ARCH_S390X
70#define DASD_DIAG_FLAGA_DEFAULT DASD_DIAG_FLAGA_FORMAT_64BIT
71
72typedef u64 blocknum_t;
73typedef s64 sblocknum_t;
74
75struct dasd_diag_bio {
76 u8 type;
77 u8 status;
78 u8 spare1[2];
79 u32 alet;
80 blocknum_t block_number;
81 u64 buffer;
82} __attribute__ ((packed, aligned(8)));
83
84struct dasd_diag_init_io {
85 u16 dev_nr;
86 u8 flaga;
87 u8 spare1[21];
88 u32 block_size;
89 u8 spare2[4];
90 blocknum_t offset;
91 sblocknum_t start_block;
92 blocknum_t end_block;
93 u8 spare3[8];
94} __attribute__ ((packed, aligned(8)));
95
96struct dasd_diag_rw_io {
97 u16 dev_nr;
98 u8 flaga;
99 u8 spare1[21];
100 u8 key;
101 u8 flags;
102 u8 spare2[2];
103 u32 block_count;
104 u32 alet;
105 u8 spare3[4];
106 u64 interrupt_params;
107 u64 bio_list;
108 u8 spare4[8];
109} __attribute__ ((packed, aligned(8)));
110#else /* CONFIG_ARCH_S390X */
111#define DASD_DIAG_FLAGA_DEFAULT 0x0
112
113typedef u32 blocknum_t;
114typedef s32 sblocknum_t;
115
35struct dasd_diag_bio { 116struct dasd_diag_bio {
36 u8 type; 117 u8 type;
37 u8 status; 118 u8 status;
38 u16 spare1; 119 u16 spare1;
39 u32 block_number; 120 blocknum_t block_number;
40 u32 alet; 121 u32 alet;
41 u32 buffer; 122 u32 buffer;
42} __attribute__ ((packed, aligned(8))); 123} __attribute__ ((packed, aligned(8)));
43 124
44struct dasd_diag_init_io { 125struct dasd_diag_init_io {
45 u16 dev_nr; 126 u16 dev_nr;
46 u16 spare1[11]; 127 u8 flaga;
128 u8 spare1[21];
47 u32 block_size; 129 u32 block_size;
48 u32 offset; 130 blocknum_t offset;
49 u32 start_block; 131 sblocknum_t start_block;
50 u32 end_block; 132 blocknum_t end_block;
51 u32 spare2[6]; 133 u8 spare2[24];
52} __attribute__ ((packed, aligned(8))); 134} __attribute__ ((packed, aligned(8)));
53 135
54struct dasd_diag_rw_io { 136struct dasd_diag_rw_io {
55 u16 dev_nr; 137 u16 dev_nr;
56 u16 spare1[11]; 138 u8 flaga;
139 u8 spare1[21];
57 u8 key; 140 u8 key;
58 u8 flags; 141 u8 flags;
59 u16 spare2; 142 u8 spare2[2];
60 u32 block_count; 143 u32 block_count;
61 u32 alet; 144 u32 alet;
62 u32 bio_list; 145 u32 bio_list;
63 u32 interrupt_params; 146 u32 interrupt_params;
64 u32 spare3[5]; 147 u8 spare3[20];
65} __attribute__ ((packed, aligned(8))); 148} __attribute__ ((packed, aligned(8)));
66 149#endif /* CONFIG_ARCH_S390X */
diff --git a/drivers/s390/block/dasd_genhd.c b/drivers/s390/block/dasd_genhd.c
index 96c49349701..a601c9a3354 100644
--- a/drivers/s390/block/dasd_genhd.c
+++ b/drivers/s390/block/dasd_genhd.c
@@ -9,7 +9,7 @@
9 * 9 *
10 * gendisk related functions for the dasd driver. 10 * gendisk related functions for the dasd driver.
11 * 11 *
12 * $Revision: 1.50 $ 12 * $Revision: 1.51 $
13 */ 13 */
14 14
15#include <linux/config.h> 15#include <linux/config.h>
@@ -31,16 +31,12 @@ int
31dasd_gendisk_alloc(struct dasd_device *device) 31dasd_gendisk_alloc(struct dasd_device *device)
32{ 32{
33 struct gendisk *gdp; 33 struct gendisk *gdp;
34 int len, feature_ro; 34 int len;
35 35
36 /* Make sure the minor for this device exists. */ 36 /* Make sure the minor for this device exists. */
37 if (device->devindex >= DASD_PER_MAJOR) 37 if (device->devindex >= DASD_PER_MAJOR)
38 return -EBUSY; 38 return -EBUSY;
39 39
40 feature_ro = dasd_get_feature(device->cdev, DASD_FEATURE_READONLY);
41 if (feature_ro < 0)
42 return feature_ro;
43
44 gdp = alloc_disk(1 << DASD_PARTN_BITS); 40 gdp = alloc_disk(1 << DASD_PARTN_BITS);
45 if (!gdp) 41 if (!gdp)
46 return -ENOMEM; 42 return -ENOMEM;
@@ -75,7 +71,7 @@ dasd_gendisk_alloc(struct dasd_device *device)
75 71
76 sprintf(gdp->devfs_name, "dasd/%s", device->cdev->dev.bus_id); 72 sprintf(gdp->devfs_name, "dasd/%s", device->cdev->dev.bus_id);
77 73
78 if (feature_ro) 74 if (device->features & DASD_FEATURE_READONLY)
79 set_disk_ro(gdp, 1); 75 set_disk_ro(gdp, 1);
80 gdp->private_data = device; 76 gdp->private_data = device;
81 gdp->queue = device->request_queue; 77 gdp->queue = device->request_queue;
diff --git a/drivers/s390/block/dasd_int.h b/drivers/s390/block/dasd_int.h
index a9f38b23598..9fab04f3056 100644
--- a/drivers/s390/block/dasd_int.h
+++ b/drivers/s390/block/dasd_int.h
@@ -6,7 +6,7 @@
6 * Bugreports.to..: <Linux390@de.ibm.com> 6 * Bugreports.to..: <Linux390@de.ibm.com>
7 * (C) IBM Corporation, IBM Deutschland Entwicklung GmbH, 1999,2000 7 * (C) IBM Corporation, IBM Deutschland Entwicklung GmbH, 1999,2000
8 * 8 *
9 * $Revision: 1.64 $ 9 * $Revision: 1.65 $
10 */ 10 */
11 11
12#ifndef DASD_INT_H 12#ifndef DASD_INT_H
@@ -286,6 +286,7 @@ struct dasd_device {
286 unsigned int bp_block; /* bytes per block */ 286 unsigned int bp_block; /* bytes per block */
287 unsigned int s2b_shift; /* log2 (bp_block/512) */ 287 unsigned int s2b_shift; /* log2 (bp_block/512) */
288 unsigned long flags; /* per device flags */ 288 unsigned long flags; /* per device flags */
289 unsigned short features; /* copy of devmap-features (read-only!) */
289 290
290 /* Device discipline stuff. */ 291 /* Device discipline stuff. */
291 struct dasd_discipline *discipline; 292 struct dasd_discipline *discipline;
diff --git a/drivers/s390/block/dasd_ioctl.c b/drivers/s390/block/dasd_ioctl.c
index 980c555aa53..789595b3fa0 100644
--- a/drivers/s390/block/dasd_ioctl.c
+++ b/drivers/s390/block/dasd_ioctl.c
@@ -7,7 +7,7 @@
7 * Bugreports.to..: <Linux390@de.ibm.com> 7 * Bugreports.to..: <Linux390@de.ibm.com>
8 * (C) IBM Corporation, IBM Deutschland Entwicklung GmbH, 1999-2001 8 * (C) IBM Corporation, IBM Deutschland Entwicklung GmbH, 1999-2001
9 * 9 *
10 * $Revision: 1.45 $ 10 * $Revision: 1.47 $
11 * 11 *
12 * i/o controls for the dasd driver. 12 * i/o controls for the dasd driver.
13 */ 13 */
@@ -296,7 +296,6 @@ dasd_ioctl_format(struct block_device *bdev, int no, long args)
296{ 296{
297 struct dasd_device *device; 297 struct dasd_device *device;
298 struct format_data_t fdata; 298 struct format_data_t fdata;
299 int feature_ro;
300 299
301 if (!capable(CAP_SYS_ADMIN)) 300 if (!capable(CAP_SYS_ADMIN))
302 return -EACCES; 301 return -EACCES;
@@ -308,10 +307,7 @@ dasd_ioctl_format(struct block_device *bdev, int no, long args)
308 if (device == NULL) 307 if (device == NULL)
309 return -ENODEV; 308 return -ENODEV;
310 309
311 feature_ro = dasd_get_feature(device->cdev, DASD_FEATURE_READONLY); 310 if (device->features & DASD_FEATURE_READONLY)
312 if (feature_ro < 0)
313 return feature_ro;
314 if (feature_ro)
315 return -EROFS; 311 return -EROFS;
316 if (copy_from_user(&fdata, (void __user *) args, 312 if (copy_from_user(&fdata, (void __user *) args,
317 sizeof (struct format_data_t))) 313 sizeof (struct format_data_t)))
@@ -384,7 +380,7 @@ dasd_ioctl_information(struct block_device *bdev, int no, long args)
384 struct dasd_device *device; 380 struct dasd_device *device;
385 struct dasd_information2_t *dasd_info; 381 struct dasd_information2_t *dasd_info;
386 unsigned long flags; 382 unsigned long flags;
387 int rc, feature_ro; 383 int rc;
388 struct ccw_device *cdev; 384 struct ccw_device *cdev;
389 385
390 device = bdev->bd_disk->private_data; 386 device = bdev->bd_disk->private_data;
@@ -394,10 +390,6 @@ dasd_ioctl_information(struct block_device *bdev, int no, long args)
394 if (!device->discipline->fill_info) 390 if (!device->discipline->fill_info)
395 return -EINVAL; 391 return -EINVAL;
396 392
397 feature_ro = dasd_get_feature(device->cdev, DASD_FEATURE_READONLY);
398 if (feature_ro < 0)
399 return feature_ro;
400
401 dasd_info = kmalloc(sizeof(struct dasd_information2_t), GFP_KERNEL); 393 dasd_info = kmalloc(sizeof(struct dasd_information2_t), GFP_KERNEL);
402 if (dasd_info == NULL) 394 if (dasd_info == NULL)
403 return -ENOMEM; 395 return -ENOMEM;
@@ -427,7 +419,8 @@ dasd_ioctl_information(struct block_device *bdev, int no, long args)
427 (dasd_check_blocksize(device->bp_block))) 419 (dasd_check_blocksize(device->bp_block)))
428 dasd_info->format = DASD_FORMAT_NONE; 420 dasd_info->format = DASD_FORMAT_NONE;
429 421
430 dasd_info->features |= feature_ro; 422 dasd_info->features |=
423 ((device->features & DASD_FEATURE_READONLY) != 0);
431 424
432 if (device->discipline) 425 if (device->discipline)
433 memcpy(dasd_info->type, device->discipline->name, 4); 426 memcpy(dasd_info->type, device->discipline->name, 4);
diff --git a/drivers/s390/block/dasd_proc.c b/drivers/s390/block/dasd_proc.c
index 43c34f8c5e6..fff9020d488 100644
--- a/drivers/s390/block/dasd_proc.c
+++ b/drivers/s390/block/dasd_proc.c
@@ -9,7 +9,7 @@
9 * 9 *
10 * /proc interface for the dasd driver. 10 * /proc interface for the dasd driver.
11 * 11 *
12 * $Revision: 1.32 $ 12 * $Revision: 1.33 $
13 */ 13 */
14 14
15#include <linux/config.h> 15#include <linux/config.h>
@@ -55,7 +55,6 @@ dasd_devices_show(struct seq_file *m, void *v)
55{ 55{
56 struct dasd_device *device; 56 struct dasd_device *device;
57 char *substr; 57 char *substr;
58 int feature;
59 58
60 device = dasd_device_from_devindex((unsigned long) v - 1); 59 device = dasd_device_from_devindex((unsigned long) v - 1);
61 if (IS_ERR(device)) 60 if (IS_ERR(device))
@@ -79,10 +78,7 @@ dasd_devices_show(struct seq_file *m, void *v)
79 else 78 else
80 seq_printf(m, " is ????????"); 79 seq_printf(m, " is ????????");
81 /* Print devices features. */ 80 /* Print devices features. */
82 feature = dasd_get_feature(device->cdev, DASD_FEATURE_READONLY); 81 substr = (device->features & DASD_FEATURE_READONLY) ? "(ro)" : " ";
83 if (feature < 0)
84 return 0;
85 substr = feature ? "(ro)" : " ";
86 seq_printf(m, "%4s: ", substr); 82 seq_printf(m, "%4s: ", substr);
87 /* Print device status information. */ 83 /* Print device status information. */
88 switch ((device != NULL) ? device->state : -1) { 84 switch ((device != NULL) ? device->state : -1) {
diff --git a/drivers/s390/char/raw3270.c b/drivers/s390/char/raw3270.c
index d5eefeaba50..328d9cbc56a 100644
--- a/drivers/s390/char/raw3270.c
+++ b/drivers/s390/char/raw3270.c
@@ -632,12 +632,9 @@ __raw3270_size_device(struct raw3270 *rp)
632 raw3270_init_request.ccw.cda = (__u32) __pa(raw3270_init_data); 632 raw3270_init_request.ccw.cda = (__u32) __pa(raw3270_init_data);
633 633
634 rc = raw3270_start_init(rp, &raw3270_init_view, &raw3270_init_request); 634 rc = raw3270_start_init(rp, &raw3270_init_view, &raw3270_init_request);
635 if (rc) { 635 if (rc)
636 /* Check error cases: -ERESTARTSYS, -EIO and -EOPNOTSUPP */ 636 /* Check error cases: -ERESTARTSYS, -EIO and -EOPNOTSUPP */
637 if (rc == -EOPNOTSUPP && MACHINE_IS_VM)
638 return __raw3270_size_device_vm(rp);
639 return rc; 637 return rc;
640 }
641 638
642 /* Wait for attention interrupt. */ 639 /* Wait for attention interrupt. */
643#ifdef CONFIG_TN3270_CONSOLE 640#ifdef CONFIG_TN3270_CONSOLE
@@ -695,7 +692,10 @@ raw3270_size_device(struct raw3270 *rp)
695 down(&raw3270_init_sem); 692 down(&raw3270_init_sem);
696 rp->view = &raw3270_init_view; 693 rp->view = &raw3270_init_view;
697 raw3270_init_view.dev = rp; 694 raw3270_init_view.dev = rp;
698 rc = __raw3270_size_device(rp); 695 if (MACHINE_IS_VM)
696 rc = __raw3270_size_device_vm(rp);
697 else
698 rc = __raw3270_size_device(rp);
699 raw3270_init_view.dev = 0; 699 raw3270_init_view.dev = 0;
700 rp->view = 0; 700 rp->view = 0;
701 up(&raw3270_init_sem); 701 up(&raw3270_init_sem);
@@ -710,6 +710,12 @@ raw3270_size_device(struct raw3270 *rp)
710 rp->model = 4; 710 rp->model = 4;
711 if (rp->rows == 27 && rp->cols == 132) 711 if (rp->rows == 27 && rp->cols == 132)
712 rp->model = 5; 712 rp->model = 5;
713 } else {
714 /* Couldn't detect size. Use default model 2. */
715 rp->model = 2;
716 rp->rows = 24;
717 rp->cols = 80;
718 return 0;
713 } 719 }
714 return rc; 720 return rc;
715} 721}
diff --git a/drivers/s390/cio/cio.c b/drivers/s390/cio/cio.c
index ea813bdce1d..185bc73c3ec 100644
--- a/drivers/s390/cio/cio.c
+++ b/drivers/s390/cio/cio.c
@@ -1,7 +1,7 @@
1/* 1/*
2 * drivers/s390/cio/cio.c 2 * drivers/s390/cio/cio.c
3 * S/390 common I/O routines -- low level i/o calls 3 * S/390 common I/O routines -- low level i/o calls
4 * $Revision: 1.134 $ 4 * $Revision: 1.135 $
5 * 5 *
6 * Copyright (C) 1999-2002 IBM Deutschland Entwicklung GmbH, 6 * Copyright (C) 1999-2002 IBM Deutschland Entwicklung GmbH,
7 * IBM Corporation 7 * IBM Corporation
@@ -815,8 +815,9 @@ __clear_subchannel_easy(unsigned int schid)
815 struct tpi_info ti; 815 struct tpi_info ti;
816 816
817 if (tpi(&ti)) { 817 if (tpi(&ti)) {
818 tsch(schid, (struct irb *)__LC_IRB); 818 tsch(ti.irq, (struct irb *)__LC_IRB);
819 return 0; 819 if (ti.irq == schid)
820 return 0;
820 } 821 }
821 udelay(100); 822 udelay(100);
822 } 823 }
diff --git a/drivers/s390/cio/device_fsm.c b/drivers/s390/cio/device_fsm.c
index ee7a05e0c3b..fbe4202a3f6 100644
--- a/drivers/s390/cio/device_fsm.c
+++ b/drivers/s390/cio/device_fsm.c
@@ -13,7 +13,7 @@
13#include <linux/init.h> 13#include <linux/init.h>
14 14
15#include <asm/ccwdev.h> 15#include <asm/ccwdev.h>
16#include <asm/qdio.h> 16#include <asm/cio.h>
17 17
18#include "cio.h" 18#include "cio.h"
19#include "cio_debug.h" 19#include "cio_debug.h"
@@ -21,7 +21,6 @@
21#include "device.h" 21#include "device.h"
22#include "chsc.h" 22#include "chsc.h"
23#include "ioasm.h" 23#include "ioasm.h"
24#include "qdio.h"
25 24
26int 25int
27device_is_online(struct subchannel *sch) 26device_is_online(struct subchannel *sch)
diff --git a/drivers/s390/cio/device_ops.c b/drivers/s390/cio/device_ops.c
index 02d01a0de16..ad3fe5aeb66 100644
--- a/drivers/s390/cio/device_ops.c
+++ b/drivers/s390/cio/device_ops.c
@@ -1,7 +1,7 @@
1/* 1/*
2 * drivers/s390/cio/device_ops.c 2 * drivers/s390/cio/device_ops.c
3 * 3 *
4 * $Revision: 1.56 $ 4 * $Revision: 1.57 $
5 * 5 *
6 * Copyright (C) 2002 IBM Deutschland Entwicklung GmbH, 6 * Copyright (C) 2002 IBM Deutschland Entwicklung GmbH,
7 * IBM Corporation 7 * IBM Corporation
@@ -19,14 +19,12 @@
19 19
20#include <asm/ccwdev.h> 20#include <asm/ccwdev.h>
21#include <asm/idals.h> 21#include <asm/idals.h>
22#include <asm/qdio.h>
23 22
24#include "cio.h" 23#include "cio.h"
25#include "cio_debug.h" 24#include "cio_debug.h"
26#include "css.h" 25#include "css.h"
27#include "chsc.h" 26#include "chsc.h"
28#include "device.h" 27#include "device.h"
29#include "qdio.h"
30 28
31int 29int
32ccw_device_set_options(struct ccw_device *cdev, unsigned long flags) 30ccw_device_set_options(struct ccw_device *cdev, unsigned long flags)
diff --git a/drivers/s390/cio/ioasm.h b/drivers/s390/cio/ioasm.h
index c874607d9a8..45480a2bc4c 100644
--- a/drivers/s390/cio/ioasm.h
+++ b/drivers/s390/cio/ioasm.h
@@ -21,7 +21,7 @@ struct tpi_info {
21 * Some S390 specific IO instructions as inline 21 * Some S390 specific IO instructions as inline
22 */ 22 */
23 23
24extern __inline__ int stsch(int irq, volatile struct schib *addr) 24static inline int stsch(int irq, volatile struct schib *addr)
25{ 25{
26 int ccode; 26 int ccode;
27 27
@@ -36,7 +36,7 @@ extern __inline__ int stsch(int irq, volatile struct schib *addr)
36 return ccode; 36 return ccode;
37} 37}
38 38
39extern __inline__ int msch(int irq, volatile struct schib *addr) 39static inline int msch(int irq, volatile struct schib *addr)
40{ 40{
41 int ccode; 41 int ccode;
42 42
@@ -51,7 +51,7 @@ extern __inline__ int msch(int irq, volatile struct schib *addr)
51 return ccode; 51 return ccode;
52} 52}
53 53
54extern __inline__ int msch_err(int irq, volatile struct schib *addr) 54static inline int msch_err(int irq, volatile struct schib *addr)
55{ 55{
56 int ccode; 56 int ccode;
57 57
@@ -79,7 +79,7 @@ extern __inline__ int msch_err(int irq, volatile struct schib *addr)
79 return ccode; 79 return ccode;
80} 80}
81 81
82extern __inline__ int tsch(int irq, volatile struct irb *addr) 82static inline int tsch(int irq, volatile struct irb *addr)
83{ 83{
84 int ccode; 84 int ccode;
85 85
@@ -94,7 +94,7 @@ extern __inline__ int tsch(int irq, volatile struct irb *addr)
94 return ccode; 94 return ccode;
95} 95}
96 96
97extern __inline__ int tpi( volatile struct tpi_info *addr) 97static inline int tpi( volatile struct tpi_info *addr)
98{ 98{
99 int ccode; 99 int ccode;
100 100
@@ -108,7 +108,7 @@ extern __inline__ int tpi( volatile struct tpi_info *addr)
108 return ccode; 108 return ccode;
109} 109}
110 110
111extern __inline__ int ssch(int irq, volatile struct orb *addr) 111static inline int ssch(int irq, volatile struct orb *addr)
112{ 112{
113 int ccode; 113 int ccode;
114 114
@@ -123,7 +123,7 @@ extern __inline__ int ssch(int irq, volatile struct orb *addr)
123 return ccode; 123 return ccode;
124} 124}
125 125
126extern __inline__ int rsch(int irq) 126static inline int rsch(int irq)
127{ 127{
128 int ccode; 128 int ccode;
129 129
@@ -138,7 +138,7 @@ extern __inline__ int rsch(int irq)
138 return ccode; 138 return ccode;
139} 139}
140 140
141extern __inline__ int csch(int irq) 141static inline int csch(int irq)
142{ 142{
143 int ccode; 143 int ccode;
144 144
@@ -153,7 +153,7 @@ extern __inline__ int csch(int irq)
153 return ccode; 153 return ccode;
154} 154}
155 155
156extern __inline__ int hsch(int irq) 156static inline int hsch(int irq)
157{ 157{
158 int ccode; 158 int ccode;
159 159
@@ -168,7 +168,7 @@ extern __inline__ int hsch(int irq)
168 return ccode; 168 return ccode;
169} 169}
170 170
171extern __inline__ int xsch(int irq) 171static inline int xsch(int irq)
172{ 172{
173 int ccode; 173 int ccode;
174 174
@@ -183,7 +183,7 @@ extern __inline__ int xsch(int irq)
183 return ccode; 183 return ccode;
184} 184}
185 185
186extern __inline__ int chsc(void *chsc_area) 186static inline int chsc(void *chsc_area)
187{ 187{
188 int cc; 188 int cc;
189 189
@@ -198,7 +198,7 @@ extern __inline__ int chsc(void *chsc_area)
198 return cc; 198 return cc;
199} 199}
200 200
201extern __inline__ int iac( void) 201static inline int iac( void)
202{ 202{
203 int ccode; 203 int ccode;
204 204
@@ -210,7 +210,7 @@ extern __inline__ int iac( void)
210 return ccode; 210 return ccode;
211} 211}
212 212
213extern __inline__ int rchp(int chpid) 213static inline int rchp(int chpid)
214{ 214{
215 int ccode; 215 int ccode;
216 216
diff --git a/drivers/s390/crypto/z90common.h b/drivers/s390/crypto/z90common.h
index bcabac7a7c4..e319e78b5ea 100644
--- a/drivers/s390/crypto/z90common.h
+++ b/drivers/s390/crypto/z90common.h
@@ -27,7 +27,7 @@
27#ifndef _Z90COMMON_H_ 27#ifndef _Z90COMMON_H_
28#define _Z90COMMON_H_ 28#define _Z90COMMON_H_
29 29
30#define VERSION_Z90COMMON_H "$Revision: 1.16 $" 30#define VERSION_Z90COMMON_H "$Revision: 1.17 $"
31 31
32 32
33#define RESPBUFFSIZE 256 33#define RESPBUFFSIZE 256
@@ -164,5 +164,4 @@ struct CPRBX {
164#define UMIN(a,b) ((a) < (b) ? (a) : (b)) 164#define UMIN(a,b) ((a) < (b) ? (a) : (b))
165#define IS_EVEN(x) ((x) == (2 * ((x) / 2))) 165#define IS_EVEN(x) ((x) == (2 * ((x) / 2)))
166 166
167
168#endif 167#endif
diff --git a/drivers/s390/crypto/z90hardware.c b/drivers/s390/crypto/z90hardware.c
index beb6a5e0da2..c215e088973 100644
--- a/drivers/s390/crypto/z90hardware.c
+++ b/drivers/s390/crypto/z90hardware.c
@@ -32,7 +32,7 @@
32#include "z90crypt.h" 32#include "z90crypt.h"
33#include "z90common.h" 33#include "z90common.h"
34 34
35#define VERSION_Z90HARDWARE_C "$Revision: 1.33 $" 35#define VERSION_Z90HARDWARE_C "$Revision: 1.34 $"
36 36
37char z90hardware_version[] __initdata = 37char z90hardware_version[] __initdata =
38 "z90hardware.o (" VERSION_Z90HARDWARE_C "/" 38 "z90hardware.o (" VERSION_Z90HARDWARE_C "/"
@@ -283,48 +283,6 @@ struct type6_msg {
283 struct CPRB CPRB; 283 struct CPRB CPRB;
284}; 284};
285 285
286union request_msg {
287 union type4_msg t4msg;
288 struct type6_msg t6msg;
289};
290
291struct request_msg_ext {
292 int q_nr;
293 unsigned char *psmid;
294 union request_msg reqMsg;
295};
296
297struct type82_hdr {
298 unsigned char reserved1;
299 unsigned char type;
300 unsigned char reserved2[2];
301 unsigned char reply_code;
302 unsigned char reserved3[3];
303};
304
305#define TYPE82_RSP_CODE 0x82
306
307#define REPLY_ERROR_MACHINE_FAILURE 0x10
308#define REPLY_ERROR_PREEMPT_FAILURE 0x12
309#define REPLY_ERROR_CHECKPT_FAILURE 0x14
310#define REPLY_ERROR_MESSAGE_TYPE 0x20
311#define REPLY_ERROR_INVALID_COMM_CD 0x21
312#define REPLY_ERROR_INVALID_MSG_LEN 0x23
313#define REPLY_ERROR_RESERVD_FIELD 0x24
314#define REPLY_ERROR_FORMAT_FIELD 0x29
315#define REPLY_ERROR_INVALID_COMMAND 0x30
316#define REPLY_ERROR_MALFORMED_MSG 0x40
317#define REPLY_ERROR_RESERVED_FIELDO 0x50
318#define REPLY_ERROR_WORD_ALIGNMENT 0x60
319#define REPLY_ERROR_MESSAGE_LENGTH 0x80
320#define REPLY_ERROR_OPERAND_INVALID 0x82
321#define REPLY_ERROR_OPERAND_SIZE 0x84
322#define REPLY_ERROR_EVEN_MOD_IN_OPND 0x85
323#define REPLY_ERROR_RESERVED_FIELD 0x88
324#define REPLY_ERROR_TRANSPORT_FAIL 0x90
325#define REPLY_ERROR_PACKET_TRUNCATED 0xA0
326#define REPLY_ERROR_ZERO_BUFFER_LEN 0xB0
327
328struct type86_hdr { 286struct type86_hdr {
329 unsigned char reserved1; 287 unsigned char reserved1;
330 unsigned char type; 288 unsigned char type;
@@ -338,7 +296,7 @@ struct type86_hdr {
338#define TYPE86_FMT2 0x02 296#define TYPE86_FMT2 0x02
339 297
340struct type86_fmt2_msg { 298struct type86_fmt2_msg {
341 struct type86_hdr hdr; 299 struct type86_hdr header;
342 unsigned char reserved[4]; 300 unsigned char reserved[4];
343 unsigned char apfs[4]; 301 unsigned char apfs[4];
344 unsigned int count1; 302 unsigned int count1;
@@ -538,6 +496,8 @@ static struct function_and_rules_block static_pke_function_and_rulesX = {
538 {'M','R','P',' ',' ',' ',' ',' '} 496 {'M','R','P',' ',' ',' ',' ',' '}
539}; 497};
540 498
499static unsigned char static_PKE_function_code[2] = {0x50, 0x4B};
500
541struct T6_keyBlock_hdrX { 501struct T6_keyBlock_hdrX {
542 unsigned short blen; 502 unsigned short blen;
543 unsigned short ulen; 503 unsigned short ulen;
@@ -688,9 +648,38 @@ static struct cca_public_sec static_cca_pub_sec = {
688#define RESPONSE_CPRB_SIZE 0x000006B8 648#define RESPONSE_CPRB_SIZE 0x000006B8
689#define RESPONSE_CPRBX_SIZE 0x00000724 649#define RESPONSE_CPRBX_SIZE 0x00000724
690 650
691#define CALLER_HEADER 12 651struct error_hdr {
652 unsigned char reserved1;
653 unsigned char type;
654 unsigned char reserved2[2];
655 unsigned char reply_code;
656 unsigned char reserved3[3];
657};
692 658
693static unsigned char static_PKE_function_code[2] = {0x50, 0x4B}; 659#define TYPE82_RSP_CODE 0x82
660
661#define REP82_ERROR_MACHINE_FAILURE 0x10
662#define REP82_ERROR_PREEMPT_FAILURE 0x12
663#define REP82_ERROR_CHECKPT_FAILURE 0x14
664#define REP82_ERROR_MESSAGE_TYPE 0x20
665#define REP82_ERROR_INVALID_COMM_CD 0x21
666#define REP82_ERROR_INVALID_MSG_LEN 0x23
667#define REP82_ERROR_RESERVD_FIELD 0x24
668#define REP82_ERROR_FORMAT_FIELD 0x29
669#define REP82_ERROR_INVALID_COMMAND 0x30
670#define REP82_ERROR_MALFORMED_MSG 0x40
671#define REP82_ERROR_RESERVED_FIELDO 0x50
672#define REP82_ERROR_WORD_ALIGNMENT 0x60
673#define REP82_ERROR_MESSAGE_LENGTH 0x80
674#define REP82_ERROR_OPERAND_INVALID 0x82
675#define REP82_ERROR_OPERAND_SIZE 0x84
676#define REP82_ERROR_EVEN_MOD_IN_OPND 0x85
677#define REP82_ERROR_RESERVED_FIELD 0x88
678#define REP82_ERROR_TRANSPORT_FAIL 0x90
679#define REP82_ERROR_PACKET_TRUNCATED 0xA0
680#define REP82_ERROR_ZERO_BUFFER_LEN 0xB0
681
682#define CALLER_HEADER 12
694 683
695static inline int 684static inline int
696testq(int q_nr, int *q_depth, int *dev_type, struct ap_status_word *stat) 685testq(int q_nr, int *q_depth, int *dev_type, struct ap_status_word *stat)
@@ -1212,9 +1201,9 @@ send_to_AP(int dev_nr, int cdx, int msg_len, unsigned char *msg_ext)
1212 struct ap_status_word stat_word; 1201 struct ap_status_word stat_word;
1213 enum devstat stat; 1202 enum devstat stat;
1214 int ccode; 1203 int ccode;
1204 u32 *q_nr_p = (u32 *)msg_ext;
1215 1205
1216 ((struct request_msg_ext *) msg_ext)->q_nr = 1206 *q_nr_p = (dev_nr << SKIP_BITL) + cdx;
1217 (dev_nr << SKIP_BITL) + cdx;
1218 PDEBUG("msg_len passed to sen: %d\n", msg_len); 1207 PDEBUG("msg_len passed to sen: %d\n", msg_len);
1219 PDEBUG("q number passed to sen: %02x%02x%02x%02x\n", 1208 PDEBUG("q number passed to sen: %02x%02x%02x%02x\n",
1220 msg_ext[0], msg_ext[1], msg_ext[2], msg_ext[3]); 1209 msg_ext[0], msg_ext[1], msg_ext[2], msg_ext[3]);
@@ -2104,7 +2093,7 @@ convert_response(unsigned char *response, unsigned char *buffer,
2104 int *respbufflen_p, unsigned char *resp_buff) 2093 int *respbufflen_p, unsigned char *resp_buff)
2105{ 2094{
2106 struct ica_rsa_modexpo *icaMsg_p = (struct ica_rsa_modexpo *) buffer; 2095 struct ica_rsa_modexpo *icaMsg_p = (struct ica_rsa_modexpo *) buffer;
2107 struct type82_hdr *t82h_p = (struct type82_hdr *) response; 2096 struct error_hdr *errh_p = (struct error_hdr *) response;
2108 struct type84_hdr *t84h_p = (struct type84_hdr *) response; 2097 struct type84_hdr *t84h_p = (struct type84_hdr *) response;
2109 struct type86_fmt2_msg *t86m_p = (struct type86_fmt2_msg *) response; 2098 struct type86_fmt2_msg *t86m_p = (struct type86_fmt2_msg *) response;
2110 int reply_code, service_rc, service_rs, src_l; 2099 int reply_code, service_rc, service_rs, src_l;
@@ -2117,12 +2106,13 @@ convert_response(unsigned char *response, unsigned char *buffer,
2117 service_rc = 0; 2106 service_rc = 0;
2118 service_rs = 0; 2107 service_rs = 0;
2119 src_l = 0; 2108 src_l = 0;
2120 switch (t82h_p->type) { 2109 switch (errh_p->type) {
2121 case TYPE82_RSP_CODE: 2110 case TYPE82_RSP_CODE:
2122 reply_code = t82h_p->reply_code; 2111 reply_code = errh_p->reply_code;
2123 src_p = (unsigned char *)t82h_p; 2112 src_p = (unsigned char *)errh_p;
2124 PRINTK("Hardware error: Type 82 Message Header: " 2113 PRINTK("Hardware error: Type %02X Message Header: "
2125 "%02x%02x%02x%02x%02x%02x%02x%02x\n", 2114 "%02x%02x%02x%02x%02x%02x%02x%02x\n",
2115 errh_p->type,
2126 src_p[0], src_p[1], src_p[2], src_p[3], 2116 src_p[0], src_p[1], src_p[2], src_p[3],
2127 src_p[4], src_p[5], src_p[6], src_p[7]); 2117 src_p[4], src_p[5], src_p[6], src_p[7]);
2128 break; 2118 break;
@@ -2131,7 +2121,7 @@ convert_response(unsigned char *response, unsigned char *buffer,
2131 src_p = response + (int)t84h_p->len - src_l; 2121 src_p = response + (int)t84h_p->len - src_l;
2132 break; 2122 break;
2133 case TYPE86_RSP_CODE: 2123 case TYPE86_RSP_CODE:
2134 reply_code = t86m_p->hdr.reply_code; 2124 reply_code = t86m_p->header.reply_code;
2135 if (reply_code != 0) 2125 if (reply_code != 0)
2136 break; 2126 break;
2137 cprb_p = (struct CPRB *) 2127 cprb_p = (struct CPRB *)
@@ -2143,6 +2133,9 @@ convert_response(unsigned char *response, unsigned char *buffer,
2143 le2toI(cprb_p->ccp_rscode, &service_rs); 2133 le2toI(cprb_p->ccp_rscode, &service_rs);
2144 if ((service_rc == 8) && (service_rs == 66)) 2134 if ((service_rc == 8) && (service_rs == 66))
2145 PDEBUG("Bad block format on PCICC\n"); 2135 PDEBUG("Bad block format on PCICC\n");
2136 else if ((service_rc == 8) && (service_rs == 65))
2137 PDEBUG("Probably an even modulus on "
2138 "PCICC\n");
2146 else if ((service_rc == 8) && (service_rs == 770)) { 2139 else if ((service_rc == 8) && (service_rs == 770)) {
2147 PDEBUG("Invalid key length on PCICC\n"); 2140 PDEBUG("Invalid key length on PCICC\n");
2148 unset_ext_bitlens(); 2141 unset_ext_bitlens();
@@ -2155,7 +2148,7 @@ convert_response(unsigned char *response, unsigned char *buffer,
2155 return REC_USE_PCICA; 2148 return REC_USE_PCICA;
2156 } 2149 }
2157 else 2150 else
2158 PRINTK("service rc/rs: %d/%d\n", 2151 PRINTK("service rc/rs (PCICC): %d/%d\n",
2159 service_rc, service_rs); 2152 service_rc, service_rs);
2160 return REC_OPERAND_INV; 2153 return REC_OPERAND_INV;
2161 } 2154 }
@@ -2169,7 +2162,10 @@ convert_response(unsigned char *response, unsigned char *buffer,
2169 if (service_rc != 0) { 2162 if (service_rc != 0) {
2170 service_rs = (int) cprbx_p->ccp_rscode; 2163 service_rs = (int) cprbx_p->ccp_rscode;
2171 if ((service_rc == 8) && (service_rs == 66)) 2164 if ((service_rc == 8) && (service_rs == 66))
2172 PDEBUG("Bad block format on PCXICC\n"); 2165 PDEBUG("Bad block format on PCIXCC\n");
2166 else if ((service_rc == 8) && (service_rs == 65))
2167 PDEBUG("Probably an even modulus on "
2168 "PCIXCC\n");
2173 else if ((service_rc == 8) && (service_rs == 770)) { 2169 else if ((service_rc == 8) && (service_rs == 770)) {
2174 PDEBUG("Invalid key length on PCIXCC\n"); 2170 PDEBUG("Invalid key length on PCIXCC\n");
2175 unset_ext_bitlens(); 2171 unset_ext_bitlens();
@@ -2182,7 +2178,7 @@ convert_response(unsigned char *response, unsigned char *buffer,
2182 return REC_USE_PCICA; 2178 return REC_USE_PCICA;
2183 } 2179 }
2184 else 2180 else
2185 PRINTK("service rc/rs: %d/%d\n", 2181 PRINTK("service rc/rs (PCIXCC): %d/%d\n",
2186 service_rc, service_rs); 2182 service_rc, service_rs);
2187 return REC_OPERAND_INV; 2183 return REC_OPERAND_INV;
2188 } 2184 }
@@ -2195,20 +2191,25 @@ convert_response(unsigned char *response, unsigned char *buffer,
2195 } 2191 }
2196 break; 2192 break;
2197 default: 2193 default:
2194 src_p = (unsigned char *)errh_p;
2195 PRINTK("Unrecognized Message Header: "
2196 "%02x%02x%02x%02x%02x%02x%02x%02x\n",
2197 src_p[0], src_p[1], src_p[2], src_p[3],
2198 src_p[4], src_p[5], src_p[6], src_p[7]);
2198 return REC_BAD_MESSAGE; 2199 return REC_BAD_MESSAGE;
2199 } 2200 }
2200 2201
2201 if (reply_code) 2202 if (reply_code)
2202 switch (reply_code) { 2203 switch (reply_code) {
2203 case REPLY_ERROR_OPERAND_INVALID: 2204 case REP82_ERROR_OPERAND_INVALID:
2204 return REC_OPERAND_INV; 2205 return REC_OPERAND_INV;
2205 case REPLY_ERROR_OPERAND_SIZE: 2206 case REP82_ERROR_OPERAND_SIZE:
2206 return REC_OPERAND_SIZE; 2207 return REC_OPERAND_SIZE;
2207 case REPLY_ERROR_EVEN_MOD_IN_OPND: 2208 case REP82_ERROR_EVEN_MOD_IN_OPND:
2208 return REC_EVEN_MOD; 2209 return REC_EVEN_MOD;
2209 case REPLY_ERROR_MESSAGE_TYPE: 2210 case REP82_ERROR_MESSAGE_TYPE:
2210 return WRONG_DEVICE_TYPE; 2211 return WRONG_DEVICE_TYPE;
2211 case REPLY_ERROR_TRANSPORT_FAIL: 2212 case REP82_ERROR_TRANSPORT_FAIL:
2212 PRINTKW("Transport failed (APFS = %02X%02X%02X%02X)\n", 2213 PRINTKW("Transport failed (APFS = %02X%02X%02X%02X)\n",
2213 t86m_p->apfs[0], t86m_p->apfs[1], 2214 t86m_p->apfs[0], t86m_p->apfs[1],
2214 t86m_p->apfs[2], t86m_p->apfs[3]); 2215 t86m_p->apfs[2], t86m_p->apfs[3]);
@@ -2229,7 +2230,7 @@ convert_response(unsigned char *response, unsigned char *buffer,
2229 PDEBUG("Length returned = %d\n", src_l); 2230 PDEBUG("Length returned = %d\n", src_l);
2230 tgt_p = resp_buff + icaMsg_p->outputdatalength - src_l; 2231 tgt_p = resp_buff + icaMsg_p->outputdatalength - src_l;
2231 memcpy(tgt_p, src_p, src_l); 2232 memcpy(tgt_p, src_p, src_l);
2232 if ((t82h_p->type == TYPE86_RSP_CODE) && (resp_buff < tgt_p)) { 2233 if ((errh_p->type == TYPE86_RSP_CODE) && (resp_buff < tgt_p)) {
2233 memset(resp_buff, 0, icaMsg_p->outputdatalength - src_l); 2234 memset(resp_buff, 0, icaMsg_p->outputdatalength - src_l);
2234 if (pad_msg(resp_buff, icaMsg_p->outputdatalength, src_l)) 2235 if (pad_msg(resp_buff, icaMsg_p->outputdatalength, src_l))
2235 return REC_INVALID_PAD; 2236 return REC_INVALID_PAD;
diff --git a/drivers/s390/crypto/z90main.c b/drivers/s390/crypto/z90main.c
index 9ec29bb41b2..6aeef3bacc3 100644
--- a/drivers/s390/crypto/z90main.c
+++ b/drivers/s390/crypto/z90main.c
@@ -31,6 +31,7 @@
31#include <linux/init.h> 31#include <linux/init.h>
32#include <linux/interrupt.h> // for tasklets 32#include <linux/interrupt.h> // for tasklets
33#include <linux/ioctl32.h> 33#include <linux/ioctl32.h>
34#include <linux/miscdevice.h>
34#include <linux/module.h> 35#include <linux/module.h>
35#include <linux/moduleparam.h> 36#include <linux/moduleparam.h>
36#include <linux/kobject_uevent.h> 37#include <linux/kobject_uevent.h>
@@ -39,19 +40,8 @@
39#include <linux/version.h> 40#include <linux/version.h>
40#include "z90crypt.h" 41#include "z90crypt.h"
41#include "z90common.h" 42#include "z90common.h"
42#ifndef Z90CRYPT_USE_HOTPLUG
43#include <linux/miscdevice.h>
44#endif
45
46#define VERSION_CODE(vers, rel, seq) (((vers)<<16) | ((rel)<<8) | (seq))
47#if LINUX_VERSION_CODE < VERSION_CODE(2,4,0) /* version < 2.4 */
48# error "This kernel is too old: not supported"
49#endif
50#if LINUX_VERSION_CODE > VERSION_CODE(2,7,0) /* version > 2.6 */
51# error "This kernel is too recent: not supported by this file"
52#endif
53 43
54#define VERSION_Z90MAIN_C "$Revision: 1.57 $" 44#define VERSION_Z90MAIN_C "$Revision: 1.62 $"
55 45
56static char z90main_version[] __initdata = 46static char z90main_version[] __initdata =
57 "z90main.o (" VERSION_Z90MAIN_C "/" 47 "z90main.o (" VERSION_Z90MAIN_C "/"
@@ -63,21 +53,12 @@ extern char z90hardware_version[];
63 * Defaults that may be modified. 53 * Defaults that may be modified.
64 */ 54 */
65 55
66#ifndef Z90CRYPT_USE_HOTPLUG
67/** 56/**
68 * You can specify a different minor at compile time. 57 * You can specify a different minor at compile time.
69 */ 58 */
70#ifndef Z90CRYPT_MINOR 59#ifndef Z90CRYPT_MINOR
71#define Z90CRYPT_MINOR MISC_DYNAMIC_MINOR 60#define Z90CRYPT_MINOR MISC_DYNAMIC_MINOR
72#endif 61#endif
73#else
74/**
75 * You can specify a different major at compile time.
76 */
77#ifndef Z90CRYPT_MAJOR
78#define Z90CRYPT_MAJOR 0
79#endif
80#endif
81 62
82/** 63/**
83 * You can specify a different domain at compile time or on the insmod 64 * You can specify a different domain at compile time or on the insmod
@@ -97,7 +78,7 @@ extern char z90hardware_version[];
97 * older than CLEANUPTIME seconds in the past. 78 * older than CLEANUPTIME seconds in the past.
98 */ 79 */
99#ifndef CLEANUPTIME 80#ifndef CLEANUPTIME
100#define CLEANUPTIME 20 81#define CLEANUPTIME 15
101#endif 82#endif
102 83
103/** 84/**
@@ -298,6 +279,10 @@ struct z90crypt {
298 * it contains the request; at READ, the response. The function 279 * it contains the request; at READ, the response. The function
299 * send_to_crypto_device converts the request to device-dependent 280 * send_to_crypto_device converts the request to device-dependent
300 * form and use the caller's OPEN-allocated buffer for the response. 281 * form and use the caller's OPEN-allocated buffer for the response.
282 *
283 * For the contents of caller_dev_dep_req and caller_dev_dep_req_p
284 * because that points to it, see the discussion in z90hardware.c.
285 * Search for "extended request message block".
301 */ 286 */
302struct caller { 287struct caller {
303 int caller_buf_l; // length of original request 288 int caller_buf_l; // length of original request
@@ -398,24 +383,9 @@ static int z90crypt_status_write(struct file *, const char __user *,
398 unsigned long, void *); 383 unsigned long, void *);
399 384
400/** 385/**
401 * Hotplug support
402 */
403
404#ifdef Z90CRYPT_USE_HOTPLUG
405#define Z90CRYPT_HOTPLUG_ADD 1
406#define Z90CRYPT_HOTPLUG_REMOVE 2
407
408static void z90crypt_hotplug_event(int, int, int);
409#endif
410
411/**
412 * Storage allocated at initialization and used throughout the life of 386 * Storage allocated at initialization and used throughout the life of
413 * this insmod 387 * this insmod
414 */ 388 */
415#ifdef Z90CRYPT_USE_HOTPLUG
416static int z90crypt_major = Z90CRYPT_MAJOR;
417#endif
418
419static int domain = DOMAIN_INDEX; 389static int domain = DOMAIN_INDEX;
420static struct z90crypt z90crypt; 390static struct z90crypt z90crypt;
421static int quiesce_z90crypt; 391static int quiesce_z90crypt;
@@ -444,14 +414,12 @@ static struct file_operations z90crypt_fops = {
444 .release = z90crypt_release 414 .release = z90crypt_release
445}; 415};
446 416
447#ifndef Z90CRYPT_USE_HOTPLUG
448static struct miscdevice z90crypt_misc_device = { 417static struct miscdevice z90crypt_misc_device = {
449 .minor = Z90CRYPT_MINOR, 418 .minor = Z90CRYPT_MINOR,
450 .name = DEV_NAME, 419 .name = DEV_NAME,
451 .fops = &z90crypt_fops, 420 .fops = &z90crypt_fops,
452 .devfs_name = DEV_NAME 421 .devfs_name = DEV_NAME
453}; 422};
454#endif
455 423
456/** 424/**
457 * Documentation values. 425 * Documentation values.
@@ -603,7 +571,6 @@ z90crypt_init_module(void)
603 return -EINVAL; 571 return -EINVAL;
604 } 572 }
605 573
606#ifndef Z90CRYPT_USE_HOTPLUG
607 /* Register as misc device with given minor (or get a dynamic one). */ 574 /* Register as misc device with given minor (or get a dynamic one). */
608 result = misc_register(&z90crypt_misc_device); 575 result = misc_register(&z90crypt_misc_device);
609 if (result < 0) { 576 if (result < 0) {
@@ -611,18 +578,6 @@ z90crypt_init_module(void)
611 z90crypt_misc_device.minor, result); 578 z90crypt_misc_device.minor, result);
612 return result; 579 return result;
613 } 580 }
614#else
615 /* Register the major (or get a dynamic one). */
616 result = register_chrdev(z90crypt_major, REG_NAME, &z90crypt_fops);
617 if (result < 0) {
618 PRINTKW("register_chrdev (major %d) failed with %d.\n",
619 z90crypt_major, result);
620 return result;
621 }
622
623 if (z90crypt_major == 0)
624 z90crypt_major = result;
625#endif
626 581
627 PDEBUG("Registered " DEV_NAME " with result %d\n", result); 582 PDEBUG("Registered " DEV_NAME " with result %d\n", result);
628 583
@@ -645,11 +600,6 @@ z90crypt_init_module(void)
645 } else 600 } else
646 PRINTK("No devices at startup\n"); 601 PRINTK("No devices at startup\n");
647 602
648#ifdef Z90CRYPT_USE_HOTPLUG
649 /* generate hotplug event for device node generation */
650 z90crypt_hotplug_event(z90crypt_major, 0, Z90CRYPT_HOTPLUG_ADD);
651#endif
652
653 /* Initialize globals. */ 603 /* Initialize globals. */
654 spin_lock_init(&queuespinlock); 604 spin_lock_init(&queuespinlock);
655 605
@@ -701,17 +651,10 @@ z90crypt_init_module(void)
701 return 0; // success 651 return 0; // success
702 652
703init_module_cleanup: 653init_module_cleanup:
704#ifndef Z90CRYPT_USE_HOTPLUG
705 if ((nresult = misc_deregister(&z90crypt_misc_device))) 654 if ((nresult = misc_deregister(&z90crypt_misc_device)))
706 PRINTK("misc_deregister failed with %d.\n", nresult); 655 PRINTK("misc_deregister failed with %d.\n", nresult);
707 else 656 else
708 PDEBUG("misc_deregister successful.\n"); 657 PDEBUG("misc_deregister successful.\n");
709#else
710 if ((nresult = unregister_chrdev(z90crypt_major, REG_NAME)))
711 PRINTK("unregister_chrdev failed with %d.\n", nresult);
712 else
713 PDEBUG("unregister_chrdev successful.\n");
714#endif
715 658
716 return result; // failure 659 return result; // failure
717} 660}
@@ -728,19 +671,10 @@ z90crypt_cleanup_module(void)
728 671
729 remove_proc_entry("driver/z90crypt", 0); 672 remove_proc_entry("driver/z90crypt", 0);
730 673
731#ifndef Z90CRYPT_USE_HOTPLUG
732 if ((nresult = misc_deregister(&z90crypt_misc_device))) 674 if ((nresult = misc_deregister(&z90crypt_misc_device)))
733 PRINTK("misc_deregister failed with %d.\n", nresult); 675 PRINTK("misc_deregister failed with %d.\n", nresult);
734 else 676 else
735 PDEBUG("misc_deregister successful.\n"); 677 PDEBUG("misc_deregister successful.\n");
736#else
737 z90crypt_hotplug_event(z90crypt_major, 0, Z90CRYPT_HOTPLUG_REMOVE);
738
739 if ((nresult = unregister_chrdev(z90crypt_major, REG_NAME)))
740 PRINTK("unregister_chrdev failed with %d.\n", nresult);
741 else
742 PDEBUG("unregister_chrdev successful.\n");
743#endif
744 678
745 /* Remove the tasks */ 679 /* Remove the tasks */
746 tasklet_kill(&reader_tasklet); 680 tasklet_kill(&reader_tasklet);
@@ -748,6 +682,9 @@ z90crypt_cleanup_module(void)
748 del_timer(&config_timer); 682 del_timer(&config_timer);
749 del_timer(&cleanup_timer); 683 del_timer(&cleanup_timer);
750 684
685 if (z90_device_work)
686 destroy_workqueue(z90_device_work);
687
751 destroy_z90crypt(); 688 destroy_z90crypt();
752 689
753 PRINTKN("Unloaded.\n"); 690 PRINTKN("Unloaded.\n");
@@ -766,8 +703,6 @@ z90crypt_cleanup_module(void)
766 * z90crypt_status_write 703 * z90crypt_status_write
767 * disable_card 704 * disable_card
768 * enable_card 705 * enable_card
769 * scan_char
770 * scan_string
771 * 706 *
772 * Helper functions: 707 * Helper functions:
773 * z90crypt_rsa 708 * z90crypt_rsa
@@ -1057,9 +992,10 @@ remove_device(struct device *device_p)
1057 * The MCL must be applied and the newer bitlengths enabled for these to work. 992 * The MCL must be applied and the newer bitlengths enabled for these to work.
1058 * 993 *
1059 * Card Type Old limit New limit 994 * Card Type Old limit New limit
995 * PCICA ??-2048 same (the lower limit is less than 128 bit...)
1060 * PCICC 512-1024 512-2048 996 * PCICC 512-1024 512-2048
1061 * PCIXCC_MCL2 512-2048 no change (applying this MCL == card is MCL3+) 997 * PCIXCC_MCL2 512-2048 ----- (applying any GA LIC will make an MCL3 card)
1062 * PCIXCC_MCL3 512-2048 128-2048 998 * PCIXCC_MCL3 ----- 128-2048
1063 * CEX2C 512-2048 128-2048 999 * CEX2C 512-2048 128-2048
1064 * 1000 *
1065 * ext_bitlens (extended bitlengths) is a global, since you should not apply an 1001 * ext_bitlens (extended bitlengths) is a global, since you should not apply an
@@ -1104,7 +1040,7 @@ select_device_type(int *dev_type_p, int bytelength)
1104 if (PCICA_avail || PCIXCC_MCL3_avail || CEX2C_avail) { 1040 if (PCICA_avail || PCIXCC_MCL3_avail || CEX2C_avail) {
1105 /** 1041 /**
1106 * bitlength is a factor, PCICA is the most capable, even with 1042 * bitlength is a factor, PCICA is the most capable, even with
1107 * the new MCL. 1043 * the new MCL for PCIXCC.
1108 */ 1044 */
1109 if ((bytelength < PCIXCC_MIN_MOD_SIZE) || 1045 if ((bytelength < PCIXCC_MIN_MOD_SIZE) ||
1110 (!ext_bitlens && (bytelength < OLD_PCIXCC_MIN_MOD_SIZE))) { 1046 (!ext_bitlens && (bytelength < OLD_PCIXCC_MIN_MOD_SIZE))) {
@@ -2144,73 +2080,15 @@ enable_card(int card_index)
2144 z90crypt.hdware_info->type_mask[devp->dev_type].user_disabled_count--; 2080 z90crypt.hdware_info->type_mask[devp->dev_type].user_disabled_count--;
2145} 2081}
2146 2082
2147static inline int
2148scan_char(unsigned char *bf, unsigned int len,
2149 unsigned int *offs, unsigned int *p_eof, unsigned char c)
2150{
2151 unsigned int i, found;
2152
2153 found = 0;
2154 for (i = 0; i < len; i++) {
2155 if (bf[i] == c) {
2156 found = 1;
2157 break;
2158 }
2159 if (bf[i] == '\0') {
2160 *p_eof = 1;
2161 break;
2162 }
2163 if (bf[i] == '\n') {
2164 break;
2165 }
2166 }
2167 *offs = i+1;
2168 return found;
2169}
2170
2171static inline int
2172scan_string(unsigned char *bf, unsigned int len,
2173 unsigned int *offs, unsigned int *p_eof, unsigned char *s)
2174{
2175 unsigned int temp_len, temp_offs, found, eof;
2176
2177 temp_len = temp_offs = found = eof = 0;
2178 while (!eof && !found) {
2179 found = scan_char(bf+temp_len, len-temp_len,
2180 &temp_offs, &eof, *s);
2181
2182 temp_len += temp_offs;
2183 if (eof) {
2184 found = 0;
2185 break;
2186 }
2187
2188 if (found) {
2189 if (len >= temp_offs+strlen(s)) {
2190 found = !strncmp(bf+temp_len-1, s, strlen(s));
2191 if (found) {
2192 *offs = temp_len+strlen(s)-1;
2193 break;
2194 }
2195 } else {
2196 found = 0;
2197 *p_eof = 1;
2198 break;
2199 }
2200 }
2201 }
2202 return found;
2203}
2204
2205static int 2083static int
2206z90crypt_status_write(struct file *file, const char __user *buffer, 2084z90crypt_status_write(struct file *file, const char __user *buffer,
2207 unsigned long count, void *data) 2085 unsigned long count, void *data)
2208{ 2086{
2209 int i, j, len, offs, found, eof; 2087 int j, eol;
2210 unsigned char *lbuf; 2088 unsigned char *lbuf, *ptr;
2211 unsigned int local_count; 2089 unsigned int local_count;
2212 2090
2213#define LBUFSIZE 600 2091#define LBUFSIZE 1200
2214 lbuf = kmalloc(LBUFSIZE, GFP_KERNEL); 2092 lbuf = kmalloc(LBUFSIZE, GFP_KERNEL);
2215 if (!lbuf) { 2093 if (!lbuf) {
2216 PRINTK("kmalloc failed!\n"); 2094 PRINTK("kmalloc failed!\n");
@@ -2227,49 +2105,46 @@ z90crypt_status_write(struct file *file, const char __user *buffer,
2227 return -EFAULT; 2105 return -EFAULT;
2228 } 2106 }
2229 2107
2230 lbuf[local_count-1] = '\0'; 2108 lbuf[local_count] = '\0';
2231 2109
2232 len = 0; 2110 ptr = strstr(lbuf, "Online devices");
2233 eof = 0; 2111 if (ptr == 0) {
2234 found = 0; 2112 PRINTK("Unable to parse data (missing \"Online devices\")\n");
2235 while (!eof) { 2113 kfree(lbuf);
2236 found = scan_string(lbuf+len, local_count-len, &offs, &eof, 2114 return count;
2237 "Online devices");
2238 len += offs;
2239 if (found == 1)
2240 break;
2241 } 2115 }
2242 2116
2243 if (eof) { 2117 ptr = strstr(ptr, "\n");
2118 if (ptr == 0) {
2119 PRINTK("Unable to parse data (missing newline after \"Online devices\")\n");
2244 kfree(lbuf); 2120 kfree(lbuf);
2245 return count; 2121 return count;
2246 } 2122 }
2123 ptr++;
2247 2124
2248 if (found) 2125 if (strstr(ptr, "Waiting work element counts") == NULL) {
2249 found = scan_char(lbuf+len, local_count-len, &offs, &eof, '\n'); 2126 PRINTK("Unable to parse data (missing \"Waiting work element counts\")\n");
2250
2251 if (!found || eof) {
2252 kfree(lbuf); 2127 kfree(lbuf);
2253 return count; 2128 return count;
2254 } 2129 }
2255 2130
2256 len += offs;
2257 j = 0; 2131 j = 0;
2258 for (i = 0; i < 80; i++) { 2132 eol = 0;
2259 switch (*(lbuf+len+i)) { 2133 while ((j < 64) && (*ptr != '\0')) {
2134 switch (*ptr) {
2260 case '\t': 2135 case '\t':
2261 case ' ': 2136 case ' ':
2262 break; 2137 break;
2263 case '\n': 2138 case '\n':
2264 default: 2139 default:
2265 eof = 1; 2140 eol = 1;
2266 break; 2141 break;
2267 case '0': 2142 case '0': // no device
2268 case '1': 2143 case '1': // PCICA
2269 case '2': 2144 case '2': // PCICC
2270 case '3': 2145 case '3': // PCIXCC_MCL2
2271 case '4': 2146 case '4': // PCIXCC_MCL3
2272 case '5': 2147 case '5': // CEX2C
2273 j++; 2148 j++;
2274 break; 2149 break;
2275 case 'd': 2150 case 'd':
@@ -2283,8 +2158,9 @@ z90crypt_status_write(struct file *file, const char __user *buffer,
2283 j++; 2158 j++;
2284 break; 2159 break;
2285 } 2160 }
2286 if (eof) 2161 if (eol)
2287 break; 2162 break;
2163 ptr++;
2288 } 2164 }
2289 2165
2290 kfree(lbuf); 2166 kfree(lbuf);
@@ -3479,45 +3355,5 @@ probe_PCIXCC_type(struct device *devPtr)
3479 return rv; 3355 return rv;
3480} 3356}
3481 3357
3482#ifdef Z90CRYPT_USE_HOTPLUG
3483static void
3484z90crypt_hotplug_event(int dev_major, int dev_minor, int action)
3485{
3486#ifdef CONFIG_HOTPLUG
3487 char *argv[3];
3488 char *envp[6];
3489 char major[20];
3490 char minor[20];
3491
3492 sprintf(major, "MAJOR=%d", dev_major);
3493 sprintf(minor, "MINOR=%d", dev_minor);
3494
3495 argv[0] = hotplug_path;
3496 argv[1] = "z90crypt";
3497 argv[2] = 0;
3498
3499 envp[0] = "HOME=/";
3500 envp[1] = "PATH=/sbin:/bin:/usr/sbin:/usr/bin";
3501
3502 switch (action) {
3503 case Z90CRYPT_HOTPLUG_ADD:
3504 envp[2] = "ACTION=add";
3505 break;
3506 case Z90CRYPT_HOTPLUG_REMOVE:
3507 envp[2] = "ACTION=remove";
3508 break;
3509 default:
3510 BUG();
3511 break;
3512 }
3513 envp[3] = major;
3514 envp[4] = minor;
3515 envp[5] = 0;
3516
3517 call_usermodehelper(argv[0], argv, envp, 0);
3518#endif
3519}
3520#endif
3521
3522module_init(z90crypt_init_module); 3358module_init(z90crypt_init_module);
3523module_exit(z90crypt_cleanup_module); 3359module_exit(z90crypt_cleanup_module);
diff --git a/drivers/s390/net/claw.c b/drivers/s390/net/claw.c
index 24c0af49c25..3092473991a 100644
--- a/drivers/s390/net/claw.c
+++ b/drivers/s390/net/claw.c
@@ -2,9 +2,9 @@
2 * drivers/s390/net/claw.c 2 * drivers/s390/net/claw.c
3 * ESCON CLAW network driver 3 * ESCON CLAW network driver
4 * 4 *
5 * $Revision: 1.35 $ $Date: 2005/03/24 12:25:38 $ 5 * $Revision: 1.38 $ $Date: 2005/08/29 09:47:04 $
6 * 6 *
7 * Linux fo zSeries version 7 * Linux for zSeries version
8 * Copyright (C) 2002,2005 IBM Corporation 8 * Copyright (C) 2002,2005 IBM Corporation
9 * Author(s) Original code written by: 9 * Author(s) Original code written by:
10 * Kazuo Iimura (iimura@jp.ibm.com) 10 * Kazuo Iimura (iimura@jp.ibm.com)
@@ -431,12 +431,12 @@ claw_pack_skb(struct claw_privbk *privptr)
431 if (!skb_queue_empty(&p_ch->collect_queue)) { 431 if (!skb_queue_empty(&p_ch->collect_queue)) {
432 /* some data */ 432 /* some data */
433 held_skb = skb_dequeue(&p_ch->collect_queue); 433 held_skb = skb_dequeue(&p_ch->collect_queue);
434 if (p_env->packing != DO_PACKED)
435 return held_skb;
436 if (held_skb) 434 if (held_skb)
437 atomic_dec(&held_skb->users); 435 dev_kfree_skb_any(held_skb);
438 else 436 else
439 return NULL; 437 return NULL;
438 if (p_env->packing != DO_PACKED)
439 return held_skb;
440 /* get a new SKB we will pack at least one */ 440 /* get a new SKB we will pack at least one */
441 new_skb = dev_alloc_skb(p_env->write_size); 441 new_skb = dev_alloc_skb(p_env->write_size);
442 if (new_skb == NULL) { 442 if (new_skb == NULL) {
@@ -455,7 +455,7 @@ claw_pack_skb(struct claw_privbk *privptr)
455 privptr->stats.tx_packets++; 455 privptr->stats.tx_packets++;
456 so_far += held_skb->len; 456 so_far += held_skb->len;
457 pkt_cnt++; 457 pkt_cnt++;
458 dev_kfree_skb_irq(held_skb); 458 dev_kfree_skb_any(held_skb);
459 held_skb = skb_dequeue(&p_ch->collect_queue); 459 held_skb = skb_dequeue(&p_ch->collect_queue);
460 if (held_skb) 460 if (held_skb)
461 atomic_dec(&held_skb->users); 461 atomic_dec(&held_skb->users);
@@ -1092,7 +1092,7 @@ claw_release(struct net_device *dev)
1092 } 1092 }
1093 } 1093 }
1094 if (privptr->pk_skb != NULL) { 1094 if (privptr->pk_skb != NULL) {
1095 dev_kfree_skb(privptr->pk_skb); 1095 dev_kfree_skb_any(privptr->pk_skb);
1096 privptr->pk_skb = NULL; 1096 privptr->pk_skb = NULL;
1097 } 1097 }
1098 if(privptr->buffs_alloc != 1) { 1098 if(privptr->buffs_alloc != 1) {
@@ -2016,7 +2016,7 @@ claw_hw_tx(struct sk_buff *skb, struct net_device *dev, long linkid)
2016 p_buf=(struct ccwbk*)privptr->p_end_ccw; 2016 p_buf=(struct ccwbk*)privptr->p_end_ccw;
2017 dumpit((char *)p_buf, sizeof(struct endccw)); 2017 dumpit((char *)p_buf, sizeof(struct endccw));
2018#endif 2018#endif
2019 dev_kfree_skb(skb); 2019 dev_kfree_skb_any(skb);
2020 if (linkid==0) { 2020 if (linkid==0) {
2021 lock=LOCK_NO; 2021 lock=LOCK_NO;
2022 } 2022 }
@@ -4061,7 +4061,7 @@ claw_purge_skb_queue(struct sk_buff_head *q)
4061 4061
4062 while ((skb = skb_dequeue(q))) { 4062 while ((skb = skb_dequeue(q))) {
4063 atomic_dec(&skb->users); 4063 atomic_dec(&skb->users);
4064 dev_kfree_skb_irq(skb); 4064 dev_kfree_skb_any(skb);
4065 } 4065 }
4066} 4066}
4067 4067
@@ -4410,7 +4410,7 @@ claw_init(void)
4410#else 4410#else
4411 "compiled into kernel " 4411 "compiled into kernel "
4412#endif 4412#endif
4413 " $Revision: 1.35 $ $Date: 2005/03/24 12:25:38 $ \n"); 4413 " $Revision: 1.38 $ $Date: 2005/08/29 09:47:04 $ \n");
4414 4414
4415 4415
4416#ifdef FUNCTRACE 4416#ifdef FUNCTRACE
diff --git a/drivers/s390/s390mach.c b/drivers/s390/s390mach.c
index 5bb255e02ac..4191fd9d4d1 100644
--- a/drivers/s390/s390mach.c
+++ b/drivers/s390/s390mach.c
@@ -240,7 +240,7 @@ s390_revalidate_registers(struct mci *mci)
240 * Floating point control register can't be restored. 240 * Floating point control register can't be restored.
241 * Task will be terminated. 241 * Task will be terminated.
242 */ 242 */
243 asm volatile ("lfpc 0(%0)" : : "a" (&zero)); 243 asm volatile ("lfpc 0(%0)" : : "a" (&zero), "m" (zero));
244 kill_task = 1; 244 kill_task = 1;
245 245
246 } 246 }
diff --git a/drivers/sbus/char/Kconfig b/drivers/sbus/char/Kconfig
index a41778a490d..3a8152906bf 100644
--- a/drivers/sbus/char/Kconfig
+++ b/drivers/sbus/char/Kconfig
@@ -69,11 +69,40 @@ config SUN_JSFLASH
69 If you say Y here, you will be able to boot from your JavaStation's 69 If you say Y here, you will be able to boot from your JavaStation's
70 Flash memory. 70 Flash memory.
71 71
72# XXX Why don't we do "source drivers/char/Config.in" somewhere? 72config BBC_I2C
73# no shit 73 tristate "UltraSPARC-III bootbus i2c controller driver"
74config RTC 74 depends on PCI && SPARC64
75 tristate "PC-style Real Time Clock Support" 75 help
76 depends on PCI && EXPERIMENTAL && SPARC32 76 The BBC devices on the UltraSPARC III have two I2C controllers. The
77 first I2C controller connects mainly to configuration PROMs (NVRAM,
78 CPU configuration, DIMM types, etc.). The second I2C controller
79 connects to environmental control devices such as fans and
80 temperature sensors. The second controller also connects to the
81 smartcard reader, if present. Say Y to enable support for these.
82
83config ENVCTRL
84 tristate "SUNW, envctrl support"
85 depends on PCI && SPARC64
86 help
87 Kernel support for temperature and fan monitoring on Sun SME
88 machines.
89
90 To compile this driver as a module, choose M here: the
91 module will be called envctrl.
92
93config DISPLAY7SEG
94 tristate "7-Segment Display support"
95 depends on PCI && SPARC64
96 ---help---
97 This is the driver for the 7-segment display and LED present on
98 Sun Microsystems CompactPCI models CP1400 and CP1500.
99
100 To compile this driver as a module, choose M here: the
101 module will be called display7seg.
102
103 If you do not have a CompactPCI model CP1400 or CP1500, or
104 another UltraSPARC-IIi-cEngine boardset with a 7-segment display,
105 you should say N to this option.
77 106
78endmenu 107endmenu
79 108
diff --git a/drivers/scsi/3w-xxxx.c b/drivers/scsi/3w-xxxx.c
index 973c51fb0fe..ae9e0203e9d 100644
--- a/drivers/scsi/3w-xxxx.c
+++ b/drivers/scsi/3w-xxxx.c
@@ -1499,22 +1499,43 @@ static int tw_scsiop_inquiry(TW_Device_Extension *tw_dev, int request_id)
1499 return 0; 1499 return 0;
1500} /* End tw_scsiop_inquiry() */ 1500} /* End tw_scsiop_inquiry() */
1501 1501
1502static void tw_transfer_internal(TW_Device_Extension *tw_dev, int request_id,
1503 void *data, unsigned int len)
1504{
1505 struct scsi_cmnd *cmd = tw_dev->srb[request_id];
1506 void *buf;
1507 unsigned int transfer_len;
1508
1509 if (cmd->use_sg) {
1510 struct scatterlist *sg =
1511 (struct scatterlist *)cmd->request_buffer;
1512 buf = kmap_atomic(sg->page, KM_IRQ0) + sg->offset;
1513 transfer_len = min(sg->length, len);
1514 } else {
1515 buf = cmd->request_buffer;
1516 transfer_len = min(cmd->request_bufflen, len);
1517 }
1518
1519 memcpy(buf, data, transfer_len);
1520
1521 if (cmd->use_sg) {
1522 struct scatterlist *sg;
1523
1524 sg = (struct scatterlist *)cmd->request_buffer;
1525 kunmap_atomic(buf - sg->offset, KM_IRQ0);
1526 }
1527}
1528
1502/* This function is called by the isr to complete an inquiry command */ 1529/* This function is called by the isr to complete an inquiry command */
1503static int tw_scsiop_inquiry_complete(TW_Device_Extension *tw_dev, int request_id) 1530static int tw_scsiop_inquiry_complete(TW_Device_Extension *tw_dev, int request_id)
1504{ 1531{
1505 unsigned char *is_unit_present; 1532 unsigned char *is_unit_present;
1506 unsigned char *request_buffer; 1533 unsigned char request_buffer[36];
1507 TW_Param *param; 1534 TW_Param *param;
1508 1535
1509 dprintk(KERN_NOTICE "3w-xxxx: tw_scsiop_inquiry_complete()\n"); 1536 dprintk(KERN_NOTICE "3w-xxxx: tw_scsiop_inquiry_complete()\n");
1510 1537
1511 /* Fill request buffer */ 1538 memset(request_buffer, 0, sizeof(request_buffer));
1512 if (tw_dev->srb[request_id]->request_buffer == NULL) {
1513 printk(KERN_WARNING "3w-xxxx: tw_scsiop_inquiry_complete(): Request buffer NULL.\n");
1514 return 1;
1515 }
1516 request_buffer = tw_dev->srb[request_id]->request_buffer;
1517 memset(request_buffer, 0, tw_dev->srb[request_id]->request_bufflen);
1518 request_buffer[0] = TYPE_DISK; /* Peripheral device type */ 1539 request_buffer[0] = TYPE_DISK; /* Peripheral device type */
1519 request_buffer[1] = 0; /* Device type modifier */ 1540 request_buffer[1] = 0; /* Device type modifier */
1520 request_buffer[2] = 0; /* No ansi/iso compliance */ 1541 request_buffer[2] = 0; /* No ansi/iso compliance */
@@ -1522,6 +1543,8 @@ static int tw_scsiop_inquiry_complete(TW_Device_Extension *tw_dev, int request_i
1522 memcpy(&request_buffer[8], "3ware ", 8); /* Vendor ID */ 1543 memcpy(&request_buffer[8], "3ware ", 8); /* Vendor ID */
1523 sprintf(&request_buffer[16], "Logical Disk %-2d ", tw_dev->srb[request_id]->device->id); 1544 sprintf(&request_buffer[16], "Logical Disk %-2d ", tw_dev->srb[request_id]->device->id);
1524 memcpy(&request_buffer[32], TW_DRIVER_VERSION, 3); 1545 memcpy(&request_buffer[32], TW_DRIVER_VERSION, 3);
1546 tw_transfer_internal(tw_dev, request_id, request_buffer,
1547 sizeof(request_buffer));
1525 1548
1526 param = (TW_Param *)tw_dev->alignment_virtual_address[request_id]; 1549 param = (TW_Param *)tw_dev->alignment_virtual_address[request_id];
1527 if (param == NULL) { 1550 if (param == NULL) {
@@ -1612,7 +1635,7 @@ static int tw_scsiop_mode_sense_complete(TW_Device_Extension *tw_dev, int reques
1612{ 1635{
1613 TW_Param *param; 1636 TW_Param *param;
1614 unsigned char *flags; 1637 unsigned char *flags;
1615 unsigned char *request_buffer; 1638 unsigned char request_buffer[8];
1616 1639
1617 dprintk(KERN_NOTICE "3w-xxxx: tw_scsiop_mode_sense_complete()\n"); 1640 dprintk(KERN_NOTICE "3w-xxxx: tw_scsiop_mode_sense_complete()\n");
1618 1641
@@ -1622,8 +1645,7 @@ static int tw_scsiop_mode_sense_complete(TW_Device_Extension *tw_dev, int reques
1622 return 1; 1645 return 1;
1623 } 1646 }
1624 flags = (char *)&(param->data[0]); 1647 flags = (char *)&(param->data[0]);
1625 request_buffer = tw_dev->srb[request_id]->buffer; 1648 memset(request_buffer, 0, sizeof(request_buffer));
1626 memset(request_buffer, 0, tw_dev->srb[request_id]->request_bufflen);
1627 1649
1628 request_buffer[0] = 0xf; /* mode data length */ 1650 request_buffer[0] = 0xf; /* mode data length */
1629 request_buffer[1] = 0; /* default medium type */ 1651 request_buffer[1] = 0; /* default medium type */
@@ -1635,6 +1657,8 @@ static int tw_scsiop_mode_sense_complete(TW_Device_Extension *tw_dev, int reques
1635 request_buffer[6] = 0x4; /* WCE on */ 1657 request_buffer[6] = 0x4; /* WCE on */
1636 else 1658 else
1637 request_buffer[6] = 0x0; /* WCE off */ 1659 request_buffer[6] = 0x0; /* WCE off */
1660 tw_transfer_internal(tw_dev, request_id, request_buffer,
1661 sizeof(request_buffer));
1638 1662
1639 return 0; 1663 return 0;
1640} /* End tw_scsiop_mode_sense_complete() */ 1664} /* End tw_scsiop_mode_sense_complete() */
@@ -1701,17 +1725,12 @@ static int tw_scsiop_read_capacity_complete(TW_Device_Extension *tw_dev, int req
1701{ 1725{
1702 unsigned char *param_data; 1726 unsigned char *param_data;
1703 u32 capacity; 1727 u32 capacity;
1704 char *buff; 1728 char buff[8];
1705 TW_Param *param; 1729 TW_Param *param;
1706 1730
1707 dprintk(KERN_NOTICE "3w-xxxx: tw_scsiop_read_capacity_complete()\n"); 1731 dprintk(KERN_NOTICE "3w-xxxx: tw_scsiop_read_capacity_complete()\n");
1708 1732
1709 buff = tw_dev->srb[request_id]->request_buffer; 1733 memset(buff, 0, sizeof(buff));
1710 if (buff == NULL) {
1711 printk(KERN_WARNING "3w-xxxx: tw_scsiop_read_capacity_complete(): Request buffer NULL.\n");
1712 return 1;
1713 }
1714 memset(buff, 0, tw_dev->srb[request_id]->request_bufflen);
1715 param = (TW_Param *)tw_dev->alignment_virtual_address[request_id]; 1734 param = (TW_Param *)tw_dev->alignment_virtual_address[request_id];
1716 if (param == NULL) { 1735 if (param == NULL) {
1717 printk(KERN_WARNING "3w-xxxx: tw_scsiop_read_capacity_complete(): Bad alignment virtual address.\n"); 1736 printk(KERN_WARNING "3w-xxxx: tw_scsiop_read_capacity_complete(): Bad alignment virtual address.\n");
@@ -1739,6 +1758,8 @@ static int tw_scsiop_read_capacity_complete(TW_Device_Extension *tw_dev, int req
1739 buff[6] = (TW_BLOCK_SIZE >> 8) & 0xff; 1758 buff[6] = (TW_BLOCK_SIZE >> 8) & 0xff;
1740 buff[7] = TW_BLOCK_SIZE & 0xff; 1759 buff[7] = TW_BLOCK_SIZE & 0xff;
1741 1760
1761 tw_transfer_internal(tw_dev, request_id, buff, sizeof(buff));
1762
1742 return 0; 1763 return 0;
1743} /* End tw_scsiop_read_capacity_complete() */ 1764} /* End tw_scsiop_read_capacity_complete() */
1744 1765
diff --git a/drivers/scsi/Kconfig b/drivers/scsi/Kconfig
index 12c208fb18c..2d21265e650 100644
--- a/drivers/scsi/Kconfig
+++ b/drivers/scsi/Kconfig
@@ -1,5 +1,11 @@
1menu "SCSI device support" 1menu "SCSI device support"
2 2
3config RAID_ATTRS
4 tristate "RAID Transport Class"
5 default n
6 ---help---
7 Provides RAID
8
3config SCSI 9config SCSI
4 tristate "SCSI device support" 10 tristate "SCSI device support"
5 ---help--- 11 ---help---
@@ -250,7 +256,7 @@ config SCSI_DECNCR
250 256
251config SCSI_DECSII 257config SCSI_DECSII
252 tristate "DEC SII Scsi Driver" 258 tristate "DEC SII Scsi Driver"
253 depends on MACH_DECSTATION && SCSI && MIPS32 259 depends on MACH_DECSTATION && SCSI && 32BIT
254 260
255config BLK_DEV_3W_XXXX_RAID 261config BLK_DEV_3W_XXXX_RAID
256 tristate "3ware 5/6/7/8xxx ATA-RAID support" 262 tristate "3ware 5/6/7/8xxx ATA-RAID support"
@@ -459,6 +465,15 @@ config SCSI_ATA_PIIX
459 465
460 If unsure, say N. 466 If unsure, say N.
461 467
468config SCSI_SATA_MV
469 tristate "Marvell SATA support"
470 depends on SCSI_SATA && PCI && EXPERIMENTAL
471 help
472 This option enables support for the Marvell Serial ATA family.
473 Currently supports 88SX[56]0[48][01] chips.
474
475 If unsure, say N.
476
462config SCSI_SATA_NV 477config SCSI_SATA_NV
463 tristate "NVIDIA SATA support" 478 tristate "NVIDIA SATA support"
464 depends on SCSI_SATA && PCI && EXPERIMENTAL 479 depends on SCSI_SATA && PCI && EXPERIMENTAL
diff --git a/drivers/scsi/Makefile b/drivers/scsi/Makefile
index 3746fb9fa2f..4b4fd94c267 100644
--- a/drivers/scsi/Makefile
+++ b/drivers/scsi/Makefile
@@ -22,6 +22,8 @@ subdir-$(CONFIG_PCMCIA) += pcmcia
22 22
23obj-$(CONFIG_SCSI) += scsi_mod.o 23obj-$(CONFIG_SCSI) += scsi_mod.o
24 24
25obj-$(CONFIG_RAID_ATTRS) += raid_class.o
26
25# --- NOTE ORDERING HERE --- 27# --- NOTE ORDERING HERE ---
26# For kernel non-modular link, transport attributes need to 28# For kernel non-modular link, transport attributes need to
27# be initialised before drivers 29# be initialised before drivers
@@ -132,6 +134,7 @@ obj-$(CONFIG_SCSI_SATA_SIS) += libata.o sata_sis.o
132obj-$(CONFIG_SCSI_SATA_SX4) += libata.o sata_sx4.o 134obj-$(CONFIG_SCSI_SATA_SX4) += libata.o sata_sx4.o
133obj-$(CONFIG_SCSI_SATA_NV) += libata.o sata_nv.o 135obj-$(CONFIG_SCSI_SATA_NV) += libata.o sata_nv.o
134obj-$(CONFIG_SCSI_SATA_ULI) += libata.o sata_uli.o 136obj-$(CONFIG_SCSI_SATA_ULI) += libata.o sata_uli.o
137obj-$(CONFIG_SCSI_SATA_MV) += libata.o sata_mv.o
135 138
136obj-$(CONFIG_ARM) += arm/ 139obj-$(CONFIG_ARM) += arm/
137 140
diff --git a/drivers/scsi/NCR5380.c b/drivers/scsi/NCR5380.c
index f8ec6fe7d85..d40ba0bd68a 100644
--- a/drivers/scsi/NCR5380.c
+++ b/drivers/scsi/NCR5380.c
@@ -88,6 +88,13 @@
88 */ 88 */
89#include <scsi/scsi_dbg.h> 89#include <scsi/scsi_dbg.h>
90 90
91#ifndef NDEBUG
92#define NDEBUG 0
93#endif
94#ifndef NDEBUG
95#define NDEBUG_ABORT 0
96#endif
97
91#if (NDEBUG & NDEBUG_LISTS) 98#if (NDEBUG & NDEBUG_LISTS)
92#define LIST(x,y) {printk("LINE:%d Adding %p to %p\n", __LINE__, (void*)(x), (void*)(y)); if ((x)==(y)) udelay(5); } 99#define LIST(x,y) {printk("LINE:%d Adding %p to %p\n", __LINE__, (void*)(x), (void*)(y)); if ((x)==(y)) udelay(5); }
93#define REMOVE(w,x,y,z) {printk("LINE:%d Removing: %p->%p %p->%p \n", __LINE__, (void*)(w), (void*)(x), (void*)(y), (void*)(z)); if ((x)==(y)) udelay(5); } 100#define REMOVE(w,x,y,z) {printk("LINE:%d Removing: %p->%p %p->%p \n", __LINE__, (void*)(w), (void*)(x), (void*)(y), (void*)(z)); if ((x)==(y)) udelay(5); }
@@ -359,7 +366,7 @@ static struct {
359 {PHASE_UNKNOWN, "UNKNOWN"} 366 {PHASE_UNKNOWN, "UNKNOWN"}
360}; 367};
361 368
362#ifdef NDEBUG 369#if NDEBUG
363static struct { 370static struct {
364 unsigned char mask; 371 unsigned char mask;
365 const char *name; 372 const char *name;
diff --git a/drivers/scsi/NCR53c406a.c b/drivers/scsi/NCR53c406a.c
index 79ae73b2368..e1f2246ee7c 100644
--- a/drivers/scsi/NCR53c406a.c
+++ b/drivers/scsi/NCR53c406a.c
@@ -62,7 +62,7 @@
62 62
63#define SYNC_MODE 0 /* Synchronous transfer mode */ 63#define SYNC_MODE 0 /* Synchronous transfer mode */
64 64
65#if DEBUG 65#ifdef DEBUG
66#undef NCR53C406A_DEBUG 66#undef NCR53C406A_DEBUG
67#define NCR53C406A_DEBUG 1 67#define NCR53C406A_DEBUG 1
68#endif 68#endif
diff --git a/drivers/scsi/aacraid/aachba.c b/drivers/scsi/aacraid/aachba.c
index ccdf440021f..a8e3dfcd0dc 100644
--- a/drivers/scsi/aacraid/aachba.c
+++ b/drivers/scsi/aacraid/aachba.c
@@ -133,6 +133,7 @@ struct inquiry_data {
133 133
134static unsigned long aac_build_sg(struct scsi_cmnd* scsicmd, struct sgmap* sgmap); 134static unsigned long aac_build_sg(struct scsi_cmnd* scsicmd, struct sgmap* sgmap);
135static unsigned long aac_build_sg64(struct scsi_cmnd* scsicmd, struct sgmap64* psg); 135static unsigned long aac_build_sg64(struct scsi_cmnd* scsicmd, struct sgmap64* psg);
136static unsigned long aac_build_sgraw(struct scsi_cmnd* scsicmd, struct sgmapraw* psg);
136static int aac_send_srb_fib(struct scsi_cmnd* scsicmd); 137static int aac_send_srb_fib(struct scsi_cmnd* scsicmd);
137#ifdef AAC_DETAILED_STATUS_INFO 138#ifdef AAC_DETAILED_STATUS_INFO
138static char *aac_get_status_string(u32 status); 139static char *aac_get_status_string(u32 status);
@@ -348,6 +349,27 @@ static void aac_io_done(struct scsi_cmnd * scsicmd)
348 spin_unlock_irqrestore(host->host_lock, cpu_flags); 349 spin_unlock_irqrestore(host->host_lock, cpu_flags);
349} 350}
350 351
352static void aac_internal_transfer(struct scsi_cmnd *scsicmd, void *data, unsigned int offset, unsigned int len)
353{
354 void *buf;
355 unsigned int transfer_len;
356 struct scatterlist *sg = scsicmd->request_buffer;
357
358 if (scsicmd->use_sg) {
359 buf = kmap_atomic(sg->page, KM_IRQ0) + sg->offset;
360 transfer_len = min(sg->length, len + offset);
361 } else {
362 buf = scsicmd->request_buffer;
363 transfer_len = min(scsicmd->request_bufflen, len + offset);
364 }
365
366 memcpy(buf + offset, data, transfer_len - offset);
367
368 if (scsicmd->use_sg)
369 kunmap_atomic(buf - sg->offset, KM_IRQ0);
370
371}
372
351static void get_container_name_callback(void *context, struct fib * fibptr) 373static void get_container_name_callback(void *context, struct fib * fibptr)
352{ 374{
353 struct aac_get_name_resp * get_name_reply; 375 struct aac_get_name_resp * get_name_reply;
@@ -363,18 +385,22 @@ static void get_container_name_callback(void *context, struct fib * fibptr)
363 /* Failure is irrelevant, using default value instead */ 385 /* Failure is irrelevant, using default value instead */
364 if ((le32_to_cpu(get_name_reply->status) == CT_OK) 386 if ((le32_to_cpu(get_name_reply->status) == CT_OK)
365 && (get_name_reply->data[0] != '\0')) { 387 && (get_name_reply->data[0] != '\0')) {
366 int count; 388 char *sp = get_name_reply->data;
367 char * dp;
368 char * sp = get_name_reply->data;
369 sp[sizeof(((struct aac_get_name_resp *)NULL)->data)-1] = '\0'; 389 sp[sizeof(((struct aac_get_name_resp *)NULL)->data)-1] = '\0';
370 while (*sp == ' ') 390 while (*sp == ' ')
371 ++sp; 391 ++sp;
372 count = sizeof(((struct inquiry_data *)NULL)->inqd_pid); 392 if (*sp) {
373 dp = ((struct inquiry_data *)scsicmd->request_buffer)->inqd_pid; 393 char d[sizeof(((struct inquiry_data *)NULL)->inqd_pid)];
374 if (*sp) do { 394 int count = sizeof(d);
375 *dp++ = (*sp) ? *sp++ : ' '; 395 char *dp = d;
376 } while (--count > 0); 396 do {
397 *dp++ = (*sp) ? *sp++ : ' ';
398 } while (--count > 0);
399 aac_internal_transfer(scsicmd, d,
400 offsetof(struct inquiry_data, inqd_pid), sizeof(d));
401 }
377 } 402 }
403
378 scsicmd->result = DID_OK << 16 | COMMAND_COMPLETE << 8 | SAM_STAT_GOOD; 404 scsicmd->result = DID_OK << 16 | COMMAND_COMPLETE << 8 | SAM_STAT_GOOD;
379 405
380 fib_complete(fibptr); 406 fib_complete(fibptr);
@@ -777,34 +803,36 @@ int aac_get_adapter_info(struct aac_dev* dev)
777 /* 803 /*
778 * 57 scatter gather elements 804 * 57 scatter gather elements
779 */ 805 */
780 dev->scsi_host_ptr->sg_tablesize = (dev->max_fib_size - 806 if (!(dev->raw_io_interface)) {
781 sizeof(struct aac_fibhdr) - 807 dev->scsi_host_ptr->sg_tablesize = (dev->max_fib_size -
782 sizeof(struct aac_write) + sizeof(struct sgmap)) /
783 sizeof(struct sgmap);
784 if (dev->dac_support) {
785 /*
786 * 38 scatter gather elements
787 */
788 dev->scsi_host_ptr->sg_tablesize =
789 (dev->max_fib_size -
790 sizeof(struct aac_fibhdr) - 808 sizeof(struct aac_fibhdr) -
791 sizeof(struct aac_write64) + 809 sizeof(struct aac_write) + sizeof(struct sgmap)) /
792 sizeof(struct sgmap64)) / 810 sizeof(struct sgmap);
793 sizeof(struct sgmap64); 811 if (dev->dac_support) {
794 } 812 /*
795 dev->scsi_host_ptr->max_sectors = AAC_MAX_32BIT_SGBCOUNT; 813 * 38 scatter gather elements
796 if(!(dev->adapter_info.options & AAC_OPT_NEW_COMM)) { 814 */
797 /* 815 dev->scsi_host_ptr->sg_tablesize =
798 * Worst case size that could cause sg overflow when 816 (dev->max_fib_size -
799 * we break up SG elements that are larger than 64KB. 817 sizeof(struct aac_fibhdr) -
800 * Would be nice if we could tell the SCSI layer what 818 sizeof(struct aac_write64) +
801 * the maximum SG element size can be. Worst case is 819 sizeof(struct sgmap64)) /
802 * (sg_tablesize-1) 4KB elements with one 64KB 820 sizeof(struct sgmap64);
803 * element. 821 }
804 * 32bit -> 468 or 238KB 64bit -> 424 or 212KB 822 dev->scsi_host_ptr->max_sectors = AAC_MAX_32BIT_SGBCOUNT;
805 */ 823 if(!(dev->adapter_info.options & AAC_OPT_NEW_COMM)) {
806 dev->scsi_host_ptr->max_sectors = 824 /*
807 (dev->scsi_host_ptr->sg_tablesize * 8) + 112; 825 * Worst case size that could cause sg overflow when
826 * we break up SG elements that are larger than 64KB.
827 * Would be nice if we could tell the SCSI layer what
828 * the maximum SG element size can be. Worst case is
829 * (sg_tablesize-1) 4KB elements with one 64KB
830 * element.
831 * 32bit -> 468 or 238KB 64bit -> 424 or 212KB
832 */
833 dev->scsi_host_ptr->max_sectors =
834 (dev->scsi_host_ptr->sg_tablesize * 8) + 112;
835 }
808 } 836 }
809 837
810 fib_complete(fibptr); 838 fib_complete(fibptr);
@@ -814,12 +842,11 @@ int aac_get_adapter_info(struct aac_dev* dev)
814} 842}
815 843
816 844
817static void read_callback(void *context, struct fib * fibptr) 845static void io_callback(void *context, struct fib * fibptr)
818{ 846{
819 struct aac_dev *dev; 847 struct aac_dev *dev;
820 struct aac_read_reply *readreply; 848 struct aac_read_reply *readreply;
821 struct scsi_cmnd *scsicmd; 849 struct scsi_cmnd *scsicmd;
822 u32 lba;
823 u32 cid; 850 u32 cid;
824 851
825 scsicmd = (struct scsi_cmnd *) context; 852 scsicmd = (struct scsi_cmnd *) context;
@@ -827,8 +854,7 @@ static void read_callback(void *context, struct fib * fibptr)
827 dev = (struct aac_dev *)scsicmd->device->host->hostdata; 854 dev = (struct aac_dev *)scsicmd->device->host->hostdata;
828 cid = ID_LUN_TO_CONTAINER(scsicmd->device->id, scsicmd->device->lun); 855 cid = ID_LUN_TO_CONTAINER(scsicmd->device->id, scsicmd->device->lun);
829 856
830 lba = ((scsicmd->cmnd[1] & 0x1F) << 16) | (scsicmd->cmnd[2] << 8) | scsicmd->cmnd[3]; 857 dprintk((KERN_DEBUG "io_callback[cpu %d]: lba = %u, t = %ld.\n", smp_processor_id(), ((scsicmd->cmnd[1] & 0x1F) << 16) | (scsicmd->cmnd[2] << 8) | scsicmd->cmnd[3], jiffies));
831 dprintk((KERN_DEBUG "read_callback[cpu %d]: lba = %u, t = %ld.\n", smp_processor_id(), lba, jiffies));
832 858
833 if (fibptr == NULL) 859 if (fibptr == NULL)
834 BUG(); 860 BUG();
@@ -847,7 +873,7 @@ static void read_callback(void *context, struct fib * fibptr)
847 scsicmd->result = DID_OK << 16 | COMMAND_COMPLETE << 8 | SAM_STAT_GOOD; 873 scsicmd->result = DID_OK << 16 | COMMAND_COMPLETE << 8 | SAM_STAT_GOOD;
848 else { 874 else {
849#ifdef AAC_DETAILED_STATUS_INFO 875#ifdef AAC_DETAILED_STATUS_INFO
850 printk(KERN_WARNING "read_callback: io failed, status = %d\n", 876 printk(KERN_WARNING "io_callback: io failed, status = %d\n",
851 le32_to_cpu(readreply->status)); 877 le32_to_cpu(readreply->status));
852#endif 878#endif
853 scsicmd->result = DID_OK << 16 | COMMAND_COMPLETE << 8 | SAM_STAT_CHECK_CONDITION; 879 scsicmd->result = DID_OK << 16 | COMMAND_COMPLETE << 8 | SAM_STAT_CHECK_CONDITION;
@@ -867,53 +893,6 @@ static void read_callback(void *context, struct fib * fibptr)
867 aac_io_done(scsicmd); 893 aac_io_done(scsicmd);
868} 894}
869 895
870static void write_callback(void *context, struct fib * fibptr)
871{
872 struct aac_dev *dev;
873 struct aac_write_reply *writereply;
874 struct scsi_cmnd *scsicmd;
875 u32 lba;
876 u32 cid;
877
878 scsicmd = (struct scsi_cmnd *) context;
879 dev = (struct aac_dev *)scsicmd->device->host->hostdata;
880 cid = ID_LUN_TO_CONTAINER(scsicmd->device->id, scsicmd->device->lun);
881
882 lba = ((scsicmd->cmnd[1] & 0x1F) << 16) | (scsicmd->cmnd[2] << 8) | scsicmd->cmnd[3];
883 dprintk((KERN_DEBUG "write_callback[cpu %d]: lba = %u, t = %ld.\n", smp_processor_id(), lba, jiffies));
884 if (fibptr == NULL)
885 BUG();
886
887 if(scsicmd->use_sg)
888 pci_unmap_sg(dev->pdev,
889 (struct scatterlist *)scsicmd->buffer,
890 scsicmd->use_sg,
891 scsicmd->sc_data_direction);
892 else if(scsicmd->request_bufflen)
893 pci_unmap_single(dev->pdev, scsicmd->SCp.dma_handle,
894 scsicmd->request_bufflen,
895 scsicmd->sc_data_direction);
896
897 writereply = (struct aac_write_reply *) fib_data(fibptr);
898 if (le32_to_cpu(writereply->status) == ST_OK)
899 scsicmd->result = DID_OK << 16 | COMMAND_COMPLETE << 8 | SAM_STAT_GOOD;
900 else {
901 printk(KERN_WARNING "write_callback: write failed, status = %d\n", writereply->status);
902 scsicmd->result = DID_OK << 16 | COMMAND_COMPLETE << 8 | SAM_STAT_CHECK_CONDITION;
903 set_sense((u8 *) &dev->fsa_dev[cid].sense_data,
904 HARDWARE_ERROR,
905 SENCODE_INTERNAL_TARGET_FAILURE,
906 ASENCODE_INTERNAL_TARGET_FAILURE, 0, 0,
907 0, 0);
908 memcpy(scsicmd->sense_buffer, &dev->fsa_dev[cid].sense_data,
909 sizeof(struct sense_data));
910 }
911
912 fib_complete(fibptr);
913 fib_free(fibptr);
914 aac_io_done(scsicmd);
915}
916
917static int aac_read(struct scsi_cmnd * scsicmd, int cid) 896static int aac_read(struct scsi_cmnd * scsicmd, int cid)
918{ 897{
919 u32 lba; 898 u32 lba;
@@ -954,7 +933,32 @@ static int aac_read(struct scsi_cmnd * scsicmd, int cid)
954 933
955 fib_init(cmd_fibcontext); 934 fib_init(cmd_fibcontext);
956 935
957 if (dev->dac_support == 1) { 936 if (dev->raw_io_interface) {
937 struct aac_raw_io *readcmd;
938 readcmd = (struct aac_raw_io *) fib_data(cmd_fibcontext);
939 readcmd->block[0] = cpu_to_le32(lba);
940 readcmd->block[1] = 0;
941 readcmd->count = cpu_to_le32(count<<9);
942 readcmd->cid = cpu_to_le16(cid);
943 readcmd->flags = cpu_to_le16(1);
944 readcmd->bpTotal = 0;
945 readcmd->bpComplete = 0;
946
947 aac_build_sgraw(scsicmd, &readcmd->sg);
948 fibsize = sizeof(struct aac_raw_io) + ((le32_to_cpu(readcmd->sg.count) - 1) * sizeof (struct sgentryraw));
949 if (fibsize > (dev->max_fib_size - sizeof(struct aac_fibhdr)))
950 BUG();
951 /*
952 * Now send the Fib to the adapter
953 */
954 status = fib_send(ContainerRawIo,
955 cmd_fibcontext,
956 fibsize,
957 FsaNormal,
958 0, 1,
959 (fib_callback) io_callback,
960 (void *) scsicmd);
961 } else if (dev->dac_support == 1) {
958 struct aac_read64 *readcmd; 962 struct aac_read64 *readcmd;
959 readcmd = (struct aac_read64 *) fib_data(cmd_fibcontext); 963 readcmd = (struct aac_read64 *) fib_data(cmd_fibcontext);
960 readcmd->command = cpu_to_le32(VM_CtHostRead64); 964 readcmd->command = cpu_to_le32(VM_CtHostRead64);
@@ -968,7 +972,7 @@ static int aac_read(struct scsi_cmnd * scsicmd, int cid)
968 fibsize = sizeof(struct aac_read64) + 972 fibsize = sizeof(struct aac_read64) +
969 ((le32_to_cpu(readcmd->sg.count) - 1) * 973 ((le32_to_cpu(readcmd->sg.count) - 1) *
970 sizeof (struct sgentry64)); 974 sizeof (struct sgentry64));
971 BUG_ON (fibsize > (sizeof(struct hw_fib) - 975 BUG_ON (fibsize > (dev->max_fib_size -
972 sizeof(struct aac_fibhdr))); 976 sizeof(struct aac_fibhdr)));
973 /* 977 /*
974 * Now send the Fib to the adapter 978 * Now send the Fib to the adapter
@@ -978,7 +982,7 @@ static int aac_read(struct scsi_cmnd * scsicmd, int cid)
978 fibsize, 982 fibsize,
979 FsaNormal, 983 FsaNormal,
980 0, 1, 984 0, 1,
981 (fib_callback) read_callback, 985 (fib_callback) io_callback,
982 (void *) scsicmd); 986 (void *) scsicmd);
983 } else { 987 } else {
984 struct aac_read *readcmd; 988 struct aac_read *readcmd;
@@ -1002,7 +1006,7 @@ static int aac_read(struct scsi_cmnd * scsicmd, int cid)
1002 fibsize, 1006 fibsize,
1003 FsaNormal, 1007 FsaNormal,
1004 0, 1, 1008 0, 1,
1005 (fib_callback) read_callback, 1009 (fib_callback) io_callback,
1006 (void *) scsicmd); 1010 (void *) scsicmd);
1007 } 1011 }
1008 1012
@@ -1061,7 +1065,32 @@ static int aac_write(struct scsi_cmnd * scsicmd, int cid)
1061 } 1065 }
1062 fib_init(cmd_fibcontext); 1066 fib_init(cmd_fibcontext);
1063 1067
1064 if(dev->dac_support == 1) { 1068 if (dev->raw_io_interface) {
1069 struct aac_raw_io *writecmd;
1070 writecmd = (struct aac_raw_io *) fib_data(cmd_fibcontext);
1071 writecmd->block[0] = cpu_to_le32(lba);
1072 writecmd->block[1] = 0;
1073 writecmd->count = cpu_to_le32(count<<9);
1074 writecmd->cid = cpu_to_le16(cid);
1075 writecmd->flags = 0;
1076 writecmd->bpTotal = 0;
1077 writecmd->bpComplete = 0;
1078
1079 aac_build_sgraw(scsicmd, &writecmd->sg);
1080 fibsize = sizeof(struct aac_raw_io) + ((le32_to_cpu(writecmd->sg.count) - 1) * sizeof (struct sgentryraw));
1081 if (fibsize > (dev->max_fib_size - sizeof(struct aac_fibhdr)))
1082 BUG();
1083 /*
1084 * Now send the Fib to the adapter
1085 */
1086 status = fib_send(ContainerRawIo,
1087 cmd_fibcontext,
1088 fibsize,
1089 FsaNormal,
1090 0, 1,
1091 (fib_callback) io_callback,
1092 (void *) scsicmd);
1093 } else if (dev->dac_support == 1) {
1065 struct aac_write64 *writecmd; 1094 struct aac_write64 *writecmd;
1066 writecmd = (struct aac_write64 *) fib_data(cmd_fibcontext); 1095 writecmd = (struct aac_write64 *) fib_data(cmd_fibcontext);
1067 writecmd->command = cpu_to_le32(VM_CtHostWrite64); 1096 writecmd->command = cpu_to_le32(VM_CtHostWrite64);
@@ -1085,7 +1114,7 @@ static int aac_write(struct scsi_cmnd * scsicmd, int cid)
1085 fibsize, 1114 fibsize,
1086 FsaNormal, 1115 FsaNormal,
1087 0, 1, 1116 0, 1,
1088 (fib_callback) write_callback, 1117 (fib_callback) io_callback,
1089 (void *) scsicmd); 1118 (void *) scsicmd);
1090 } else { 1119 } else {
1091 struct aac_write *writecmd; 1120 struct aac_write *writecmd;
@@ -1111,7 +1140,7 @@ static int aac_write(struct scsi_cmnd * scsicmd, int cid)
1111 fibsize, 1140 fibsize,
1112 FsaNormal, 1141 FsaNormal,
1113 0, 1, 1142 0, 1,
1114 (fib_callback) write_callback, 1143 (fib_callback) io_callback,
1115 (void *) scsicmd); 1144 (void *) scsicmd);
1116 } 1145 }
1117 1146
@@ -1340,44 +1369,45 @@ int aac_scsi_cmd(struct scsi_cmnd * scsicmd)
1340 switch (scsicmd->cmnd[0]) { 1369 switch (scsicmd->cmnd[0]) {
1341 case INQUIRY: 1370 case INQUIRY:
1342 { 1371 {
1343 struct inquiry_data *inq_data_ptr; 1372 struct inquiry_data inq_data;
1344 1373
1345 dprintk((KERN_DEBUG "INQUIRY command, ID: %d.\n", scsicmd->device->id)); 1374 dprintk((KERN_DEBUG "INQUIRY command, ID: %d.\n", scsicmd->device->id));
1346 inq_data_ptr = (struct inquiry_data *)scsicmd->request_buffer; 1375 memset(&inq_data, 0, sizeof (struct inquiry_data));
1347 memset(inq_data_ptr, 0, sizeof (struct inquiry_data));
1348 1376
1349 inq_data_ptr->inqd_ver = 2; /* claim compliance to SCSI-2 */ 1377 inq_data.inqd_ver = 2; /* claim compliance to SCSI-2 */
1350 inq_data_ptr->inqd_dtq = 0x80; /* set RMB bit to one indicating that the medium is removable */ 1378 inq_data.inqd_dtq = 0x80; /* set RMB bit to one indicating that the medium is removable */
1351 inq_data_ptr->inqd_rdf = 2; /* A response data format value of two indicates that the data shall be in the format specified in SCSI-2 */ 1379 inq_data.inqd_rdf = 2; /* A response data format value of two indicates that the data shall be in the format specified in SCSI-2 */
1352 inq_data_ptr->inqd_len = 31; 1380 inq_data.inqd_len = 31;
1353 /*Format for "pad2" is RelAdr | WBus32 | WBus16 | Sync | Linked |Reserved| CmdQue | SftRe */ 1381 /*Format for "pad2" is RelAdr | WBus32 | WBus16 | Sync | Linked |Reserved| CmdQue | SftRe */
1354 inq_data_ptr->inqd_pad2= 0x32 ; /*WBus16|Sync|CmdQue */ 1382 inq_data.inqd_pad2= 0x32 ; /*WBus16|Sync|CmdQue */
1355 /* 1383 /*
1356 * Set the Vendor, Product, and Revision Level 1384 * Set the Vendor, Product, and Revision Level
1357 * see: <vendor>.c i.e. aac.c 1385 * see: <vendor>.c i.e. aac.c
1358 */ 1386 */
1359 if (scsicmd->device->id == host->this_id) { 1387 if (scsicmd->device->id == host->this_id) {
1360 setinqstr(cardtype, (void *) (inq_data_ptr->inqd_vid), (sizeof(container_types)/sizeof(char *))); 1388 setinqstr(cardtype, (void *) (inq_data.inqd_vid), (sizeof(container_types)/sizeof(char *)));
1361 inq_data_ptr->inqd_pdt = INQD_PDT_PROC; /* Processor device */ 1389 inq_data.inqd_pdt = INQD_PDT_PROC; /* Processor device */
1390 aac_internal_transfer(scsicmd, &inq_data, 0, sizeof(inq_data));
1362 scsicmd->result = DID_OK << 16 | COMMAND_COMPLETE << 8 | SAM_STAT_GOOD; 1391 scsicmd->result = DID_OK << 16 | COMMAND_COMPLETE << 8 | SAM_STAT_GOOD;
1363 scsicmd->scsi_done(scsicmd); 1392 scsicmd->scsi_done(scsicmd);
1364 return 0; 1393 return 0;
1365 } 1394 }
1366 setinqstr(cardtype, (void *) (inq_data_ptr->inqd_vid), fsa_dev_ptr[cid].type); 1395 setinqstr(cardtype, (void *) (inq_data.inqd_vid), fsa_dev_ptr[cid].type);
1367 inq_data_ptr->inqd_pdt = INQD_PDT_DA; /* Direct/random access device */ 1396 inq_data.inqd_pdt = INQD_PDT_DA; /* Direct/random access device */
1397 aac_internal_transfer(scsicmd, &inq_data, 0, sizeof(inq_data));
1368 return aac_get_container_name(scsicmd, cid); 1398 return aac_get_container_name(scsicmd, cid);
1369 } 1399 }
1370 case READ_CAPACITY: 1400 case READ_CAPACITY:
1371 { 1401 {
1372 u32 capacity; 1402 u32 capacity;
1373 char *cp; 1403 char cp[8];
1374 1404
1375 dprintk((KERN_DEBUG "READ CAPACITY command.\n")); 1405 dprintk((KERN_DEBUG "READ CAPACITY command.\n"));
1376 if (fsa_dev_ptr[cid].size <= 0x100000000LL) 1406 if (fsa_dev_ptr[cid].size <= 0x100000000LL)
1377 capacity = fsa_dev_ptr[cid].size - 1; 1407 capacity = fsa_dev_ptr[cid].size - 1;
1378 else 1408 else
1379 capacity = (u32)-1; 1409 capacity = (u32)-1;
1380 cp = scsicmd->request_buffer; 1410
1381 cp[0] = (capacity >> 24) & 0xff; 1411 cp[0] = (capacity >> 24) & 0xff;
1382 cp[1] = (capacity >> 16) & 0xff; 1412 cp[1] = (capacity >> 16) & 0xff;
1383 cp[2] = (capacity >> 8) & 0xff; 1413 cp[2] = (capacity >> 8) & 0xff;
@@ -1386,6 +1416,7 @@ int aac_scsi_cmd(struct scsi_cmnd * scsicmd)
1386 cp[5] = 0; 1416 cp[5] = 0;
1387 cp[6] = 2; 1417 cp[6] = 2;
1388 cp[7] = 0; 1418 cp[7] = 0;
1419 aac_internal_transfer(scsicmd, cp, 0, sizeof(cp));
1389 1420
1390 scsicmd->result = DID_OK << 16 | COMMAND_COMPLETE << 8 | SAM_STAT_GOOD; 1421 scsicmd->result = DID_OK << 16 | COMMAND_COMPLETE << 8 | SAM_STAT_GOOD;
1391 scsicmd->scsi_done(scsicmd); 1422 scsicmd->scsi_done(scsicmd);
@@ -1395,15 +1426,15 @@ int aac_scsi_cmd(struct scsi_cmnd * scsicmd)
1395 1426
1396 case MODE_SENSE: 1427 case MODE_SENSE:
1397 { 1428 {
1398 char *mode_buf; 1429 char mode_buf[4];
1399 1430
1400 dprintk((KERN_DEBUG "MODE SENSE command.\n")); 1431 dprintk((KERN_DEBUG "MODE SENSE command.\n"));
1401 mode_buf = scsicmd->request_buffer;
1402 mode_buf[0] = 3; /* Mode data length */ 1432 mode_buf[0] = 3; /* Mode data length */
1403 mode_buf[1] = 0; /* Medium type - default */ 1433 mode_buf[1] = 0; /* Medium type - default */
1404 mode_buf[2] = 0; /* Device-specific param, bit 8: 0/1 = write enabled/protected */ 1434 mode_buf[2] = 0; /* Device-specific param, bit 8: 0/1 = write enabled/protected */
1405 mode_buf[3] = 0; /* Block descriptor length */ 1435 mode_buf[3] = 0; /* Block descriptor length */
1406 1436
1437 aac_internal_transfer(scsicmd, mode_buf, 0, sizeof(mode_buf));
1407 scsicmd->result = DID_OK << 16 | COMMAND_COMPLETE << 8 | SAM_STAT_GOOD; 1438 scsicmd->result = DID_OK << 16 | COMMAND_COMPLETE << 8 | SAM_STAT_GOOD;
1408 scsicmd->scsi_done(scsicmd); 1439 scsicmd->scsi_done(scsicmd);
1409 1440
@@ -1411,10 +1442,9 @@ int aac_scsi_cmd(struct scsi_cmnd * scsicmd)
1411 } 1442 }
1412 case MODE_SENSE_10: 1443 case MODE_SENSE_10:
1413 { 1444 {
1414 char *mode_buf; 1445 char mode_buf[8];
1415 1446
1416 dprintk((KERN_DEBUG "MODE SENSE 10 byte command.\n")); 1447 dprintk((KERN_DEBUG "MODE SENSE 10 byte command.\n"));
1417 mode_buf = scsicmd->request_buffer;
1418 mode_buf[0] = 0; /* Mode data length (MSB) */ 1448 mode_buf[0] = 0; /* Mode data length (MSB) */
1419 mode_buf[1] = 6; /* Mode data length (LSB) */ 1449 mode_buf[1] = 6; /* Mode data length (LSB) */
1420 mode_buf[2] = 0; /* Medium type - default */ 1450 mode_buf[2] = 0; /* Medium type - default */
@@ -1423,6 +1453,7 @@ int aac_scsi_cmd(struct scsi_cmnd * scsicmd)
1423 mode_buf[5] = 0; /* reserved */ 1453 mode_buf[5] = 0; /* reserved */
1424 mode_buf[6] = 0; /* Block descriptor length (MSB) */ 1454 mode_buf[6] = 0; /* Block descriptor length (MSB) */
1425 mode_buf[7] = 0; /* Block descriptor length (LSB) */ 1455 mode_buf[7] = 0; /* Block descriptor length (LSB) */
1456 aac_internal_transfer(scsicmd, mode_buf, 0, sizeof(mode_buf));
1426 1457
1427 scsicmd->result = DID_OK << 16 | COMMAND_COMPLETE << 8 | SAM_STAT_GOOD; 1458 scsicmd->result = DID_OK << 16 | COMMAND_COMPLETE << 8 | SAM_STAT_GOOD;
1428 scsicmd->scsi_done(scsicmd); 1459 scsicmd->scsi_done(scsicmd);
@@ -1894,7 +1925,7 @@ static int aac_send_srb_fib(struct scsi_cmnd* scsicmd)
1894 srbcmd->id = cpu_to_le32(scsicmd->device->id); 1925 srbcmd->id = cpu_to_le32(scsicmd->device->id);
1895 srbcmd->lun = cpu_to_le32(scsicmd->device->lun); 1926 srbcmd->lun = cpu_to_le32(scsicmd->device->lun);
1896 srbcmd->flags = cpu_to_le32(flag); 1927 srbcmd->flags = cpu_to_le32(flag);
1897 timeout = (scsicmd->timeout-jiffies)/HZ; 1928 timeout = scsicmd->timeout_per_command/HZ;
1898 if(timeout == 0){ 1929 if(timeout == 0){
1899 timeout = 1; 1930 timeout = 1;
1900 } 1931 }
@@ -2077,6 +2108,76 @@ static unsigned long aac_build_sg64(struct scsi_cmnd* scsicmd, struct sgmap64* p
2077 return byte_count; 2108 return byte_count;
2078} 2109}
2079 2110
2111static unsigned long aac_build_sgraw(struct scsi_cmnd* scsicmd, struct sgmapraw* psg)
2112{
2113 struct Scsi_Host *host = scsicmd->device->host;
2114 struct aac_dev *dev = (struct aac_dev *)host->hostdata;
2115 unsigned long byte_count = 0;
2116
2117 // Get rid of old data
2118 psg->count = 0;
2119 psg->sg[0].next = 0;
2120 psg->sg[0].prev = 0;
2121 psg->sg[0].addr[0] = 0;
2122 psg->sg[0].addr[1] = 0;
2123 psg->sg[0].count = 0;
2124 psg->sg[0].flags = 0;
2125 if (scsicmd->use_sg) {
2126 struct scatterlist *sg;
2127 int i;
2128 int sg_count;
2129 sg = (struct scatterlist *) scsicmd->request_buffer;
2130
2131 sg_count = pci_map_sg(dev->pdev, sg, scsicmd->use_sg,
2132 scsicmd->sc_data_direction);
2133
2134 for (i = 0; i < sg_count; i++) {
2135 int count = sg_dma_len(sg);
2136 u64 addr = sg_dma_address(sg);
2137 psg->sg[i].next = 0;
2138 psg->sg[i].prev = 0;
2139 psg->sg[i].addr[1] = cpu_to_le32((u32)(addr>>32));
2140 psg->sg[i].addr[0] = cpu_to_le32((u32)(addr & 0xffffffff));
2141 psg->sg[i].count = cpu_to_le32(count);
2142 psg->sg[i].flags = 0;
2143 byte_count += count;
2144 sg++;
2145 }
2146 psg->count = cpu_to_le32(sg_count);
2147 /* hba wants the size to be exact */
2148 if(byte_count > scsicmd->request_bufflen){
2149 u32 temp = le32_to_cpu(psg->sg[i-1].count) -
2150 (byte_count - scsicmd->request_bufflen);
2151 psg->sg[i-1].count = cpu_to_le32(temp);
2152 byte_count = scsicmd->request_bufflen;
2153 }
2154 /* Check for command underflow */
2155 if(scsicmd->underflow && (byte_count < scsicmd->underflow)){
2156 printk(KERN_WARNING"aacraid: cmd len %08lX cmd underflow %08X\n",
2157 byte_count, scsicmd->underflow);
2158 }
2159 }
2160 else if(scsicmd->request_bufflen) {
2161 int count;
2162 u64 addr;
2163 scsicmd->SCp.dma_handle = pci_map_single(dev->pdev,
2164 scsicmd->request_buffer,
2165 scsicmd->request_bufflen,
2166 scsicmd->sc_data_direction);
2167 addr = scsicmd->SCp.dma_handle;
2168 count = scsicmd->request_bufflen;
2169 psg->count = cpu_to_le32(1);
2170 psg->sg[0].next = 0;
2171 psg->sg[0].prev = 0;
2172 psg->sg[0].addr[1] = cpu_to_le32((u32)(addr>>32));
2173 psg->sg[0].addr[0] = cpu_to_le32((u32)(addr & 0xffffffff));
2174 psg->sg[0].count = cpu_to_le32(count);
2175 psg->sg[0].flags = 0;
2176 byte_count = scsicmd->request_bufflen;
2177 }
2178 return byte_count;
2179}
2180
2080#ifdef AAC_DETAILED_STATUS_INFO 2181#ifdef AAC_DETAILED_STATUS_INFO
2081 2182
2082struct aac_srb_status_info { 2183struct aac_srb_status_info {
diff --git a/drivers/scsi/aacraid/aacraid.h b/drivers/scsi/aacraid/aacraid.h
index 4ab07861b45..e40528185d4 100644
--- a/drivers/scsi/aacraid/aacraid.h
+++ b/drivers/scsi/aacraid/aacraid.h
@@ -110,6 +110,22 @@ struct user_sgentry64 {
110 u32 count; /* Length. */ 110 u32 count; /* Length. */
111}; 111};
112 112
113struct sgentryraw {
114 __le32 next; /* reserved for F/W use */
115 __le32 prev; /* reserved for F/W use */
116 __le32 addr[2];
117 __le32 count;
118 __le32 flags; /* reserved for F/W use */
119};
120
121struct user_sgentryraw {
122 u32 next; /* reserved for F/W use */
123 u32 prev; /* reserved for F/W use */
124 u32 addr[2];
125 u32 count;
126 u32 flags; /* reserved for F/W use */
127};
128
113/* 129/*
114 * SGMAP 130 * SGMAP
115 * 131 *
@@ -137,6 +153,16 @@ struct user_sgmap64 {
137 struct user_sgentry64 sg[1]; 153 struct user_sgentry64 sg[1];
138}; 154};
139 155
156struct sgmapraw {
157 __le32 count;
158 struct sgentryraw sg[1];
159};
160
161struct user_sgmapraw {
162 u32 count;
163 struct user_sgentryraw sg[1];
164};
165
140struct creation_info 166struct creation_info
141{ 167{
142 u8 buildnum; /* e.g., 588 */ 168 u8 buildnum; /* e.g., 588 */
@@ -351,6 +377,7 @@ struct hw_fib {
351 */ 377 */
352#define ContainerCommand 500 378#define ContainerCommand 500
353#define ContainerCommand64 501 379#define ContainerCommand64 501
380#define ContainerRawIo 502
354/* 381/*
355 * Cluster Commands 382 * Cluster Commands
356 */ 383 */
@@ -456,6 +483,7 @@ struct adapter_ops
456{ 483{
457 void (*adapter_interrupt)(struct aac_dev *dev); 484 void (*adapter_interrupt)(struct aac_dev *dev);
458 void (*adapter_notify)(struct aac_dev *dev, u32 event); 485 void (*adapter_notify)(struct aac_dev *dev, u32 event);
486 void (*adapter_disable_int)(struct aac_dev *dev);
459 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); 487 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);
460 int (*adapter_check_health)(struct aac_dev *dev); 488 int (*adapter_check_health)(struct aac_dev *dev);
461}; 489};
@@ -981,6 +1009,9 @@ struct aac_dev
981 u8 nondasd_support; 1009 u8 nondasd_support;
982 u8 dac_support; 1010 u8 dac_support;
983 u8 raid_scsi_mode; 1011 u8 raid_scsi_mode;
1012 /* macro side-effects BEWARE */
1013# define raw_io_interface \
1014 init->InitStructRevision==cpu_to_le32(ADAPTER_INIT_STRUCT_REVISION_4)
984 u8 printf_enabled; 1015 u8 printf_enabled;
985}; 1016};
986 1017
@@ -990,6 +1021,9 @@ struct aac_dev
990#define aac_adapter_notify(dev, event) \ 1021#define aac_adapter_notify(dev, event) \
991 (dev)->a_ops.adapter_notify(dev, event) 1022 (dev)->a_ops.adapter_notify(dev, event)
992 1023
1024#define aac_adapter_disable_int(dev) \
1025 (dev)->a_ops.adapter_disable_int(dev)
1026
993#define aac_adapter_sync_cmd(dev, command, p1, p2, p3, p4, p5, p6, status, r1, r2, r3, r4) \ 1027#define aac_adapter_sync_cmd(dev, command, p1, p2, p3, p4, p5, p6, status, r1, r2, r3, r4) \
994 (dev)->a_ops.adapter_sync_cmd(dev, command, p1, p2, p3, p4, p5, p6, status, r1, r2, r3, r4) 1028 (dev)->a_ops.adapter_sync_cmd(dev, command, p1, p2, p3, p4, p5, p6, status, r1, r2, r3, r4)
995 1029
@@ -1156,6 +1190,17 @@ struct aac_write_reply
1156 __le32 committed; 1190 __le32 committed;
1157}; 1191};
1158 1192
1193struct aac_raw_io
1194{
1195 __le32 block[2];
1196 __le32 count;
1197 __le16 cid;
1198 __le16 flags; /* 00 W, 01 R */
1199 __le16 bpTotal; /* reserved for F/W use */
1200 __le16 bpComplete; /* reserved for F/W use */
1201 struct sgmapraw sg;
1202};
1203
1159#define CT_FLUSH_CACHE 129 1204#define CT_FLUSH_CACHE 129
1160struct aac_synchronize { 1205struct aac_synchronize {
1161 __le32 command; /* VM_ContainerConfig */ 1206 __le32 command; /* VM_ContainerConfig */
@@ -1196,7 +1241,7 @@ struct aac_srb
1196}; 1241};
1197 1242
1198/* 1243/*
1199 * This and assocated data structs are used by the 1244 * This and associated data structs are used by the
1200 * ioctl caller and are in cpu order. 1245 * ioctl caller and are in cpu order.
1201 */ 1246 */
1202struct user_aac_srb 1247struct user_aac_srb
@@ -1508,11 +1553,12 @@ struct fib_ioctl
1508 1553
1509struct revision 1554struct revision
1510{ 1555{
1511 u32 compat; 1556 __le32 compat;
1512 u32 version; 1557 __le32 version;
1513 u32 build; 1558 __le32 build;
1514}; 1559};
1515 1560
1561
1516/* 1562/*
1517 * Ugly - non Linux like ioctl coding for back compat. 1563 * Ugly - non Linux like ioctl coding for back compat.
1518 */ 1564 */
@@ -1733,3 +1779,4 @@ int aac_get_adapter_info(struct aac_dev* dev);
1733int aac_send_shutdown(struct aac_dev *dev); 1779int aac_send_shutdown(struct aac_dev *dev);
1734extern int numacb; 1780extern int numacb;
1735extern int acbsize; 1781extern int acbsize;
1782extern char aac_driver_version[];
diff --git a/drivers/scsi/aacraid/commctrl.c b/drivers/scsi/aacraid/commctrl.c
index 85387099aab..71f1cad9b5f 100644
--- a/drivers/scsi/aacraid/commctrl.c
+++ b/drivers/scsi/aacraid/commctrl.c
@@ -287,7 +287,6 @@ return_fib:
287 kfree(fib->hw_fib); 287 kfree(fib->hw_fib);
288 kfree(fib); 288 kfree(fib);
289 status = 0; 289 status = 0;
290 fibctx->jiffies = jiffies/HZ;
291 } else { 290 } else {
292 spin_unlock_irqrestore(&dev->fib_lock, flags); 291 spin_unlock_irqrestore(&dev->fib_lock, flags);
293 if (f.wait) { 292 if (f.wait) {
@@ -302,6 +301,7 @@ return_fib:
302 status = -EAGAIN; 301 status = -EAGAIN;
303 } 302 }
304 } 303 }
304 fibctx->jiffies = jiffies/HZ;
305 return status; 305 return status;
306} 306}
307 307
@@ -405,10 +405,20 @@ static int close_getadapter_fib(struct aac_dev * dev, void __user *arg)
405static int check_revision(struct aac_dev *dev, void __user *arg) 405static int check_revision(struct aac_dev *dev, void __user *arg)
406{ 406{
407 struct revision response; 407 struct revision response;
408 408 char *driver_version = aac_driver_version;
409 response.compat = 1; 409 u32 version;
410 response.version = le32_to_cpu(dev->adapter_info.kernelrev); 410
411 response.build = le32_to_cpu(dev->adapter_info.kernelbuild); 411 response.compat = cpu_to_le32(1);
412 version = (simple_strtol(driver_version,
413 &driver_version, 10) << 24) | 0x00000400;
414 version += simple_strtol(driver_version + 1, &driver_version, 10) << 16;
415 version += simple_strtol(driver_version + 1, NULL, 10);
416 response.version = cpu_to_le32(version);
417# if (defined(AAC_DRIVER_BUILD))
418 response.build = cpu_to_le32(AAC_DRIVER_BUILD);
419# else
420 response.build = cpu_to_le32(9999);
421# endif
412 422
413 if (copy_to_user(arg, &response, sizeof(response))) 423 if (copy_to_user(arg, &response, sizeof(response)))
414 return -EFAULT; 424 return -EFAULT;
diff --git a/drivers/scsi/aacraid/comminit.c b/drivers/scsi/aacraid/comminit.c
index 43557bf661f..75abd045328 100644
--- a/drivers/scsi/aacraid/comminit.c
+++ b/drivers/scsi/aacraid/comminit.c
@@ -44,7 +44,9 @@
44 44
45#include "aacraid.h" 45#include "aacraid.h"
46 46
47struct aac_common aac_config; 47struct aac_common aac_config = {
48 .irq_mod = 1
49};
48 50
49static int aac_alloc_comm(struct aac_dev *dev, void **commaddr, unsigned long commsize, unsigned long commalign) 51static int aac_alloc_comm(struct aac_dev *dev, void **commaddr, unsigned long commsize, unsigned long commalign)
50{ 52{
diff --git a/drivers/scsi/aacraid/commsup.c b/drivers/scsi/aacraid/commsup.c
index 5322865942e..a1d303f0348 100644
--- a/drivers/scsi/aacraid/commsup.c
+++ b/drivers/scsi/aacraid/commsup.c
@@ -254,6 +254,7 @@ static void fib_dealloc(struct fib * fibptr)
254static int aac_get_entry (struct aac_dev * dev, u32 qid, struct aac_entry **entry, u32 * index, unsigned long *nonotify) 254static int aac_get_entry (struct aac_dev * dev, u32 qid, struct aac_entry **entry, u32 * index, unsigned long *nonotify)
255{ 255{
256 struct aac_queue * q; 256 struct aac_queue * q;
257 unsigned long idx;
257 258
258 /* 259 /*
259 * All of the queues wrap when they reach the end, so we check 260 * All of the queues wrap when they reach the end, so we check
@@ -263,10 +264,23 @@ static int aac_get_entry (struct aac_dev * dev, u32 qid, struct aac_entry **entr
263 */ 264 */
264 265
265 q = &dev->queues->queue[qid]; 266 q = &dev->queues->queue[qid];
266 267
267 *index = le32_to_cpu(*(q->headers.producer)); 268 idx = *index = le32_to_cpu(*(q->headers.producer));
268 if ((*index - 2) == le32_to_cpu(*(q->headers.consumer))) 269 /* Interrupt Moderation, only interrupt for first two entries */
270 if (idx != le32_to_cpu(*(q->headers.consumer))) {
271 if (--idx == 0) {
272 if (qid == AdapHighCmdQueue)
273 idx = ADAP_HIGH_CMD_ENTRIES;
274 else if (qid == AdapNormCmdQueue)
275 idx = ADAP_NORM_CMD_ENTRIES;
276 else if (qid == AdapHighRespQueue)
277 idx = ADAP_HIGH_RESP_ENTRIES;
278 else if (qid == AdapNormRespQueue)
279 idx = ADAP_NORM_RESP_ENTRIES;
280 }
281 if (idx != le32_to_cpu(*(q->headers.consumer)))
269 *nonotify = 1; 282 *nonotify = 1;
283 }
270 284
271 if (qid == AdapHighCmdQueue) { 285 if (qid == AdapHighCmdQueue) {
272 if (*index >= ADAP_HIGH_CMD_ENTRIES) 286 if (*index >= ADAP_HIGH_CMD_ENTRIES)
diff --git a/drivers/scsi/aacraid/linit.c b/drivers/scsi/aacraid/linit.c
index 562da90480a..4ff29d7f582 100644
--- a/drivers/scsi/aacraid/linit.c
+++ b/drivers/scsi/aacraid/linit.c
@@ -27,8 +27,11 @@
27 * Abstract: Linux Driver entry module for Adaptec RAID Array Controller 27 * Abstract: Linux Driver entry module for Adaptec RAID Array Controller
28 */ 28 */
29 29
30#define AAC_DRIVER_VERSION "1.1.2-lk2" 30#define AAC_DRIVER_VERSION "1.1-4"
31#define AAC_DRIVER_BUILD_DATE __DATE__ 31#ifndef AAC_DRIVER_BRANCH
32#define AAC_DRIVER_BRANCH ""
33#endif
34#define AAC_DRIVER_BUILD_DATE __DATE__ " " __TIME__
32#define AAC_DRIVERNAME "aacraid" 35#define AAC_DRIVERNAME "aacraid"
33 36
34#include <linux/compat.h> 37#include <linux/compat.h>
@@ -58,16 +61,24 @@
58 61
59#include "aacraid.h" 62#include "aacraid.h"
60 63
64#ifdef AAC_DRIVER_BUILD
65#define _str(x) #x
66#define str(x) _str(x)
67#define AAC_DRIVER_FULL_VERSION AAC_DRIVER_VERSION "[" str(AAC_DRIVER_BUILD) "]" AAC_DRIVER_BRANCH
68#else
69#define AAC_DRIVER_FULL_VERSION AAC_DRIVER_VERSION AAC_DRIVER_BRANCH " " AAC_DRIVER_BUILD_DATE
70#endif
61 71
62MODULE_AUTHOR("Red Hat Inc and Adaptec"); 72MODULE_AUTHOR("Red Hat Inc and Adaptec");
63MODULE_DESCRIPTION("Dell PERC2, 2/Si, 3/Si, 3/Di, " 73MODULE_DESCRIPTION("Dell PERC2, 2/Si, 3/Si, 3/Di, "
64 "Adaptec Advanced Raid Products, " 74 "Adaptec Advanced Raid Products, "
65 "and HP NetRAID-4M SCSI driver"); 75 "and HP NetRAID-4M SCSI driver");
66MODULE_LICENSE("GPL"); 76MODULE_LICENSE("GPL");
67MODULE_VERSION(AAC_DRIVER_VERSION); 77MODULE_VERSION(AAC_DRIVER_FULL_VERSION);
68 78
69static LIST_HEAD(aac_devices); 79static LIST_HEAD(aac_devices);
70static int aac_cfg_major = -1; 80static int aac_cfg_major = -1;
81char aac_driver_version[] = AAC_DRIVER_FULL_VERSION;
71 82
72/* 83/*
73 * Because of the way Linux names scsi devices, the order in this table has 84 * Because of the way Linux names scsi devices, the order in this table has
@@ -109,36 +120,39 @@ static struct pci_device_id aac_pci_tbl[] = {
109 { 0x9005, 0x0286, 0x9005, 0x02a3, 0, 0, 29 }, /* ICP5085AU (Hurricane) */ 120 { 0x9005, 0x0286, 0x9005, 0x02a3, 0, 0, 29 }, /* ICP5085AU (Hurricane) */
110 { 0x9005, 0x0285, 0x9005, 0x02a4, 0, 0, 30 }, /* ICP9085LI (Marauder-X) */ 121 { 0x9005, 0x0285, 0x9005, 0x02a4, 0, 0, 30 }, /* ICP9085LI (Marauder-X) */
111 { 0x9005, 0x0285, 0x9005, 0x02a5, 0, 0, 31 }, /* ICP5085BR (Marauder-E) */ 122 { 0x9005, 0x0285, 0x9005, 0x02a5, 0, 0, 31 }, /* ICP5085BR (Marauder-E) */
112 { 0x9005, 0x0287, 0x9005, 0x0800, 0, 0, 32 }, /* Themisto Jupiter Platform */ 123 { 0x9005, 0x0286, 0x9005, 0x02a6, 0, 0, 32 }, /* ICP9067MA (Intruder-6) */
113 { 0x9005, 0x0200, 0x9005, 0x0200, 0, 0, 32 }, /* Themisto Jupiter Platform */ 124 { 0x9005, 0x0287, 0x9005, 0x0800, 0, 0, 33 }, /* Themisto Jupiter Platform */
114 { 0x9005, 0x0286, 0x9005, 0x0800, 0, 0, 33 }, /* Callisto Jupiter Platform */ 125 { 0x9005, 0x0200, 0x9005, 0x0200, 0, 0, 33 }, /* Themisto Jupiter Platform */
115 { 0x9005, 0x0285, 0x9005, 0x028e, 0, 0, 34 }, /* ASR-2020SA SATA PCI-X ZCR (Skyhawk) */ 126 { 0x9005, 0x0286, 0x9005, 0x0800, 0, 0, 34 }, /* Callisto Jupiter Platform */
116 { 0x9005, 0x0285, 0x9005, 0x028f, 0, 0, 35 }, /* ASR-2025SA SATA SO-DIMM PCI-X ZCR (Terminator) */ 127 { 0x9005, 0x0285, 0x9005, 0x028e, 0, 0, 35 }, /* ASR-2020SA SATA PCI-X ZCR (Skyhawk) */
117 { 0x9005, 0x0285, 0x9005, 0x0290, 0, 0, 36 }, /* AAR-2410SA PCI SATA 4ch (Jaguar II) */ 128 { 0x9005, 0x0285, 0x9005, 0x028f, 0, 0, 36 }, /* ASR-2025SA SATA SO-DIMM PCI-X ZCR (Terminator) */
118 { 0x9005, 0x0285, 0x1028, 0x0291, 0, 0, 37 }, /* CERC SATA RAID 2 PCI SATA 6ch (DellCorsair) */ 129 { 0x9005, 0x0285, 0x9005, 0x0290, 0, 0, 37 }, /* AAR-2410SA PCI SATA 4ch (Jaguar II) */
119 { 0x9005, 0x0285, 0x9005, 0x0292, 0, 0, 38 }, /* AAR-2810SA PCI SATA 8ch (Corsair-8) */ 130 { 0x9005, 0x0285, 0x1028, 0x0291, 0, 0, 38 }, /* CERC SATA RAID 2 PCI SATA 6ch (DellCorsair) */
120 { 0x9005, 0x0285, 0x9005, 0x0293, 0, 0, 39 }, /* AAR-21610SA PCI SATA 16ch (Corsair-16) */ 131 { 0x9005, 0x0285, 0x9005, 0x0292, 0, 0, 39 }, /* AAR-2810SA PCI SATA 8ch (Corsair-8) */
121 { 0x9005, 0x0285, 0x9005, 0x0294, 0, 0, 40 }, /* ESD SO-DIMM PCI-X SATA ZCR (Prowler) */ 132 { 0x9005, 0x0285, 0x9005, 0x0293, 0, 0, 40 }, /* AAR-21610SA PCI SATA 16ch (Corsair-16) */
122 { 0x9005, 0x0285, 0x103C, 0x3227, 0, 0, 41 }, /* AAR-2610SA PCI SATA 6ch */ 133 { 0x9005, 0x0285, 0x9005, 0x0294, 0, 0, 41 }, /* ESD SO-DIMM PCI-X SATA ZCR (Prowler) */
123 { 0x9005, 0x0285, 0x9005, 0x0296, 0, 0, 42 }, /* ASR-2240S (SabreExpress) */ 134 { 0x9005, 0x0285, 0x103C, 0x3227, 0, 0, 42 }, /* AAR-2610SA PCI SATA 6ch */
124 { 0x9005, 0x0285, 0x9005, 0x0297, 0, 0, 43 }, /* ASR-4005SAS */ 135 { 0x9005, 0x0285, 0x9005, 0x0296, 0, 0, 43 }, /* ASR-2240S (SabreExpress) */
125 { 0x9005, 0x0285, 0x1014, 0x02F2, 0, 0, 44 }, /* IBM 8i (AvonPark) */ 136 { 0x9005, 0x0285, 0x9005, 0x0297, 0, 0, 44 }, /* ASR-4005SAS */
126 { 0x9005, 0x0285, 0x1014, 0x0312, 0, 0, 44 }, /* IBM 8i (AvonPark Lite) */ 137 { 0x9005, 0x0285, 0x1014, 0x02F2, 0, 0, 45 }, /* IBM 8i (AvonPark) */
127 { 0x9005, 0x0285, 0x9005, 0x0298, 0, 0, 45 }, /* ASR-4000SAS (BlackBird) */ 138 { 0x9005, 0x0285, 0x1014, 0x0312, 0, 0, 45 }, /* IBM 8i (AvonPark Lite) */
128 { 0x9005, 0x0285, 0x9005, 0x0299, 0, 0, 46 }, /* ASR-4800SAS (Marauder-X) */ 139 { 0x9005, 0x0286, 0x1014, 0x9580, 0, 0, 46 }, /* IBM 8k/8k-l8 (Aurora) */
129 { 0x9005, 0x0285, 0x9005, 0x029a, 0, 0, 47 }, /* ASR-4805SAS (Marauder-E) */ 140 { 0x9005, 0x0286, 0x1014, 0x9540, 0, 0, 47 }, /* IBM 8k/8k-l4 (Aurora Lite) */
130 { 0x9005, 0x0286, 0x9005, 0x02a2, 0, 0, 48 }, /* ASR-4810SAS (Hurricane */ 141 { 0x9005, 0x0285, 0x9005, 0x0298, 0, 0, 48 }, /* ASR-4000SAS (BlackBird) */
131 142 { 0x9005, 0x0285, 0x9005, 0x0299, 0, 0, 49 }, /* ASR-4800SAS (Marauder-X) */
132 { 0x9005, 0x0285, 0x1028, 0x0287, 0, 0, 49 }, /* Perc 320/DC*/ 143 { 0x9005, 0x0285, 0x9005, 0x029a, 0, 0, 50 }, /* ASR-4805SAS (Marauder-E) */
133 { 0x1011, 0x0046, 0x9005, 0x0365, 0, 0, 50 }, /* Adaptec 5400S (Mustang)*/ 144 { 0x9005, 0x0286, 0x9005, 0x02a2, 0, 0, 51 }, /* ASR-4810SAS (Hurricane */
134 { 0x1011, 0x0046, 0x9005, 0x0364, 0, 0, 51 }, /* Adaptec 5400S (Mustang)*/ 145
135 { 0x1011, 0x0046, 0x9005, 0x1364, 0, 0, 52 }, /* Dell PERC2/QC */ 146 { 0x9005, 0x0285, 0x1028, 0x0287, 0, 0, 52 }, /* Perc 320/DC*/
136 { 0x1011, 0x0046, 0x103c, 0x10c2, 0, 0, 53 }, /* HP NetRAID-4M */ 147 { 0x1011, 0x0046, 0x9005, 0x0365, 0, 0, 53 }, /* Adaptec 5400S (Mustang)*/
137 148 { 0x1011, 0x0046, 0x9005, 0x0364, 0, 0, 54 }, /* Adaptec 5400S (Mustang)*/
138 { 0x9005, 0x0285, 0x1028, PCI_ANY_ID, 0, 0, 54 }, /* Dell Catchall */ 149 { 0x1011, 0x0046, 0x9005, 0x1364, 0, 0, 55 }, /* Dell PERC2/QC */
139 { 0x9005, 0x0285, 0x17aa, PCI_ANY_ID, 0, 0, 55 }, /* Legend Catchall */ 150 { 0x1011, 0x0046, 0x103c, 0x10c2, 0, 0, 56 }, /* HP NetRAID-4M */
140 { 0x9005, 0x0285, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 56 }, /* Adaptec Catch All */ 151
141 { 0x9005, 0x0286, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 57 }, /* Adaptec Rocket Catch All */ 152 { 0x9005, 0x0285, 0x1028, PCI_ANY_ID, 0, 0, 57 }, /* Dell Catchall */
153 { 0x9005, 0x0285, 0x17aa, PCI_ANY_ID, 0, 0, 58 }, /* Legend Catchall */
154 { 0x9005, 0x0285, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 59 }, /* Adaptec Catch All */
155 { 0x9005, 0x0286, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 60 }, /* Adaptec Rocket Catch All */
142 { 0,} 156 { 0,}
143}; 157};
144MODULE_DEVICE_TABLE(pci, aac_pci_tbl); 158MODULE_DEVICE_TABLE(pci, aac_pci_tbl);
@@ -180,8 +194,9 @@ static struct aac_driver_ident aac_drivers[] = {
180 { aac_rkt_init, "aacraid", "ICP ", "ICP9047MA ", 1 }, /* ICP9047MA (Lancer) */ 194 { aac_rkt_init, "aacraid", "ICP ", "ICP9047MA ", 1 }, /* ICP9047MA (Lancer) */
181 { aac_rkt_init, "aacraid", "ICP ", "ICP9087MA ", 1 }, /* ICP9087MA (Lancer) */ 195 { aac_rkt_init, "aacraid", "ICP ", "ICP9087MA ", 1 }, /* ICP9087MA (Lancer) */
182 { aac_rkt_init, "aacraid", "ICP ", "ICP5085AU ", 1 }, /* ICP5085AU (Hurricane) */ 196 { aac_rkt_init, "aacraid", "ICP ", "ICP5085AU ", 1 }, /* ICP5085AU (Hurricane) */
183 { aac_rkt_init, "aacraid", "ICP ", "ICP9085LI ", 1 }, /* ICP9085LI (Marauder-X) */ 197 { aac_rx_init, "aacraid", "ICP ", "ICP9085LI ", 1 }, /* ICP9085LI (Marauder-X) */
184 { aac_rkt_init, "aacraid", "ICP ", "ICP5085BR ", 1 }, /* ICP5085BR (Marauder-E) */ 198 { aac_rx_init, "aacraid", "ICP ", "ICP5085BR ", 1 }, /* ICP5085BR (Marauder-E) */
199 { aac_rkt_init, "aacraid", "ICP ", "ICP9067MA ", 1 }, /* ICP9067MA (Intruder-6) */
185 { NULL , "aacraid", "ADAPTEC ", "Themisto ", 0, AAC_QUIRK_SLAVE }, /* Jupiter Platform */ 200 { NULL , "aacraid", "ADAPTEC ", "Themisto ", 0, AAC_QUIRK_SLAVE }, /* Jupiter Platform */
186 { aac_rkt_init, "aacraid", "ADAPTEC ", "Callisto ", 2, AAC_QUIRK_MASTER }, /* Jupiter Platform */ 201 { aac_rkt_init, "aacraid", "ADAPTEC ", "Callisto ", 2, AAC_QUIRK_MASTER }, /* Jupiter Platform */
187 { aac_rx_init, "aacraid", "ADAPTEC ", "ASR-2020SA ", 1 }, /* ASR-2020SA SATA PCI-X ZCR (Skyhawk) */ 202 { aac_rx_init, "aacraid", "ADAPTEC ", "ASR-2020SA ", 1 }, /* ASR-2020SA SATA PCI-X ZCR (Skyhawk) */
@@ -195,10 +210,12 @@ static struct aac_driver_ident aac_drivers[] = {
195 { aac_rx_init, "aacraid", "ADAPTEC ", "ASR-2240S ", 1 }, /* ASR-2240S (SabreExpress) */ 210 { aac_rx_init, "aacraid", "ADAPTEC ", "ASR-2240S ", 1 }, /* ASR-2240S (SabreExpress) */
196 { aac_rx_init, "aacraid", "ADAPTEC ", "ASR-4005SAS ", 1 }, /* ASR-4005SAS */ 211 { aac_rx_init, "aacraid", "ADAPTEC ", "ASR-4005SAS ", 1 }, /* ASR-4005SAS */
197 { aac_rx_init, "ServeRAID","IBM ", "ServeRAID 8i ", 1 }, /* IBM 8i (AvonPark) */ 212 { aac_rx_init, "ServeRAID","IBM ", "ServeRAID 8i ", 1 }, /* IBM 8i (AvonPark) */
213 { aac_rkt_init, "ServeRAID","IBM ", "ServeRAID 8k-l8 ", 1 }, /* IBM 8k/8k-l8 (Aurora) */
214 { aac_rkt_init, "ServeRAID","IBM ", "ServeRAID 8k-l4 ", 1 }, /* IBM 8k/8k-l4 (Aurora Lite) */
198 { aac_rx_init, "aacraid", "ADAPTEC ", "ASR-4000SAS ", 1 }, /* ASR-4000SAS (BlackBird & AvonPark) */ 215 { aac_rx_init, "aacraid", "ADAPTEC ", "ASR-4000SAS ", 1 }, /* ASR-4000SAS (BlackBird & AvonPark) */
199 { aac_rx_init, "aacraid", "ADAPTEC ", "ASR-4800SAS ", 1 }, /* ASR-4800SAS (Marauder-X) */ 216 { aac_rx_init, "aacraid", "ADAPTEC ", "ASR-4800SAS ", 1 }, /* ASR-4800SAS (Marauder-X) */
200 { aac_rx_init, "aacraid", "ADAPTEC ", "ASR-4805SAS ", 1 }, /* ASR-4805SAS (Marauder-E) */ 217 { aac_rx_init, "aacraid", "ADAPTEC ", "ASR-4805SAS ", 1 }, /* ASR-4805SAS (Marauder-E) */
201 { aac_rx_init, "aacraid", "ADAPTEC ", "ASR-4810SAS ", 1 }, /* ASR-4810SAS (Hurricane) */ 218 { aac_rkt_init, "aacraid", "ADAPTEC ", "ASR-4810SAS ", 1 }, /* ASR-4810SAS (Hurricane) */
202 219
203 { aac_rx_init, "percraid", "DELL ", "PERC 320/DC ", 2, AAC_QUIRK_31BIT | AAC_QUIRK_34SG }, /* Perc 320/DC*/ 220 { aac_rx_init, "percraid", "DELL ", "PERC 320/DC ", 2, AAC_QUIRK_31BIT | AAC_QUIRK_34SG }, /* Perc 320/DC*/
204 { aac_sa_init, "aacraid", "ADAPTEC ", "Adaptec 5400S ", 4, AAC_QUIRK_34SG }, /* Adaptec 5400S (Mustang)*/ 221 { aac_sa_init, "aacraid", "ADAPTEC ", "Adaptec 5400S ", 4, AAC_QUIRK_34SG }, /* Adaptec 5400S (Mustang)*/
@@ -839,11 +856,12 @@ static int __devinit aac_probe_one(struct pci_dev *pdev,
839 856
840 return 0; 857 return 0;
841 858
842out_deinit: 859 out_deinit:
843 kill_proc(aac->thread_pid, SIGKILL, 0); 860 kill_proc(aac->thread_pid, SIGKILL, 0);
844 wait_for_completion(&aac->aif_completion); 861 wait_for_completion(&aac->aif_completion);
845 862
846 aac_send_shutdown(aac); 863 aac_send_shutdown(aac);
864 aac_adapter_disable_int(aac);
847 fib_map_free(aac); 865 fib_map_free(aac);
848 pci_free_consistent(aac->pdev, aac->comm_size, aac->comm_addr, aac->comm_phys); 866 pci_free_consistent(aac->pdev, aac->comm_size, aac->comm_addr, aac->comm_phys);
849 kfree(aac->queues); 867 kfree(aac->queues);
@@ -860,6 +878,13 @@ out_deinit:
860 return error; 878 return error;
861} 879}
862 880
881static void aac_shutdown(struct pci_dev *dev)
882{
883 struct Scsi_Host *shost = pci_get_drvdata(dev);
884 struct aac_dev *aac = (struct aac_dev *)shost->hostdata;
885 aac_send_shutdown(aac);
886}
887
863static void __devexit aac_remove_one(struct pci_dev *pdev) 888static void __devexit aac_remove_one(struct pci_dev *pdev)
864{ 889{
865 struct Scsi_Host *shost = pci_get_drvdata(pdev); 890 struct Scsi_Host *shost = pci_get_drvdata(pdev);
@@ -871,6 +896,7 @@ static void __devexit aac_remove_one(struct pci_dev *pdev)
871 wait_for_completion(&aac->aif_completion); 896 wait_for_completion(&aac->aif_completion);
872 897
873 aac_send_shutdown(aac); 898 aac_send_shutdown(aac);
899 aac_adapter_disable_int(aac);
874 fib_map_free(aac); 900 fib_map_free(aac);
875 pci_free_consistent(aac->pdev, aac->comm_size, aac->comm_addr, 901 pci_free_consistent(aac->pdev, aac->comm_size, aac->comm_addr,
876 aac->comm_phys); 902 aac->comm_phys);
@@ -891,14 +917,15 @@ static struct pci_driver aac_pci_driver = {
891 .id_table = aac_pci_tbl, 917 .id_table = aac_pci_tbl,
892 .probe = aac_probe_one, 918 .probe = aac_probe_one,
893 .remove = __devexit_p(aac_remove_one), 919 .remove = __devexit_p(aac_remove_one),
920 .shutdown = aac_shutdown,
894}; 921};
895 922
896static int __init aac_init(void) 923static int __init aac_init(void)
897{ 924{
898 int error; 925 int error;
899 926
900 printk(KERN_INFO "Red Hat/Adaptec aacraid driver (%s %s)\n", 927 printk(KERN_INFO "Adaptec %s driver (%s)\n",
901 AAC_DRIVER_VERSION, AAC_DRIVER_BUILD_DATE); 928 AAC_DRIVERNAME, aac_driver_version);
902 929
903 error = pci_module_init(&aac_pci_driver); 930 error = pci_module_init(&aac_pci_driver);
904 if (error) 931 if (error)
@@ -909,6 +936,7 @@ static int __init aac_init(void)
909 printk(KERN_WARNING 936 printk(KERN_WARNING
910 "aacraid: unable to register \"aac\" device.\n"); 937 "aacraid: unable to register \"aac\" device.\n");
911 } 938 }
939
912 return 0; 940 return 0;
913} 941}
914 942
diff --git a/drivers/scsi/aacraid/rkt.c b/drivers/scsi/aacraid/rkt.c
index 7d68b782513..557287a0b80 100644
--- a/drivers/scsi/aacraid/rkt.c
+++ b/drivers/scsi/aacraid/rkt.c
@@ -88,6 +88,16 @@ static irqreturn_t aac_rkt_intr(int irq, void *dev_id, struct pt_regs *regs)
88} 88}
89 89
90/** 90/**
91 * aac_rkt_disable_interrupt - Disable interrupts
92 * @dev: Adapter
93 */
94
95static void aac_rkt_disable_interrupt(struct aac_dev *dev)
96{
97 rkt_writeb(dev, MUnit.OIMR, dev->OIMR = 0xff);
98}
99
100/**
91 * rkt_sync_cmd - send a command and wait 101 * rkt_sync_cmd - send a command and wait
92 * @dev: Adapter 102 * @dev: Adapter
93 * @command: Command to execute 103 * @command: Command to execute
@@ -412,10 +422,19 @@ int aac_rkt_init(struct aac_dev *dev)
412 * Fill in the function dispatch table. 422 * Fill in the function dispatch table.
413 */ 423 */
414 dev->a_ops.adapter_interrupt = aac_rkt_interrupt_adapter; 424 dev->a_ops.adapter_interrupt = aac_rkt_interrupt_adapter;
425 dev->a_ops.adapter_disable_int = aac_rkt_disable_interrupt;
415 dev->a_ops.adapter_notify = aac_rkt_notify_adapter; 426 dev->a_ops.adapter_notify = aac_rkt_notify_adapter;
416 dev->a_ops.adapter_sync_cmd = rkt_sync_cmd; 427 dev->a_ops.adapter_sync_cmd = rkt_sync_cmd;
417 dev->a_ops.adapter_check_health = aac_rkt_check_health; 428 dev->a_ops.adapter_check_health = aac_rkt_check_health;
418 429
430 /*
431 * First clear out all interrupts. Then enable the one's that we
432 * can handle.
433 */
434 rkt_writeb(dev, MUnit.OIMR, 0xff);
435 rkt_writel(dev, MUnit.ODR, 0xffffffff);
436 rkt_writeb(dev, MUnit.OIMR, dev->OIMR = 0xfb);
437
419 if (aac_init_adapter(dev) == NULL) 438 if (aac_init_adapter(dev) == NULL)
420 goto error_irq; 439 goto error_irq;
421 /* 440 /*
@@ -438,6 +457,7 @@ error_kfree:
438 kfree(dev->queues); 457 kfree(dev->queues);
439 458
440error_irq: 459error_irq:
460 rkt_writeb(dev, MUnit.OIMR, dev->OIMR = 0xff);
441 free_irq(dev->scsi_host_ptr->irq, (void *)dev); 461 free_irq(dev->scsi_host_ptr->irq, (void *)dev);
442 462
443error_iounmap: 463error_iounmap:
diff --git a/drivers/scsi/aacraid/rx.c b/drivers/scsi/aacraid/rx.c
index 1ff25f49fad..a8459faf87c 100644
--- a/drivers/scsi/aacraid/rx.c
+++ b/drivers/scsi/aacraid/rx.c
@@ -88,6 +88,16 @@ static irqreturn_t aac_rx_intr(int irq, void *dev_id, struct pt_regs *regs)
88} 88}
89 89
90/** 90/**
91 * aac_rx_disable_interrupt - Disable interrupts
92 * @dev: Adapter
93 */
94
95static void aac_rx_disable_interrupt(struct aac_dev *dev)
96{
97 rx_writeb(dev, MUnit.OIMR, dev->OIMR = 0xff);
98}
99
100/**
91 * rx_sync_cmd - send a command and wait 101 * rx_sync_cmd - send a command and wait
92 * @dev: Adapter 102 * @dev: Adapter
93 * @command: Command to execute 103 * @command: Command to execute
@@ -412,10 +422,19 @@ int aac_rx_init(struct aac_dev *dev)
412 * Fill in the function dispatch table. 422 * Fill in the function dispatch table.
413 */ 423 */
414 dev->a_ops.adapter_interrupt = aac_rx_interrupt_adapter; 424 dev->a_ops.adapter_interrupt = aac_rx_interrupt_adapter;
425 dev->a_ops.adapter_disable_int = aac_rx_disable_interrupt;
415 dev->a_ops.adapter_notify = aac_rx_notify_adapter; 426 dev->a_ops.adapter_notify = aac_rx_notify_adapter;
416 dev->a_ops.adapter_sync_cmd = rx_sync_cmd; 427 dev->a_ops.adapter_sync_cmd = rx_sync_cmd;
417 dev->a_ops.adapter_check_health = aac_rx_check_health; 428 dev->a_ops.adapter_check_health = aac_rx_check_health;
418 429
430 /*
431 * First clear out all interrupts. Then enable the one's that we
432 * can handle.
433 */
434 rx_writeb(dev, MUnit.OIMR, 0xff);
435 rx_writel(dev, MUnit.ODR, 0xffffffff);
436 rx_writeb(dev, MUnit.OIMR, dev->OIMR = 0xfb);
437
419 if (aac_init_adapter(dev) == NULL) 438 if (aac_init_adapter(dev) == NULL)
420 goto error_irq; 439 goto error_irq;
421 /* 440 /*
@@ -438,6 +457,7 @@ error_kfree:
438 kfree(dev->queues); 457 kfree(dev->queues);
439 458
440error_irq: 459error_irq:
460 rx_writeb(dev, MUnit.OIMR, dev->OIMR = 0xff);
441 free_irq(dev->scsi_host_ptr->irq, (void *)dev); 461 free_irq(dev->scsi_host_ptr->irq, (void *)dev);
442 462
443error_iounmap: 463error_iounmap:
diff --git a/drivers/scsi/aacraid/sa.c b/drivers/scsi/aacraid/sa.c
index 0680249ab86..3900abc5850 100644
--- a/drivers/scsi/aacraid/sa.c
+++ b/drivers/scsi/aacraid/sa.c
@@ -82,6 +82,16 @@ static irqreturn_t aac_sa_intr(int irq, void *dev_id, struct pt_regs *regs)
82} 82}
83 83
84/** 84/**
85 * aac_sa_disable_interrupt - disable interrupt
86 * @dev: Which adapter to enable.
87 */
88
89static void aac_sa_disable_interrupt (struct aac_dev *dev)
90{
91 sa_writew(dev, SaDbCSR.PRISETIRQMASK, 0xffff);
92}
93
94/**
85 * aac_sa_notify_adapter - handle adapter notification 95 * aac_sa_notify_adapter - handle adapter notification
86 * @dev: Adapter that notification is for 96 * @dev: Adapter that notification is for
87 * @event: Event to notidy 97 * @event: Event to notidy
@@ -214,9 +224,8 @@ static int sa_sync_cmd(struct aac_dev *dev, u32 command,
214 224
215static void aac_sa_interrupt_adapter (struct aac_dev *dev) 225static void aac_sa_interrupt_adapter (struct aac_dev *dev)
216{ 226{
217 u32 ret;
218 sa_sync_cmd(dev, BREAKPOINT_REQUEST, 0, 0, 0, 0, 0, 0, 227 sa_sync_cmd(dev, BREAKPOINT_REQUEST, 0, 0, 0, 0, 0, 0,
219 &ret, NULL, NULL, NULL, NULL); 228 NULL, NULL, NULL, NULL, NULL);
220} 229}
221 230
222/** 231/**
@@ -352,10 +361,18 @@ int aac_sa_init(struct aac_dev *dev)
352 */ 361 */
353 362
354 dev->a_ops.adapter_interrupt = aac_sa_interrupt_adapter; 363 dev->a_ops.adapter_interrupt = aac_sa_interrupt_adapter;
364 dev->a_ops.adapter_disable_int = aac_sa_disable_interrupt;
355 dev->a_ops.adapter_notify = aac_sa_notify_adapter; 365 dev->a_ops.adapter_notify = aac_sa_notify_adapter;
356 dev->a_ops.adapter_sync_cmd = sa_sync_cmd; 366 dev->a_ops.adapter_sync_cmd = sa_sync_cmd;
357 dev->a_ops.adapter_check_health = aac_sa_check_health; 367 dev->a_ops.adapter_check_health = aac_sa_check_health;
358 368
369 /*
370 * First clear out all interrupts. Then enable the one's that
371 * we can handle.
372 */
373 sa_writew(dev, SaDbCSR.PRISETIRQMASK, 0xffff);
374 sa_writew(dev, SaDbCSR.PRICLEARIRQMASK, (PrintfReady | DOORBELL_1 |
375 DOORBELL_2 | DOORBELL_3 | DOORBELL_4));
359 376
360 if(aac_init_adapter(dev) == NULL) 377 if(aac_init_adapter(dev) == NULL)
361 goto error_irq; 378 goto error_irq;
@@ -381,6 +398,7 @@ error_kfree:
381 kfree(dev->queues); 398 kfree(dev->queues);
382 399
383error_irq: 400error_irq:
401 sa_writew(dev, SaDbCSR.PRISETIRQMASK, 0xffff);
384 free_irq(dev->scsi_host_ptr->irq, (void *)dev); 402 free_irq(dev->scsi_host_ptr->irq, (void *)dev);
385 403
386error_iounmap: 404error_iounmap:
diff --git a/drivers/scsi/advansys.c b/drivers/scsi/advansys.c
index 0fb93363eb2..37ec5411e32 100644
--- a/drivers/scsi/advansys.c
+++ b/drivers/scsi/advansys.c
@@ -9200,8 +9200,8 @@ asc_prt_scsi_cmnd(struct scsi_cmnd *s)
9200 (unsigned) s->serial_number, s->retries, s->allowed); 9200 (unsigned) s->serial_number, s->retries, s->allowed);
9201 9201
9202 printk( 9202 printk(
9203" timeout_per_command %d, timeout_total %d, timeout %d\n", 9203" timeout_per_command %d\n",
9204 s->timeout_per_command, s->timeout_total, s->timeout); 9204 s->timeout_per_command);
9205 9205
9206 printk( 9206 printk(
9207" scsi_done 0x%lx, done 0x%lx, host_scribble 0x%lx, result 0x%x\n", 9207" scsi_done 0x%lx, done 0x%lx, host_scribble 0x%lx, result 0x%x\n",
diff --git a/drivers/scsi/ahci.c b/drivers/scsi/ahci.c
index 179c95c878a..320df6cd3de 100644
--- a/drivers/scsi/ahci.c
+++ b/drivers/scsi/ahci.c
@@ -189,7 +189,6 @@ static void ahci_irq_clear(struct ata_port *ap);
189static void ahci_eng_timeout(struct ata_port *ap); 189static void ahci_eng_timeout(struct ata_port *ap);
190static int ahci_port_start(struct ata_port *ap); 190static int ahci_port_start(struct ata_port *ap);
191static void ahci_port_stop(struct ata_port *ap); 191static void ahci_port_stop(struct ata_port *ap);
192static void ahci_host_stop(struct ata_host_set *host_set);
193static void ahci_tf_read(struct ata_port *ap, struct ata_taskfile *tf); 192static void ahci_tf_read(struct ata_port *ap, struct ata_taskfile *tf);
194static void ahci_qc_prep(struct ata_queued_cmd *qc); 193static void ahci_qc_prep(struct ata_queued_cmd *qc);
195static u8 ahci_check_status(struct ata_port *ap); 194static u8 ahci_check_status(struct ata_port *ap);
@@ -242,7 +241,6 @@ static struct ata_port_operations ahci_ops = {
242 241
243 .port_start = ahci_port_start, 242 .port_start = ahci_port_start,
244 .port_stop = ahci_port_stop, 243 .port_stop = ahci_port_stop,
245 .host_stop = ahci_host_stop,
246}; 244};
247 245
248static struct ata_port_info ahci_port_info[] = { 246static struct ata_port_info ahci_port_info[] = {
@@ -252,7 +250,7 @@ static struct ata_port_info ahci_port_info[] = {
252 .host_flags = ATA_FLAG_SATA | ATA_FLAG_NO_LEGACY | 250 .host_flags = ATA_FLAG_SATA | ATA_FLAG_NO_LEGACY |
253 ATA_FLAG_SATA_RESET | ATA_FLAG_MMIO | 251 ATA_FLAG_SATA_RESET | ATA_FLAG_MMIO |
254 ATA_FLAG_PIO_DMA, 252 ATA_FLAG_PIO_DMA,
255 .pio_mask = 0x03, /* pio3-4 */ 253 .pio_mask = 0x1f, /* pio0-4 */
256 .udma_mask = 0x7f, /* udma0-6 ; FIXME */ 254 .udma_mask = 0x7f, /* udma0-6 ; FIXME */
257 .port_ops = &ahci_ops, 255 .port_ops = &ahci_ops,
258 }, 256 },
@@ -296,17 +294,9 @@ static inline unsigned long ahci_port_base_ul (unsigned long base, unsigned int
296 return base + 0x100 + (port * 0x80); 294 return base + 0x100 + (port * 0x80);
297} 295}
298 296
299static inline void *ahci_port_base (void *base, unsigned int port) 297static inline void __iomem *ahci_port_base (void __iomem *base, unsigned int port)
300{ 298{
301 return (void *) ahci_port_base_ul((unsigned long)base, port); 299 return (void __iomem *) ahci_port_base_ul((unsigned long)base, port);
302}
303
304static void ahci_host_stop(struct ata_host_set *host_set)
305{
306 struct ahci_host_priv *hpriv = host_set->private_data;
307 kfree(hpriv);
308
309 ata_host_stop(host_set);
310} 300}
311 301
312static int ahci_port_start(struct ata_port *ap) 302static int ahci_port_start(struct ata_port *ap)
@@ -314,8 +304,9 @@ static int ahci_port_start(struct ata_port *ap)
314 struct device *dev = ap->host_set->dev; 304 struct device *dev = ap->host_set->dev;
315 struct ahci_host_priv *hpriv = ap->host_set->private_data; 305 struct ahci_host_priv *hpriv = ap->host_set->private_data;
316 struct ahci_port_priv *pp; 306 struct ahci_port_priv *pp;
317 void *mem, *mmio = ap->host_set->mmio_base; 307 void __iomem *mmio = ap->host_set->mmio_base;
318 void *port_mmio = ahci_port_base(mmio, ap->port_no); 308 void __iomem *port_mmio = ahci_port_base(mmio, ap->port_no);
309 void *mem;
319 dma_addr_t mem_dma; 310 dma_addr_t mem_dma;
320 311
321 pp = kmalloc(sizeof(*pp), GFP_KERNEL); 312 pp = kmalloc(sizeof(*pp), GFP_KERNEL);
@@ -383,8 +374,8 @@ static void ahci_port_stop(struct ata_port *ap)
383{ 374{
384 struct device *dev = ap->host_set->dev; 375 struct device *dev = ap->host_set->dev;
385 struct ahci_port_priv *pp = ap->private_data; 376 struct ahci_port_priv *pp = ap->private_data;
386 void *mmio = ap->host_set->mmio_base; 377 void __iomem *mmio = ap->host_set->mmio_base;
387 void *port_mmio = ahci_port_base(mmio, ap->port_no); 378 void __iomem *port_mmio = ahci_port_base(mmio, ap->port_no);
388 u32 tmp; 379 u32 tmp;
389 380
390 tmp = readl(port_mmio + PORT_CMD); 381 tmp = readl(port_mmio + PORT_CMD);
@@ -546,8 +537,8 @@ static void ahci_qc_prep(struct ata_queued_cmd *qc)
546 537
547static void ahci_intr_error(struct ata_port *ap, u32 irq_stat) 538static void ahci_intr_error(struct ata_port *ap, u32 irq_stat)
548{ 539{
549 void *mmio = ap->host_set->mmio_base; 540 void __iomem *mmio = ap->host_set->mmio_base;
550 void *port_mmio = ahci_port_base(mmio, ap->port_no); 541 void __iomem *port_mmio = ahci_port_base(mmio, ap->port_no);
551 u32 tmp; 542 u32 tmp;
552 int work; 543 int work;
553 544
@@ -595,8 +586,8 @@ static void ahci_intr_error(struct ata_port *ap, u32 irq_stat)
595static void ahci_eng_timeout(struct ata_port *ap) 586static void ahci_eng_timeout(struct ata_port *ap)
596{ 587{
597 struct ata_host_set *host_set = ap->host_set; 588 struct ata_host_set *host_set = ap->host_set;
598 void *mmio = host_set->mmio_base; 589 void __iomem *mmio = host_set->mmio_base;
599 void *port_mmio = ahci_port_base(mmio, ap->port_no); 590 void __iomem *port_mmio = ahci_port_base(mmio, ap->port_no);
600 struct ata_queued_cmd *qc; 591 struct ata_queued_cmd *qc;
601 unsigned long flags; 592 unsigned long flags;
602 593
@@ -626,8 +617,8 @@ static void ahci_eng_timeout(struct ata_port *ap)
626 617
627static inline int ahci_host_intr(struct ata_port *ap, struct ata_queued_cmd *qc) 618static inline int ahci_host_intr(struct ata_port *ap, struct ata_queued_cmd *qc)
628{ 619{
629 void *mmio = ap->host_set->mmio_base; 620 void __iomem *mmio = ap->host_set->mmio_base;
630 void *port_mmio = ahci_port_base(mmio, ap->port_no); 621 void __iomem *port_mmio = ahci_port_base(mmio, ap->port_no);
631 u32 status, serr, ci; 622 u32 status, serr, ci;
632 623
633 serr = readl(port_mmio + PORT_SCR_ERR); 624 serr = readl(port_mmio + PORT_SCR_ERR);
@@ -663,7 +654,7 @@ static irqreturn_t ahci_interrupt (int irq, void *dev_instance, struct pt_regs *
663 struct ata_host_set *host_set = dev_instance; 654 struct ata_host_set *host_set = dev_instance;
664 struct ahci_host_priv *hpriv; 655 struct ahci_host_priv *hpriv;
665 unsigned int i, handled = 0; 656 unsigned int i, handled = 0;
666 void *mmio; 657 void __iomem *mmio;
667 u32 irq_stat, irq_ack = 0; 658 u32 irq_stat, irq_ack = 0;
668 659
669 VPRINTK("ENTER\n"); 660 VPRINTK("ENTER\n");
@@ -709,7 +700,7 @@ static irqreturn_t ahci_interrupt (int irq, void *dev_instance, struct pt_regs *
709static int ahci_qc_issue(struct ata_queued_cmd *qc) 700static int ahci_qc_issue(struct ata_queued_cmd *qc)
710{ 701{
711 struct ata_port *ap = qc->ap; 702 struct ata_port *ap = qc->ap;
712 void *port_mmio = (void *) ap->ioaddr.cmd_addr; 703 void __iomem *port_mmio = (void __iomem *) ap->ioaddr.cmd_addr;
713 704
714 writel(1, port_mmio + PORT_CMD_ISSUE); 705 writel(1, port_mmio + PORT_CMD_ISSUE);
715 readl(port_mmio + PORT_CMD_ISSUE); /* flush */ 706 readl(port_mmio + PORT_CMD_ISSUE); /* flush */
@@ -894,7 +885,7 @@ static void ahci_print_info(struct ata_probe_ent *probe_ent)
894{ 885{
895 struct ahci_host_priv *hpriv = probe_ent->private_data; 886 struct ahci_host_priv *hpriv = probe_ent->private_data;
896 struct pci_dev *pdev = to_pci_dev(probe_ent->dev); 887 struct pci_dev *pdev = to_pci_dev(probe_ent->dev);
897 void *mmio = probe_ent->mmio_base; 888 void __iomem *mmio = probe_ent->mmio_base;
898 u32 vers, cap, impl, speed; 889 u32 vers, cap, impl, speed;
899 const char *speed_s; 890 const char *speed_s;
900 u16 cc; 891 u16 cc;
@@ -967,7 +958,7 @@ static int ahci_init_one (struct pci_dev *pdev, const struct pci_device_id *ent)
967 struct ata_probe_ent *probe_ent = NULL; 958 struct ata_probe_ent *probe_ent = NULL;
968 struct ahci_host_priv *hpriv; 959 struct ahci_host_priv *hpriv;
969 unsigned long base; 960 unsigned long base;
970 void *mmio_base; 961 void __iomem *mmio_base;
971 unsigned int board_idx = (unsigned int) ent->driver_data; 962 unsigned int board_idx = (unsigned int) ent->driver_data;
972 int have_msi, pci_dev_busy = 0; 963 int have_msi, pci_dev_busy = 0;
973 int rc; 964 int rc;
@@ -1004,8 +995,7 @@ static int ahci_init_one (struct pci_dev *pdev, const struct pci_device_id *ent)
1004 probe_ent->dev = pci_dev_to_dev(pdev); 995 probe_ent->dev = pci_dev_to_dev(pdev);
1005 INIT_LIST_HEAD(&probe_ent->node); 996 INIT_LIST_HEAD(&probe_ent->node);
1006 997
1007 mmio_base = ioremap(pci_resource_start(pdev, AHCI_PCI_BAR), 998 mmio_base = pci_iomap(pdev, AHCI_PCI_BAR, 0);
1008 pci_resource_len(pdev, AHCI_PCI_BAR));
1009 if (mmio_base == NULL) { 999 if (mmio_base == NULL) {
1010 rc = -ENOMEM; 1000 rc = -ENOMEM;
1011 goto err_out_free_ent; 1001 goto err_out_free_ent;
@@ -1049,7 +1039,7 @@ static int ahci_init_one (struct pci_dev *pdev, const struct pci_device_id *ent)
1049err_out_hpriv: 1039err_out_hpriv:
1050 kfree(hpriv); 1040 kfree(hpriv);
1051err_out_iounmap: 1041err_out_iounmap:
1052 iounmap(mmio_base); 1042 pci_iounmap(pdev, mmio_base);
1053err_out_free_ent: 1043err_out_free_ent:
1054 kfree(probe_ent); 1044 kfree(probe_ent);
1055err_out_msi: 1045err_out_msi:
@@ -1089,7 +1079,8 @@ static void ahci_remove_one (struct pci_dev *pdev)
1089 scsi_host_put(ap->host); 1079 scsi_host_put(ap->host);
1090 } 1080 }
1091 1081
1092 host_set->ops->host_stop(host_set); 1082 kfree(hpriv);
1083 pci_iounmap(pdev, host_set->mmio_base);
1093 kfree(host_set); 1084 kfree(host_set);
1094 1085
1095 if (have_msi) 1086 if (have_msi)
@@ -1106,7 +1097,6 @@ static int __init ahci_init(void)
1106 return pci_module_init(&ahci_pci_driver); 1097 return pci_module_init(&ahci_pci_driver);
1107} 1098}
1108 1099
1109
1110static void __exit ahci_exit(void) 1100static void __exit ahci_exit(void)
1111{ 1101{
1112 pci_unregister_driver(&ahci_pci_driver); 1102 pci_unregister_driver(&ahci_pci_driver);
diff --git a/drivers/scsi/aic7xxx/Kconfig.aic79xx b/drivers/scsi/aic7xxx/Kconfig.aic79xx
index c2523a30a7f..69ed77fcb71 100644
--- a/drivers/scsi/aic7xxx/Kconfig.aic79xx
+++ b/drivers/scsi/aic7xxx/Kconfig.aic79xx
@@ -5,6 +5,7 @@
5config SCSI_AIC79XX 5config SCSI_AIC79XX
6 tristate "Adaptec AIC79xx U320 support" 6 tristate "Adaptec AIC79xx U320 support"
7 depends on PCI && SCSI 7 depends on PCI && SCSI
8 select SCSI_SPI_ATTRS
8 help 9 help
9 This driver supports all of Adaptec's Ultra 320 PCI-X 10 This driver supports all of Adaptec's Ultra 320 PCI-X
10 based SCSI controllers. 11 based SCSI controllers.
diff --git a/drivers/scsi/aic7xxx/aic7770.c b/drivers/scsi/aic7xxx/aic7770.c
index 00f3bd1e181..527efd36f5c 100644
--- a/drivers/scsi/aic7xxx/aic7770.c
+++ b/drivers/scsi/aic7xxx/aic7770.c
@@ -126,7 +126,6 @@ aic7770_find_device(uint32_t id)
126int 126int
127aic7770_config(struct ahc_softc *ahc, struct aic7770_identity *entry, u_int io) 127aic7770_config(struct ahc_softc *ahc, struct aic7770_identity *entry, u_int io)
128{ 128{
129 u_long l;
130 int error; 129 int error;
131 int have_seeprom; 130 int have_seeprom;
132 u_int hostconf; 131 u_int hostconf;
diff --git a/drivers/scsi/aic7xxx/aic79xx.h b/drivers/scsi/aic7xxx/aic79xx.h
index fd4b2f3eb0c..653fb0b42ae 100644
--- a/drivers/scsi/aic7xxx/aic79xx.h
+++ b/drivers/scsi/aic7xxx/aic79xx.h
@@ -1247,9 +1247,6 @@ struct ahd_softc {
1247 uint16_t user_tagenable;/* Tagged Queuing allowed */ 1247 uint16_t user_tagenable;/* Tagged Queuing allowed */
1248}; 1248};
1249 1249
1250TAILQ_HEAD(ahd_softc_tailq, ahd_softc);
1251extern struct ahd_softc_tailq ahd_tailq;
1252
1253/*************************** IO Cell Configuration ****************************/ 1250/*************************** IO Cell Configuration ****************************/
1254#define AHD_PRECOMP_SLEW_INDEX \ 1251#define AHD_PRECOMP_SLEW_INDEX \
1255 (AHD_ANNEXCOL_PRECOMP_SLEW - AHD_ANNEXCOL_PER_DEV0) 1252 (AHD_ANNEXCOL_PRECOMP_SLEW - AHD_ANNEXCOL_PER_DEV0)
@@ -1374,8 +1371,6 @@ void ahd_enable_coalescing(struct ahd_softc *ahd,
1374void ahd_pause_and_flushwork(struct ahd_softc *ahd); 1371void ahd_pause_and_flushwork(struct ahd_softc *ahd);
1375int ahd_suspend(struct ahd_softc *ahd); 1372int ahd_suspend(struct ahd_softc *ahd);
1376int ahd_resume(struct ahd_softc *ahd); 1373int ahd_resume(struct ahd_softc *ahd);
1377void ahd_softc_insert(struct ahd_softc *);
1378struct ahd_softc *ahd_find_softc(struct ahd_softc *ahd);
1379void ahd_set_unit(struct ahd_softc *, int); 1374void ahd_set_unit(struct ahd_softc *, int);
1380void ahd_set_name(struct ahd_softc *, char *); 1375void ahd_set_name(struct ahd_softc *, char *);
1381struct scb *ahd_get_scb(struct ahd_softc *ahd, u_int col_idx); 1376struct scb *ahd_get_scb(struct ahd_softc *ahd, u_int col_idx);
@@ -1524,7 +1519,6 @@ void ahd_print_scb(struct scb *scb);
1524void ahd_print_devinfo(struct ahd_softc *ahd, 1519void ahd_print_devinfo(struct ahd_softc *ahd,
1525 struct ahd_devinfo *devinfo); 1520 struct ahd_devinfo *devinfo);
1526void ahd_dump_sglist(struct scb *scb); 1521void ahd_dump_sglist(struct scb *scb);
1527void ahd_dump_all_cards_state(void);
1528void ahd_dump_card_state(struct ahd_softc *ahd); 1522void ahd_dump_card_state(struct ahd_softc *ahd);
1529int ahd_print_register(ahd_reg_parse_entry_t *table, 1523int ahd_print_register(ahd_reg_parse_entry_t *table,
1530 u_int num_entries, 1524 u_int num_entries,
diff --git a/drivers/scsi/aic7xxx/aic79xx_core.c b/drivers/scsi/aic7xxx/aic79xx_core.c
index 137fb1a37dd..4e8f00df978 100644
--- a/drivers/scsi/aic7xxx/aic79xx_core.c
+++ b/drivers/scsi/aic7xxx/aic79xx_core.c
@@ -52,8 +52,6 @@
52#include <dev/aic7xxx/aicasm/aicasm_insformat.h> 52#include <dev/aic7xxx/aicasm/aicasm_insformat.h>
53#endif 53#endif
54 54
55/******************************** Globals *************************************/
56struct ahd_softc_tailq ahd_tailq = TAILQ_HEAD_INITIALIZER(ahd_tailq);
57 55
58/***************************** Lookup Tables **********************************/ 56/***************************** Lookup Tables **********************************/
59char *ahd_chip_names[] = 57char *ahd_chip_names[] =
@@ -5180,74 +5178,6 @@ ahd_softc_init(struct ahd_softc *ahd)
5180} 5178}
5181 5179
5182void 5180void
5183ahd_softc_insert(struct ahd_softc *ahd)
5184{
5185 struct ahd_softc *list_ahd;
5186
5187#if AHD_PCI_CONFIG > 0
5188 /*
5189 * Second Function PCI devices need to inherit some
5190 * settings from function 0.
5191 */
5192 if ((ahd->features & AHD_MULTI_FUNC) != 0) {
5193 TAILQ_FOREACH(list_ahd, &ahd_tailq, links) {
5194 ahd_dev_softc_t list_pci;
5195 ahd_dev_softc_t pci;
5196
5197 list_pci = list_ahd->dev_softc;
5198 pci = ahd->dev_softc;
5199 if (ahd_get_pci_slot(list_pci) == ahd_get_pci_slot(pci)
5200 && ahd_get_pci_bus(list_pci) == ahd_get_pci_bus(pci)) {
5201 struct ahd_softc *master;
5202 struct ahd_softc *slave;
5203
5204 if (ahd_get_pci_function(list_pci) == 0) {
5205 master = list_ahd;
5206 slave = ahd;
5207 } else {
5208 master = ahd;
5209 slave = list_ahd;
5210 }
5211 slave->flags &= ~AHD_BIOS_ENABLED;
5212 slave->flags |=
5213 master->flags & AHD_BIOS_ENABLED;
5214 break;
5215 }
5216 }
5217 }
5218#endif
5219
5220 /*
5221 * Insertion sort into our list of softcs.
5222 */
5223 list_ahd = TAILQ_FIRST(&ahd_tailq);
5224 while (list_ahd != NULL
5225 && ahd_softc_comp(ahd, list_ahd) <= 0)
5226 list_ahd = TAILQ_NEXT(list_ahd, links);
5227 if (list_ahd != NULL)
5228 TAILQ_INSERT_BEFORE(list_ahd, ahd, links);
5229 else
5230 TAILQ_INSERT_TAIL(&ahd_tailq, ahd, links);
5231 ahd->init_level++;
5232}
5233
5234/*
5235 * Verify that the passed in softc pointer is for a
5236 * controller that is still configured.
5237 */
5238struct ahd_softc *
5239ahd_find_softc(struct ahd_softc *ahd)
5240{
5241 struct ahd_softc *list_ahd;
5242
5243 TAILQ_FOREACH(list_ahd, &ahd_tailq, links) {
5244 if (list_ahd == ahd)
5245 return (ahd);
5246 }
5247 return (NULL);
5248}
5249
5250void
5251ahd_set_unit(struct ahd_softc *ahd, int unit) 5181ahd_set_unit(struct ahd_softc *ahd, int unit)
5252{ 5182{
5253 ahd->unit = unit; 5183 ahd->unit = unit;
@@ -7902,18 +7832,10 @@ ahd_reset_channel(struct ahd_softc *ahd, char channel, int initiate_reset)
7902static void 7832static void
7903ahd_reset_poll(void *arg) 7833ahd_reset_poll(void *arg)
7904{ 7834{
7905 struct ahd_softc *ahd; 7835 struct ahd_softc *ahd = arg;
7906 u_int scsiseq1; 7836 u_int scsiseq1;
7907 u_long l;
7908 u_long s; 7837 u_long s;
7909 7838
7910 ahd_list_lock(&l);
7911 ahd = ahd_find_softc((struct ahd_softc *)arg);
7912 if (ahd == NULL) {
7913 printf("ahd_reset_poll: Instance %p no longer exists\n", arg);
7914 ahd_list_unlock(&l);
7915 return;
7916 }
7917 ahd_lock(ahd, &s); 7839 ahd_lock(ahd, &s);
7918 ahd_pause(ahd); 7840 ahd_pause(ahd);
7919 ahd_update_modes(ahd); 7841 ahd_update_modes(ahd);
@@ -7924,7 +7846,6 @@ ahd_reset_poll(void *arg)
7924 ahd_reset_poll, ahd); 7846 ahd_reset_poll, ahd);
7925 ahd_unpause(ahd); 7847 ahd_unpause(ahd);
7926 ahd_unlock(ahd, &s); 7848 ahd_unlock(ahd, &s);
7927 ahd_list_unlock(&l);
7928 return; 7849 return;
7929 } 7850 }
7930 7851
@@ -7936,25 +7857,16 @@ ahd_reset_poll(void *arg)
7936 ahd->flags &= ~AHD_RESET_POLL_ACTIVE; 7857 ahd->flags &= ~AHD_RESET_POLL_ACTIVE;
7937 ahd_unlock(ahd, &s); 7858 ahd_unlock(ahd, &s);
7938 ahd_release_simq(ahd); 7859 ahd_release_simq(ahd);
7939 ahd_list_unlock(&l);
7940} 7860}
7941 7861
7942/**************************** Statistics Processing ***************************/ 7862/**************************** Statistics Processing ***************************/
7943static void 7863static void
7944ahd_stat_timer(void *arg) 7864ahd_stat_timer(void *arg)
7945{ 7865{
7946 struct ahd_softc *ahd; 7866 struct ahd_softc *ahd = arg;
7947 u_long l;
7948 u_long s; 7867 u_long s;
7949 int enint_coal; 7868 int enint_coal;
7950 7869
7951 ahd_list_lock(&l);
7952 ahd = ahd_find_softc((struct ahd_softc *)arg);
7953 if (ahd == NULL) {
7954 printf("ahd_stat_timer: Instance %p no longer exists\n", arg);
7955 ahd_list_unlock(&l);
7956 return;
7957 }
7958 ahd_lock(ahd, &s); 7870 ahd_lock(ahd, &s);
7959 7871
7960 enint_coal = ahd->hs_mailbox & ENINT_COALESCE; 7872 enint_coal = ahd->hs_mailbox & ENINT_COALESCE;
@@ -7981,7 +7893,6 @@ ahd_stat_timer(void *arg)
7981 ahd_timer_reset(&ahd->stat_timer, AHD_STAT_UPDATE_US, 7893 ahd_timer_reset(&ahd->stat_timer, AHD_STAT_UPDATE_US,
7982 ahd_stat_timer, ahd); 7894 ahd_stat_timer, ahd);
7983 ahd_unlock(ahd, &s); 7895 ahd_unlock(ahd, &s);
7984 ahd_list_unlock(&l);
7985} 7896}
7986 7897
7987/****************************** Status Processing *****************************/ 7898/****************************** Status Processing *****************************/
@@ -8745,16 +8656,6 @@ sized:
8745 return (last_probe); 8656 return (last_probe);
8746} 8657}
8747 8658
8748void
8749ahd_dump_all_cards_state(void)
8750{
8751 struct ahd_softc *list_ahd;
8752
8753 TAILQ_FOREACH(list_ahd, &ahd_tailq, links) {
8754 ahd_dump_card_state(list_ahd);
8755 }
8756}
8757
8758int 8659int
8759ahd_print_register(ahd_reg_parse_entry_t *table, u_int num_entries, 8660ahd_print_register(ahd_reg_parse_entry_t *table, u_int num_entries,
8760 const char *name, u_int address, u_int value, 8661 const char *name, u_int address, u_int value,
@@ -9039,7 +8940,6 @@ ahd_dump_card_state(struct ahd_softc *ahd)
9039 ahd_outb(ahd, STACK, (ahd->saved_stack[i] >> 8) & 0xFF); 8940 ahd_outb(ahd, STACK, (ahd->saved_stack[i] >> 8) & 0xFF);
9040 } 8941 }
9041 printf("\n<<<<<<<<<<<<<<<<< Dump Card State Ends >>>>>>>>>>>>>>>>>>\n"); 8942 printf("\n<<<<<<<<<<<<<<<<< Dump Card State Ends >>>>>>>>>>>>>>>>>>\n");
9042 ahd_platform_dump_card_state(ahd);
9043 ahd_restore_modes(ahd, saved_modes); 8943 ahd_restore_modes(ahd, saved_modes);
9044 if (paused == 0) 8944 if (paused == 0)
9045 ahd_unpause(ahd); 8945 ahd_unpause(ahd);
diff --git a/drivers/scsi/aic7xxx/aic79xx_osm.c b/drivers/scsi/aic7xxx/aic79xx_osm.c
index 329cb233133..6b6d4e28779 100644
--- a/drivers/scsi/aic7xxx/aic79xx_osm.c
+++ b/drivers/scsi/aic7xxx/aic79xx_osm.c
@@ -46,32 +46,14 @@
46#include "aic79xx_inline.h" 46#include "aic79xx_inline.h"
47#include <scsi/scsicam.h> 47#include <scsi/scsicam.h>
48 48
49/* 49static struct scsi_transport_template *ahd_linux_transport_template = NULL;
50 * Include aiclib.c as part of our
51 * "module dependencies are hard" work around.
52 */
53#include "aiclib.c"
54 50
55#include <linux/init.h> /* __setup */ 51#include <linux/init.h> /* __setup */
56
57#if LINUX_VERSION_CODE < KERNEL_VERSION(2,5,0)
58#include "sd.h" /* For geometry detection */
59#endif
60
61#include <linux/mm.h> /* For fetching system memory size */ 52#include <linux/mm.h> /* For fetching system memory size */
53#include <linux/blkdev.h> /* For block_size() */
62#include <linux/delay.h> /* For ssleep/msleep */ 54#include <linux/delay.h> /* For ssleep/msleep */
63 55
64/* 56/*
65 * Lock protecting manipulation of the ahd softc list.
66 */
67spinlock_t ahd_list_spinlock;
68
69#if LINUX_VERSION_CODE < KERNEL_VERSION(2,5,0)
70/* For dynamic sglist size calculation. */
71u_int ahd_linux_nseg;
72#endif
73
74/*
75 * Bucket size for counting good commands in between bad ones. 57 * Bucket size for counting good commands in between bad ones.
76 */ 58 */
77#define AHD_LINUX_ERR_THRESH 1000 59#define AHD_LINUX_ERR_THRESH 1000
@@ -188,71 +170,6 @@ static adapter_tag_info_t aic79xx_tag_info[] =
188}; 170};
189 171
190/* 172/*
191 * By default, read streaming is disabled. In theory,
192 * read streaming should enhance performance, but early
193 * U320 drive firmware actually performs slower with
194 * read streaming enabled.
195 */
196#ifdef CONFIG_AIC79XX_ENABLE_RD_STRM
197#define AIC79XX_CONFIGED_RD_STRM 0xFFFF
198#else
199#define AIC79XX_CONFIGED_RD_STRM 0
200#endif
201
202static uint16_t aic79xx_rd_strm_info[] =
203{
204 AIC79XX_CONFIGED_RD_STRM,
205 AIC79XX_CONFIGED_RD_STRM,
206 AIC79XX_CONFIGED_RD_STRM,
207 AIC79XX_CONFIGED_RD_STRM,
208 AIC79XX_CONFIGED_RD_STRM,
209 AIC79XX_CONFIGED_RD_STRM,
210 AIC79XX_CONFIGED_RD_STRM,
211 AIC79XX_CONFIGED_RD_STRM,
212 AIC79XX_CONFIGED_RD_STRM,
213 AIC79XX_CONFIGED_RD_STRM,
214 AIC79XX_CONFIGED_RD_STRM,
215 AIC79XX_CONFIGED_RD_STRM,
216 AIC79XX_CONFIGED_RD_STRM,
217 AIC79XX_CONFIGED_RD_STRM,
218 AIC79XX_CONFIGED_RD_STRM,
219 AIC79XX_CONFIGED_RD_STRM
220};
221
222/*
223 * DV option:
224 *
225 * positive value = DV Enabled
226 * zero = DV Disabled
227 * negative value = DV Default for adapter type/seeprom
228 */
229#ifdef CONFIG_AIC79XX_DV_SETTING
230#define AIC79XX_CONFIGED_DV CONFIG_AIC79XX_DV_SETTING
231#else
232#define AIC79XX_CONFIGED_DV -1
233#endif
234
235static int8_t aic79xx_dv_settings[] =
236{
237 AIC79XX_CONFIGED_DV,
238 AIC79XX_CONFIGED_DV,
239 AIC79XX_CONFIGED_DV,
240 AIC79XX_CONFIGED_DV,
241 AIC79XX_CONFIGED_DV,
242 AIC79XX_CONFIGED_DV,
243 AIC79XX_CONFIGED_DV,
244 AIC79XX_CONFIGED_DV,
245 AIC79XX_CONFIGED_DV,
246 AIC79XX_CONFIGED_DV,
247 AIC79XX_CONFIGED_DV,
248 AIC79XX_CONFIGED_DV,
249 AIC79XX_CONFIGED_DV,
250 AIC79XX_CONFIGED_DV,
251 AIC79XX_CONFIGED_DV,
252 AIC79XX_CONFIGED_DV
253};
254
255/*
256 * The I/O cell on the chip is very configurable in respect to its analog 173 * The I/O cell on the chip is very configurable in respect to its analog
257 * characteristics. Set the defaults here; they can be overriden with 174 * characteristics. Set the defaults here; they can be overriden with
258 * the proper insmod parameters. 175 * the proper insmod parameters.
@@ -375,13 +292,6 @@ static uint32_t aic79xx_pci_parity = ~0;
375uint32_t aic79xx_allow_memio = ~0; 292uint32_t aic79xx_allow_memio = ~0;
376 293
377/* 294/*
378 * aic79xx_detect() has been run, so register all device arrivals
379 * immediately with the system rather than deferring to the sorted
380 * attachment performed by aic79xx_detect().
381 */
382int aic79xx_detect_complete;
383
384/*
385 * So that we can set how long each device is given as a selection timeout. 295 * So that we can set how long each device is given as a selection timeout.
386 * The table of values goes like this: 296 * The table of values goes like this:
387 * 0 - 256ms 297 * 0 - 256ms
@@ -412,7 +322,7 @@ MODULE_AUTHOR("Maintainer: Justin T. Gibbs <gibbs@scsiguy.com>");
412MODULE_DESCRIPTION("Adaptec Aic790X U320 SCSI Host Bus Adapter driver"); 322MODULE_DESCRIPTION("Adaptec Aic790X U320 SCSI Host Bus Adapter driver");
413MODULE_LICENSE("Dual BSD/GPL"); 323MODULE_LICENSE("Dual BSD/GPL");
414MODULE_VERSION(AIC79XX_DRIVER_VERSION); 324MODULE_VERSION(AIC79XX_DRIVER_VERSION);
415module_param(aic79xx, charp, 0); 325module_param(aic79xx, charp, 0444);
416MODULE_PARM_DESC(aic79xx, 326MODULE_PARM_DESC(aic79xx,
417"period delimited, options string.\n" 327"period delimited, options string.\n"
418" verbose Enable verbose/diagnostic logging\n" 328" verbose Enable verbose/diagnostic logging\n"
@@ -427,8 +337,6 @@ MODULE_PARM_DESC(aic79xx,
427" reverse_scan Sort PCI devices highest Bus/Slot to lowest\n" 337" reverse_scan Sort PCI devices highest Bus/Slot to lowest\n"
428" tag_info:<tag_str> Set per-target tag depth\n" 338" tag_info:<tag_str> Set per-target tag depth\n"
429" global_tag_depth:<int> Global tag depth for all targets on all buses\n" 339" global_tag_depth:<int> Global tag depth for all targets on all buses\n"
430" rd_strm:<rd_strm_masks> Set per-target read streaming setting.\n"
431" dv:<dv_settings> Set per-controller Domain Validation Setting.\n"
432" slewrate:<slewrate_list>Set the signal slew rate (0-15).\n" 340" slewrate:<slewrate_list>Set the signal slew rate (0-15).\n"
433" precomp:<pcomp_list> Set the signal precompensation (0-7).\n" 341" precomp:<pcomp_list> Set the signal precompensation (0-7).\n"
434" amplitude:<int> Set the signal amplitude (0-7).\n" 342" amplitude:<int> Set the signal amplitude (0-7).\n"
@@ -441,249 +349,35 @@ MODULE_PARM_DESC(aic79xx,
441" Shorten the selection timeout to 128ms\n" 349" Shorten the selection timeout to 128ms\n"
442"\n" 350"\n"
443" options aic79xx 'aic79xx=verbose.tag_info:{{}.{}.{..10}}.seltime:1'\n" 351" options aic79xx 'aic79xx=verbose.tag_info:{{}.{}.{..10}}.seltime:1'\n"
444"\n" 352"\n");
445" Sample /etc/modprobe.conf line:\n"
446" Change Read Streaming for Controller's 2 and 3\n"
447"\n"
448" options aic79xx 'aic79xx=rd_strm:{..0xFFF0.0xC0F0}'");
449 353
450static void ahd_linux_handle_scsi_status(struct ahd_softc *, 354static void ahd_linux_handle_scsi_status(struct ahd_softc *,
451 struct ahd_linux_device *, 355 struct scsi_device *,
452 struct scb *); 356 struct scb *);
453static void ahd_linux_queue_cmd_complete(struct ahd_softc *ahd, 357static void ahd_linux_queue_cmd_complete(struct ahd_softc *ahd,
454 Scsi_Cmnd *cmd); 358 struct scsi_cmnd *cmd);
455static void ahd_linux_filter_inquiry(struct ahd_softc *ahd,
456 struct ahd_devinfo *devinfo);
457static void ahd_linux_dev_timed_unfreeze(u_long arg);
458static void ahd_linux_sem_timeout(u_long arg); 359static void ahd_linux_sem_timeout(u_long arg);
360static int ahd_linux_queue_recovery_cmd(struct scsi_cmnd *cmd, scb_flag flag);
459static void ahd_linux_initialize_scsi_bus(struct ahd_softc *ahd); 361static void ahd_linux_initialize_scsi_bus(struct ahd_softc *ahd);
460static void ahd_linux_size_nseg(void);
461static void ahd_linux_thread_run_complete_queue(struct ahd_softc *ahd);
462static void ahd_linux_start_dv(struct ahd_softc *ahd);
463static void ahd_linux_dv_timeout(struct scsi_cmnd *cmd);
464static int ahd_linux_dv_thread(void *data);
465static void ahd_linux_kill_dv_thread(struct ahd_softc *ahd);
466static void ahd_linux_dv_target(struct ahd_softc *ahd, u_int target);
467static void ahd_linux_dv_transition(struct ahd_softc *ahd,
468 struct scsi_cmnd *cmd,
469 struct ahd_devinfo *devinfo,
470 struct ahd_linux_target *targ);
471static void ahd_linux_dv_fill_cmd(struct ahd_softc *ahd,
472 struct scsi_cmnd *cmd,
473 struct ahd_devinfo *devinfo);
474static void ahd_linux_dv_inq(struct ahd_softc *ahd,
475 struct scsi_cmnd *cmd,
476 struct ahd_devinfo *devinfo,
477 struct ahd_linux_target *targ,
478 u_int request_length);
479static void ahd_linux_dv_tur(struct ahd_softc *ahd,
480 struct scsi_cmnd *cmd,
481 struct ahd_devinfo *devinfo);
482static void ahd_linux_dv_rebd(struct ahd_softc *ahd,
483 struct scsi_cmnd *cmd,
484 struct ahd_devinfo *devinfo,
485 struct ahd_linux_target *targ);
486static void ahd_linux_dv_web(struct ahd_softc *ahd,
487 struct scsi_cmnd *cmd,
488 struct ahd_devinfo *devinfo,
489 struct ahd_linux_target *targ);
490static void ahd_linux_dv_reb(struct ahd_softc *ahd,
491 struct scsi_cmnd *cmd,
492 struct ahd_devinfo *devinfo,
493 struct ahd_linux_target *targ);
494static void ahd_linux_dv_su(struct ahd_softc *ahd,
495 struct scsi_cmnd *cmd,
496 struct ahd_devinfo *devinfo,
497 struct ahd_linux_target *targ);
498static int ahd_linux_fallback(struct ahd_softc *ahd,
499 struct ahd_devinfo *devinfo);
500static __inline int ahd_linux_dv_fallback(struct ahd_softc *ahd,
501 struct ahd_devinfo *devinfo);
502static void ahd_linux_dv_complete(Scsi_Cmnd *cmd);
503static void ahd_linux_generate_dv_pattern(struct ahd_linux_target *targ);
504static u_int ahd_linux_user_tagdepth(struct ahd_softc *ahd, 362static u_int ahd_linux_user_tagdepth(struct ahd_softc *ahd,
505 struct ahd_devinfo *devinfo); 363 struct ahd_devinfo *devinfo);
506static u_int ahd_linux_user_dv_setting(struct ahd_softc *ahd); 364static void ahd_linux_device_queue_depth(struct scsi_device *);
507static void ahd_linux_setup_user_rd_strm_settings(struct ahd_softc *ahd); 365static int ahd_linux_run_command(struct ahd_softc*,
508static void ahd_linux_device_queue_depth(struct ahd_softc *ahd, 366 struct ahd_linux_device *,
509 struct ahd_linux_device *dev); 367 struct scsi_cmnd *);
510static struct ahd_linux_target* ahd_linux_alloc_target(struct ahd_softc*,
511 u_int, u_int);
512static void ahd_linux_free_target(struct ahd_softc*,
513 struct ahd_linux_target*);
514static struct ahd_linux_device* ahd_linux_alloc_device(struct ahd_softc*,
515 struct ahd_linux_target*,
516 u_int);
517static void ahd_linux_free_device(struct ahd_softc*,
518 struct ahd_linux_device*);
519static void ahd_linux_run_device_queue(struct ahd_softc*,
520 struct ahd_linux_device*);
521static void ahd_linux_setup_tag_info_global(char *p); 368static void ahd_linux_setup_tag_info_global(char *p);
522static aic_option_callback_t ahd_linux_setup_tag_info; 369static int aic79xx_setup(char *c);
523static aic_option_callback_t ahd_linux_setup_rd_strm_info;
524static aic_option_callback_t ahd_linux_setup_dv;
525static aic_option_callback_t ahd_linux_setup_iocell_info;
526static int ahd_linux_next_unit(void);
527static void ahd_runq_tasklet(unsigned long data);
528static int aic79xx_setup(char *c);
529
530/****************************** Inlines ***************************************/
531static __inline void ahd_schedule_completeq(struct ahd_softc *ahd);
532static __inline void ahd_schedule_runq(struct ahd_softc *ahd);
533static __inline void ahd_setup_runq_tasklet(struct ahd_softc *ahd);
534static __inline void ahd_teardown_runq_tasklet(struct ahd_softc *ahd);
535static __inline struct ahd_linux_device*
536 ahd_linux_get_device(struct ahd_softc *ahd, u_int channel,
537 u_int target, u_int lun, int alloc);
538static struct ahd_cmd *ahd_linux_run_complete_queue(struct ahd_softc *ahd);
539static __inline void ahd_linux_check_device_queue(struct ahd_softc *ahd,
540 struct ahd_linux_device *dev);
541static __inline struct ahd_linux_device *
542 ahd_linux_next_device_to_run(struct ahd_softc *ahd);
543static __inline void ahd_linux_run_device_queues(struct ahd_softc *ahd);
544static __inline void ahd_linux_unmap_scb(struct ahd_softc*, struct scb*);
545
546static __inline void
547ahd_schedule_completeq(struct ahd_softc *ahd)
548{
549 if ((ahd->platform_data->flags & AHD_RUN_CMPLT_Q_TIMER) == 0) {
550 ahd->platform_data->flags |= AHD_RUN_CMPLT_Q_TIMER;
551 ahd->platform_data->completeq_timer.expires = jiffies;
552 add_timer(&ahd->platform_data->completeq_timer);
553 }
554}
555
556/*
557 * Must be called with our lock held.
558 */
559static __inline void
560ahd_schedule_runq(struct ahd_softc *ahd)
561{
562 tasklet_schedule(&ahd->platform_data->runq_tasklet);
563}
564
565static __inline
566void ahd_setup_runq_tasklet(struct ahd_softc *ahd)
567{
568 tasklet_init(&ahd->platform_data->runq_tasklet, ahd_runq_tasklet,
569 (unsigned long)ahd);
570}
571 370
572static __inline void 371static int ahd_linux_unit;
573ahd_teardown_runq_tasklet(struct ahd_softc *ahd)
574{
575 tasklet_kill(&ahd->platform_data->runq_tasklet);
576}
577 372
578static __inline struct ahd_linux_device*
579ahd_linux_get_device(struct ahd_softc *ahd, u_int channel, u_int target,
580 u_int lun, int alloc)
581{
582 struct ahd_linux_target *targ;
583 struct ahd_linux_device *dev;
584 u_int target_offset;
585 373
586 target_offset = target; 374/****************************** Inlines ***************************************/
587 if (channel != 0) 375static __inline void ahd_linux_unmap_scb(struct ahd_softc*, struct scb*);
588 target_offset += 8;
589 targ = ahd->platform_data->targets[target_offset];
590 if (targ == NULL) {
591 if (alloc != 0) {
592 targ = ahd_linux_alloc_target(ahd, channel, target);
593 if (targ == NULL)
594 return (NULL);
595 } else
596 return (NULL);
597 }
598 dev = targ->devices[lun];
599 if (dev == NULL && alloc != 0)
600 dev = ahd_linux_alloc_device(ahd, targ, lun);
601 return (dev);
602}
603
604#define AHD_LINUX_MAX_RETURNED_ERRORS 4
605static struct ahd_cmd *
606ahd_linux_run_complete_queue(struct ahd_softc *ahd)
607{
608 struct ahd_cmd *acmd;
609 u_long done_flags;
610 int with_errors;
611
612 with_errors = 0;
613 ahd_done_lock(ahd, &done_flags);
614 while ((acmd = TAILQ_FIRST(&ahd->platform_data->completeq)) != NULL) {
615 Scsi_Cmnd *cmd;
616
617 if (with_errors > AHD_LINUX_MAX_RETURNED_ERRORS) {
618 /*
619 * Linux uses stack recursion to requeue
620 * commands that need to be retried. Avoid
621 * blowing out the stack by "spoon feeding"
622 * commands that completed with error back
623 * the operating system in case they are going
624 * to be retried. "ick"
625 */
626 ahd_schedule_completeq(ahd);
627 break;
628 }
629 TAILQ_REMOVE(&ahd->platform_data->completeq,
630 acmd, acmd_links.tqe);
631 cmd = &acmd_scsi_cmd(acmd);
632 cmd->host_scribble = NULL;
633 if (ahd_cmd_get_transaction_status(cmd) != DID_OK
634 || (cmd->result & 0xFF) != SCSI_STATUS_OK)
635 with_errors++;
636
637 cmd->scsi_done(cmd);
638 }
639 ahd_done_unlock(ahd, &done_flags);
640 return (acmd);
641}
642
643static __inline void
644ahd_linux_check_device_queue(struct ahd_softc *ahd,
645 struct ahd_linux_device *dev)
646{
647 if ((dev->flags & AHD_DEV_FREEZE_TIL_EMPTY) != 0
648 && dev->active == 0) {
649 dev->flags &= ~AHD_DEV_FREEZE_TIL_EMPTY;
650 dev->qfrozen--;
651 }
652
653 if (TAILQ_FIRST(&dev->busyq) == NULL
654 || dev->openings == 0 || dev->qfrozen != 0)
655 return;
656
657 ahd_linux_run_device_queue(ahd, dev);
658}
659
660static __inline struct ahd_linux_device *
661ahd_linux_next_device_to_run(struct ahd_softc *ahd)
662{
663
664 if ((ahd->flags & AHD_RESOURCE_SHORTAGE) != 0
665 || (ahd->platform_data->qfrozen != 0
666 && AHD_DV_SIMQ_FROZEN(ahd) == 0))
667 return (NULL);
668 return (TAILQ_FIRST(&ahd->platform_data->device_runq));
669}
670
671static __inline void
672ahd_linux_run_device_queues(struct ahd_softc *ahd)
673{
674 struct ahd_linux_device *dev;
675
676 while ((dev = ahd_linux_next_device_to_run(ahd)) != NULL) {
677 TAILQ_REMOVE(&ahd->platform_data->device_runq, dev, links);
678 dev->flags &= ~AHD_DEV_ON_RUN_LIST;
679 ahd_linux_check_device_queue(ahd, dev);
680 }
681}
682 376
683static __inline void 377static __inline void
684ahd_linux_unmap_scb(struct ahd_softc *ahd, struct scb *scb) 378ahd_linux_unmap_scb(struct ahd_softc *ahd, struct scb *scb)
685{ 379{
686 Scsi_Cmnd *cmd; 380 struct scsi_cmnd *cmd;
687 int direction; 381 int direction;
688 382
689 cmd = scb->io_ctx; 383 cmd = scb->io_ctx;
@@ -705,197 +399,6 @@ ahd_linux_unmap_scb(struct ahd_softc *ahd, struct scb *scb)
705#define BUILD_SCSIID(ahd, cmd) \ 399#define BUILD_SCSIID(ahd, cmd) \
706 ((((cmd)->device->id << TID_SHIFT) & TID) | (ahd)->our_id) 400 ((((cmd)->device->id << TID_SHIFT) & TID) | (ahd)->our_id)
707 401
708/************************ Host template entry points *************************/
709static int ahd_linux_detect(Scsi_Host_Template *);
710static const char *ahd_linux_info(struct Scsi_Host *);
711static int ahd_linux_queue(Scsi_Cmnd *, void (*)(Scsi_Cmnd *));
712#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,5,0)
713static int ahd_linux_slave_alloc(Scsi_Device *);
714static int ahd_linux_slave_configure(Scsi_Device *);
715static void ahd_linux_slave_destroy(Scsi_Device *);
716#if defined(__i386__)
717static int ahd_linux_biosparam(struct scsi_device*,
718 struct block_device*, sector_t, int[]);
719#endif
720#else
721static int ahd_linux_release(struct Scsi_Host *);
722static void ahd_linux_select_queue_depth(struct Scsi_Host *host,
723 Scsi_Device *scsi_devs);
724#if defined(__i386__)
725static int ahd_linux_biosparam(Disk *, kdev_t, int[]);
726#endif
727#endif
728static int ahd_linux_bus_reset(Scsi_Cmnd *);
729static int ahd_linux_dev_reset(Scsi_Cmnd *);
730static int ahd_linux_abort(Scsi_Cmnd *);
731
732/*
733 * Calculate a safe value for AHD_NSEG (as expressed through ahd_linux_nseg).
734 *
735 * In pre-2.5.X...
736 * The midlayer allocates an S/G array dynamically when a command is issued
737 * using SCSI malloc. This array, which is in an OS dependent format that
738 * must later be copied to our private S/G list, is sized to house just the
739 * number of segments needed for the current transfer. Since the code that
740 * sizes the SCSI malloc pool does not take into consideration fragmentation
741 * of the pool, executing transactions numbering just a fraction of our
742 * concurrent transaction limit with SG list lengths aproaching AHC_NSEG will
743 * quickly depleat the SCSI malloc pool of usable space. Unfortunately, the
744 * mid-layer does not properly handle this scsi malloc failures for the S/G
745 * array and the result can be a lockup of the I/O subsystem. We try to size
746 * our S/G list so that it satisfies our drivers allocation requirements in
747 * addition to avoiding fragmentation of the SCSI malloc pool.
748 */
749static void
750ahd_linux_size_nseg(void)
751{
752#if LINUX_VERSION_CODE < KERNEL_VERSION(2,5,0)
753 u_int cur_size;
754 u_int best_size;
755
756 /*
757 * The SCSI allocator rounds to the nearest 512 bytes
758 * an cannot allocate across a page boundary. Our algorithm
759 * is to start at 1K of scsi malloc space per-command and
760 * loop through all factors of the PAGE_SIZE and pick the best.
761 */
762 best_size = 0;
763 for (cur_size = 1024; cur_size <= PAGE_SIZE; cur_size *= 2) {
764 u_int nseg;
765
766 nseg = cur_size / sizeof(struct scatterlist);
767 if (nseg < AHD_LINUX_MIN_NSEG)
768 continue;
769
770 if (best_size == 0) {
771 best_size = cur_size;
772 ahd_linux_nseg = nseg;
773 } else {
774 u_int best_rem;
775 u_int cur_rem;
776
777 /*
778 * Compare the traits of the current "best_size"
779 * with the current size to determine if the
780 * current size is a better size.
781 */
782 best_rem = best_size % sizeof(struct scatterlist);
783 cur_rem = cur_size % sizeof(struct scatterlist);
784 if (cur_rem < best_rem) {
785 best_size = cur_size;
786 ahd_linux_nseg = nseg;
787 }
788 }
789 }
790#endif
791}
792
793/*
794 * Try to detect an Adaptec 79XX controller.
795 */
796static int
797ahd_linux_detect(Scsi_Host_Template *template)
798{
799 struct ahd_softc *ahd;
800 int found;
801 int error = 0;
802
803#if LINUX_VERSION_CODE < KERNEL_VERSION(2,5,0)
804 /*
805 * It is a bug that the upper layer takes
806 * this lock just prior to calling us.
807 */
808 spin_unlock_irq(&io_request_lock);
809#endif
810
811 /*
812 * Sanity checking of Linux SCSI data structures so
813 * that some of our hacks^H^H^H^H^Hassumptions aren't
814 * violated.
815 */
816 if (offsetof(struct ahd_cmd_internal, end)
817 > offsetof(struct scsi_cmnd, host_scribble)) {
818 printf("ahd_linux_detect: SCSI data structures changed.\n");
819 printf("ahd_linux_detect: Unable to attach\n");
820 return (0);
821 }
822 /*
823 * Determine an appropriate size for our Scatter Gatther lists.
824 */
825 ahd_linux_size_nseg();
826#ifdef MODULE
827 /*
828 * If we've been passed any parameters, process them now.
829 */
830 if (aic79xx)
831 aic79xx_setup(aic79xx);
832#endif
833
834 template->proc_name = "aic79xx";
835
836 /*
837 * Initialize our softc list lock prior to
838 * probing for any adapters.
839 */
840 ahd_list_lockinit();
841
842#ifdef CONFIG_PCI
843 error = ahd_linux_pci_init();
844 if (error)
845 return error;
846#endif
847
848 /*
849 * Register with the SCSI layer all
850 * controllers we've found.
851 */
852 found = 0;
853 TAILQ_FOREACH(ahd, &ahd_tailq, links) {
854
855 if (ahd_linux_register_host(ahd, template) == 0)
856 found++;
857 }
858#if LINUX_VERSION_CODE < KERNEL_VERSION(2,5,0)
859 spin_lock_irq(&io_request_lock);
860#endif
861 aic79xx_detect_complete++;
862 return 0;
863}
864
865#if LINUX_VERSION_CODE < KERNEL_VERSION(2,5,0)
866/*
867 * Free the passed in Scsi_Host memory structures prior to unloading the
868 * module.
869 */
870static int
871ahd_linux_release(struct Scsi_Host * host)
872{
873 struct ahd_softc *ahd;
874 u_long l;
875
876 ahd_list_lock(&l);
877 if (host != NULL) {
878
879 /*
880 * We should be able to just perform
881 * the free directly, but check our
882 * list for extra sanity.
883 */
884 ahd = ahd_find_softc(*(struct ahd_softc **)host->hostdata);
885 if (ahd != NULL) {
886 u_long s;
887
888 ahd_lock(ahd, &s);
889 ahd_intr_enable(ahd, FALSE);
890 ahd_unlock(ahd, &s);
891 ahd_free(ahd);
892 }
893 }
894 ahd_list_unlock(&l);
895 return (0);
896}
897#endif
898
899/* 402/*
900 * Return a string describing the driver. 403 * Return a string describing the driver.
901 */ 404 */
@@ -928,220 +431,177 @@ ahd_linux_info(struct Scsi_Host *host)
928 * Queue an SCB to the controller. 431 * Queue an SCB to the controller.
929 */ 432 */
930static int 433static int
931ahd_linux_queue(Scsi_Cmnd * cmd, void (*scsi_done) (Scsi_Cmnd *)) 434ahd_linux_queue(struct scsi_cmnd * cmd, void (*scsi_done) (struct scsi_cmnd *))
932{ 435{
933 struct ahd_softc *ahd; 436 struct ahd_softc *ahd;
934 struct ahd_linux_device *dev; 437 struct ahd_linux_device *dev = scsi_transport_device_data(cmd->device);
935 u_long flags;
936 438
937 ahd = *(struct ahd_softc **)cmd->device->host->hostdata; 439 ahd = *(struct ahd_softc **)cmd->device->host->hostdata;
938 440
939 /* 441 /*
940 * Save the callback on completion function.
941 */
942 cmd->scsi_done = scsi_done;
943
944 ahd_midlayer_entrypoint_lock(ahd, &flags);
945
946 /*
947 * Close the race of a command that was in the process of 442 * Close the race of a command that was in the process of
948 * being queued to us just as our simq was frozen. Let 443 * being queued to us just as our simq was frozen. Let
949 * DV commands through so long as we are only frozen to 444 * DV commands through so long as we are only frozen to
950 * perform DV. 445 * perform DV.
951 */ 446 */
952 if (ahd->platform_data->qfrozen != 0 447 if (ahd->platform_data->qfrozen != 0) {
953 && AHD_DV_CMD(cmd) == 0) { 448 printf("%s: queue frozen\n", ahd_name(ahd));
954 449
955 ahd_cmd_set_transaction_status(cmd, CAM_REQUEUE_REQ); 450 return SCSI_MLQUEUE_HOST_BUSY;
956 ahd_linux_queue_cmd_complete(ahd, cmd);
957 ahd_schedule_completeq(ahd);
958 ahd_midlayer_entrypoint_unlock(ahd, &flags);
959 return (0);
960 }
961 dev = ahd_linux_get_device(ahd, cmd->device->channel,
962 cmd->device->id, cmd->device->lun,
963 /*alloc*/TRUE);
964 if (dev == NULL) {
965 ahd_cmd_set_transaction_status(cmd, CAM_RESRC_UNAVAIL);
966 ahd_linux_queue_cmd_complete(ahd, cmd);
967 ahd_schedule_completeq(ahd);
968 ahd_midlayer_entrypoint_unlock(ahd, &flags);
969 printf("%s: aic79xx_linux_queue - Unable to allocate device!\n",
970 ahd_name(ahd));
971 return (0);
972 } 451 }
973 if (cmd->cmd_len > MAX_CDB_LEN) 452
974 return (-EINVAL); 453 /*
454 * Save the callback on completion function.
455 */
456 cmd->scsi_done = scsi_done;
457
975 cmd->result = CAM_REQ_INPROG << 16; 458 cmd->result = CAM_REQ_INPROG << 16;
976 TAILQ_INSERT_TAIL(&dev->busyq, (struct ahd_cmd *)cmd, acmd_links.tqe); 459
977 if ((dev->flags & AHD_DEV_ON_RUN_LIST) == 0) { 460 return ahd_linux_run_command(ahd, dev, cmd);
978 TAILQ_INSERT_TAIL(&ahd->platform_data->device_runq, dev, links); 461}
979 dev->flags |= AHD_DEV_ON_RUN_LIST; 462
980 ahd_linux_run_device_queues(ahd); 463static inline struct scsi_target **
981 } 464ahd_linux_target_in_softc(struct scsi_target *starget)
982 ahd_midlayer_entrypoint_unlock(ahd, &flags); 465{
983 return (0); 466 struct ahd_softc *ahd =
467 *((struct ahd_softc **)dev_to_shost(&starget->dev)->hostdata);
468 unsigned int target_offset;
469
470 target_offset = starget->id;
471 if (starget->channel != 0)
472 target_offset += 8;
473
474 return &ahd->platform_data->starget[target_offset];
984} 475}
985 476
986#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,5,0)
987static int 477static int
988ahd_linux_slave_alloc(Scsi_Device *device) 478ahd_linux_target_alloc(struct scsi_target *starget)
989{ 479{
990 struct ahd_softc *ahd; 480 struct ahd_softc *ahd =
481 *((struct ahd_softc **)dev_to_shost(&starget->dev)->hostdata);
482 unsigned long flags;
483 struct scsi_target **ahd_targp = ahd_linux_target_in_softc(starget);
484 struct ahd_linux_target *targ = scsi_transport_target_data(starget);
485 struct ahd_devinfo devinfo;
486 struct ahd_initiator_tinfo *tinfo;
487 struct ahd_tmode_tstate *tstate;
488 char channel = starget->channel + 'A';
991 489
992 ahd = *((struct ahd_softc **)device->host->hostdata); 490 ahd_lock(ahd, &flags);
993 if (bootverbose) 491
994 printf("%s: Slave Alloc %d\n", ahd_name(ahd), device->id); 492 BUG_ON(*ahd_targp != NULL);
995 return (0); 493
494 *ahd_targp = starget;
495 memset(targ, 0, sizeof(*targ));
496
497 tinfo = ahd_fetch_transinfo(ahd, channel, ahd->our_id,
498 starget->id, &tstate);
499 ahd_compile_devinfo(&devinfo, ahd->our_id, starget->id,
500 CAM_LUN_WILDCARD, channel,
501 ROLE_INITIATOR);
502 spi_min_period(starget) = AHD_SYNCRATE_MAX; /* We can do U320 */
503 if ((ahd->bugs & AHD_PACED_NEGTABLE_BUG) != 0)
504 spi_max_offset(starget) = MAX_OFFSET_PACED_BUG;
505 else
506 spi_max_offset(starget) = MAX_OFFSET_PACED;
507 spi_max_width(starget) = ahd->features & AHD_WIDE;
508
509 ahd_set_syncrate(ahd, &devinfo, 0, 0, 0,
510 AHD_TRANS_GOAL, /*paused*/FALSE);
511 ahd_set_width(ahd, &devinfo, MSG_EXT_WDTR_BUS_8_BIT,
512 AHD_TRANS_GOAL, /*paused*/FALSE);
513 ahd_unlock(ahd, &flags);
514
515 return 0;
516}
517
518static void
519ahd_linux_target_destroy(struct scsi_target *starget)
520{
521 struct scsi_target **ahd_targp = ahd_linux_target_in_softc(starget);
522
523 *ahd_targp = NULL;
996} 524}
997 525
998static int 526static int
999ahd_linux_slave_configure(Scsi_Device *device) 527ahd_linux_slave_alloc(struct scsi_device *sdev)
1000{ 528{
1001 struct ahd_softc *ahd; 529 struct ahd_softc *ahd =
1002 struct ahd_linux_device *dev; 530 *((struct ahd_softc **)sdev->host->hostdata);
1003 u_long flags; 531 struct scsi_target *starget = sdev->sdev_target;
532 struct ahd_linux_target *targ = scsi_transport_target_data(starget);
533 struct ahd_linux_device *dev;
1004 534
1005 ahd = *((struct ahd_softc **)device->host->hostdata);
1006 if (bootverbose) 535 if (bootverbose)
1007 printf("%s: Slave Configure %d\n", ahd_name(ahd), device->id); 536 printf("%s: Slave Alloc %d\n", ahd_name(ahd), sdev->id);
1008 ahd_midlayer_entrypoint_lock(ahd, &flags); 537
538 BUG_ON(targ->sdev[sdev->lun] != NULL);
539
540 dev = scsi_transport_device_data(sdev);
541 memset(dev, 0, sizeof(*dev));
542
1009 /* 543 /*
1010 * Since Linux has attached to the device, configure 544 * We start out life using untagged
1011 * it so we don't free and allocate the device 545 * transactions of which we allow one.
1012 * structure on every command.
1013 */ 546 */
1014 dev = ahd_linux_get_device(ahd, device->channel, 547 dev->openings = 1;
1015 device->id, device->lun, 548
1016 /*alloc*/TRUE); 549 /*
1017 if (dev != NULL) { 550 * Set maxtags to 0. This will be changed if we
1018 dev->flags &= ~AHD_DEV_UNCONFIGURED; 551 * later determine that we are dealing with
1019 dev->flags |= AHD_DEV_SLAVE_CONFIGURED; 552 * a tagged queuing capable device.
1020 dev->scsi_device = device; 553 */
1021 ahd_linux_device_queue_depth(ahd, dev); 554 dev->maxtags = 0;
1022 } 555
1023 ahd_midlayer_entrypoint_unlock(ahd, &flags); 556 targ->sdev[sdev->lun] = sdev;
557
1024 return (0); 558 return (0);
1025} 559}
1026 560
1027static void 561static int
1028ahd_linux_slave_destroy(Scsi_Device *device) 562ahd_linux_slave_configure(struct scsi_device *sdev)
1029{ 563{
1030 struct ahd_softc *ahd; 564 struct ahd_softc *ahd;
1031 struct ahd_linux_device *dev;
1032 u_long flags;
1033 565
1034 ahd = *((struct ahd_softc **)device->host->hostdata); 566 ahd = *((struct ahd_softc **)sdev->host->hostdata);
1035 if (bootverbose) 567 if (bootverbose)
1036 printf("%s: Slave Destroy %d\n", ahd_name(ahd), device->id); 568 printf("%s: Slave Configure %d\n", ahd_name(ahd), sdev->id);
1037 ahd_midlayer_entrypoint_lock(ahd, &flags);
1038 dev = ahd_linux_get_device(ahd, device->channel,
1039 device->id, device->lun,
1040 /*alloc*/FALSE);
1041 569
1042 /* 570 ahd_linux_device_queue_depth(sdev);
1043 * Filter out "silly" deletions of real devices by only 571
1044 * deleting devices that have had slave_configure() 572 /* Initial Domain Validation */
1045 * called on them. All other devices that have not 573 if (!spi_initial_dv(sdev->sdev_target))
1046 * been configured will automatically be deleted by 574 spi_dv_device(sdev);
1047 * the refcounting process. 575
1048 */ 576 return 0;
1049 if (dev != NULL
1050 && (dev->flags & AHD_DEV_SLAVE_CONFIGURED) != 0) {
1051 dev->flags |= AHD_DEV_UNCONFIGURED;
1052 if (TAILQ_EMPTY(&dev->busyq)
1053 && dev->active == 0
1054 && (dev->flags & AHD_DEV_TIMER_ACTIVE) == 0)
1055 ahd_linux_free_device(ahd, dev);
1056 }
1057 ahd_midlayer_entrypoint_unlock(ahd, &flags);
1058} 577}
1059#else 578
1060/*
1061 * Sets the queue depth for each SCSI device hanging
1062 * off the input host adapter.
1063 */
1064static void 579static void
1065ahd_linux_select_queue_depth(struct Scsi_Host * host, 580ahd_linux_slave_destroy(struct scsi_device *sdev)
1066 Scsi_Device * scsi_devs)
1067{ 581{
1068 Scsi_Device *device;
1069 Scsi_Device *ldev;
1070 struct ahd_softc *ahd; 582 struct ahd_softc *ahd;
1071 u_long flags; 583 struct ahd_linux_device *dev = scsi_transport_device_data(sdev);
584 struct ahd_linux_target *targ = scsi_transport_target_data(sdev->sdev_target);
1072 585
1073 ahd = *((struct ahd_softc **)host->hostdata); 586 ahd = *((struct ahd_softc **)sdev->host->hostdata);
1074 ahd_lock(ahd, &flags); 587 if (bootverbose)
1075 for (device = scsi_devs; device != NULL; device = device->next) { 588 printf("%s: Slave Destroy %d\n", ahd_name(ahd), sdev->id);
1076 589
1077 /* 590 BUG_ON(dev->active);
1078 * Watch out for duplicate devices. This works around
1079 * some quirks in how the SCSI scanning code does its
1080 * device management.
1081 */
1082 for (ldev = scsi_devs; ldev != device; ldev = ldev->next) {
1083 if (ldev->host == device->host
1084 && ldev->channel == device->channel
1085 && ldev->id == device->id
1086 && ldev->lun == device->lun)
1087 break;
1088 }
1089 /* Skip duplicate. */
1090 if (ldev != device)
1091 continue;
1092 591
1093 if (device->host == host) { 592 targ->sdev[sdev->lun] = NULL;
1094 struct ahd_linux_device *dev;
1095 593
1096 /*
1097 * Since Linux has attached to the device, configure
1098 * it so we don't free and allocate the device
1099 * structure on every command.
1100 */
1101 dev = ahd_linux_get_device(ahd, device->channel,
1102 device->id, device->lun,
1103 /*alloc*/TRUE);
1104 if (dev != NULL) {
1105 dev->flags &= ~AHD_DEV_UNCONFIGURED;
1106 dev->scsi_device = device;
1107 ahd_linux_device_queue_depth(ahd, dev);
1108 device->queue_depth = dev->openings
1109 + dev->active;
1110 if ((dev->flags & (AHD_DEV_Q_BASIC
1111 | AHD_DEV_Q_TAGGED)) == 0) {
1112 /*
1113 * We allow the OS to queue 2 untagged
1114 * transactions to us at any time even
1115 * though we can only execute them
1116 * serially on the controller/device.
1117 * This should remove some latency.
1118 */
1119 device->queue_depth = 2;
1120 }
1121 }
1122 }
1123 }
1124 ahd_unlock(ahd, &flags);
1125} 594}
1126#endif
1127 595
1128#if defined(__i386__) 596#if defined(__i386__)
1129/* 597/*
1130 * Return the disk geometry for the given SCSI device. 598 * Return the disk geometry for the given SCSI device.
1131 */ 599 */
1132static int 600static int
1133#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,5,0)
1134ahd_linux_biosparam(struct scsi_device *sdev, struct block_device *bdev, 601ahd_linux_biosparam(struct scsi_device *sdev, struct block_device *bdev,
1135 sector_t capacity, int geom[]) 602 sector_t capacity, int geom[])
1136{ 603{
1137 uint8_t *bh; 604 uint8_t *bh;
1138#else
1139ahd_linux_biosparam(Disk *disk, kdev_t dev, int geom[])
1140{
1141 struct scsi_device *sdev = disk->device;
1142 u_long capacity = disk->capacity;
1143 struct buffer_head *bh;
1144#endif
1145 int heads; 605 int heads;
1146 int sectors; 606 int sectors;
1147 int cylinders; 607 int cylinders;
@@ -1151,22 +611,11 @@ ahd_linux_biosparam(Disk *disk, kdev_t dev, int geom[])
1151 611
1152 ahd = *((struct ahd_softc **)sdev->host->hostdata); 612 ahd = *((struct ahd_softc **)sdev->host->hostdata);
1153 613
1154#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,5,0)
1155 bh = scsi_bios_ptable(bdev); 614 bh = scsi_bios_ptable(bdev);
1156#elif LINUX_VERSION_CODE >= KERNEL_VERSION(2,4,17)
1157 bh = bread(MKDEV(MAJOR(dev), MINOR(dev) & ~0xf), 0, block_size(dev));
1158#else
1159 bh = bread(MKDEV(MAJOR(dev), MINOR(dev) & ~0xf), 0, 1024);
1160#endif
1161
1162 if (bh) { 615 if (bh) {
1163 ret = scsi_partsize(bh, capacity, 616 ret = scsi_partsize(bh, capacity,
1164 &geom[2], &geom[0], &geom[1]); 617 &geom[2], &geom[0], &geom[1]);
1165#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,5,0)
1166 kfree(bh); 618 kfree(bh);
1167#else
1168 brelse(bh);
1169#endif
1170 if (ret != -1) 619 if (ret != -1)
1171 return (ret); 620 return (ret);
1172 } 621 }
@@ -1194,392 +643,35 @@ ahd_linux_biosparam(Disk *disk, kdev_t dev, int geom[])
1194 * Abort the current SCSI command(s). 643 * Abort the current SCSI command(s).
1195 */ 644 */
1196static int 645static int
1197ahd_linux_abort(Scsi_Cmnd *cmd) 646ahd_linux_abort(struct scsi_cmnd *cmd)
1198{ 647{
1199 struct ahd_softc *ahd; 648 int error;
1200 struct ahd_cmd *acmd;
1201 struct ahd_cmd *list_acmd;
1202 struct ahd_linux_device *dev;
1203 struct scb *pending_scb;
1204 u_long s;
1205 u_int saved_scbptr;
1206 u_int active_scbptr;
1207 u_int last_phase;
1208 u_int cdb_byte;
1209 int retval;
1210 int was_paused;
1211 int paused;
1212 int wait;
1213 int disconnected;
1214 ahd_mode_state saved_modes;
1215
1216 pending_scb = NULL;
1217 paused = FALSE;
1218 wait = FALSE;
1219 ahd = *(struct ahd_softc **)cmd->device->host->hostdata;
1220 acmd = (struct ahd_cmd *)cmd;
1221
1222 printf("%s:%d:%d:%d: Attempting to abort cmd %p:",
1223 ahd_name(ahd), cmd->device->channel, cmd->device->id,
1224 cmd->device->lun, cmd);
1225 for (cdb_byte = 0; cdb_byte < cmd->cmd_len; cdb_byte++)
1226 printf(" 0x%x", cmd->cmnd[cdb_byte]);
1227 printf("\n");
1228
1229 /*
1230 * In all versions of Linux, we have to work around
1231 * a major flaw in how the mid-layer is locked down
1232 * if we are to sleep successfully in our error handler
1233 * while allowing our interrupt handler to run. Since
1234 * the midlayer acquires either the io_request_lock or
1235 * our lock prior to calling us, we must use the
1236 * spin_unlock_irq() method for unlocking our lock.
1237 * This will force interrupts to be enabled on the
1238 * current CPU. Since the EH thread should not have
1239 * been running with CPU interrupts disabled other than
1240 * by acquiring either the io_request_lock or our own
1241 * lock, this *should* be safe.
1242 */
1243 ahd_midlayer_entrypoint_lock(ahd, &s);
1244
1245 /*
1246 * First determine if we currently own this command.
1247 * Start by searching the device queue. If not found
1248 * there, check the pending_scb list. If not found
1249 * at all, and the system wanted us to just abort the
1250 * command, return success.
1251 */
1252 dev = ahd_linux_get_device(ahd, cmd->device->channel,
1253 cmd->device->id, cmd->device->lun,
1254 /*alloc*/FALSE);
1255
1256 if (dev == NULL) {
1257 /*
1258 * No target device for this command exists,
1259 * so we must not still own the command.
1260 */
1261 printf("%s:%d:%d:%d: Is not an active device\n",
1262 ahd_name(ahd), cmd->device->channel, cmd->device->id,
1263 cmd->device->lun);
1264 retval = SUCCESS;
1265 goto no_cmd;
1266 }
1267
1268 TAILQ_FOREACH(list_acmd, &dev->busyq, acmd_links.tqe) {
1269 if (list_acmd == acmd)
1270 break;
1271 }
1272
1273 if (list_acmd != NULL) {
1274 printf("%s:%d:%d:%d: Command found on device queue\n",
1275 ahd_name(ahd), cmd->device->channel, cmd->device->id,
1276 cmd->device->lun);
1277 TAILQ_REMOVE(&dev->busyq, list_acmd, acmd_links.tqe);
1278 cmd->result = DID_ABORT << 16;
1279 ahd_linux_queue_cmd_complete(ahd, cmd);
1280 retval = SUCCESS;
1281 goto done;
1282 }
1283 649
1284 /* 650 error = ahd_linux_queue_recovery_cmd(cmd, SCB_ABORT);
1285 * See if we can find a matching cmd in the pending list. 651 if (error != 0)
1286 */ 652 printf("aic79xx_abort returns 0x%x\n", error);
1287 LIST_FOREACH(pending_scb, &ahd->pending_scbs, pending_links) { 653 return error;
1288 if (pending_scb->io_ctx == cmd)
1289 break;
1290 }
1291
1292 if (pending_scb == NULL) {
1293 printf("%s:%d:%d:%d: Command not found\n",
1294 ahd_name(ahd), cmd->device->channel, cmd->device->id,
1295 cmd->device->lun);
1296 goto no_cmd;
1297 }
1298
1299 if ((pending_scb->flags & SCB_RECOVERY_SCB) != 0) {
1300 /*
1301 * We can't queue two recovery actions using the same SCB
1302 */
1303 retval = FAILED;
1304 goto done;
1305 }
1306
1307 /*
1308 * Ensure that the card doesn't do anything
1309 * behind our back. Also make sure that we
1310 * didn't "just" miss an interrupt that would
1311 * affect this cmd.
1312 */
1313 was_paused = ahd_is_paused(ahd);
1314 ahd_pause_and_flushwork(ahd);
1315 paused = TRUE;
1316
1317 if ((pending_scb->flags & SCB_ACTIVE) == 0) {
1318 printf("%s:%d:%d:%d: Command already completed\n",
1319 ahd_name(ahd), cmd->device->channel, cmd->device->id,
1320 cmd->device->lun);
1321 goto no_cmd;
1322 }
1323
1324 printf("%s: At time of recovery, card was %spaused\n",
1325 ahd_name(ahd), was_paused ? "" : "not ");
1326 ahd_dump_card_state(ahd);
1327
1328 disconnected = TRUE;
1329 if (ahd_search_qinfifo(ahd, cmd->device->id, cmd->device->channel + 'A',
1330 cmd->device->lun, SCB_GET_TAG(pending_scb),
1331 ROLE_INITIATOR, CAM_REQ_ABORTED,
1332 SEARCH_COMPLETE) > 0) {
1333 printf("%s:%d:%d:%d: Cmd aborted from QINFIFO\n",
1334 ahd_name(ahd), cmd->device->channel, cmd->device->id,
1335 cmd->device->lun);
1336 retval = SUCCESS;
1337 goto done;
1338 }
1339
1340 saved_modes = ahd_save_modes(ahd);
1341 ahd_set_modes(ahd, AHD_MODE_SCSI, AHD_MODE_SCSI);
1342 last_phase = ahd_inb(ahd, LASTPHASE);
1343 saved_scbptr = ahd_get_scbptr(ahd);
1344 active_scbptr = saved_scbptr;
1345 if (disconnected && (ahd_inb(ahd, SEQ_FLAGS) & NOT_IDENTIFIED) == 0) {
1346 struct scb *bus_scb;
1347
1348 bus_scb = ahd_lookup_scb(ahd, active_scbptr);
1349 if (bus_scb == pending_scb)
1350 disconnected = FALSE;
1351 }
1352
1353 /*
1354 * At this point, pending_scb is the scb associated with the
1355 * passed in command. That command is currently active on the
1356 * bus or is in the disconnected state.
1357 */
1358 if (last_phase != P_BUSFREE
1359 && SCB_GET_TAG(pending_scb) == active_scbptr) {
1360
1361 /*
1362 * We're active on the bus, so assert ATN
1363 * and hope that the target responds.
1364 */
1365 pending_scb = ahd_lookup_scb(ahd, active_scbptr);
1366 pending_scb->flags |= SCB_RECOVERY_SCB|SCB_ABORT;
1367 ahd_outb(ahd, MSG_OUT, HOST_MSG);
1368 ahd_outb(ahd, SCSISIGO, last_phase|ATNO);
1369 printf("%s:%d:%d:%d: Device is active, asserting ATN\n",
1370 ahd_name(ahd), cmd->device->channel,
1371 cmd->device->id, cmd->device->lun);
1372 wait = TRUE;
1373 } else if (disconnected) {
1374
1375 /*
1376 * Actually re-queue this SCB in an attempt
1377 * to select the device before it reconnects.
1378 */
1379 pending_scb->flags |= SCB_RECOVERY_SCB|SCB_ABORT;
1380 ahd_set_scbptr(ahd, SCB_GET_TAG(pending_scb));
1381 pending_scb->hscb->cdb_len = 0;
1382 pending_scb->hscb->task_attribute = 0;
1383 pending_scb->hscb->task_management = SIU_TASKMGMT_ABORT_TASK;
1384
1385 if ((pending_scb->flags & SCB_PACKETIZED) != 0) {
1386 /*
1387 * Mark the SCB has having an outstanding
1388 * task management function. Should the command
1389 * complete normally before the task management
1390 * function can be sent, the host will be notified
1391 * to abort our requeued SCB.
1392 */
1393 ahd_outb(ahd, SCB_TASK_MANAGEMENT,
1394 pending_scb->hscb->task_management);
1395 } else {
1396 /*
1397 * If non-packetized, set the MK_MESSAGE control
1398 * bit indicating that we desire to send a message.
1399 * We also set the disconnected flag since there is
1400 * no guarantee that our SCB control byte matches
1401 * the version on the card. We don't want the
1402 * sequencer to abort the command thinking an
1403 * unsolicited reselection occurred.
1404 */
1405 pending_scb->hscb->control |= MK_MESSAGE|DISCONNECTED;
1406
1407 /*
1408 * The sequencer will never re-reference the
1409 * in-core SCB. To make sure we are notified
1410 * during reslection, set the MK_MESSAGE flag in
1411 * the card's copy of the SCB.
1412 */
1413 ahd_outb(ahd, SCB_CONTROL,
1414 ahd_inb(ahd, SCB_CONTROL)|MK_MESSAGE);
1415 }
1416
1417 /*
1418 * Clear out any entries in the QINFIFO first
1419 * so we are the next SCB for this target
1420 * to run.
1421 */
1422 ahd_search_qinfifo(ahd, cmd->device->id,
1423 cmd->device->channel + 'A', cmd->device->lun,
1424 SCB_LIST_NULL, ROLE_INITIATOR,
1425 CAM_REQUEUE_REQ, SEARCH_COMPLETE);
1426 ahd_qinfifo_requeue_tail(ahd, pending_scb);
1427 ahd_set_scbptr(ahd, saved_scbptr);
1428 ahd_print_path(ahd, pending_scb);
1429 printf("Device is disconnected, re-queuing SCB\n");
1430 wait = TRUE;
1431 } else {
1432 printf("%s:%d:%d:%d: Unable to deliver message\n",
1433 ahd_name(ahd), cmd->device->channel,
1434 cmd->device->id, cmd->device->lun);
1435 retval = FAILED;
1436 goto done;
1437 }
1438
1439no_cmd:
1440 /*
1441 * Our assumption is that if we don't have the command, no
1442 * recovery action was required, so we return success. Again,
1443 * the semantics of the mid-layer recovery engine are not
1444 * well defined, so this may change in time.
1445 */
1446 retval = SUCCESS;
1447done:
1448 if (paused)
1449 ahd_unpause(ahd);
1450 if (wait) {
1451 struct timer_list timer;
1452 int ret;
1453
1454 pending_scb->platform_data->flags |= AHD_SCB_UP_EH_SEM;
1455 spin_unlock_irq(&ahd->platform_data->spin_lock);
1456 init_timer(&timer);
1457 timer.data = (u_long)pending_scb;
1458 timer.expires = jiffies + (5 * HZ);
1459 timer.function = ahd_linux_sem_timeout;
1460 add_timer(&timer);
1461 printf("Recovery code sleeping\n");
1462 down(&ahd->platform_data->eh_sem);
1463 printf("Recovery code awake\n");
1464 ret = del_timer_sync(&timer);
1465 if (ret == 0) {
1466 printf("Timer Expired\n");
1467 retval = FAILED;
1468 }
1469 spin_lock_irq(&ahd->platform_data->spin_lock);
1470 }
1471 ahd_schedule_runq(ahd);
1472 ahd_linux_run_complete_queue(ahd);
1473 ahd_midlayer_entrypoint_unlock(ahd, &s);
1474 return (retval);
1475}
1476
1477
1478static void
1479ahd_linux_dev_reset_complete(Scsi_Cmnd *cmd)
1480{
1481 free(cmd, M_DEVBUF);
1482} 654}
1483 655
1484/* 656/*
1485 * Attempt to send a target reset message to the device that timed out. 657 * Attempt to send a target reset message to the device that timed out.
1486 */ 658 */
1487static int 659static int
1488ahd_linux_dev_reset(Scsi_Cmnd *cmd) 660ahd_linux_dev_reset(struct scsi_cmnd *cmd)
1489{ 661{
1490 struct ahd_softc *ahd; 662 int error;
1491 struct scsi_cmnd *recovery_cmd;
1492 struct ahd_linux_device *dev;
1493 struct ahd_initiator_tinfo *tinfo;
1494 struct ahd_tmode_tstate *tstate;
1495 struct scb *scb;
1496 struct hardware_scb *hscb;
1497 u_long s;
1498 struct timer_list timer;
1499 int retval;
1500
1501 ahd = *(struct ahd_softc **)cmd->device->host->hostdata;
1502 recovery_cmd = malloc(sizeof(struct scsi_cmnd), M_DEVBUF, M_WAITOK);
1503 if (!recovery_cmd)
1504 return (FAILED);
1505 memset(recovery_cmd, 0, sizeof(struct scsi_cmnd));
1506 recovery_cmd->device = cmd->device;
1507 recovery_cmd->scsi_done = ahd_linux_dev_reset_complete;
1508#ifdef AHD_DEBUG
1509 if ((ahd_debug & AHD_SHOW_RECOVERY) != 0)
1510 printf("%s:%d:%d:%d: Device reset called for cmd %p\n",
1511 ahd_name(ahd), cmd->device->channel, cmd->device->id,
1512 cmd->device->lun, cmd);
1513#endif
1514 ahd_lock(ahd, &s);
1515
1516 dev = ahd_linux_get_device(ahd, cmd->device->channel, cmd->device->id,
1517 cmd->device->lun, /*alloc*/FALSE);
1518 if (dev == NULL) {
1519 ahd_unlock(ahd, &s);
1520 kfree(recovery_cmd);
1521 return (FAILED);
1522 }
1523 if ((scb = ahd_get_scb(ahd, AHD_NEVER_COL_IDX)) == NULL) {
1524 ahd_unlock(ahd, &s);
1525 kfree(recovery_cmd);
1526 return (FAILED);
1527 }
1528 tinfo = ahd_fetch_transinfo(ahd, 'A', ahd->our_id,
1529 cmd->device->id, &tstate);
1530 recovery_cmd->result = CAM_REQ_INPROG << 16;
1531 recovery_cmd->host_scribble = (char *)scb;
1532 scb->io_ctx = recovery_cmd;
1533 scb->platform_data->dev = dev;
1534 scb->sg_count = 0;
1535 ahd_set_residual(scb, 0);
1536 ahd_set_sense_residual(scb, 0);
1537 hscb = scb->hscb;
1538 hscb->control = 0;
1539 hscb->scsiid = BUILD_SCSIID(ahd, cmd);
1540 hscb->lun = cmd->device->lun;
1541 hscb->cdb_len = 0;
1542 hscb->task_management = SIU_TASKMGMT_LUN_RESET;
1543 scb->flags |= SCB_DEVICE_RESET|SCB_RECOVERY_SCB|SCB_ACTIVE;
1544 if ((tinfo->curr.ppr_options & MSG_EXT_PPR_IU_REQ) != 0) {
1545 scb->flags |= SCB_PACKETIZED;
1546 } else {
1547 hscb->control |= MK_MESSAGE;
1548 }
1549 dev->openings--;
1550 dev->active++;
1551 dev->commands_issued++;
1552 LIST_INSERT_HEAD(&ahd->pending_scbs, scb, pending_links);
1553 ahd_queue_scb(ahd, scb);
1554 663
1555 scb->platform_data->flags |= AHD_SCB_UP_EH_SEM; 664 error = ahd_linux_queue_recovery_cmd(cmd, SCB_DEVICE_RESET);
1556 ahd_unlock(ahd, &s); 665 if (error != 0)
1557 init_timer(&timer); 666 printf("aic79xx_dev_reset returns 0x%x\n", error);
1558 timer.data = (u_long)scb; 667 return error;
1559 timer.expires = jiffies + (5 * HZ);
1560 timer.function = ahd_linux_sem_timeout;
1561 add_timer(&timer);
1562 printf("Recovery code sleeping\n");
1563 down(&ahd->platform_data->eh_sem);
1564 printf("Recovery code awake\n");
1565 retval = SUCCESS;
1566 if (del_timer_sync(&timer) == 0) {
1567 printf("Timer Expired\n");
1568 retval = FAILED;
1569 }
1570 ahd_lock(ahd, &s);
1571 ahd_schedule_runq(ahd);
1572 ahd_linux_run_complete_queue(ahd);
1573 ahd_unlock(ahd, &s);
1574 printf("%s: Device reset returning 0x%x\n", ahd_name(ahd), retval);
1575 return (retval);
1576} 668}
1577 669
1578/* 670/*
1579 * Reset the SCSI bus. 671 * Reset the SCSI bus.
1580 */ 672 */
1581static int 673static int
1582ahd_linux_bus_reset(Scsi_Cmnd *cmd) 674ahd_linux_bus_reset(struct scsi_cmnd *cmd)
1583{ 675{
1584 struct ahd_softc *ahd; 676 struct ahd_softc *ahd;
1585 u_long s; 677 u_long s;
@@ -1594,7 +686,6 @@ ahd_linux_bus_reset(Scsi_Cmnd *cmd)
1594 ahd_lock(ahd, &s); 686 ahd_lock(ahd, &s);
1595 found = ahd_reset_channel(ahd, cmd->device->channel + 'A', 687 found = ahd_reset_channel(ahd, cmd->device->channel + 'A',
1596 /*initiate reset*/TRUE); 688 /*initiate reset*/TRUE);
1597 ahd_linux_run_complete_queue(ahd);
1598 ahd_unlock(ahd, &s); 689 ahd_unlock(ahd, &s);
1599 690
1600 if (bootverbose) 691 if (bootverbose)
@@ -1604,9 +695,10 @@ ahd_linux_bus_reset(Scsi_Cmnd *cmd)
1604 return (SUCCESS); 695 return (SUCCESS);
1605} 696}
1606 697
1607Scsi_Host_Template aic79xx_driver_template = { 698struct scsi_host_template aic79xx_driver_template = {
1608 .module = THIS_MODULE, 699 .module = THIS_MODULE,
1609 .name = "aic79xx", 700 .name = "aic79xx",
701 .proc_name = "aic79xx",
1610 .proc_info = ahd_linux_proc_info, 702 .proc_info = ahd_linux_proc_info,
1611 .info = ahd_linux_info, 703 .info = ahd_linux_info,
1612 .queuecommand = ahd_linux_queue, 704 .queuecommand = ahd_linux_queue,
@@ -1623,37 +715,10 @@ Scsi_Host_Template aic79xx_driver_template = {
1623 .slave_alloc = ahd_linux_slave_alloc, 715 .slave_alloc = ahd_linux_slave_alloc,
1624 .slave_configure = ahd_linux_slave_configure, 716 .slave_configure = ahd_linux_slave_configure,
1625 .slave_destroy = ahd_linux_slave_destroy, 717 .slave_destroy = ahd_linux_slave_destroy,
718 .target_alloc = ahd_linux_target_alloc,
719 .target_destroy = ahd_linux_target_destroy,
1626}; 720};
1627 721
1628/**************************** Tasklet Handler *********************************/
1629
1630/*
1631 * In 2.4.X and above, this routine is called from a tasklet,
1632 * so we must re-acquire our lock prior to executing this code.
1633 * In all prior kernels, ahd_schedule_runq() calls this routine
1634 * directly and ahd_schedule_runq() is called with our lock held.
1635 */
1636static void
1637ahd_runq_tasklet(unsigned long data)
1638{
1639 struct ahd_softc* ahd;
1640 struct ahd_linux_device *dev;
1641 u_long flags;
1642
1643 ahd = (struct ahd_softc *)data;
1644 ahd_lock(ahd, &flags);
1645 while ((dev = ahd_linux_next_device_to_run(ahd)) != NULL) {
1646
1647 TAILQ_REMOVE(&ahd->platform_data->device_runq, dev, links);
1648 dev->flags &= ~AHD_DEV_ON_RUN_LIST;
1649 ahd_linux_check_device_queue(ahd, dev);
1650 /* Yeild to our interrupt handler */
1651 ahd_unlock(ahd, &flags);
1652 ahd_lock(ahd, &flags);
1653 }
1654 ahd_unlock(ahd, &flags);
1655}
1656
1657/******************************** Bus DMA *************************************/ 722/******************************** Bus DMA *************************************/
1658int 723int
1659ahd_dma_tag_create(struct ahd_softc *ahd, bus_dma_tag_t parent, 724ahd_dma_tag_create(struct ahd_softc *ahd, bus_dma_tag_t parent,
@@ -1693,36 +758,10 @@ int
1693ahd_dmamem_alloc(struct ahd_softc *ahd, bus_dma_tag_t dmat, void** vaddr, 758ahd_dmamem_alloc(struct ahd_softc *ahd, bus_dma_tag_t dmat, void** vaddr,
1694 int flags, bus_dmamap_t *mapp) 759 int flags, bus_dmamap_t *mapp)
1695{ 760{
1696 bus_dmamap_t map;
1697
1698 map = malloc(sizeof(*map), M_DEVBUF, M_NOWAIT);
1699 if (map == NULL)
1700 return (ENOMEM);
1701 /*
1702 * Although we can dma data above 4GB, our
1703 * "consistent" memory is below 4GB for
1704 * space efficiency reasons (only need a 4byte
1705 * address). For this reason, we have to reset
1706 * our dma mask when doing allocations.
1707 */
1708 if (ahd->dev_softc != NULL)
1709 if (pci_set_dma_mask(ahd->dev_softc, 0xFFFFFFFF)) {
1710 printk(KERN_WARNING "aic79xx: No suitable DMA available.\n");
1711 kfree(map);
1712 return (ENODEV);
1713 }
1714 *vaddr = pci_alloc_consistent(ahd->dev_softc, 761 *vaddr = pci_alloc_consistent(ahd->dev_softc,
1715 dmat->maxsize, &map->bus_addr); 762 dmat->maxsize, mapp);
1716 if (ahd->dev_softc != NULL)
1717 if (pci_set_dma_mask(ahd->dev_softc,
1718 ahd->platform_data->hw_dma_mask)) {
1719 printk(KERN_WARNING "aic79xx: No suitable DMA available.\n");
1720 kfree(map);
1721 return (ENODEV);
1722 }
1723 if (*vaddr == NULL) 763 if (*vaddr == NULL)
1724 return (ENOMEM); 764 return (ENOMEM);
1725 *mapp = map;
1726 return(0); 765 return(0);
1727} 766}
1728 767
@@ -1731,7 +770,7 @@ ahd_dmamem_free(struct ahd_softc *ahd, bus_dma_tag_t dmat,
1731 void* vaddr, bus_dmamap_t map) 770 void* vaddr, bus_dmamap_t map)
1732{ 771{
1733 pci_free_consistent(ahd->dev_softc, dmat->maxsize, 772 pci_free_consistent(ahd->dev_softc, dmat->maxsize,
1734 vaddr, map->bus_addr); 773 vaddr, map);
1735} 774}
1736 775
1737int 776int
@@ -1745,7 +784,7 @@ ahd_dmamap_load(struct ahd_softc *ahd, bus_dma_tag_t dmat, bus_dmamap_t map,
1745 */ 784 */
1746 bus_dma_segment_t stack_sg; 785 bus_dma_segment_t stack_sg;
1747 786
1748 stack_sg.ds_addr = map->bus_addr; 787 stack_sg.ds_addr = map;
1749 stack_sg.ds_len = dmat->maxsize; 788 stack_sg.ds_len = dmat->maxsize;
1750 cb(cb_arg, &stack_sg, /*nseg*/1, /*error*/0); 789 cb(cb_arg, &stack_sg, /*nseg*/1, /*error*/0);
1751 return (0); 790 return (0);
@@ -1754,11 +793,6 @@ ahd_dmamap_load(struct ahd_softc *ahd, bus_dma_tag_t dmat, bus_dmamap_t map,
1754void 793void
1755ahd_dmamap_destroy(struct ahd_softc *ahd, bus_dma_tag_t dmat, bus_dmamap_t map) 794ahd_dmamap_destroy(struct ahd_softc *ahd, bus_dma_tag_t dmat, bus_dmamap_t map)
1756{ 795{
1757 /*
1758 * The map may is NULL in our < 2.3.X implementation.
1759 */
1760 if (map != NULL)
1761 free(map, M_DEVBUF);
1762} 796}
1763 797
1764int 798int
@@ -1823,41 +857,6 @@ ahd_softc_comp(struct ahd_softc *lahd, struct ahd_softc *rahd)
1823} 857}
1824 858
1825static void 859static void
1826ahd_linux_setup_tag_info(u_long arg, int instance, int targ, int32_t value)
1827{
1828
1829 if ((instance >= 0) && (targ >= 0)
1830 && (instance < NUM_ELEMENTS(aic79xx_tag_info))
1831 && (targ < AHD_NUM_TARGETS)) {
1832 aic79xx_tag_info[instance].tag_commands[targ] = value & 0x1FF;
1833 if (bootverbose)
1834 printf("tag_info[%d:%d] = %d\n", instance, targ, value);
1835 }
1836}
1837
1838static void
1839ahd_linux_setup_rd_strm_info(u_long arg, int instance, int targ, int32_t value)
1840{
1841 if ((instance >= 0)
1842 && (instance < NUM_ELEMENTS(aic79xx_rd_strm_info))) {
1843 aic79xx_rd_strm_info[instance] = value & 0xFFFF;
1844 if (bootverbose)
1845 printf("rd_strm[%d] = 0x%x\n", instance, value);
1846 }
1847}
1848
1849static void
1850ahd_linux_setup_dv(u_long arg, int instance, int targ, int32_t value)
1851{
1852 if ((instance >= 0)
1853 && (instance < NUM_ELEMENTS(aic79xx_dv_settings))) {
1854 aic79xx_dv_settings[instance] = value;
1855 if (bootverbose)
1856 printf("dv[%d] = %d\n", instance, value);
1857 }
1858}
1859
1860static void
1861ahd_linux_setup_iocell_info(u_long index, int instance, int targ, int32_t value) 860ahd_linux_setup_iocell_info(u_long index, int instance, int targ, int32_t value)
1862{ 861{
1863 862
@@ -1887,6 +886,99 @@ ahd_linux_setup_tag_info_global(char *p)
1887 } 886 }
1888} 887}
1889 888
889static void
890ahd_linux_setup_tag_info(u_long arg, int instance, int targ, int32_t value)
891{
892
893 if ((instance >= 0) && (targ >= 0)
894 && (instance < NUM_ELEMENTS(aic79xx_tag_info))
895 && (targ < AHD_NUM_TARGETS)) {
896 aic79xx_tag_info[instance].tag_commands[targ] = value & 0x1FF;
897 if (bootverbose)
898 printf("tag_info[%d:%d] = %d\n", instance, targ, value);
899 }
900}
901
902static char *
903ahd_parse_brace_option(char *opt_name, char *opt_arg, char *end, int depth,
904 void (*callback)(u_long, int, int, int32_t),
905 u_long callback_arg)
906{
907 char *tok_end;
908 char *tok_end2;
909 int i;
910 int instance;
911 int targ;
912 int done;
913 char tok_list[] = {'.', ',', '{', '}', '\0'};
914
915 /* All options use a ':' name/arg separator */
916 if (*opt_arg != ':')
917 return (opt_arg);
918 opt_arg++;
919 instance = -1;
920 targ = -1;
921 done = FALSE;
922 /*
923 * Restore separator that may be in
924 * the middle of our option argument.
925 */
926 tok_end = strchr(opt_arg, '\0');
927 if (tok_end < end)
928 *tok_end = ',';
929 while (!done) {
930 switch (*opt_arg) {
931 case '{':
932 if (instance == -1) {
933 instance = 0;
934 } else {
935 if (depth > 1) {
936 if (targ == -1)
937 targ = 0;
938 } else {
939 printf("Malformed Option %s\n",
940 opt_name);
941 done = TRUE;
942 }
943 }
944 opt_arg++;
945 break;
946 case '}':
947 if (targ != -1)
948 targ = -1;
949 else if (instance != -1)
950 instance = -1;
951 opt_arg++;
952 break;
953 case ',':
954 case '.':
955 if (instance == -1)
956 done = TRUE;
957 else if (targ >= 0)
958 targ++;
959 else if (instance >= 0)
960 instance++;
961 opt_arg++;
962 break;
963 case '\0':
964 done = TRUE;
965 break;
966 default:
967 tok_end = end;
968 for (i = 0; tok_list[i]; i++) {
969 tok_end2 = strchr(opt_arg, tok_list[i]);
970 if ((tok_end2) && (tok_end2 < tok_end))
971 tok_end = tok_end2;
972 }
973 callback(callback_arg, instance, targ,
974 simple_strtol(opt_arg, NULL, 0));
975 opt_arg = tok_end;
976 break;
977 }
978 }
979 return (opt_arg);
980}
981
1890/* 982/*
1891 * Handle Linux boot parameters. This routine allows for assigning a value 983 * Handle Linux boot parameters. This routine allows for assigning a value
1892 * to a parameter with a ':' between the parameter and the value. 984 * to a parameter with a ':' between the parameter and the value.
@@ -1916,8 +1008,6 @@ aic79xx_setup(char *s)
1916 { "seltime", &aic79xx_seltime }, 1008 { "seltime", &aic79xx_seltime },
1917 { "tag_info", NULL }, 1009 { "tag_info", NULL },
1918 { "global_tag_depth", NULL}, 1010 { "global_tag_depth", NULL},
1919 { "rd_strm", NULL },
1920 { "dv", NULL },
1921 { "slewrate", NULL }, 1011 { "slewrate", NULL },
1922 { "precomp", NULL }, 1012 { "precomp", NULL },
1923 { "amplitude", NULL }, 1013 { "amplitude", NULL },
@@ -1946,24 +1036,18 @@ aic79xx_setup(char *s)
1946 if (strncmp(p, "global_tag_depth", n) == 0) { 1036 if (strncmp(p, "global_tag_depth", n) == 0) {
1947 ahd_linux_setup_tag_info_global(p + n); 1037 ahd_linux_setup_tag_info_global(p + n);
1948 } else if (strncmp(p, "tag_info", n) == 0) { 1038 } else if (strncmp(p, "tag_info", n) == 0) {
1949 s = aic_parse_brace_option("tag_info", p + n, end, 1039 s = ahd_parse_brace_option("tag_info", p + n, end,
1950 2, ahd_linux_setup_tag_info, 0); 1040 2, ahd_linux_setup_tag_info, 0);
1951 } else if (strncmp(p, "rd_strm", n) == 0) {
1952 s = aic_parse_brace_option("rd_strm", p + n, end,
1953 1, ahd_linux_setup_rd_strm_info, 0);
1954 } else if (strncmp(p, "dv", n) == 0) {
1955 s = aic_parse_brace_option("dv", p + n, end, 1,
1956 ahd_linux_setup_dv, 0);
1957 } else if (strncmp(p, "slewrate", n) == 0) { 1041 } else if (strncmp(p, "slewrate", n) == 0) {
1958 s = aic_parse_brace_option("slewrate", 1042 s = ahd_parse_brace_option("slewrate",
1959 p + n, end, 1, ahd_linux_setup_iocell_info, 1043 p + n, end, 1, ahd_linux_setup_iocell_info,
1960 AIC79XX_SLEWRATE_INDEX); 1044 AIC79XX_SLEWRATE_INDEX);
1961 } else if (strncmp(p, "precomp", n) == 0) { 1045 } else if (strncmp(p, "precomp", n) == 0) {
1962 s = aic_parse_brace_option("precomp", 1046 s = ahd_parse_brace_option("precomp",
1963 p + n, end, 1, ahd_linux_setup_iocell_info, 1047 p + n, end, 1, ahd_linux_setup_iocell_info,
1964 AIC79XX_PRECOMP_INDEX); 1048 AIC79XX_PRECOMP_INDEX);
1965 } else if (strncmp(p, "amplitude", n) == 0) { 1049 } else if (strncmp(p, "amplitude", n) == 0) {
1966 s = aic_parse_brace_option("amplitude", 1050 s = ahd_parse_brace_option("amplitude",
1967 p + n, end, 1, ahd_linux_setup_iocell_info, 1051 p + n, end, 1, ahd_linux_setup_iocell_info,
1968 AIC79XX_AMPLITUDE_INDEX); 1052 AIC79XX_AMPLITUDE_INDEX);
1969 } else if (p[n] == ':') { 1053 } else if (p[n] == ':') {
@@ -1982,13 +1066,12 @@ __setup("aic79xx=", aic79xx_setup);
1982uint32_t aic79xx_verbose; 1066uint32_t aic79xx_verbose;
1983 1067
1984int 1068int
1985ahd_linux_register_host(struct ahd_softc *ahd, Scsi_Host_Template *template) 1069ahd_linux_register_host(struct ahd_softc *ahd, struct scsi_host_template *template)
1986{ 1070{
1987 char buf[80]; 1071 char buf[80];
1988 struct Scsi_Host *host; 1072 struct Scsi_Host *host;
1989 char *new_name; 1073 char *new_name;
1990 u_long s; 1074 u_long s;
1991 u_long target;
1992 1075
1993 template->name = ahd->description; 1076 template->name = ahd->description;
1994 host = scsi_host_alloc(template, sizeof(struct ahd_softc *)); 1077 host = scsi_host_alloc(template, sizeof(struct ahd_softc *));
@@ -1997,11 +1080,7 @@ ahd_linux_register_host(struct ahd_softc *ahd, Scsi_Host_Template *template)
1997 1080
1998 *((struct ahd_softc **)host->hostdata) = ahd; 1081 *((struct ahd_softc **)host->hostdata) = ahd;
1999 ahd_lock(ahd, &s); 1082 ahd_lock(ahd, &s);
2000#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,5,0)
2001 scsi_assign_lock(host, &ahd->platform_data->spin_lock); 1083 scsi_assign_lock(host, &ahd->platform_data->spin_lock);
2002#elif AHD_SCSI_HAS_HOST_LOCK != 0
2003 host->lock = &ahd->platform_data->spin_lock;
2004#endif
2005 ahd->platform_data->host = host; 1084 ahd->platform_data->host = host;
2006 host->can_queue = AHD_MAX_QUEUE; 1085 host->can_queue = AHD_MAX_QUEUE;
2007 host->cmd_per_lun = 2; 1086 host->cmd_per_lun = 2;
@@ -2012,7 +1091,7 @@ ahd_linux_register_host(struct ahd_softc *ahd, Scsi_Host_Template *template)
2012 host->max_lun = AHD_NUM_LUNS; 1091 host->max_lun = AHD_NUM_LUNS;
2013 host->max_channel = 0; 1092 host->max_channel = 0;
2014 host->sg_tablesize = AHD_NSEG; 1093 host->sg_tablesize = AHD_NSEG;
2015 ahd_set_unit(ahd, ahd_linux_next_unit()); 1094 ahd_set_unit(ahd, ahd_linux_unit++);
2016 sprintf(buf, "scsi%d", host->host_no); 1095 sprintf(buf, "scsi%d", host->host_no);
2017 new_name = malloc(strlen(buf) + 1, M_DEVBUF, M_NOWAIT); 1096 new_name = malloc(strlen(buf) + 1, M_DEVBUF, M_NOWAIT);
2018 if (new_name != NULL) { 1097 if (new_name != NULL) {
@@ -2020,54 +1099,14 @@ ahd_linux_register_host(struct ahd_softc *ahd, Scsi_Host_Template *template)
2020 ahd_set_name(ahd, new_name); 1099 ahd_set_name(ahd, new_name);
2021 } 1100 }
2022 host->unique_id = ahd->unit; 1101 host->unique_id = ahd->unit;
2023#if LINUX_VERSION_CODE < KERNEL_VERSION(2,5,0)
2024 scsi_set_pci_device(host, ahd->dev_softc);
2025#endif
2026 ahd_linux_setup_user_rd_strm_settings(ahd);
2027 ahd_linux_initialize_scsi_bus(ahd); 1102 ahd_linux_initialize_scsi_bus(ahd);
2028 ahd_unlock(ahd, &s);
2029 ahd->platform_data->dv_pid = kernel_thread(ahd_linux_dv_thread, ahd, 0);
2030 ahd_lock(ahd, &s);
2031 if (ahd->platform_data->dv_pid < 0) {
2032 printf("%s: Failed to create DV thread, error= %d\n",
2033 ahd_name(ahd), ahd->platform_data->dv_pid);
2034 return (-ahd->platform_data->dv_pid);
2035 }
2036 /*
2037 * Initially allocate *all* of our linux target objects
2038 * so that the DV thread will scan them all in parallel
2039 * just after driver initialization. Any device that
2040 * does not exist will have its target object destroyed
2041 * by the selection timeout handler. In the case of a
2042 * device that appears after the initial DV scan, async
2043 * negotiation will occur for the first command, and DV
2044 * will comence should that first command be successful.
2045 */
2046 for (target = 0; target < host->max_id; target++) {
2047
2048 /*
2049 * Skip our own ID. Some Compaq/HP storage devices
2050 * have enclosure management devices that respond to
2051 * single bit selection (i.e. selecting ourselves).
2052 * It is expected that either an external application
2053 * or a modified kernel will be used to probe this
2054 * ID if it is appropriate. To accommodate these
2055 * installations, ahc_linux_alloc_target() will allocate
2056 * for our ID if asked to do so.
2057 */
2058 if (target == ahd->our_id)
2059 continue;
2060
2061 ahd_linux_alloc_target(ahd, 0, target);
2062 }
2063 ahd_intr_enable(ahd, TRUE); 1103 ahd_intr_enable(ahd, TRUE);
2064 ahd_linux_start_dv(ahd);
2065 ahd_unlock(ahd, &s); 1104 ahd_unlock(ahd, &s);
2066 1105
2067#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,5,0) 1106 host->transportt = ahd_linux_transport_template;
1107
2068 scsi_add_host(host, &ahd->dev_softc->dev); /* XXX handle failure */ 1108 scsi_add_host(host, &ahd->dev_softc->dev); /* XXX handle failure */
2069 scsi_scan_host(host); 1109 scsi_scan_host(host);
2070#endif
2071 return (0); 1110 return (0);
2072} 1111}
2073 1112
@@ -2081,29 +1120,6 @@ ahd_linux_get_memsize(void)
2081} 1120}
2082 1121
2083/* 1122/*
2084 * Find the smallest available unit number to use
2085 * for a new device. We don't just use a static
2086 * count to handle the "repeated hot-(un)plug"
2087 * scenario.
2088 */
2089static int
2090ahd_linux_next_unit(void)
2091{
2092 struct ahd_softc *ahd;
2093 int unit;
2094
2095 unit = 0;
2096retry:
2097 TAILQ_FOREACH(ahd, &ahd_tailq, links) {
2098 if (ahd->unit == unit) {
2099 unit++;
2100 goto retry;
2101 }
2102 }
2103 return (unit);
2104}
2105
2106/*
2107 * Place the SCSI bus into a known state by either resetting it, 1123 * Place the SCSI bus into a known state by either resetting it,
2108 * or forcing transfer negotiations on the next command to any 1124 * or forcing transfer negotiations on the next command to any
2109 * target. 1125 * target.
@@ -2162,20 +1178,9 @@ ahd_platform_alloc(struct ahd_softc *ahd, void *platform_arg)
2162 if (ahd->platform_data == NULL) 1178 if (ahd->platform_data == NULL)
2163 return (ENOMEM); 1179 return (ENOMEM);
2164 memset(ahd->platform_data, 0, sizeof(struct ahd_platform_data)); 1180 memset(ahd->platform_data, 0, sizeof(struct ahd_platform_data));
2165 TAILQ_INIT(&ahd->platform_data->completeq);
2166 TAILQ_INIT(&ahd->platform_data->device_runq);
2167 ahd->platform_data->irq = AHD_LINUX_NOIRQ; 1181 ahd->platform_data->irq = AHD_LINUX_NOIRQ;
2168 ahd->platform_data->hw_dma_mask = 0xFFFFFFFF;
2169 ahd_lockinit(ahd); 1182 ahd_lockinit(ahd);
2170 ahd_done_lockinit(ahd);
2171 init_timer(&ahd->platform_data->completeq_timer);
2172 ahd->platform_data->completeq_timer.data = (u_long)ahd;
2173 ahd->platform_data->completeq_timer.function =
2174 (ahd_linux_callback_t *)ahd_linux_thread_run_complete_queue;
2175 init_MUTEX_LOCKED(&ahd->platform_data->eh_sem); 1183 init_MUTEX_LOCKED(&ahd->platform_data->eh_sem);
2176 init_MUTEX_LOCKED(&ahd->platform_data->dv_sem);
2177 init_MUTEX_LOCKED(&ahd->platform_data->dv_cmd_sem);
2178 ahd_setup_runq_tasklet(ahd);
2179 ahd->seltime = (aic79xx_seltime & 0x3) << 4; 1184 ahd->seltime = (aic79xx_seltime & 0x3) << 4;
2180 return (0); 1185 return (0);
2181} 1186}
@@ -2183,39 +1188,27 @@ ahd_platform_alloc(struct ahd_softc *ahd, void *platform_arg)
2183void 1188void
2184ahd_platform_free(struct ahd_softc *ahd) 1189ahd_platform_free(struct ahd_softc *ahd)
2185{ 1190{
2186 struct ahd_linux_target *targ; 1191 struct scsi_target *starget;
2187 struct ahd_linux_device *dev;
2188 int i, j; 1192 int i, j;
2189 1193
2190 if (ahd->platform_data != NULL) { 1194 if (ahd->platform_data != NULL) {
2191 del_timer_sync(&ahd->platform_data->completeq_timer);
2192 ahd_linux_kill_dv_thread(ahd);
2193 ahd_teardown_runq_tasklet(ahd);
2194 if (ahd->platform_data->host != NULL) { 1195 if (ahd->platform_data->host != NULL) {
2195#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,5,0)
2196 scsi_remove_host(ahd->platform_data->host); 1196 scsi_remove_host(ahd->platform_data->host);
2197#endif
2198 scsi_host_put(ahd->platform_data->host); 1197 scsi_host_put(ahd->platform_data->host);
2199 } 1198 }
2200 1199
2201 /* destroy all of the device and target objects */ 1200 /* destroy all of the device and target objects */
2202 for (i = 0; i < AHD_NUM_TARGETS; i++) { 1201 for (i = 0; i < AHD_NUM_TARGETS; i++) {
2203 targ = ahd->platform_data->targets[i]; 1202 starget = ahd->platform_data->starget[i];
2204 if (targ != NULL) { 1203 if (starget != NULL) {
2205 /* Keep target around through the loop. */
2206 targ->refcount++;
2207 for (j = 0; j < AHD_NUM_LUNS; j++) { 1204 for (j = 0; j < AHD_NUM_LUNS; j++) {
2208 1205 struct ahd_linux_target *targ =
2209 if (targ->devices[j] == NULL) 1206 scsi_transport_target_data(starget);
1207 if (targ->sdev[j] == NULL)
2210 continue; 1208 continue;
2211 dev = targ->devices[j]; 1209 targ->sdev[j] = NULL;
2212 ahd_linux_free_device(ahd, dev);
2213 } 1210 }
2214 /* 1211 ahd->platform_data->starget[i] = NULL;
2215 * Forcibly free the target now that
2216 * all devices are gone.
2217 */
2218 ahd_linux_free_target(ahd, targ);
2219 } 1212 }
2220 } 1213 }
2221 1214
@@ -2233,16 +1226,6 @@ ahd_platform_free(struct ahd_softc *ahd)
2233 release_mem_region(ahd->platform_data->mem_busaddr, 1226 release_mem_region(ahd->platform_data->mem_busaddr,
2234 0x1000); 1227 0x1000);
2235 } 1228 }
2236#if LINUX_VERSION_CODE < KERNEL_VERSION(2,5,0)
2237 /*
2238 * In 2.4 we detach from the scsi midlayer before the PCI
2239 * layer invokes our remove callback. No per-instance
2240 * detach is provided, so we must reach inside the PCI
2241 * subsystem's internals and detach our driver manually.
2242 */
2243 if (ahd->dev_softc != NULL)
2244 ahd->dev_softc->driver = NULL;
2245#endif
2246 free(ahd->platform_data, M_DEVBUF); 1229 free(ahd->platform_data, M_DEVBUF);
2247 } 1230 }
2248} 1231}
@@ -2280,13 +1263,22 @@ void
2280ahd_platform_set_tags(struct ahd_softc *ahd, struct ahd_devinfo *devinfo, 1263ahd_platform_set_tags(struct ahd_softc *ahd, struct ahd_devinfo *devinfo,
2281 ahd_queue_alg alg) 1264 ahd_queue_alg alg)
2282{ 1265{
1266 struct scsi_target *starget;
1267 struct ahd_linux_target *targ;
2283 struct ahd_linux_device *dev; 1268 struct ahd_linux_device *dev;
1269 struct scsi_device *sdev;
2284 int was_queuing; 1270 int was_queuing;
2285 int now_queuing; 1271 int now_queuing;
2286 1272
2287 dev = ahd_linux_get_device(ahd, devinfo->channel - 'A', 1273 starget = ahd->platform_data->starget[devinfo->target];
2288 devinfo->target, 1274 targ = scsi_transport_target_data(starget);
2289 devinfo->lun, /*alloc*/FALSE); 1275 BUG_ON(targ == NULL);
1276 sdev = targ->sdev[devinfo->lun];
1277 if (sdev == NULL)
1278 return;
1279
1280 dev = scsi_transport_device_data(sdev);
1281
2290 if (dev == NULL) 1282 if (dev == NULL)
2291 return; 1283 return;
2292 was_queuing = dev->flags & (AHD_DEV_Q_BASIC|AHD_DEV_Q_TAGGED); 1284 was_queuing = dev->flags & (AHD_DEV_Q_BASIC|AHD_DEV_Q_TAGGED);
@@ -2339,1434 +1331,37 @@ ahd_platform_set_tags(struct ahd_softc *ahd, struct ahd_devinfo *devinfo,
2339 dev->maxtags = 0; 1331 dev->maxtags = 0;
2340 dev->openings = 1 - dev->active; 1332 dev->openings = 1 - dev->active;
2341 } 1333 }
2342#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,5,0)
2343 if (dev->scsi_device != NULL) {
2344 switch ((dev->flags & (AHD_DEV_Q_BASIC|AHD_DEV_Q_TAGGED))) {
2345 case AHD_DEV_Q_BASIC:
2346 scsi_adjust_queue_depth(dev->scsi_device,
2347 MSG_SIMPLE_TASK,
2348 dev->openings + dev->active);
2349 break;
2350 case AHD_DEV_Q_TAGGED:
2351 scsi_adjust_queue_depth(dev->scsi_device,
2352 MSG_ORDERED_TASK,
2353 dev->openings + dev->active);
2354 break;
2355 default:
2356 /*
2357 * We allow the OS to queue 2 untagged transactions to
2358 * us at any time even though we can only execute them
2359 * serially on the controller/device. This should
2360 * remove some latency.
2361 */
2362 scsi_adjust_queue_depth(dev->scsi_device,
2363 /*NON-TAGGED*/0,
2364 /*queue depth*/2);
2365 break;
2366 }
2367 }
2368#endif
2369}
2370
2371int
2372ahd_platform_abort_scbs(struct ahd_softc *ahd, int target, char channel,
2373 int lun, u_int tag, role_t role, uint32_t status)
2374{
2375 int targ;
2376 int maxtarg;
2377 int maxlun;
2378 int clun;
2379 int count;
2380
2381 if (tag != SCB_LIST_NULL)
2382 return (0);
2383
2384 targ = 0;
2385 if (target != CAM_TARGET_WILDCARD) {
2386 targ = target;
2387 maxtarg = targ + 1;
2388 } else {
2389 maxtarg = (ahd->features & AHD_WIDE) ? 16 : 8;
2390 }
2391 clun = 0;
2392 if (lun != CAM_LUN_WILDCARD) {
2393 clun = lun;
2394 maxlun = clun + 1;
2395 } else {
2396 maxlun = AHD_NUM_LUNS;
2397 }
2398
2399 count = 0;
2400 for (; targ < maxtarg; targ++) {
2401
2402 for (; clun < maxlun; clun++) {
2403 struct ahd_linux_device *dev;
2404 struct ahd_busyq *busyq;
2405 struct ahd_cmd *acmd;
2406
2407 dev = ahd_linux_get_device(ahd, /*chan*/0, targ,
2408 clun, /*alloc*/FALSE);
2409 if (dev == NULL)
2410 continue;
2411
2412 busyq = &dev->busyq;
2413 while ((acmd = TAILQ_FIRST(busyq)) != NULL) {
2414 Scsi_Cmnd *cmd;
2415
2416 cmd = &acmd_scsi_cmd(acmd);
2417 TAILQ_REMOVE(busyq, acmd,
2418 acmd_links.tqe);
2419 count++;
2420 cmd->result = status << 16;
2421 ahd_linux_queue_cmd_complete(ahd, cmd);
2422 }
2423 }
2424 }
2425
2426 return (count);
2427}
2428
2429static void
2430ahd_linux_thread_run_complete_queue(struct ahd_softc *ahd)
2431{
2432 u_long flags;
2433
2434 ahd_lock(ahd, &flags);
2435 del_timer(&ahd->platform_data->completeq_timer);
2436 ahd->platform_data->flags &= ~AHD_RUN_CMPLT_Q_TIMER;
2437 ahd_linux_run_complete_queue(ahd);
2438 ahd_unlock(ahd, &flags);
2439}
2440
2441static void
2442ahd_linux_start_dv(struct ahd_softc *ahd)
2443{
2444
2445 /*
2446 * Freeze the simq and signal ahd_linux_queue to not let any
2447 * more commands through
2448 */
2449 if ((ahd->platform_data->flags & AHD_DV_ACTIVE) == 0) {
2450#ifdef AHD_DEBUG
2451 if (ahd_debug & AHD_SHOW_DV)
2452 printf("%s: Starting DV\n", ahd_name(ahd));
2453#endif
2454
2455 ahd->platform_data->flags |= AHD_DV_ACTIVE;
2456 ahd_freeze_simq(ahd);
2457
2458 /* Wake up the DV kthread */
2459 up(&ahd->platform_data->dv_sem);
2460 }
2461}
2462
2463static int
2464ahd_linux_dv_thread(void *data)
2465{
2466 struct ahd_softc *ahd;
2467 int target;
2468 u_long s;
2469
2470 ahd = (struct ahd_softc *)data;
2471
2472#ifdef AHD_DEBUG
2473 if (ahd_debug & AHD_SHOW_DV)
2474 printf("In DV Thread\n");
2475#endif
2476
2477 /*
2478 * Complete thread creation.
2479 */
2480 lock_kernel();
2481#if LINUX_VERSION_CODE < KERNEL_VERSION(2,5,60)
2482 /*
2483 * Don't care about any signals.
2484 */
2485 siginitsetinv(&current->blocked, 0);
2486
2487 daemonize();
2488 sprintf(current->comm, "ahd_dv_%d", ahd->unit);
2489#else
2490 daemonize("ahd_dv_%d", ahd->unit);
2491 current->flags |= PF_NOFREEZE;
2492#endif
2493 unlock_kernel();
2494
2495 while (1) {
2496 /*
2497 * Use down_interruptible() rather than down() to
2498 * avoid inclusion in the load average.
2499 */
2500 down_interruptible(&ahd->platform_data->dv_sem);
2501
2502 /* Check to see if we've been signaled to exit */
2503 ahd_lock(ahd, &s);
2504 if ((ahd->platform_data->flags & AHD_DV_SHUTDOWN) != 0) {
2505 ahd_unlock(ahd, &s);
2506 break;
2507 }
2508 ahd_unlock(ahd, &s);
2509
2510#ifdef AHD_DEBUG
2511 if (ahd_debug & AHD_SHOW_DV)
2512 printf("%s: Beginning Domain Validation\n",
2513 ahd_name(ahd));
2514#endif
2515
2516 /*
2517 * Wait for any pending commands to drain before proceeding.
2518 */
2519 ahd_lock(ahd, &s);
2520 while (LIST_FIRST(&ahd->pending_scbs) != NULL) {
2521 ahd->platform_data->flags |= AHD_DV_WAIT_SIMQ_EMPTY;
2522 ahd_unlock(ahd, &s);
2523 down_interruptible(&ahd->platform_data->dv_sem);
2524 ahd_lock(ahd, &s);
2525 }
2526
2527 /*
2528 * Wait for the SIMQ to be released so that DV is the
2529 * only reason the queue is frozen.
2530 */
2531 while (AHD_DV_SIMQ_FROZEN(ahd) == 0) {
2532 ahd->platform_data->flags |= AHD_DV_WAIT_SIMQ_RELEASE;
2533 ahd_unlock(ahd, &s);
2534 down_interruptible(&ahd->platform_data->dv_sem);
2535 ahd_lock(ahd, &s);
2536 }
2537 ahd_unlock(ahd, &s);
2538
2539 for (target = 0; target < AHD_NUM_TARGETS; target++)
2540 ahd_linux_dv_target(ahd, target);
2541
2542 ahd_lock(ahd, &s);
2543 ahd->platform_data->flags &= ~AHD_DV_ACTIVE;
2544 ahd_unlock(ahd, &s);
2545
2546 /*
2547 * Release the SIMQ so that normal commands are
2548 * allowed to continue on the bus.
2549 */
2550 ahd_release_simq(ahd);
2551 }
2552 up(&ahd->platform_data->eh_sem);
2553 return (0);
2554}
2555
2556static void
2557ahd_linux_kill_dv_thread(struct ahd_softc *ahd)
2558{
2559 u_long s;
2560
2561 ahd_lock(ahd, &s);
2562 if (ahd->platform_data->dv_pid != 0) {
2563 ahd->platform_data->flags |= AHD_DV_SHUTDOWN;
2564 ahd_unlock(ahd, &s);
2565 up(&ahd->platform_data->dv_sem);
2566
2567 /*
2568 * Use the eh_sem as an indicator that the
2569 * dv thread is exiting. Note that the dv
2570 * thread must still return after performing
2571 * the up on our semaphore before it has
2572 * completely exited this module. Unfortunately,
2573 * there seems to be no easy way to wait for the
2574 * exit of a thread for which you are not the
2575 * parent (dv threads are parented by init).
2576 * Cross your fingers...
2577 */
2578 down(&ahd->platform_data->eh_sem);
2579
2580 /*
2581 * Mark the dv thread as already dead. This
2582 * avoids attempting to kill it a second time.
2583 * This is necessary because we must kill the
2584 * DV thread before calling ahd_free() in the
2585 * module shutdown case to avoid bogus locking
2586 * in the SCSI mid-layer, but we ahd_free() is
2587 * called without killing the DV thread in the
2588 * instance detach case, so ahd_platform_free()
2589 * calls us again to verify that the DV thread
2590 * is dead.
2591 */
2592 ahd->platform_data->dv_pid = 0;
2593 } else {
2594 ahd_unlock(ahd, &s);
2595 }
2596}
2597
2598#define AHD_LINUX_DV_INQ_SHORT_LEN 36
2599#define AHD_LINUX_DV_INQ_LEN 256
2600#define AHD_LINUX_DV_TIMEOUT (HZ / 4)
2601
2602#define AHD_SET_DV_STATE(ahd, targ, newstate) \
2603 ahd_set_dv_state(ahd, targ, newstate, __LINE__)
2604
2605static __inline void
2606ahd_set_dv_state(struct ahd_softc *ahd, struct ahd_linux_target *targ,
2607 ahd_dv_state newstate, u_int line)
2608{
2609 ahd_dv_state oldstate;
2610
2611 oldstate = targ->dv_state;
2612#ifdef AHD_DEBUG
2613 if (ahd_debug & AHD_SHOW_DV)
2614 printf("%s:%d: Going from state %d to state %d\n",
2615 ahd_name(ahd), line, oldstate, newstate);
2616#endif
2617
2618 if (oldstate == newstate)
2619 targ->dv_state_retry++;
2620 else
2621 targ->dv_state_retry = 0;
2622 targ->dv_state = newstate;
2623}
2624
2625static void
2626ahd_linux_dv_target(struct ahd_softc *ahd, u_int target_offset)
2627{
2628 struct ahd_devinfo devinfo;
2629 struct ahd_linux_target *targ;
2630 struct scsi_cmnd *cmd;
2631 struct scsi_device *scsi_dev;
2632 struct scsi_sense_data *sense;
2633 uint8_t *buffer;
2634 u_long s;
2635 u_int timeout;
2636 int echo_size;
2637
2638 sense = NULL;
2639 buffer = NULL;
2640 echo_size = 0;
2641 ahd_lock(ahd, &s);
2642 targ = ahd->platform_data->targets[target_offset];
2643 if (targ == NULL || (targ->flags & AHD_DV_REQUIRED) == 0) {
2644 ahd_unlock(ahd, &s);
2645 return;
2646 }
2647 ahd_compile_devinfo(&devinfo, ahd->our_id, targ->target, /*lun*/0,
2648 targ->channel + 'A', ROLE_INITIATOR);
2649#ifdef AHD_DEBUG
2650 if (ahd_debug & AHD_SHOW_DV) {
2651 ahd_print_devinfo(ahd, &devinfo);
2652 printf("Performing DV\n");
2653 }
2654#endif
2655
2656 ahd_unlock(ahd, &s);
2657
2658 cmd = malloc(sizeof(struct scsi_cmnd), M_DEVBUF, M_WAITOK);
2659 scsi_dev = malloc(sizeof(struct scsi_device), M_DEVBUF, M_WAITOK);
2660 scsi_dev->host = ahd->platform_data->host;
2661 scsi_dev->id = devinfo.target;
2662 scsi_dev->lun = devinfo.lun;
2663 scsi_dev->channel = devinfo.channel - 'A';
2664 ahd->platform_data->dv_scsi_dev = scsi_dev;
2665
2666 AHD_SET_DV_STATE(ahd, targ, AHD_DV_STATE_INQ_SHORT_ASYNC);
2667
2668 while (targ->dv_state != AHD_DV_STATE_EXIT) {
2669 timeout = AHD_LINUX_DV_TIMEOUT;
2670 switch (targ->dv_state) {
2671 case AHD_DV_STATE_INQ_SHORT_ASYNC:
2672 case AHD_DV_STATE_INQ_ASYNC:
2673 case AHD_DV_STATE_INQ_ASYNC_VERIFY:
2674 /*
2675 * Set things to async narrow to reduce the
2676 * chance that the INQ will fail.
2677 */
2678 ahd_lock(ahd, &s);
2679 ahd_set_syncrate(ahd, &devinfo, 0, 0, 0,
2680 AHD_TRANS_GOAL, /*paused*/FALSE);
2681 ahd_set_width(ahd, &devinfo, MSG_EXT_WDTR_BUS_8_BIT,
2682 AHD_TRANS_GOAL, /*paused*/FALSE);
2683 ahd_unlock(ahd, &s);
2684 timeout = 10 * HZ;
2685 targ->flags &= ~AHD_INQ_VALID;
2686 /* FALLTHROUGH */
2687 case AHD_DV_STATE_INQ_VERIFY:
2688 {
2689 u_int inq_len;
2690
2691 if (targ->dv_state == AHD_DV_STATE_INQ_SHORT_ASYNC)
2692 inq_len = AHD_LINUX_DV_INQ_SHORT_LEN;
2693 else
2694 inq_len = targ->inq_data->additional_length + 5;
2695 ahd_linux_dv_inq(ahd, cmd, &devinfo, targ, inq_len);
2696 break;
2697 }
2698 case AHD_DV_STATE_TUR:
2699 case AHD_DV_STATE_BUSY:
2700 timeout = 5 * HZ;
2701 ahd_linux_dv_tur(ahd, cmd, &devinfo);
2702 break;
2703 case AHD_DV_STATE_REBD:
2704 ahd_linux_dv_rebd(ahd, cmd, &devinfo, targ);
2705 break;
2706 case AHD_DV_STATE_WEB:
2707 ahd_linux_dv_web(ahd, cmd, &devinfo, targ);
2708 break;
2709
2710 case AHD_DV_STATE_REB:
2711 ahd_linux_dv_reb(ahd, cmd, &devinfo, targ);
2712 break;
2713
2714 case AHD_DV_STATE_SU:
2715 ahd_linux_dv_su(ahd, cmd, &devinfo, targ);
2716 timeout = 50 * HZ;
2717 break;
2718
2719 default:
2720 ahd_print_devinfo(ahd, &devinfo);
2721 printf("Unknown DV state %d\n", targ->dv_state);
2722 goto out;
2723 }
2724
2725 /* Queue the command and wait for it to complete */
2726 /* Abuse eh_timeout in the scsi_cmnd struct for our purposes */
2727 init_timer(&cmd->eh_timeout);
2728#ifdef AHD_DEBUG
2729 if ((ahd_debug & AHD_SHOW_MESSAGES) != 0)
2730 /*
2731 * All of the printfs during negotiation
2732 * really slow down the negotiation.
2733 * Add a bit of time just to be safe.
2734 */
2735 timeout += HZ;
2736#endif
2737 scsi_add_timer(cmd, timeout, ahd_linux_dv_timeout);
2738 /*
2739 * In 2.5.X, it is assumed that all calls from the
2740 * "midlayer" (which we are emulating) will have the
2741 * ahd host lock held. For other kernels, the
2742 * io_request_lock must be held.
2743 */
2744#if AHD_SCSI_HAS_HOST_LOCK != 0
2745 ahd_lock(ahd, &s);
2746#else
2747 spin_lock_irqsave(&io_request_lock, s);
2748#endif
2749 ahd_linux_queue(cmd, ahd_linux_dv_complete);
2750#if AHD_SCSI_HAS_HOST_LOCK != 0
2751 ahd_unlock(ahd, &s);
2752#else
2753 spin_unlock_irqrestore(&io_request_lock, s);
2754#endif
2755 down_interruptible(&ahd->platform_data->dv_cmd_sem);
2756 /*
2757 * Wait for the SIMQ to be released so that DV is the
2758 * only reason the queue is frozen.
2759 */
2760 ahd_lock(ahd, &s);
2761 while (AHD_DV_SIMQ_FROZEN(ahd) == 0) {
2762 ahd->platform_data->flags |= AHD_DV_WAIT_SIMQ_RELEASE;
2763 ahd_unlock(ahd, &s);
2764 down_interruptible(&ahd->platform_data->dv_sem);
2765 ahd_lock(ahd, &s);
2766 }
2767 ahd_unlock(ahd, &s);
2768
2769 ahd_linux_dv_transition(ahd, cmd, &devinfo, targ);
2770 }
2771
2772out:
2773 if ((targ->flags & AHD_INQ_VALID) != 0
2774 && ahd_linux_get_device(ahd, devinfo.channel - 'A',
2775 devinfo.target, devinfo.lun,
2776 /*alloc*/FALSE) == NULL) {
2777 /*
2778 * The DV state machine failed to configure this device.
2779 * This is normal if DV is disabled. Since we have inquiry
2780 * data, filter it and use the "optimistic" negotiation
2781 * parameters found in the inquiry string.
2782 */
2783 ahd_linux_filter_inquiry(ahd, &devinfo);
2784 if ((targ->flags & (AHD_BASIC_DV|AHD_ENHANCED_DV)) != 0) {
2785 ahd_print_devinfo(ahd, &devinfo);
2786 printf("DV failed to configure device. "
2787 "Please file a bug report against "
2788 "this driver.\n");
2789 }
2790 }
2791
2792 if (cmd != NULL)
2793 free(cmd, M_DEVBUF);
2794
2795 if (ahd->platform_data->dv_scsi_dev != NULL) {
2796 free(ahd->platform_data->dv_scsi_dev, M_DEVBUF);
2797 ahd->platform_data->dv_scsi_dev = NULL;
2798 }
2799
2800 ahd_lock(ahd, &s);
2801 if (targ->dv_buffer != NULL) {
2802 free(targ->dv_buffer, M_DEVBUF);
2803 targ->dv_buffer = NULL;
2804 }
2805 if (targ->dv_buffer1 != NULL) {
2806 free(targ->dv_buffer1, M_DEVBUF);
2807 targ->dv_buffer1 = NULL;
2808 }
2809 targ->flags &= ~AHD_DV_REQUIRED;
2810 if (targ->refcount == 0)
2811 ahd_linux_free_target(ahd, targ);
2812 ahd_unlock(ahd, &s);
2813}
2814
2815static __inline int
2816ahd_linux_dv_fallback(struct ahd_softc *ahd, struct ahd_devinfo *devinfo)
2817{
2818 u_long s;
2819 int retval;
2820
2821 ahd_lock(ahd, &s);
2822 retval = ahd_linux_fallback(ahd, devinfo);
2823 ahd_unlock(ahd, &s);
2824
2825 return (retval);
2826}
2827
2828static void
2829ahd_linux_dv_transition(struct ahd_softc *ahd, struct scsi_cmnd *cmd,
2830 struct ahd_devinfo *devinfo,
2831 struct ahd_linux_target *targ)
2832{
2833 u_int32_t status;
2834
2835 status = aic_error_action(cmd, targ->inq_data,
2836 ahd_cmd_get_transaction_status(cmd),
2837 ahd_cmd_get_scsi_status(cmd));
2838
2839
2840#ifdef AHD_DEBUG
2841 if (ahd_debug & AHD_SHOW_DV) {
2842 ahd_print_devinfo(ahd, devinfo);
2843 printf("Entering ahd_linux_dv_transition, state= %d, "
2844 "status= 0x%x, cmd->result= 0x%x\n", targ->dv_state,
2845 status, cmd->result);
2846 }
2847#endif
2848 1334
2849 switch (targ->dv_state) { 1335 switch ((dev->flags & (AHD_DEV_Q_BASIC|AHD_DEV_Q_TAGGED))) {
2850 case AHD_DV_STATE_INQ_SHORT_ASYNC: 1336 case AHD_DEV_Q_BASIC:
2851 case AHD_DV_STATE_INQ_ASYNC: 1337 scsi_adjust_queue_depth(sdev,
2852 switch (status & SS_MASK) { 1338 MSG_SIMPLE_TASK,
2853 case SS_NOP: 1339 dev->openings + dev->active);
2854 {
2855 AHD_SET_DV_STATE(ahd, targ, targ->dv_state+1);
2856 break;
2857 }
2858 case SS_INQ_REFRESH:
2859 AHD_SET_DV_STATE(ahd, targ,
2860 AHD_DV_STATE_INQ_SHORT_ASYNC);
2861 break;
2862 case SS_TUR:
2863 case SS_RETRY:
2864 AHD_SET_DV_STATE(ahd, targ, targ->dv_state);
2865 if (ahd_cmd_get_transaction_status(cmd)
2866 == CAM_REQUEUE_REQ)
2867 targ->dv_state_retry--;
2868 if ((status & SS_ERRMASK) == EBUSY)
2869 AHD_SET_DV_STATE(ahd, targ, AHD_DV_STATE_BUSY);
2870 if (targ->dv_state_retry < 10)
2871 break;
2872 /* FALLTHROUGH */
2873 default:
2874 AHD_SET_DV_STATE(ahd, targ, AHD_DV_STATE_EXIT);
2875#ifdef AHD_DEBUG
2876 if (ahd_debug & AHD_SHOW_DV) {
2877 ahd_print_devinfo(ahd, devinfo);
2878 printf("Failed DV inquiry, skipping\n");
2879 }
2880#endif
2881 break;
2882 }
2883 break; 1340 break;
2884 case AHD_DV_STATE_INQ_ASYNC_VERIFY: 1341 case AHD_DEV_Q_TAGGED:
2885 switch (status & SS_MASK) { 1342 scsi_adjust_queue_depth(sdev,
2886 case SS_NOP: 1343 MSG_ORDERED_TASK,
2887 { 1344 dev->openings + dev->active);
2888 u_int xportflags;
2889 u_int spi3data;
2890
2891 if (memcmp(targ->inq_data, targ->dv_buffer,
2892 AHD_LINUX_DV_INQ_LEN) != 0) {
2893 /*
2894 * Inquiry data must have changed.
2895 * Try from the top again.
2896 */
2897 AHD_SET_DV_STATE(ahd, targ,
2898 AHD_DV_STATE_INQ_SHORT_ASYNC);
2899 break;
2900 }
2901
2902 AHD_SET_DV_STATE(ahd, targ, targ->dv_state+1);
2903 targ->flags |= AHD_INQ_VALID;
2904 if (ahd_linux_user_dv_setting(ahd) == 0)
2905 break;
2906
2907 xportflags = targ->inq_data->flags;
2908 if ((xportflags & (SID_Sync|SID_WBus16)) == 0)
2909 break;
2910
2911 spi3data = targ->inq_data->spi3data;
2912 switch (spi3data & SID_SPI_CLOCK_DT_ST) {
2913 default:
2914 case SID_SPI_CLOCK_ST:
2915 /* Assume only basic DV is supported. */
2916 targ->flags |= AHD_BASIC_DV;
2917 break;
2918 case SID_SPI_CLOCK_DT:
2919 case SID_SPI_CLOCK_DT_ST:
2920 targ->flags |= AHD_ENHANCED_DV;
2921 break;
2922 }
2923 break;
2924 }
2925 case SS_INQ_REFRESH:
2926 AHD_SET_DV_STATE(ahd, targ,
2927 AHD_DV_STATE_INQ_SHORT_ASYNC);
2928 break;
2929 case SS_TUR:
2930 case SS_RETRY:
2931 AHD_SET_DV_STATE(ahd, targ, targ->dv_state);
2932 if (ahd_cmd_get_transaction_status(cmd)
2933 == CAM_REQUEUE_REQ)
2934 targ->dv_state_retry--;
2935
2936 if ((status & SS_ERRMASK) == EBUSY)
2937 AHD_SET_DV_STATE(ahd, targ, AHD_DV_STATE_BUSY);
2938 if (targ->dv_state_retry < 10)
2939 break;
2940 /* FALLTHROUGH */
2941 default:
2942 AHD_SET_DV_STATE(ahd, targ, AHD_DV_STATE_EXIT);
2943#ifdef AHD_DEBUG
2944 if (ahd_debug & AHD_SHOW_DV) {
2945 ahd_print_devinfo(ahd, devinfo);
2946 printf("Failed DV inquiry, skipping\n");
2947 }
2948#endif
2949 break;
2950 }
2951 break; 1345 break;
2952 case AHD_DV_STATE_INQ_VERIFY:
2953 switch (status & SS_MASK) {
2954 case SS_NOP:
2955 {
2956
2957 if (memcmp(targ->inq_data, targ->dv_buffer,
2958 AHD_LINUX_DV_INQ_LEN) == 0) {
2959 AHD_SET_DV_STATE(ahd, targ, AHD_DV_STATE_EXIT);
2960 break;
2961 }
2962
2963#ifdef AHD_DEBUG
2964 if (ahd_debug & AHD_SHOW_DV) {
2965 int i;
2966
2967 ahd_print_devinfo(ahd, devinfo);
2968 printf("Inquiry buffer mismatch:");
2969 for (i = 0; i < AHD_LINUX_DV_INQ_LEN; i++) {
2970 if ((i & 0xF) == 0)
2971 printf("\n ");
2972 printf("0x%x:0x0%x ",
2973 ((uint8_t *)targ->inq_data)[i],
2974 targ->dv_buffer[i]);
2975 }
2976 printf("\n");
2977 }
2978#endif
2979
2980 if (ahd_linux_dv_fallback(ahd, devinfo) != 0) {
2981 AHD_SET_DV_STATE(ahd, targ, AHD_DV_STATE_EXIT);
2982 break;
2983 }
2984 /*
2985 * Do not count "falling back"
2986 * against our retries.
2987 */
2988 targ->dv_state_retry = 0;
2989 AHD_SET_DV_STATE(ahd, targ, targ->dv_state);
2990 break;
2991 }
2992 case SS_INQ_REFRESH:
2993 AHD_SET_DV_STATE(ahd, targ,
2994 AHD_DV_STATE_INQ_SHORT_ASYNC);
2995 break;
2996 case SS_TUR:
2997 case SS_RETRY:
2998 AHD_SET_DV_STATE(ahd, targ, targ->dv_state);
2999 if (ahd_cmd_get_transaction_status(cmd)
3000 == CAM_REQUEUE_REQ) {
3001 targ->dv_state_retry--;
3002 } else if ((status & SSQ_FALLBACK) != 0) {
3003 if (ahd_linux_dv_fallback(ahd, devinfo) != 0) {
3004 AHD_SET_DV_STATE(ahd, targ,
3005 AHD_DV_STATE_EXIT);
3006 break;
3007 }
3008 /*
3009 * Do not count "falling back"
3010 * against our retries.
3011 */
3012 targ->dv_state_retry = 0;
3013 } else if ((status & SS_ERRMASK) == EBUSY)
3014 AHD_SET_DV_STATE(ahd, targ, AHD_DV_STATE_BUSY);
3015 if (targ->dv_state_retry < 10)
3016 break;
3017 /* FALLTHROUGH */
3018 default:
3019 AHD_SET_DV_STATE(ahd, targ, AHD_DV_STATE_EXIT);
3020#ifdef AHD_DEBUG
3021 if (ahd_debug & AHD_SHOW_DV) {
3022 ahd_print_devinfo(ahd, devinfo);
3023 printf("Failed DV inquiry, skipping\n");
3024 }
3025#endif
3026 break;
3027 }
3028 break;
3029
3030 case AHD_DV_STATE_TUR:
3031 switch (status & SS_MASK) {
3032 case SS_NOP:
3033 if ((targ->flags & AHD_BASIC_DV) != 0) {
3034 ahd_linux_filter_inquiry(ahd, devinfo);
3035 AHD_SET_DV_STATE(ahd, targ,
3036 AHD_DV_STATE_INQ_VERIFY);
3037 } else if ((targ->flags & AHD_ENHANCED_DV) != 0) {
3038 AHD_SET_DV_STATE(ahd, targ, AHD_DV_STATE_REBD);
3039 } else {
3040 AHD_SET_DV_STATE(ahd, targ, AHD_DV_STATE_EXIT);
3041 }
3042 break;
3043 case SS_RETRY:
3044 case SS_TUR:
3045 if ((status & SS_ERRMASK) == EBUSY) {
3046 AHD_SET_DV_STATE(ahd, targ, AHD_DV_STATE_BUSY);
3047 break;
3048 }
3049 AHD_SET_DV_STATE(ahd, targ, targ->dv_state);
3050 if (ahd_cmd_get_transaction_status(cmd)
3051 == CAM_REQUEUE_REQ) {
3052 targ->dv_state_retry--;
3053 } else if ((status & SSQ_FALLBACK) != 0) {
3054 if (ahd_linux_dv_fallback(ahd, devinfo) != 0) {
3055 AHD_SET_DV_STATE(ahd, targ,
3056 AHD_DV_STATE_EXIT);
3057 break;
3058 }
3059 /*
3060 * Do not count "falling back"
3061 * against our retries.
3062 */
3063 targ->dv_state_retry = 0;
3064 }
3065 if (targ->dv_state_retry >= 10) {
3066#ifdef AHD_DEBUG
3067 if (ahd_debug & AHD_SHOW_DV) {
3068 ahd_print_devinfo(ahd, devinfo);
3069 printf("DV TUR reties exhausted\n");
3070 }
3071#endif
3072 AHD_SET_DV_STATE(ahd, targ, AHD_DV_STATE_EXIT);
3073 break;
3074 }
3075 if (status & SSQ_DELAY)
3076 ssleep(1);
3077
3078 break;
3079 case SS_START:
3080 AHD_SET_DV_STATE(ahd, targ, AHD_DV_STATE_SU);
3081 break;
3082 case SS_INQ_REFRESH:
3083 AHD_SET_DV_STATE(ahd, targ,
3084 AHD_DV_STATE_INQ_SHORT_ASYNC);
3085 break;
3086 default:
3087 AHD_SET_DV_STATE(ahd, targ, AHD_DV_STATE_EXIT);
3088 break;
3089 }
3090 break;
3091
3092 case AHD_DV_STATE_REBD:
3093 switch (status & SS_MASK) {
3094 case SS_NOP:
3095 {
3096 uint32_t echo_size;
3097
3098 AHD_SET_DV_STATE(ahd, targ, AHD_DV_STATE_WEB);
3099 echo_size = scsi_3btoul(&targ->dv_buffer[1]);
3100 echo_size &= 0x1FFF;
3101#ifdef AHD_DEBUG
3102 if (ahd_debug & AHD_SHOW_DV) {
3103 ahd_print_devinfo(ahd, devinfo);
3104 printf("Echo buffer size= %d\n", echo_size);
3105 }
3106#endif
3107 if (echo_size == 0) {
3108 AHD_SET_DV_STATE(ahd, targ, AHD_DV_STATE_EXIT);
3109 break;
3110 }
3111
3112 /* Generate the buffer pattern */
3113 targ->dv_echo_size = echo_size;
3114 ahd_linux_generate_dv_pattern(targ);
3115 /*
3116 * Setup initial negotiation values.
3117 */
3118 ahd_linux_filter_inquiry(ahd, devinfo);
3119 break;
3120 }
3121 case SS_INQ_REFRESH:
3122 AHD_SET_DV_STATE(ahd, targ,
3123 AHD_DV_STATE_INQ_SHORT_ASYNC);
3124 break;
3125 case SS_RETRY:
3126 AHD_SET_DV_STATE(ahd, targ, targ->dv_state);
3127 if (ahd_cmd_get_transaction_status(cmd)
3128 == CAM_REQUEUE_REQ)
3129 targ->dv_state_retry--;
3130 if (targ->dv_state_retry <= 10)
3131 break;
3132#ifdef AHD_DEBUG
3133 if (ahd_debug & AHD_SHOW_DV) {
3134 ahd_print_devinfo(ahd, devinfo);
3135 printf("DV REBD reties exhausted\n");
3136 }
3137#endif
3138 /* FALLTHROUGH */
3139 case SS_FATAL:
3140 default:
3141 /*
3142 * Setup initial negotiation values
3143 * and try level 1 DV.
3144 */
3145 ahd_linux_filter_inquiry(ahd, devinfo);
3146 AHD_SET_DV_STATE(ahd, targ, AHD_DV_STATE_INQ_VERIFY);
3147 targ->dv_echo_size = 0;
3148 break;
3149 }
3150 break;
3151
3152 case AHD_DV_STATE_WEB:
3153 switch (status & SS_MASK) {
3154 case SS_NOP:
3155 AHD_SET_DV_STATE(ahd, targ, AHD_DV_STATE_REB);
3156 break;
3157 case SS_INQ_REFRESH:
3158 AHD_SET_DV_STATE(ahd, targ,
3159 AHD_DV_STATE_INQ_SHORT_ASYNC);
3160 break;
3161 case SS_RETRY:
3162 AHD_SET_DV_STATE(ahd, targ, targ->dv_state);
3163 if (ahd_cmd_get_transaction_status(cmd)
3164 == CAM_REQUEUE_REQ) {
3165 targ->dv_state_retry--;
3166 } else if ((status & SSQ_FALLBACK) != 0) {
3167 if (ahd_linux_dv_fallback(ahd, devinfo) != 0) {
3168 AHD_SET_DV_STATE(ahd, targ,
3169 AHD_DV_STATE_EXIT);
3170 break;
3171 }
3172 /*
3173 * Do not count "falling back"
3174 * against our retries.
3175 */
3176 targ->dv_state_retry = 0;
3177 }
3178 if (targ->dv_state_retry <= 10)
3179 break;
3180 /* FALLTHROUGH */
3181#ifdef AHD_DEBUG
3182 if (ahd_debug & AHD_SHOW_DV) {
3183 ahd_print_devinfo(ahd, devinfo);
3184 printf("DV WEB reties exhausted\n");
3185 }
3186#endif
3187 default:
3188 AHD_SET_DV_STATE(ahd, targ, AHD_DV_STATE_EXIT);
3189 break;
3190 }
3191 break;
3192
3193 case AHD_DV_STATE_REB:
3194 switch (status & SS_MASK) {
3195 case SS_NOP:
3196 if (memcmp(targ->dv_buffer, targ->dv_buffer1,
3197 targ->dv_echo_size) != 0) {
3198 if (ahd_linux_dv_fallback(ahd, devinfo) != 0)
3199 AHD_SET_DV_STATE(ahd, targ,
3200 AHD_DV_STATE_EXIT);
3201 else
3202 AHD_SET_DV_STATE(ahd, targ,
3203 AHD_DV_STATE_WEB);
3204 break;
3205 }
3206
3207 if (targ->dv_buffer != NULL) {
3208 free(targ->dv_buffer, M_DEVBUF);
3209 targ->dv_buffer = NULL;
3210 }
3211 if (targ->dv_buffer1 != NULL) {
3212 free(targ->dv_buffer1, M_DEVBUF);
3213 targ->dv_buffer1 = NULL;
3214 }
3215 AHD_SET_DV_STATE(ahd, targ, AHD_DV_STATE_EXIT);
3216 break;
3217 case SS_INQ_REFRESH:
3218 AHD_SET_DV_STATE(ahd, targ,
3219 AHD_DV_STATE_INQ_SHORT_ASYNC);
3220 break;
3221 case SS_RETRY:
3222 AHD_SET_DV_STATE(ahd, targ, targ->dv_state);
3223 if (ahd_cmd_get_transaction_status(cmd)
3224 == CAM_REQUEUE_REQ) {
3225 targ->dv_state_retry--;
3226 } else if ((status & SSQ_FALLBACK) != 0) {
3227 if (ahd_linux_dv_fallback(ahd, devinfo) != 0) {
3228 AHD_SET_DV_STATE(ahd, targ,
3229 AHD_DV_STATE_EXIT);
3230 break;
3231 }
3232 AHD_SET_DV_STATE(ahd, targ, AHD_DV_STATE_WEB);
3233 }
3234 if (targ->dv_state_retry <= 10) {
3235 if ((status & (SSQ_DELAY_RANDOM|SSQ_DELAY))!= 0)
3236 msleep(ahd->our_id*1000/10);
3237 break;
3238 }
3239#ifdef AHD_DEBUG
3240 if (ahd_debug & AHD_SHOW_DV) {
3241 ahd_print_devinfo(ahd, devinfo);
3242 printf("DV REB reties exhausted\n");
3243 }
3244#endif
3245 /* FALLTHROUGH */
3246 default:
3247 AHD_SET_DV_STATE(ahd, targ, AHD_DV_STATE_EXIT);
3248 break;
3249 }
3250 break;
3251
3252 case AHD_DV_STATE_SU:
3253 switch (status & SS_MASK) {
3254 case SS_NOP:
3255 case SS_INQ_REFRESH:
3256 AHD_SET_DV_STATE(ahd, targ,
3257 AHD_DV_STATE_INQ_SHORT_ASYNC);
3258 break;
3259 default:
3260 AHD_SET_DV_STATE(ahd, targ, AHD_DV_STATE_EXIT);
3261 break;
3262 }
3263 break;
3264
3265 case AHD_DV_STATE_BUSY:
3266 switch (status & SS_MASK) {
3267 case SS_NOP:
3268 case SS_INQ_REFRESH:
3269 AHD_SET_DV_STATE(ahd, targ,
3270 AHD_DV_STATE_INQ_SHORT_ASYNC);
3271 break;
3272 case SS_TUR:
3273 case SS_RETRY:
3274 AHD_SET_DV_STATE(ahd, targ, targ->dv_state);
3275 if (ahd_cmd_get_transaction_status(cmd)
3276 == CAM_REQUEUE_REQ) {
3277 targ->dv_state_retry--;
3278 } else if (targ->dv_state_retry < 60) {
3279 if ((status & SSQ_DELAY) != 0)
3280 ssleep(1);
3281 } else {
3282#ifdef AHD_DEBUG
3283 if (ahd_debug & AHD_SHOW_DV) {
3284 ahd_print_devinfo(ahd, devinfo);
3285 printf("DV BUSY reties exhausted\n");
3286 }
3287#endif
3288 AHD_SET_DV_STATE(ahd, targ, AHD_DV_STATE_EXIT);
3289 }
3290 break;
3291 default:
3292 AHD_SET_DV_STATE(ahd, targ, AHD_DV_STATE_EXIT);
3293 break;
3294 }
3295 break;
3296
3297 default: 1346 default:
3298 printf("%s: Invalid DV completion state %d\n", ahd_name(ahd),
3299 targ->dv_state);
3300 AHD_SET_DV_STATE(ahd, targ, AHD_DV_STATE_EXIT);
3301 break;
3302 }
3303}
3304
3305static void
3306ahd_linux_dv_fill_cmd(struct ahd_softc *ahd, struct scsi_cmnd *cmd,
3307 struct ahd_devinfo *devinfo)
3308{
3309 memset(cmd, 0, sizeof(struct scsi_cmnd));
3310 cmd->device = ahd->platform_data->dv_scsi_dev;
3311 cmd->scsi_done = ahd_linux_dv_complete;
3312}
3313
3314/*
3315 * Synthesize an inquiry command. On the return trip, it'll be
3316 * sniffed and the device transfer settings set for us.
3317 */
3318static void
3319ahd_linux_dv_inq(struct ahd_softc *ahd, struct scsi_cmnd *cmd,
3320 struct ahd_devinfo *devinfo, struct ahd_linux_target *targ,
3321 u_int request_length)
3322{
3323
3324#ifdef AHD_DEBUG
3325 if (ahd_debug & AHD_SHOW_DV) {
3326 ahd_print_devinfo(ahd, devinfo);
3327 printf("Sending INQ\n");
3328 }
3329#endif
3330 if (targ->inq_data == NULL)
3331 targ->inq_data = malloc(AHD_LINUX_DV_INQ_LEN,
3332 M_DEVBUF, M_WAITOK);
3333 if (targ->dv_state > AHD_DV_STATE_INQ_ASYNC) {
3334 if (targ->dv_buffer != NULL)
3335 free(targ->dv_buffer, M_DEVBUF);
3336 targ->dv_buffer = malloc(AHD_LINUX_DV_INQ_LEN,
3337 M_DEVBUF, M_WAITOK);
3338 }
3339
3340 ahd_linux_dv_fill_cmd(ahd, cmd, devinfo);
3341 cmd->sc_data_direction = DMA_FROM_DEVICE;
3342 cmd->cmd_len = 6;
3343 cmd->cmnd[0] = INQUIRY;
3344 cmd->cmnd[4] = request_length;
3345 cmd->request_bufflen = request_length;
3346 if (targ->dv_state > AHD_DV_STATE_INQ_ASYNC)
3347 cmd->request_buffer = targ->dv_buffer;
3348 else
3349 cmd->request_buffer = targ->inq_data;
3350 memset(cmd->request_buffer, 0, AHD_LINUX_DV_INQ_LEN);
3351}
3352
3353static void
3354ahd_linux_dv_tur(struct ahd_softc *ahd, struct scsi_cmnd *cmd,
3355 struct ahd_devinfo *devinfo)
3356{
3357
3358#ifdef AHD_DEBUG
3359 if (ahd_debug & AHD_SHOW_DV) {
3360 ahd_print_devinfo(ahd, devinfo);
3361 printf("Sending TUR\n");
3362 }
3363#endif
3364 /* Do a TUR to clear out any non-fatal transitional state */
3365 ahd_linux_dv_fill_cmd(ahd, cmd, devinfo);
3366 cmd->sc_data_direction = DMA_NONE;
3367 cmd->cmd_len = 6;
3368 cmd->cmnd[0] = TEST_UNIT_READY;
3369}
3370
3371#define AHD_REBD_LEN 4
3372
3373static void
3374ahd_linux_dv_rebd(struct ahd_softc *ahd, struct scsi_cmnd *cmd,
3375 struct ahd_devinfo *devinfo, struct ahd_linux_target *targ)
3376{
3377
3378#ifdef AHD_DEBUG
3379 if (ahd_debug & AHD_SHOW_DV) {
3380 ahd_print_devinfo(ahd, devinfo);
3381 printf("Sending REBD\n");
3382 }
3383#endif
3384 if (targ->dv_buffer != NULL)
3385 free(targ->dv_buffer, M_DEVBUF);
3386 targ->dv_buffer = malloc(AHD_REBD_LEN, M_DEVBUF, M_WAITOK);
3387 ahd_linux_dv_fill_cmd(ahd, cmd, devinfo);
3388 cmd->sc_data_direction = DMA_FROM_DEVICE;
3389 cmd->cmd_len = 10;
3390 cmd->cmnd[0] = READ_BUFFER;
3391 cmd->cmnd[1] = 0x0b;
3392 scsi_ulto3b(AHD_REBD_LEN, &cmd->cmnd[6]);
3393 cmd->request_bufflen = AHD_REBD_LEN;
3394 cmd->underflow = cmd->request_bufflen;
3395 cmd->request_buffer = targ->dv_buffer;
3396}
3397
3398static void
3399ahd_linux_dv_web(struct ahd_softc *ahd, struct scsi_cmnd *cmd,
3400 struct ahd_devinfo *devinfo, struct ahd_linux_target *targ)
3401{
3402
3403#ifdef AHD_DEBUG
3404 if (ahd_debug & AHD_SHOW_DV) {
3405 ahd_print_devinfo(ahd, devinfo);
3406 printf("Sending WEB\n");
3407 }
3408#endif
3409 ahd_linux_dv_fill_cmd(ahd, cmd, devinfo);
3410 cmd->sc_data_direction = DMA_TO_DEVICE;
3411 cmd->cmd_len = 10;
3412 cmd->cmnd[0] = WRITE_BUFFER;
3413 cmd->cmnd[1] = 0x0a;
3414 scsi_ulto3b(targ->dv_echo_size, &cmd->cmnd[6]);
3415 cmd->request_bufflen = targ->dv_echo_size;
3416 cmd->underflow = cmd->request_bufflen;
3417 cmd->request_buffer = targ->dv_buffer;
3418}
3419
3420static void
3421ahd_linux_dv_reb(struct ahd_softc *ahd, struct scsi_cmnd *cmd,
3422 struct ahd_devinfo *devinfo, struct ahd_linux_target *targ)
3423{
3424
3425#ifdef AHD_DEBUG
3426 if (ahd_debug & AHD_SHOW_DV) {
3427 ahd_print_devinfo(ahd, devinfo);
3428 printf("Sending REB\n");
3429 }
3430#endif
3431 ahd_linux_dv_fill_cmd(ahd, cmd, devinfo);
3432 cmd->sc_data_direction = DMA_FROM_DEVICE;
3433 cmd->cmd_len = 10;
3434 cmd->cmnd[0] = READ_BUFFER;
3435 cmd->cmnd[1] = 0x0a;
3436 scsi_ulto3b(targ->dv_echo_size, &cmd->cmnd[6]);
3437 cmd->request_bufflen = targ->dv_echo_size;
3438 cmd->underflow = cmd->request_bufflen;
3439 cmd->request_buffer = targ->dv_buffer1;
3440}
3441
3442static void
3443ahd_linux_dv_su(struct ahd_softc *ahd, struct scsi_cmnd *cmd,
3444 struct ahd_devinfo *devinfo,
3445 struct ahd_linux_target *targ)
3446{
3447 u_int le;
3448
3449 le = SID_IS_REMOVABLE(targ->inq_data) ? SSS_LOEJ : 0;
3450
3451#ifdef AHD_DEBUG
3452 if (ahd_debug & AHD_SHOW_DV) {
3453 ahd_print_devinfo(ahd, devinfo);
3454 printf("Sending SU\n");
3455 }
3456#endif
3457 ahd_linux_dv_fill_cmd(ahd, cmd, devinfo);
3458 cmd->sc_data_direction = DMA_NONE;
3459 cmd->cmd_len = 6;
3460 cmd->cmnd[0] = START_STOP_UNIT;
3461 cmd->cmnd[4] = le | SSS_START;
3462}
3463
3464static int
3465ahd_linux_fallback(struct ahd_softc *ahd, struct ahd_devinfo *devinfo)
3466{
3467 struct ahd_linux_target *targ;
3468 struct ahd_initiator_tinfo *tinfo;
3469 struct ahd_transinfo *goal;
3470 struct ahd_tmode_tstate *tstate;
3471 u_int width;
3472 u_int period;
3473 u_int offset;
3474 u_int ppr_options;
3475 u_int cur_speed;
3476 u_int wide_speed;
3477 u_int narrow_speed;
3478 u_int fallback_speed;
3479
3480#ifdef AHD_DEBUG
3481 if (ahd_debug & AHD_SHOW_DV) {
3482 ahd_print_devinfo(ahd, devinfo);
3483 printf("Trying to fallback\n");
3484 }
3485#endif
3486 targ = ahd->platform_data->targets[devinfo->target_offset];
3487 tinfo = ahd_fetch_transinfo(ahd, devinfo->channel,
3488 devinfo->our_scsiid,
3489 devinfo->target, &tstate);
3490 goal = &tinfo->goal;
3491 width = goal->width;
3492 period = goal->period;
3493 offset = goal->offset;
3494 ppr_options = goal->ppr_options;
3495 if (offset == 0)
3496 period = AHD_ASYNC_XFER_PERIOD;
3497 if (targ->dv_next_narrow_period == 0)
3498 targ->dv_next_narrow_period = MAX(period, AHD_SYNCRATE_ULTRA2);
3499 if (targ->dv_next_wide_period == 0)
3500 targ->dv_next_wide_period = period;
3501 if (targ->dv_max_width == 0)
3502 targ->dv_max_width = width;
3503 if (targ->dv_max_ppr_options == 0)
3504 targ->dv_max_ppr_options = ppr_options;
3505 if (targ->dv_last_ppr_options == 0)
3506 targ->dv_last_ppr_options = ppr_options;
3507
3508 cur_speed = aic_calc_speed(width, period, offset, AHD_SYNCRATE_MIN);
3509 wide_speed = aic_calc_speed(MSG_EXT_WDTR_BUS_16_BIT,
3510 targ->dv_next_wide_period,
3511 MAX_OFFSET, AHD_SYNCRATE_MIN);
3512 narrow_speed = aic_calc_speed(MSG_EXT_WDTR_BUS_8_BIT,
3513 targ->dv_next_narrow_period,
3514 MAX_OFFSET, AHD_SYNCRATE_MIN);
3515 fallback_speed = aic_calc_speed(width, period+1, offset,
3516 AHD_SYNCRATE_MIN);
3517#ifdef AHD_DEBUG
3518 if (ahd_debug & AHD_SHOW_DV) {
3519 printf("cur_speed= %d, wide_speed= %d, narrow_speed= %d, "
3520 "fallback_speed= %d\n", cur_speed, wide_speed,
3521 narrow_speed, fallback_speed);
3522 }
3523#endif
3524
3525 if (cur_speed > 160000) {
3526 /*
3527 * Paced/DT/IU_REQ only transfer speeds. All we
3528 * can do is fallback in terms of syncrate.
3529 */
3530 period++;
3531 } else if (cur_speed > 80000) {
3532 if ((ppr_options & MSG_EXT_PPR_IU_REQ) != 0) {
3533 /*
3534 * Try without IU_REQ as it may be confusing
3535 * an expander.
3536 */
3537 ppr_options &= ~MSG_EXT_PPR_IU_REQ;
3538 } else {
3539 /*
3540 * Paced/DT only transfer speeds. All we
3541 * can do is fallback in terms of syncrate.
3542 */
3543 period++;
3544 ppr_options = targ->dv_max_ppr_options;
3545 }
3546 } else if (cur_speed > 3300) {
3547
3548 /* 1347 /*
3549 * In this range we the following 1348 * We allow the OS to queue 2 untagged transactions to
3550 * options ordered from highest to 1349 * us at any time even though we can only execute them
3551 * lowest desireability: 1350 * serially on the controller/device. This should
3552 * 1351 * remove some latency.
3553 * o Wide/DT
3554 * o Wide/non-DT
3555 * o Narrow at a potentally higher sync rate.
3556 *
3557 * All modes are tested with and without IU_REQ
3558 * set since using IUs may confuse an expander.
3559 */ 1352 */
3560 if ((ppr_options & MSG_EXT_PPR_IU_REQ) != 0) { 1353 scsi_adjust_queue_depth(sdev,
3561 1354 /*NON-TAGGED*/0,
3562 ppr_options &= ~MSG_EXT_PPR_IU_REQ; 1355 /*queue depth*/2);
3563 } else if ((ppr_options & MSG_EXT_PPR_DT_REQ) != 0) { 1356 break;
3564 /*
3565 * Try going non-DT.
3566 */
3567 ppr_options = targ->dv_max_ppr_options;
3568 ppr_options &= ~MSG_EXT_PPR_DT_REQ;
3569 } else if (targ->dv_last_ppr_options != 0) {
3570 /*
3571 * Try without QAS or any other PPR options.
3572 * We may need a non-PPR message to work with
3573 * an expander. We look at the "last PPR options"
3574 * so we will perform this fallback even if the
3575 * target responded to our PPR negotiation with
3576 * no option bits set.
3577 */
3578 ppr_options = 0;
3579 } else if (width == MSG_EXT_WDTR_BUS_16_BIT) {
3580 /*
3581 * If the next narrow speed is greater than
3582 * the next wide speed, fallback to narrow.
3583 * Otherwise fallback to the next DT/Wide setting.
3584 * The narrow async speed will always be smaller
3585 * than the wide async speed, so handle this case
3586 * specifically.
3587 */
3588 ppr_options = targ->dv_max_ppr_options;
3589 if (narrow_speed > fallback_speed
3590 || period >= AHD_ASYNC_XFER_PERIOD) {
3591 targ->dv_next_wide_period = period+1;
3592 width = MSG_EXT_WDTR_BUS_8_BIT;
3593 period = targ->dv_next_narrow_period;
3594 } else {
3595 period++;
3596 }
3597 } else if ((ahd->features & AHD_WIDE) != 0
3598 && targ->dv_max_width != 0
3599 && wide_speed >= fallback_speed
3600 && (targ->dv_next_wide_period <= AHD_ASYNC_XFER_PERIOD
3601 || period >= AHD_ASYNC_XFER_PERIOD)) {
3602
3603 /*
3604 * We are narrow. Try falling back
3605 * to the next wide speed with
3606 * all supported ppr options set.
3607 */
3608 targ->dv_next_narrow_period = period+1;
3609 width = MSG_EXT_WDTR_BUS_16_BIT;
3610 period = targ->dv_next_wide_period;
3611 ppr_options = targ->dv_max_ppr_options;
3612 } else {
3613 /* Only narrow fallback is allowed. */
3614 period++;
3615 ppr_options = targ->dv_max_ppr_options;
3616 }
3617 } else {
3618 return (-1);
3619 }
3620 offset = MAX_OFFSET;
3621 ahd_find_syncrate(ahd, &period, &ppr_options, AHD_SYNCRATE_PACED);
3622 ahd_set_width(ahd, devinfo, width, AHD_TRANS_GOAL, FALSE);
3623 if (period == 0) {
3624 period = 0;
3625 offset = 0;
3626 ppr_options = 0;
3627 if (width == MSG_EXT_WDTR_BUS_8_BIT)
3628 targ->dv_next_narrow_period = AHD_ASYNC_XFER_PERIOD;
3629 else
3630 targ->dv_next_wide_period = AHD_ASYNC_XFER_PERIOD;
3631 }
3632 ahd_set_syncrate(ahd, devinfo, period, offset,
3633 ppr_options, AHD_TRANS_GOAL, FALSE);
3634 targ->dv_last_ppr_options = ppr_options;
3635 return (0);
3636}
3637
3638static void
3639ahd_linux_dv_timeout(struct scsi_cmnd *cmd)
3640{
3641 struct ahd_softc *ahd;
3642 struct scb *scb;
3643 u_long flags;
3644
3645 ahd = *((struct ahd_softc **)cmd->device->host->hostdata);
3646 ahd_lock(ahd, &flags);
3647
3648#ifdef AHD_DEBUG
3649 if (ahd_debug & AHD_SHOW_DV) {
3650 printf("%s: Timeout while doing DV command %x.\n",
3651 ahd_name(ahd), cmd->cmnd[0]);
3652 ahd_dump_card_state(ahd);
3653 }
3654#endif
3655
3656 /*
3657 * Guard against "done race". No action is
3658 * required if we just completed.
3659 */
3660 if ((scb = (struct scb *)cmd->host_scribble) == NULL) {
3661 ahd_unlock(ahd, &flags);
3662 return;
3663 } 1357 }
3664
3665 /*
3666 * Command has not completed. Mark this
3667 * SCB as having failing status prior to
3668 * resetting the bus, so we get the correct
3669 * error code.
3670 */
3671 if ((scb->flags & SCB_SENSE) != 0)
3672 ahd_set_transaction_status(scb, CAM_AUTOSENSE_FAIL);
3673 else
3674 ahd_set_transaction_status(scb, CAM_CMD_TIMEOUT);
3675 ahd_reset_channel(ahd, cmd->device->channel + 'A', /*initiate*/TRUE);
3676
3677 /*
3678 * Add a minimal bus settle delay for devices that are slow to
3679 * respond after bus resets.
3680 */
3681 ahd_freeze_simq(ahd);
3682 init_timer(&ahd->platform_data->reset_timer);
3683 ahd->platform_data->reset_timer.data = (u_long)ahd;
3684 ahd->platform_data->reset_timer.expires = jiffies + HZ / 2;
3685 ahd->platform_data->reset_timer.function =
3686 (ahd_linux_callback_t *)ahd_release_simq;
3687 add_timer(&ahd->platform_data->reset_timer);
3688 if (ahd_linux_next_device_to_run(ahd) != NULL)
3689 ahd_schedule_runq(ahd);
3690 ahd_linux_run_complete_queue(ahd);
3691 ahd_unlock(ahd, &flags);
3692}
3693
3694static void
3695ahd_linux_dv_complete(struct scsi_cmnd *cmd)
3696{
3697 struct ahd_softc *ahd;
3698
3699 ahd = *((struct ahd_softc **)cmd->device->host->hostdata);
3700
3701 /* Delete the DV timer before it goes off! */
3702 scsi_delete_timer(cmd);
3703
3704#ifdef AHD_DEBUG
3705 if (ahd_debug & AHD_SHOW_DV)
3706 printf("%s:%c:%d: Command completed, status= 0x%x\n",
3707 ahd_name(ahd), cmd->device->channel, cmd->device->id,
3708 cmd->result);
3709#endif
3710
3711 /* Wake up the state machine */
3712 up(&ahd->platform_data->dv_cmd_sem);
3713} 1358}
3714 1359
3715static void 1360int
3716ahd_linux_generate_dv_pattern(struct ahd_linux_target *targ) 1361ahd_platform_abort_scbs(struct ahd_softc *ahd, int target, char channel,
1362 int lun, u_int tag, role_t role, uint32_t status)
3717{ 1363{
3718 uint16_t b; 1364 return 0;
3719 u_int i;
3720 u_int j;
3721
3722 if (targ->dv_buffer != NULL)
3723 free(targ->dv_buffer, M_DEVBUF);
3724 targ->dv_buffer = malloc(targ->dv_echo_size, M_DEVBUF, M_WAITOK);
3725 if (targ->dv_buffer1 != NULL)
3726 free(targ->dv_buffer1, M_DEVBUF);
3727 targ->dv_buffer1 = malloc(targ->dv_echo_size, M_DEVBUF, M_WAITOK);
3728
3729 i = 0;
3730
3731 b = 0x0001;
3732 for (j = 0 ; i < targ->dv_echo_size; j++) {
3733 if (j < 32) {
3734 /*
3735 * 32bytes of sequential numbers.
3736 */
3737 targ->dv_buffer[i++] = j & 0xff;
3738 } else if (j < 48) {
3739 /*
3740 * 32bytes of repeating 0x0000, 0xffff.
3741 */
3742 targ->dv_buffer[i++] = (j & 0x02) ? 0xff : 0x00;
3743 } else if (j < 64) {
3744 /*
3745 * 32bytes of repeating 0x5555, 0xaaaa.
3746 */
3747 targ->dv_buffer[i++] = (j & 0x02) ? 0xaa : 0x55;
3748 } else {
3749 /*
3750 * Remaining buffer is filled with a repeating
3751 * patter of:
3752 *
3753 * 0xffff
3754 * ~0x0001 << shifted once in each loop.
3755 */
3756 if (j & 0x02) {
3757 if (j & 0x01) {
3758 targ->dv_buffer[i++] = ~(b >> 8) & 0xff;
3759 b <<= 1;
3760 if (b == 0x0000)
3761 b = 0x0001;
3762 } else {
3763 targ->dv_buffer[i++] = (~b & 0xff);
3764 }
3765 } else {
3766 targ->dv_buffer[i++] = 0xff;
3767 }
3768 }
3769 }
3770} 1365}
3771 1366
3772static u_int 1367static u_int
@@ -3800,100 +1395,23 @@ ahd_linux_user_tagdepth(struct ahd_softc *ahd, struct ahd_devinfo *devinfo)
3800 return (tags); 1395 return (tags);
3801} 1396}
3802 1397
3803static u_int
3804ahd_linux_user_dv_setting(struct ahd_softc *ahd)
3805{
3806 static int warned_user;
3807 int dv;
3808
3809 if (ahd->unit >= NUM_ELEMENTS(aic79xx_dv_settings)) {
3810
3811 if (warned_user == 0) {
3812 printf(KERN_WARNING
3813"aic79xx: WARNING: Insufficient dv settings instances\n"
3814"aic79xx: for installed controllers. Using defaults\n"
3815"aic79xx: Please update the aic79xx_dv_settings array in"
3816"aic79xx: the aic79xx_osm.c source file.\n");
3817 warned_user++;
3818 }
3819 dv = -1;
3820 } else {
3821
3822 dv = aic79xx_dv_settings[ahd->unit];
3823 }
3824
3825 if (dv < 0) {
3826 /*
3827 * Apply the default.
3828 */
3829 dv = 1;
3830 if (ahd->seep_config != 0)
3831 dv = (ahd->seep_config->bios_control & CFENABLEDV);
3832 }
3833 return (dv);
3834}
3835
3836static void
3837ahd_linux_setup_user_rd_strm_settings(struct ahd_softc *ahd)
3838{
3839 static int warned_user;
3840 u_int rd_strm_mask;
3841 u_int target_id;
3842
3843 /*
3844 * If we have specific read streaming info for this controller,
3845 * apply it. Otherwise use the defaults.
3846 */
3847 if (ahd->unit >= NUM_ELEMENTS(aic79xx_rd_strm_info)) {
3848
3849 if (warned_user == 0) {
3850
3851 printf(KERN_WARNING
3852"aic79xx: WARNING: Insufficient rd_strm instances\n"
3853"aic79xx: for installed controllers. Using defaults\n"
3854"aic79xx: Please update the aic79xx_rd_strm_info array\n"
3855"aic79xx: in the aic79xx_osm.c source file.\n");
3856 warned_user++;
3857 }
3858 rd_strm_mask = AIC79XX_CONFIGED_RD_STRM;
3859 } else {
3860
3861 rd_strm_mask = aic79xx_rd_strm_info[ahd->unit];
3862 }
3863 for (target_id = 0; target_id < 16; target_id++) {
3864 struct ahd_devinfo devinfo;
3865 struct ahd_initiator_tinfo *tinfo;
3866 struct ahd_tmode_tstate *tstate;
3867
3868 tinfo = ahd_fetch_transinfo(ahd, 'A', ahd->our_id,
3869 target_id, &tstate);
3870 ahd_compile_devinfo(&devinfo, ahd->our_id, target_id,
3871 CAM_LUN_WILDCARD, 'A', ROLE_INITIATOR);
3872 tinfo->user.ppr_options &= ~MSG_EXT_PPR_RD_STRM;
3873 if ((rd_strm_mask & devinfo.target_mask) != 0)
3874 tinfo->user.ppr_options |= MSG_EXT_PPR_RD_STRM;
3875 }
3876}
3877
3878/* 1398/*
3879 * Determines the queue depth for a given device. 1399 * Determines the queue depth for a given device.
3880 */ 1400 */
3881static void 1401static void
3882ahd_linux_device_queue_depth(struct ahd_softc *ahd, 1402ahd_linux_device_queue_depth(struct scsi_device *sdev)
3883 struct ahd_linux_device *dev)
3884{ 1403{
3885 struct ahd_devinfo devinfo; 1404 struct ahd_devinfo devinfo;
3886 u_int tags; 1405 u_int tags;
1406 struct ahd_softc *ahd = *((struct ahd_softc **)sdev->host->hostdata);
3887 1407
3888 ahd_compile_devinfo(&devinfo, 1408 ahd_compile_devinfo(&devinfo,
3889 ahd->our_id, 1409 ahd->our_id,
3890 dev->target->target, dev->lun, 1410 sdev->sdev_target->id, sdev->lun,
3891 dev->target->channel == 0 ? 'A' : 'B', 1411 sdev->sdev_target->channel == 0 ? 'A' : 'B',
3892 ROLE_INITIATOR); 1412 ROLE_INITIATOR);
3893 tags = ahd_linux_user_tagdepth(ahd, &devinfo); 1413 tags = ahd_linux_user_tagdepth(ahd, &devinfo);
3894 if (tags != 0 1414 if (tags != 0 && sdev->tagged_supported != 0) {
3895 && dev->scsi_device != NULL
3896 && dev->scsi_device->tagged_supported != 0) {
3897 1415
3898 ahd_set_tags(ahd, &devinfo, AHD_QUEUE_TAGGED); 1416 ahd_set_tags(ahd, &devinfo, AHD_QUEUE_TAGGED);
3899 ahd_print_devinfo(ahd, &devinfo); 1417 ahd_print_devinfo(ahd, &devinfo);
@@ -3903,11 +1421,10 @@ ahd_linux_device_queue_depth(struct ahd_softc *ahd,
3903 } 1421 }
3904} 1422}
3905 1423
3906static void 1424static int
3907ahd_linux_run_device_queue(struct ahd_softc *ahd, struct ahd_linux_device *dev) 1425ahd_linux_run_command(struct ahd_softc *ahd, struct ahd_linux_device *dev,
1426 struct scsi_cmnd *cmd)
3908{ 1427{
3909 struct ahd_cmd *acmd;
3910 struct scsi_cmnd *cmd;
3911 struct scb *scb; 1428 struct scb *scb;
3912 struct hardware_scb *hscb; 1429 struct hardware_scb *hscb;
3913 struct ahd_initiator_tinfo *tinfo; 1430 struct ahd_initiator_tinfo *tinfo;
@@ -3915,157 +1432,122 @@ ahd_linux_run_device_queue(struct ahd_softc *ahd, struct ahd_linux_device *dev)
3915 u_int col_idx; 1432 u_int col_idx;
3916 uint16_t mask; 1433 uint16_t mask;
3917 1434
3918 if ((dev->flags & AHD_DEV_ON_RUN_LIST) != 0) 1435 /*
3919 panic("running device on run list"); 1436 * Get an scb to use.
3920 1437 */
3921 while ((acmd = TAILQ_FIRST(&dev->busyq)) != NULL 1438 tinfo = ahd_fetch_transinfo(ahd, 'A', ahd->our_id,
3922 && dev->openings > 0 && dev->qfrozen == 0) { 1439 cmd->device->id, &tstate);
3923 1440 if ((dev->flags & (AHD_DEV_Q_TAGGED|AHD_DEV_Q_BASIC)) == 0
3924 /* 1441 || (tinfo->curr.ppr_options & MSG_EXT_PPR_IU_REQ) != 0) {
3925 * Schedule us to run later. The only reason we are not 1442 col_idx = AHD_NEVER_COL_IDX;
3926 * running is because the whole controller Q is frozen. 1443 } else {
3927 */ 1444 col_idx = AHD_BUILD_COL_IDX(cmd->device->id,
3928 if (ahd->platform_data->qfrozen != 0 1445 cmd->device->lun);
3929 && AHD_DV_SIMQ_FROZEN(ahd) == 0) { 1446 }
3930 1447 if ((scb = ahd_get_scb(ahd, col_idx)) == NULL) {
3931 TAILQ_INSERT_TAIL(&ahd->platform_data->device_runq, 1448 ahd->flags |= AHD_RESOURCE_SHORTAGE;
3932 dev, links); 1449 return SCSI_MLQUEUE_HOST_BUSY;
3933 dev->flags |= AHD_DEV_ON_RUN_LIST; 1450 }
3934 return;
3935 }
3936
3937 cmd = &acmd_scsi_cmd(acmd);
3938 1451
3939 /* 1452 scb->io_ctx = cmd;
3940 * Get an scb to use. 1453 scb->platform_data->dev = dev;
3941 */ 1454 hscb = scb->hscb;
3942 tinfo = ahd_fetch_transinfo(ahd, 'A', ahd->our_id, 1455 cmd->host_scribble = (char *)scb;
3943 cmd->device->id, &tstate);
3944 if ((dev->flags & (AHD_DEV_Q_TAGGED|AHD_DEV_Q_BASIC)) == 0
3945 || (tinfo->curr.ppr_options & MSG_EXT_PPR_IU_REQ) != 0) {
3946 col_idx = AHD_NEVER_COL_IDX;
3947 } else {
3948 col_idx = AHD_BUILD_COL_IDX(cmd->device->id,
3949 cmd->device->lun);
3950 }
3951 if ((scb = ahd_get_scb(ahd, col_idx)) == NULL) {
3952 TAILQ_INSERT_TAIL(&ahd->platform_data->device_runq,
3953 dev, links);
3954 dev->flags |= AHD_DEV_ON_RUN_LIST;
3955 ahd->flags |= AHD_RESOURCE_SHORTAGE;
3956 return;
3957 }
3958 TAILQ_REMOVE(&dev->busyq, acmd, acmd_links.tqe);
3959 scb->io_ctx = cmd;
3960 scb->platform_data->dev = dev;
3961 hscb = scb->hscb;
3962 cmd->host_scribble = (char *)scb;
3963 1456
3964 /* 1457 /*
3965 * Fill out basics of the HSCB. 1458 * Fill out basics of the HSCB.
3966 */ 1459 */
3967 hscb->control = 0; 1460 hscb->control = 0;
3968 hscb->scsiid = BUILD_SCSIID(ahd, cmd); 1461 hscb->scsiid = BUILD_SCSIID(ahd, cmd);
3969 hscb->lun = cmd->device->lun; 1462 hscb->lun = cmd->device->lun;
3970 scb->hscb->task_management = 0; 1463 scb->hscb->task_management = 0;
3971 mask = SCB_GET_TARGET_MASK(ahd, scb); 1464 mask = SCB_GET_TARGET_MASK(ahd, scb);
3972 1465
3973 if ((ahd->user_discenable & mask) != 0) 1466 if ((ahd->user_discenable & mask) != 0)
3974 hscb->control |= DISCENB; 1467 hscb->control |= DISCENB;
3975 1468
3976 if (AHD_DV_CMD(cmd) != 0) 1469 if ((tinfo->curr.ppr_options & MSG_EXT_PPR_IU_REQ) != 0)
3977 scb->flags |= SCB_SILENT; 1470 scb->flags |= SCB_PACKETIZED;
3978 1471
3979 if ((tinfo->curr.ppr_options & MSG_EXT_PPR_IU_REQ) != 0) 1472 if ((tstate->auto_negotiate & mask) != 0) {
3980 scb->flags |= SCB_PACKETIZED; 1473 scb->flags |= SCB_AUTO_NEGOTIATE;
1474 scb->hscb->control |= MK_MESSAGE;
1475 }
3981 1476
3982 if ((tstate->auto_negotiate & mask) != 0) { 1477 if ((dev->flags & (AHD_DEV_Q_TAGGED|AHD_DEV_Q_BASIC)) != 0) {
3983 scb->flags |= SCB_AUTO_NEGOTIATE; 1478 int msg_bytes;
3984 scb->hscb->control |= MK_MESSAGE; 1479 uint8_t tag_msgs[2];
3985 }
3986 1480
3987 if ((dev->flags & (AHD_DEV_Q_TAGGED|AHD_DEV_Q_BASIC)) != 0) { 1481 msg_bytes = scsi_populate_tag_msg(cmd, tag_msgs);
3988#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,5,0) 1482 if (msg_bytes && tag_msgs[0] != MSG_SIMPLE_TASK) {
3989 int msg_bytes; 1483 hscb->control |= tag_msgs[0];
3990 uint8_t tag_msgs[2]; 1484 if (tag_msgs[0] == MSG_ORDERED_TASK)
3991
3992 msg_bytes = scsi_populate_tag_msg(cmd, tag_msgs);
3993 if (msg_bytes && tag_msgs[0] != MSG_SIMPLE_TASK) {
3994 hscb->control |= tag_msgs[0];
3995 if (tag_msgs[0] == MSG_ORDERED_TASK)
3996 dev->commands_since_idle_or_otag = 0;
3997 } else
3998#endif
3999 if (dev->commands_since_idle_or_otag == AHD_OTAG_THRESH
4000 && (dev->flags & AHD_DEV_Q_TAGGED) != 0) {
4001 hscb->control |= MSG_ORDERED_TASK;
4002 dev->commands_since_idle_or_otag = 0; 1485 dev->commands_since_idle_or_otag = 0;
4003 } else { 1486 } else
4004 hscb->control |= MSG_SIMPLE_TASK; 1487 if (dev->commands_since_idle_or_otag == AHD_OTAG_THRESH
4005 } 1488 && (dev->flags & AHD_DEV_Q_TAGGED) != 0) {
1489 hscb->control |= MSG_ORDERED_TASK;
1490 dev->commands_since_idle_or_otag = 0;
1491 } else {
1492 hscb->control |= MSG_SIMPLE_TASK;
4006 } 1493 }
1494 }
4007 1495
4008 hscb->cdb_len = cmd->cmd_len; 1496 hscb->cdb_len = cmd->cmd_len;
4009 memcpy(hscb->shared_data.idata.cdb, cmd->cmnd, hscb->cdb_len); 1497 memcpy(hscb->shared_data.idata.cdb, cmd->cmnd, hscb->cdb_len);
4010 1498
4011 scb->sg_count = 0; 1499 scb->platform_data->xfer_len = 0;
4012 ahd_set_residual(scb, 0); 1500 ahd_set_residual(scb, 0);
4013 ahd_set_sense_residual(scb, 0); 1501 ahd_set_sense_residual(scb, 0);
4014 if (cmd->use_sg != 0) { 1502 scb->sg_count = 0;
4015 void *sg; 1503 if (cmd->use_sg != 0) {
4016 struct scatterlist *cur_seg; 1504 void *sg;
4017 u_int nseg; 1505 struct scatterlist *cur_seg;
4018 int dir; 1506 u_int nseg;
4019 1507 int dir;
4020 cur_seg = (struct scatterlist *)cmd->request_buffer; 1508
4021 dir = cmd->sc_data_direction; 1509 cur_seg = (struct scatterlist *)cmd->request_buffer;
4022 nseg = pci_map_sg(ahd->dev_softc, cur_seg, 1510 dir = cmd->sc_data_direction;
4023 cmd->use_sg, dir); 1511 nseg = pci_map_sg(ahd->dev_softc, cur_seg,
4024 scb->platform_data->xfer_len = 0; 1512 cmd->use_sg, dir);
4025 for (sg = scb->sg_list; nseg > 0; nseg--, cur_seg++) { 1513 scb->platform_data->xfer_len = 0;
4026 dma_addr_t addr; 1514 for (sg = scb->sg_list; nseg > 0; nseg--, cur_seg++) {
4027 bus_size_t len;
4028
4029 addr = sg_dma_address(cur_seg);
4030 len = sg_dma_len(cur_seg);
4031 scb->platform_data->xfer_len += len;
4032 sg = ahd_sg_setup(ahd, scb, sg, addr, len,
4033 /*last*/nseg == 1);
4034 }
4035 } else if (cmd->request_bufflen != 0) {
4036 void *sg;
4037 dma_addr_t addr; 1515 dma_addr_t addr;
4038 int dir; 1516 bus_size_t len;
4039
4040 sg = scb->sg_list;
4041 dir = cmd->sc_data_direction;
4042 addr = pci_map_single(ahd->dev_softc,
4043 cmd->request_buffer,
4044 cmd->request_bufflen, dir);
4045 scb->platform_data->xfer_len = cmd->request_bufflen;
4046 scb->platform_data->buf_busaddr = addr;
4047 sg = ahd_sg_setup(ahd, scb, sg, addr,
4048 cmd->request_bufflen, /*last*/TRUE);
4049 }
4050 1517
4051 LIST_INSERT_HEAD(&ahd->pending_scbs, scb, pending_links); 1518 addr = sg_dma_address(cur_seg);
4052 dev->openings--; 1519 len = sg_dma_len(cur_seg);
4053 dev->active++; 1520 scb->platform_data->xfer_len += len;
4054 dev->commands_issued++; 1521 sg = ahd_sg_setup(ahd, scb, sg, addr, len,
4055 1522 /*last*/nseg == 1);
4056 /* Update the error counting bucket and dump if needed */
4057 if (dev->target->cmds_since_error) {
4058 dev->target->cmds_since_error++;
4059 if (dev->target->cmds_since_error >
4060 AHD_LINUX_ERR_THRESH)
4061 dev->target->cmds_since_error = 0;
4062 } 1523 }
1524 } else if (cmd->request_bufflen != 0) {
1525 void *sg;
1526 dma_addr_t addr;
1527 int dir;
4063 1528
4064 if ((dev->flags & AHD_DEV_PERIODIC_OTAG) != 0) 1529 sg = scb->sg_list;
4065 dev->commands_since_idle_or_otag++; 1530 dir = cmd->sc_data_direction;
4066 scb->flags |= SCB_ACTIVE; 1531 addr = pci_map_single(ahd->dev_softc,
4067 ahd_queue_scb(ahd, scb); 1532 cmd->request_buffer,
1533 cmd->request_bufflen, dir);
1534 scb->platform_data->xfer_len = cmd->request_bufflen;
1535 scb->platform_data->buf_busaddr = addr;
1536 sg = ahd_sg_setup(ahd, scb, sg, addr,
1537 cmd->request_bufflen, /*last*/TRUE);
4068 } 1538 }
1539
1540 LIST_INSERT_HEAD(&ahd->pending_scbs, scb, pending_links);
1541 dev->openings--;
1542 dev->active++;
1543 dev->commands_issued++;
1544
1545 if ((dev->flags & AHD_DEV_PERIODIC_OTAG) != 0)
1546 dev->commands_since_idle_or_otag++;
1547 scb->flags |= SCB_ACTIVE;
1548 ahd_queue_scb(ahd, scb);
1549
1550 return 0;
4069} 1551}
4070 1552
4071/* 1553/*
@@ -4081,9 +1563,6 @@ ahd_linux_isr(int irq, void *dev_id, struct pt_regs * regs)
4081 ahd = (struct ahd_softc *) dev_id; 1563 ahd = (struct ahd_softc *) dev_id;
4082 ahd_lock(ahd, &flags); 1564 ahd_lock(ahd, &flags);
4083 ours = ahd_intr(ahd); 1565 ours = ahd_intr(ahd);
4084 if (ahd_linux_next_device_to_run(ahd) != NULL)
4085 ahd_schedule_runq(ahd);
4086 ahd_linux_run_complete_queue(ahd);
4087 ahd_unlock(ahd, &flags); 1566 ahd_unlock(ahd, &flags);
4088 return IRQ_RETVAL(ours); 1567 return IRQ_RETVAL(ours);
4089} 1568}
@@ -4092,111 +1571,6 @@ void
4092ahd_platform_flushwork(struct ahd_softc *ahd) 1571ahd_platform_flushwork(struct ahd_softc *ahd)
4093{ 1572{
4094 1573
4095 while (ahd_linux_run_complete_queue(ahd) != NULL)
4096 ;
4097}
4098
4099static struct ahd_linux_target*
4100ahd_linux_alloc_target(struct ahd_softc *ahd, u_int channel, u_int target)
4101{
4102 struct ahd_linux_target *targ;
4103
4104 targ = malloc(sizeof(*targ), M_DEVBUF, M_NOWAIT);
4105 if (targ == NULL)
4106 return (NULL);
4107 memset(targ, 0, sizeof(*targ));
4108 targ->channel = channel;
4109 targ->target = target;
4110 targ->ahd = ahd;
4111 targ->flags = AHD_DV_REQUIRED;
4112 ahd->platform_data->targets[target] = targ;
4113 return (targ);
4114}
4115
4116static void
4117ahd_linux_free_target(struct ahd_softc *ahd, struct ahd_linux_target *targ)
4118{
4119 struct ahd_devinfo devinfo;
4120 struct ahd_initiator_tinfo *tinfo;
4121 struct ahd_tmode_tstate *tstate;
4122 u_int our_id;
4123 u_int target_offset;
4124 char channel;
4125
4126 /*
4127 * Force a negotiation to async/narrow on any
4128 * future command to this device unless a bus
4129 * reset occurs between now and that command.
4130 */
4131 channel = 'A' + targ->channel;
4132 our_id = ahd->our_id;
4133 target_offset = targ->target;
4134 tinfo = ahd_fetch_transinfo(ahd, channel, our_id,
4135 targ->target, &tstate);
4136 ahd_compile_devinfo(&devinfo, our_id, targ->target, CAM_LUN_WILDCARD,
4137 channel, ROLE_INITIATOR);
4138 ahd_set_syncrate(ahd, &devinfo, 0, 0, 0,
4139 AHD_TRANS_GOAL, /*paused*/FALSE);
4140 ahd_set_width(ahd, &devinfo, MSG_EXT_WDTR_BUS_8_BIT,
4141 AHD_TRANS_GOAL, /*paused*/FALSE);
4142 ahd_update_neg_request(ahd, &devinfo, tstate, tinfo, AHD_NEG_ALWAYS);
4143 ahd->platform_data->targets[target_offset] = NULL;
4144 if (targ->inq_data != NULL)
4145 free(targ->inq_data, M_DEVBUF);
4146 if (targ->dv_buffer != NULL)
4147 free(targ->dv_buffer, M_DEVBUF);
4148 if (targ->dv_buffer1 != NULL)
4149 free(targ->dv_buffer1, M_DEVBUF);
4150 free(targ, M_DEVBUF);
4151}
4152
4153static struct ahd_linux_device*
4154ahd_linux_alloc_device(struct ahd_softc *ahd,
4155 struct ahd_linux_target *targ, u_int lun)
4156{
4157 struct ahd_linux_device *dev;
4158
4159 dev = malloc(sizeof(*dev), M_DEVBUG, M_NOWAIT);
4160 if (dev == NULL)
4161 return (NULL);
4162 memset(dev, 0, sizeof(*dev));
4163 init_timer(&dev->timer);
4164 TAILQ_INIT(&dev->busyq);
4165 dev->flags = AHD_DEV_UNCONFIGURED;
4166 dev->lun = lun;
4167 dev->target = targ;
4168
4169 /*
4170 * We start out life using untagged
4171 * transactions of which we allow one.
4172 */
4173 dev->openings = 1;
4174
4175 /*
4176 * Set maxtags to 0. This will be changed if we
4177 * later determine that we are dealing with
4178 * a tagged queuing capable device.
4179 */
4180 dev->maxtags = 0;
4181
4182 targ->refcount++;
4183 targ->devices[lun] = dev;
4184 return (dev);
4185}
4186
4187static void
4188ahd_linux_free_device(struct ahd_softc *ahd, struct ahd_linux_device *dev)
4189{
4190 struct ahd_linux_target *targ;
4191
4192 del_timer(&dev->timer);
4193 targ = dev->target;
4194 targ->devices[dev->lun] = NULL;
4195 free(dev, M_DEVBUF);
4196 targ->refcount--;
4197 if (targ->refcount == 0
4198 && (targ->flags & AHD_DV_REQUIRED) == 0)
4199 ahd_linux_free_target(ahd, targ);
4200} 1574}
4201 1575
4202void 1576void
@@ -4207,10 +1581,14 @@ ahd_send_async(struct ahd_softc *ahd, char channel,
4207 case AC_TRANSFER_NEG: 1581 case AC_TRANSFER_NEG:
4208 { 1582 {
4209 char buf[80]; 1583 char buf[80];
1584 struct scsi_target *starget;
4210 struct ahd_linux_target *targ; 1585 struct ahd_linux_target *targ;
4211 struct info_str info; 1586 struct info_str info;
4212 struct ahd_initiator_tinfo *tinfo; 1587 struct ahd_initiator_tinfo *tinfo;
4213 struct ahd_tmode_tstate *tstate; 1588 struct ahd_tmode_tstate *tstate;
1589 unsigned int target_ppr_options;
1590
1591 BUG_ON(target == CAM_TARGET_WILDCARD);
4214 1592
4215 info.buffer = buf; 1593 info.buffer = buf;
4216 info.length = sizeof(buf); 1594 info.length = sizeof(buf);
@@ -4234,58 +1612,47 @@ ahd_send_async(struct ahd_softc *ahd, char channel,
4234 * Don't bother reporting results that 1612 * Don't bother reporting results that
4235 * are identical to those last reported. 1613 * are identical to those last reported.
4236 */ 1614 */
4237 targ = ahd->platform_data->targets[target]; 1615 starget = ahd->platform_data->starget[target];
4238 if (targ == NULL) 1616 if (starget == NULL)
4239 break; 1617 break;
4240 if (tinfo->curr.period == targ->last_tinfo.period 1618 targ = scsi_transport_target_data(starget);
4241 && tinfo->curr.width == targ->last_tinfo.width 1619
4242 && tinfo->curr.offset == targ->last_tinfo.offset 1620 target_ppr_options =
4243 && tinfo->curr.ppr_options == targ->last_tinfo.ppr_options) 1621 (spi_dt(starget) ? MSG_EXT_PPR_DT_REQ : 0)
1622 + (spi_qas(starget) ? MSG_EXT_PPR_QAS_REQ : 0)
1623 + (spi_iu(starget) ? MSG_EXT_PPR_IU_REQ : 0)
1624 + (spi_rd_strm(starget) ? MSG_EXT_PPR_RD_STRM : 0)
1625 + (spi_pcomp_en(starget) ? MSG_EXT_PPR_PCOMP_EN : 0)
1626 + (spi_rti(starget) ? MSG_EXT_PPR_RTI : 0)
1627 + (spi_wr_flow(starget) ? MSG_EXT_PPR_WR_FLOW : 0)
1628 + (spi_hold_mcs(starget) ? MSG_EXT_PPR_HOLD_MCS : 0);
1629
1630 if (tinfo->curr.period == spi_period(starget)
1631 && tinfo->curr.width == spi_width(starget)
1632 && tinfo->curr.offset == spi_offset(starget)
1633 && tinfo->curr.ppr_options == target_ppr_options)
4244 if (bootverbose == 0) 1634 if (bootverbose == 0)
4245 break; 1635 break;
4246 1636
4247 targ->last_tinfo.period = tinfo->curr.period; 1637 spi_period(starget) = tinfo->curr.period;
4248 targ->last_tinfo.width = tinfo->curr.width; 1638 spi_width(starget) = tinfo->curr.width;
4249 targ->last_tinfo.offset = tinfo->curr.offset; 1639 spi_offset(starget) = tinfo->curr.offset;
4250 targ->last_tinfo.ppr_options = tinfo->curr.ppr_options; 1640 spi_dt(starget) = tinfo->curr.ppr_options & MSG_EXT_PPR_DT_REQ ? 1 : 0;
4251 1641 spi_qas(starget) = tinfo->curr.ppr_options & MSG_EXT_PPR_QAS_REQ ? 1 : 0;
4252 printf("(%s:%c:", ahd_name(ahd), channel); 1642 spi_iu(starget) = tinfo->curr.ppr_options & MSG_EXT_PPR_IU_REQ ? 1 : 0;
4253 if (target == CAM_TARGET_WILDCARD) 1643 spi_rd_strm(starget) = tinfo->curr.ppr_options & MSG_EXT_PPR_RD_STRM ? 1 : 0;
4254 printf("*): "); 1644 spi_pcomp_en(starget) = tinfo->curr.ppr_options & MSG_EXT_PPR_PCOMP_EN ? 1 : 0;
4255 else 1645 spi_rti(starget) = tinfo->curr.ppr_options & MSG_EXT_PPR_RTI ? 1 : 0;
4256 printf("%d): ", target); 1646 spi_wr_flow(starget) = tinfo->curr.ppr_options & MSG_EXT_PPR_WR_FLOW ? 1 : 0;
4257 ahd_format_transinfo(&info, &tinfo->curr); 1647 spi_hold_mcs(starget) = tinfo->curr.ppr_options & MSG_EXT_PPR_HOLD_MCS ? 1 : 0;
4258 if (info.pos < info.length) 1648 spi_display_xfer_agreement(starget);
4259 *info.buffer = '\0';
4260 else
4261 buf[info.length - 1] = '\0';
4262 printf("%s", buf);
4263 break; 1649 break;
4264 } 1650 }
4265 case AC_SENT_BDR: 1651 case AC_SENT_BDR:
4266 { 1652 {
4267#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,5,0)
4268 WARN_ON(lun != CAM_LUN_WILDCARD); 1653 WARN_ON(lun != CAM_LUN_WILDCARD);
4269 scsi_report_device_reset(ahd->platform_data->host, 1654 scsi_report_device_reset(ahd->platform_data->host,
4270 channel - 'A', target); 1655 channel - 'A', target);
4271#else
4272 Scsi_Device *scsi_dev;
4273
4274 /*
4275 * Find the SCSI device associated with this
4276 * request and indicate that a UA is expected.
4277 */
4278 for (scsi_dev = ahd->platform_data->host->host_queue;
4279 scsi_dev != NULL; scsi_dev = scsi_dev->next) {
4280 if (channel - 'A' == scsi_dev->channel
4281 && target == scsi_dev->id
4282 && (lun == CAM_LUN_WILDCARD
4283 || lun == scsi_dev->lun)) {
4284 scsi_dev->was_reset = 1;
4285 scsi_dev->expecting_cc_ua = 1;
4286 }
4287 }
4288#endif
4289 break; 1656 break;
4290 } 1657 }
4291 case AC_BUS_RESET: 1658 case AC_BUS_RESET:
@@ -4305,7 +1672,7 @@ ahd_send_async(struct ahd_softc *ahd, char channel,
4305void 1672void
4306ahd_done(struct ahd_softc *ahd, struct scb *scb) 1673ahd_done(struct ahd_softc *ahd, struct scb *scb)
4307{ 1674{
4308 Scsi_Cmnd *cmd; 1675 struct scsi_cmnd *cmd;
4309 struct ahd_linux_device *dev; 1676 struct ahd_linux_device *dev;
4310 1677
4311 if ((scb->flags & SCB_ACTIVE) == 0) { 1678 if ((scb->flags & SCB_ACTIVE) == 0) {
@@ -4373,19 +1740,8 @@ ahd_done(struct ahd_softc *ahd, struct scb *scb)
4373 ahd_set_transaction_status(scb, CAM_REQ_CMP); 1740 ahd_set_transaction_status(scb, CAM_REQ_CMP);
4374 } 1741 }
4375 } else if (ahd_get_transaction_status(scb) == CAM_SCSI_STATUS_ERROR) { 1742 } else if (ahd_get_transaction_status(scb) == CAM_SCSI_STATUS_ERROR) {
4376 ahd_linux_handle_scsi_status(ahd, dev, scb); 1743 ahd_linux_handle_scsi_status(ahd, cmd->device, scb);
4377 } else if (ahd_get_transaction_status(scb) == CAM_SEL_TIMEOUT) {
4378 dev->flags |= AHD_DEV_UNCONFIGURED;
4379 if (AHD_DV_CMD(cmd) == FALSE)
4380 dev->target->flags &= ~AHD_DV_REQUIRED;
4381 } 1744 }
4382 /*
4383 * Start DV for devices that require it assuming the first command
4384 * sent does not result in a selection timeout.
4385 */
4386 if (ahd_get_transaction_status(scb) != CAM_SEL_TIMEOUT
4387 && (dev->target->flags & AHD_DV_REQUIRED) != 0)
4388 ahd_linux_start_dv(ahd);
4389 1745
4390 if (dev->openings == 1 1746 if (dev->openings == 1
4391 && ahd_get_transaction_status(scb) == CAM_REQ_CMP 1747 && ahd_get_transaction_status(scb) == CAM_REQ_CMP
@@ -4406,47 +1762,32 @@ ahd_done(struct ahd_softc *ahd, struct scb *scb)
4406 if (dev->active == 0) 1762 if (dev->active == 0)
4407 dev->commands_since_idle_or_otag = 0; 1763 dev->commands_since_idle_or_otag = 0;
4408 1764
4409 if (TAILQ_EMPTY(&dev->busyq)) {
4410 if ((dev->flags & AHD_DEV_UNCONFIGURED) != 0
4411 && dev->active == 0
4412 && (dev->flags & AHD_DEV_TIMER_ACTIVE) == 0)
4413 ahd_linux_free_device(ahd, dev);
4414 } else if ((dev->flags & AHD_DEV_ON_RUN_LIST) == 0) {
4415 TAILQ_INSERT_TAIL(&ahd->platform_data->device_runq, dev, links);
4416 dev->flags |= AHD_DEV_ON_RUN_LIST;
4417 }
4418
4419 if ((scb->flags & SCB_RECOVERY_SCB) != 0) { 1765 if ((scb->flags & SCB_RECOVERY_SCB) != 0) {
4420 printf("Recovery SCB completes\n"); 1766 printf("Recovery SCB completes\n");
4421 if (ahd_get_transaction_status(scb) == CAM_BDR_SENT 1767 if (ahd_get_transaction_status(scb) == CAM_BDR_SENT
4422 || ahd_get_transaction_status(scb) == CAM_REQ_ABORTED) 1768 || ahd_get_transaction_status(scb) == CAM_REQ_ABORTED)
4423 ahd_set_transaction_status(scb, CAM_CMD_TIMEOUT); 1769 ahd_set_transaction_status(scb, CAM_CMD_TIMEOUT);
4424 if ((scb->platform_data->flags & AHD_SCB_UP_EH_SEM) != 0) { 1770 if ((ahd->platform_data->flags & AHD_SCB_UP_EH_SEM) != 0) {
4425 scb->platform_data->flags &= ~AHD_SCB_UP_EH_SEM; 1771 ahd->platform_data->flags &= ~AHD_SCB_UP_EH_SEM;
4426 up(&ahd->platform_data->eh_sem); 1772 up(&ahd->platform_data->eh_sem);
4427 } 1773 }
4428 } 1774 }
4429 1775
4430 ahd_free_scb(ahd, scb); 1776 ahd_free_scb(ahd, scb);
4431 ahd_linux_queue_cmd_complete(ahd, cmd); 1777 ahd_linux_queue_cmd_complete(ahd, cmd);
4432
4433 if ((ahd->platform_data->flags & AHD_DV_WAIT_SIMQ_EMPTY) != 0
4434 && LIST_FIRST(&ahd->pending_scbs) == NULL) {
4435 ahd->platform_data->flags &= ~AHD_DV_WAIT_SIMQ_EMPTY;
4436 up(&ahd->platform_data->dv_sem);
4437 }
4438} 1778}
4439 1779
4440static void 1780static void
4441ahd_linux_handle_scsi_status(struct ahd_softc *ahd, 1781ahd_linux_handle_scsi_status(struct ahd_softc *ahd,
4442 struct ahd_linux_device *dev, struct scb *scb) 1782 struct scsi_device *sdev, struct scb *scb)
4443{ 1783{
4444 struct ahd_devinfo devinfo; 1784 struct ahd_devinfo devinfo;
1785 struct ahd_linux_device *dev = scsi_transport_device_data(sdev);
4445 1786
4446 ahd_compile_devinfo(&devinfo, 1787 ahd_compile_devinfo(&devinfo,
4447 ahd->our_id, 1788 ahd->our_id,
4448 dev->target->target, dev->lun, 1789 sdev->sdev_target->id, sdev->lun,
4449 dev->target->channel == 0 ? 'A' : 'B', 1790 sdev->sdev_target->channel == 0 ? 'A' : 'B',
4450 ROLE_INITIATOR); 1791 ROLE_INITIATOR);
4451 1792
4452 /* 1793 /*
@@ -4465,7 +1806,7 @@ ahd_linux_handle_scsi_status(struct ahd_softc *ahd,
4465 case SCSI_STATUS_CHECK_COND: 1806 case SCSI_STATUS_CHECK_COND:
4466 case SCSI_STATUS_CMD_TERMINATED: 1807 case SCSI_STATUS_CMD_TERMINATED:
4467 { 1808 {
4468 Scsi_Cmnd *cmd; 1809 struct scsi_cmnd *cmd;
4469 1810
4470 /* 1811 /*
4471 * Copy sense information to the OS's cmd 1812 * Copy sense information to the OS's cmd
@@ -4518,7 +1859,6 @@ ahd_linux_handle_scsi_status(struct ahd_softc *ahd,
4518 break; 1859 break;
4519 } 1860 }
4520 case SCSI_STATUS_QUEUE_FULL: 1861 case SCSI_STATUS_QUEUE_FULL:
4521 {
4522 /* 1862 /*
4523 * By the time the core driver has returned this 1863 * By the time the core driver has returned this
4524 * command, all other commands that were queued 1864 * command, all other commands that were queued
@@ -4579,98 +1919,23 @@ ahd_linux_handle_scsi_status(struct ahd_softc *ahd,
4579 (dev->flags & AHD_DEV_Q_BASIC) 1919 (dev->flags & AHD_DEV_Q_BASIC)
4580 ? AHD_QUEUE_BASIC : AHD_QUEUE_TAGGED); 1920 ? AHD_QUEUE_BASIC : AHD_QUEUE_TAGGED);
4581 ahd_set_scsi_status(scb, SCSI_STATUS_BUSY); 1921 ahd_set_scsi_status(scb, SCSI_STATUS_BUSY);
4582 /* FALLTHROUGH */
4583 }
4584 case SCSI_STATUS_BUSY:
4585 /*
4586 * Set a short timer to defer sending commands for
4587 * a bit since Linux will not delay in this case.
4588 */
4589 if ((dev->flags & AHD_DEV_TIMER_ACTIVE) != 0) {
4590 printf("%s:%c:%d: Device Timer still active during "
4591 "busy processing\n", ahd_name(ahd),
4592 dev->target->channel, dev->target->target);
4593 break;
4594 }
4595 dev->flags |= AHD_DEV_TIMER_ACTIVE;
4596 dev->qfrozen++;
4597 init_timer(&dev->timer);
4598 dev->timer.data = (u_long)dev;
4599 dev->timer.expires = jiffies + (HZ/2);
4600 dev->timer.function = ahd_linux_dev_timed_unfreeze;
4601 add_timer(&dev->timer);
4602 break;
4603 } 1922 }
4604} 1923}
4605 1924
4606static void 1925static void
4607ahd_linux_queue_cmd_complete(struct ahd_softc *ahd, Scsi_Cmnd *cmd) 1926ahd_linux_queue_cmd_complete(struct ahd_softc *ahd, struct scsi_cmnd *cmd)
4608{ 1927{
4609 /* 1928 /*
4610 * Typically, the complete queue has very few entries
4611 * queued to it before the queue is emptied by
4612 * ahd_linux_run_complete_queue, so sorting the entries
4613 * by generation number should be inexpensive.
4614 * We perform the sort so that commands that complete
4615 * with an error are retuned in the order origionally
4616 * queued to the controller so that any subsequent retries
4617 * are performed in order. The underlying ahd routines do
4618 * not guarantee the order that aborted commands will be
4619 * returned to us.
4620 */
4621 struct ahd_completeq *completeq;
4622 struct ahd_cmd *list_cmd;
4623 struct ahd_cmd *acmd;
4624
4625 /*
4626 * Map CAM error codes into Linux Error codes. We 1929 * Map CAM error codes into Linux Error codes. We
4627 * avoid the conversion so that the DV code has the 1930 * avoid the conversion so that the DV code has the
4628 * full error information available when making 1931 * full error information available when making
4629 * state change decisions. 1932 * state change decisions.
4630 */ 1933 */
4631 if (AHD_DV_CMD(cmd) == FALSE) { 1934 {
4632 uint32_t status; 1935 uint32_t status;
4633 u_int new_status; 1936 u_int new_status;
4634 1937
4635 status = ahd_cmd_get_transaction_status(cmd); 1938 status = ahd_cmd_get_transaction_status(cmd);
4636 if (status != CAM_REQ_CMP) {
4637 struct ahd_linux_device *dev;
4638 struct ahd_devinfo devinfo;
4639 cam_status cam_status;
4640 uint32_t action;
4641 u_int scsi_status;
4642
4643 dev = ahd_linux_get_device(ahd, cmd->device->channel,
4644 cmd->device->id,
4645 cmd->device->lun,
4646 /*alloc*/FALSE);
4647
4648 if (dev == NULL)
4649 goto no_fallback;
4650
4651 ahd_compile_devinfo(&devinfo,
4652 ahd->our_id,
4653 dev->target->target, dev->lun,
4654 dev->target->channel == 0 ? 'A':'B',
4655 ROLE_INITIATOR);
4656
4657 scsi_status = ahd_cmd_get_scsi_status(cmd);
4658 cam_status = ahd_cmd_get_transaction_status(cmd);
4659 action = aic_error_action(cmd, dev->target->inq_data,
4660 cam_status, scsi_status);
4661 if ((action & SSQ_FALLBACK) != 0) {
4662
4663 /* Update stats */
4664 dev->target->errors_detected++;
4665 if (dev->target->cmds_since_error == 0)
4666 dev->target->cmds_since_error++;
4667 else {
4668 dev->target->cmds_since_error = 0;
4669 ahd_linux_fallback(ahd, &devinfo);
4670 }
4671 }
4672 }
4673no_fallback:
4674 switch (status) { 1939 switch (status) {
4675 case CAM_REQ_INPROG: 1940 case CAM_REQ_INPROG:
4676 case CAM_REQ_CMP: 1941 case CAM_REQ_CMP:
@@ -4715,26 +1980,7 @@ no_fallback:
4715 new_status = DID_ERROR; 1980 new_status = DID_ERROR;
4716 break; 1981 break;
4717 case CAM_REQUEUE_REQ: 1982 case CAM_REQUEUE_REQ:
4718 /* 1983 new_status = DID_REQUEUE;
4719 * If we want the request requeued, make sure there
4720 * are sufficent retries. In the old scsi error code,
4721 * we used to be able to specify a result code that
4722 * bypassed the retry count. Now we must use this
4723 * hack. We also "fake" a check condition with
4724 * a sense code of ABORTED COMMAND. This seems to
4725 * evoke a retry even if this command is being sent
4726 * via the eh thread. Ick! Ick! Ick!
4727 */
4728 if (cmd->retries > 0)
4729 cmd->retries--;
4730 new_status = DID_OK;
4731 ahd_cmd_set_scsi_status(cmd, SCSI_STATUS_CHECK_COND);
4732 cmd->result |= (DRIVER_SENSE << 24);
4733 memset(cmd->sense_buffer, 0,
4734 sizeof(cmd->sense_buffer));
4735 cmd->sense_buffer[0] = SSD_ERRCODE_VALID
4736 | SSD_CURRENT_ERROR;
4737 cmd->sense_buffer[2] = SSD_KEY_ABORTED_COMMAND;
4738 break; 1984 break;
4739 default: 1985 default:
4740 /* We should never get here */ 1986 /* We should never get here */
@@ -4745,116 +1991,23 @@ no_fallback:
4745 ahd_cmd_set_transaction_status(cmd, new_status); 1991 ahd_cmd_set_transaction_status(cmd, new_status);
4746 } 1992 }
4747 1993
4748 completeq = &ahd->platform_data->completeq; 1994 cmd->scsi_done(cmd);
4749 list_cmd = TAILQ_FIRST(completeq);
4750 acmd = (struct ahd_cmd *)cmd;
4751 while (list_cmd != NULL
4752 && acmd_scsi_cmd(list_cmd).serial_number
4753 < acmd_scsi_cmd(acmd).serial_number)
4754 list_cmd = TAILQ_NEXT(list_cmd, acmd_links.tqe);
4755 if (list_cmd != NULL)
4756 TAILQ_INSERT_BEFORE(list_cmd, acmd, acmd_links.tqe);
4757 else
4758 TAILQ_INSERT_TAIL(completeq, acmd, acmd_links.tqe);
4759} 1995}
4760 1996
4761static void 1997static void
4762ahd_linux_filter_inquiry(struct ahd_softc *ahd, struct ahd_devinfo *devinfo) 1998ahd_linux_sem_timeout(u_long arg)
4763{ 1999{
4764 struct scsi_inquiry_data *sid; 2000 struct ahd_softc *ahd;
4765 struct ahd_initiator_tinfo *tinfo; 2001 u_long s;
4766 struct ahd_transinfo *user;
4767 struct ahd_transinfo *goal;
4768 struct ahd_transinfo *curr;
4769 struct ahd_tmode_tstate *tstate;
4770 struct ahd_linux_device *dev;
4771 u_int width;
4772 u_int period;
4773 u_int offset;
4774 u_int ppr_options;
4775 u_int trans_version;
4776 u_int prot_version;
4777
4778 /*
4779 * Determine if this lun actually exists. If so,
4780 * hold on to its corresponding device structure.
4781 * If not, make sure we release the device and
4782 * don't bother processing the rest of this inquiry
4783 * command.
4784 */
4785 dev = ahd_linux_get_device(ahd, devinfo->channel - 'A',
4786 devinfo->target, devinfo->lun,
4787 /*alloc*/TRUE);
4788
4789 sid = (struct scsi_inquiry_data *)dev->target->inq_data;
4790 if (SID_QUAL(sid) == SID_QUAL_LU_CONNECTED) {
4791
4792 dev->flags &= ~AHD_DEV_UNCONFIGURED;
4793 } else {
4794 dev->flags |= AHD_DEV_UNCONFIGURED;
4795 return;
4796 }
4797 2002
4798 /* 2003 ahd = (struct ahd_softc *)arg;
4799 * Update our notion of this device's transfer
4800 * negotiation capabilities.
4801 */
4802 tinfo = ahd_fetch_transinfo(ahd, devinfo->channel,
4803 devinfo->our_scsiid,
4804 devinfo->target, &tstate);
4805 user = &tinfo->user;
4806 goal = &tinfo->goal;
4807 curr = &tinfo->curr;
4808 width = user->width;
4809 period = user->period;
4810 offset = user->offset;
4811 ppr_options = user->ppr_options;
4812 trans_version = user->transport_version;
4813 prot_version = MIN(user->protocol_version, SID_ANSI_REV(sid));
4814 2004
4815 /* 2005 ahd_lock(ahd, &s);
4816 * Only attempt SPI3/4 once we've verified that 2006 if ((ahd->platform_data->flags & AHD_SCB_UP_EH_SEM) != 0) {
4817 * the device claims to support SPI3/4 features. 2007 ahd->platform_data->flags &= ~AHD_SCB_UP_EH_SEM;
4818 */ 2008 up(&ahd->platform_data->eh_sem);
4819 if (prot_version < SCSI_REV_2)
4820 trans_version = SID_ANSI_REV(sid);
4821 else
4822 trans_version = SCSI_REV_2;
4823
4824 if ((sid->flags & SID_WBus16) == 0)
4825 width = MSG_EXT_WDTR_BUS_8_BIT;
4826 if ((sid->flags & SID_Sync) == 0) {
4827 period = 0;
4828 offset = 0;
4829 ppr_options = 0;
4830 }
4831 if ((sid->spi3data & SID_SPI_QAS) == 0)
4832 ppr_options &= ~MSG_EXT_PPR_QAS_REQ;
4833 if ((sid->spi3data & SID_SPI_CLOCK_DT) == 0)
4834 ppr_options &= MSG_EXT_PPR_QAS_REQ;
4835 if ((sid->spi3data & SID_SPI_IUS) == 0)
4836 ppr_options &= (MSG_EXT_PPR_DT_REQ
4837 | MSG_EXT_PPR_QAS_REQ);
4838
4839 if (prot_version > SCSI_REV_2
4840 && ppr_options != 0)
4841 trans_version = user->transport_version;
4842
4843 ahd_validate_width(ahd, /*tinfo limit*/NULL, &width, ROLE_UNKNOWN);
4844 ahd_find_syncrate(ahd, &period, &ppr_options, AHD_SYNCRATE_MAX);
4845 ahd_validate_offset(ahd, /*tinfo limit*/NULL, period,
4846 &offset, width, ROLE_UNKNOWN);
4847 if (offset == 0 || period == 0) {
4848 period = 0;
4849 offset = 0;
4850 ppr_options = 0;
4851 } 2009 }
4852 /* Apply our filtered user settings. */ 2010 ahd_unlock(ahd, &s);
4853 curr->transport_version = trans_version;
4854 curr->protocol_version = prot_version;
4855 ahd_set_width(ahd, devinfo, width, AHD_TRANS_GOAL, /*paused*/FALSE);
4856 ahd_set_syncrate(ahd, devinfo, period, offset, ppr_options,
4857 AHD_TRANS_GOAL, /*paused*/FALSE);
4858} 2011}
4859 2012
4860void 2013void
@@ -4882,12 +2035,6 @@ ahd_release_simq(struct ahd_softc *ahd)
4882 if (ahd->platform_data->qfrozen == 0) { 2035 if (ahd->platform_data->qfrozen == 0) {
4883 unblock_reqs = 1; 2036 unblock_reqs = 1;
4884 } 2037 }
4885 if (AHD_DV_SIMQ_FROZEN(ahd)
4886 && ((ahd->platform_data->flags & AHD_DV_WAIT_SIMQ_RELEASE) != 0)) {
4887 ahd->platform_data->flags &= ~AHD_DV_WAIT_SIMQ_RELEASE;
4888 up(&ahd->platform_data->dv_sem);
4889 }
4890 ahd_schedule_runq(ahd);
4891 ahd_unlock(ahd, &s); 2038 ahd_unlock(ahd, &s);
4892 /* 2039 /*
4893 * There is still a race here. The mid-layer 2040 * There is still a race here. The mid-layer
@@ -4899,118 +2046,743 @@ ahd_release_simq(struct ahd_softc *ahd)
4899 scsi_unblock_requests(ahd->platform_data->host); 2046 scsi_unblock_requests(ahd->platform_data->host);
4900} 2047}
4901 2048
4902static void 2049static int
4903ahd_linux_sem_timeout(u_long arg) 2050ahd_linux_queue_recovery_cmd(struct scsi_cmnd *cmd, scb_flag flag)
4904{ 2051{
4905 struct scb *scb; 2052 struct ahd_softc *ahd;
4906 struct ahd_softc *ahd; 2053 struct ahd_linux_device *dev;
4907 u_long s; 2054 struct scb *pending_scb;
2055 u_int saved_scbptr;
2056 u_int active_scbptr;
2057 u_int last_phase;
2058 u_int saved_scsiid;
2059 u_int cdb_byte;
2060 int retval;
2061 int was_paused;
2062 int paused;
2063 int wait;
2064 int disconnected;
2065 ahd_mode_state saved_modes;
4908 2066
4909 scb = (struct scb *)arg; 2067 pending_scb = NULL;
4910 ahd = scb->ahd_softc; 2068 paused = FALSE;
4911 ahd_lock(ahd, &s); 2069 wait = FALSE;
4912 if ((scb->platform_data->flags & AHD_SCB_UP_EH_SEM) != 0) { 2070 ahd = *(struct ahd_softc **)cmd->device->host->hostdata;
4913 scb->platform_data->flags &= ~AHD_SCB_UP_EH_SEM; 2071
4914 up(&ahd->platform_data->eh_sem); 2072 printf("%s:%d:%d:%d: Attempting to queue a%s message:",
2073 ahd_name(ahd), cmd->device->channel,
2074 cmd->device->id, cmd->device->lun,
2075 flag == SCB_ABORT ? "n ABORT" : " TARGET RESET");
2076
2077 printf("CDB:");
2078 for (cdb_byte = 0; cdb_byte < cmd->cmd_len; cdb_byte++)
2079 printf(" 0x%x", cmd->cmnd[cdb_byte]);
2080 printf("\n");
2081
2082 spin_lock_irq(&ahd->platform_data->spin_lock);
2083
2084 /*
2085 * First determine if we currently own this command.
2086 * Start by searching the device queue. If not found
2087 * there, check the pending_scb list. If not found
2088 * at all, and the system wanted us to just abort the
2089 * command, return success.
2090 */
2091 dev = scsi_transport_device_data(cmd->device);
2092
2093 if (dev == NULL) {
2094 /*
2095 * No target device for this command exists,
2096 * so we must not still own the command.
2097 */
2098 printf("%s:%d:%d:%d: Is not an active device\n",
2099 ahd_name(ahd), cmd->device->channel, cmd->device->id,
2100 cmd->device->lun);
2101 retval = SUCCESS;
2102 goto no_cmd;
4915 } 2103 }
4916 ahd_unlock(ahd, &s); 2104
2105 /*
2106 * See if we can find a matching cmd in the pending list.
2107 */
2108 LIST_FOREACH(pending_scb, &ahd->pending_scbs, pending_links) {
2109 if (pending_scb->io_ctx == cmd)
2110 break;
2111 }
2112
2113 if (pending_scb == NULL && flag == SCB_DEVICE_RESET) {
2114
2115 /* Any SCB for this device will do for a target reset */
2116 LIST_FOREACH(pending_scb, &ahd->pending_scbs, pending_links) {
2117 if (ahd_match_scb(ahd, pending_scb, cmd->device->id,
2118 cmd->device->channel + 'A',
2119 CAM_LUN_WILDCARD,
2120 SCB_LIST_NULL, ROLE_INITIATOR) == 0)
2121 break;
2122 }
2123 }
2124
2125 if (pending_scb == NULL) {
2126 printf("%s:%d:%d:%d: Command not found\n",
2127 ahd_name(ahd), cmd->device->channel, cmd->device->id,
2128 cmd->device->lun);
2129 goto no_cmd;
2130 }
2131
2132 if ((pending_scb->flags & SCB_RECOVERY_SCB) != 0) {
2133 /*
2134 * We can't queue two recovery actions using the same SCB
2135 */
2136 retval = FAILED;
2137 goto done;
2138 }
2139
2140 /*
2141 * Ensure that the card doesn't do anything
2142 * behind our back. Also make sure that we
2143 * didn't "just" miss an interrupt that would
2144 * affect this cmd.
2145 */
2146 was_paused = ahd_is_paused(ahd);
2147 ahd_pause_and_flushwork(ahd);
2148 paused = TRUE;
2149
2150 if ((pending_scb->flags & SCB_ACTIVE) == 0) {
2151 printf("%s:%d:%d:%d: Command already completed\n",
2152 ahd_name(ahd), cmd->device->channel, cmd->device->id,
2153 cmd->device->lun);
2154 goto no_cmd;
2155 }
2156
2157 printf("%s: At time of recovery, card was %spaused\n",
2158 ahd_name(ahd), was_paused ? "" : "not ");
2159 ahd_dump_card_state(ahd);
2160
2161 disconnected = TRUE;
2162 if (flag == SCB_ABORT) {
2163 if (ahd_search_qinfifo(ahd, cmd->device->id,
2164 cmd->device->channel + 'A',
2165 cmd->device->lun,
2166 pending_scb->hscb->tag,
2167 ROLE_INITIATOR, CAM_REQ_ABORTED,
2168 SEARCH_COMPLETE) > 0) {
2169 printf("%s:%d:%d:%d: Cmd aborted from QINFIFO\n",
2170 ahd_name(ahd), cmd->device->channel,
2171 cmd->device->id, cmd->device->lun);
2172 retval = SUCCESS;
2173 goto done;
2174 }
2175 } else if (ahd_search_qinfifo(ahd, cmd->device->id,
2176 cmd->device->channel + 'A',
2177 cmd->device->lun, pending_scb->hscb->tag,
2178 ROLE_INITIATOR, /*status*/0,
2179 SEARCH_COUNT) > 0) {
2180 disconnected = FALSE;
2181 }
2182
2183 saved_modes = ahd_save_modes(ahd);
2184 ahd_set_modes(ahd, AHD_MODE_SCSI, AHD_MODE_SCSI);
2185 last_phase = ahd_inb(ahd, LASTPHASE);
2186 saved_scbptr = ahd_get_scbptr(ahd);
2187 active_scbptr = saved_scbptr;
2188 if (disconnected && (ahd_inb(ahd, SEQ_FLAGS) & NOT_IDENTIFIED) == 0) {
2189 struct scb *bus_scb;
2190
2191 bus_scb = ahd_lookup_scb(ahd, active_scbptr);
2192 if (bus_scb == pending_scb)
2193 disconnected = FALSE;
2194 else if (flag != SCB_ABORT
2195 && ahd_inb(ahd, SAVED_SCSIID) == pending_scb->hscb->scsiid
2196 && ahd_inb(ahd, SAVED_LUN) == SCB_GET_LUN(pending_scb))
2197 disconnected = FALSE;
2198 }
2199
2200 /*
2201 * At this point, pending_scb is the scb associated with the
2202 * passed in command. That command is currently active on the
2203 * bus or is in the disconnected state.
2204 */
2205 saved_scsiid = ahd_inb(ahd, SAVED_SCSIID);
2206 if (last_phase != P_BUSFREE
2207 && (SCB_GET_TAG(pending_scb) == active_scbptr
2208 || (flag == SCB_DEVICE_RESET
2209 && SCSIID_TARGET(ahd, saved_scsiid) == cmd->device->id))) {
2210
2211 /*
2212 * We're active on the bus, so assert ATN
2213 * and hope that the target responds.
2214 */
2215 pending_scb = ahd_lookup_scb(ahd, active_scbptr);
2216 pending_scb->flags |= SCB_RECOVERY_SCB|flag;
2217 ahd_outb(ahd, MSG_OUT, HOST_MSG);
2218 ahd_outb(ahd, SCSISIGO, last_phase|ATNO);
2219 printf("%s:%d:%d:%d: Device is active, asserting ATN\n",
2220 ahd_name(ahd), cmd->device->channel,
2221 cmd->device->id, cmd->device->lun);
2222 wait = TRUE;
2223 } else if (disconnected) {
2224
2225 /*
2226 * Actually re-queue this SCB in an attempt
2227 * to select the device before it reconnects.
2228 */
2229 pending_scb->flags |= SCB_RECOVERY_SCB|SCB_ABORT;
2230 ahd_set_scbptr(ahd, SCB_GET_TAG(pending_scb));
2231 pending_scb->hscb->cdb_len = 0;
2232 pending_scb->hscb->task_attribute = 0;
2233 pending_scb->hscb->task_management = SIU_TASKMGMT_ABORT_TASK;
2234
2235 if ((pending_scb->flags & SCB_PACKETIZED) != 0) {
2236 /*
2237 * Mark the SCB has having an outstanding
2238 * task management function. Should the command
2239 * complete normally before the task management
2240 * function can be sent, the host will be notified
2241 * to abort our requeued SCB.
2242 */
2243 ahd_outb(ahd, SCB_TASK_MANAGEMENT,
2244 pending_scb->hscb->task_management);
2245 } else {
2246 /*
2247 * If non-packetized, set the MK_MESSAGE control
2248 * bit indicating that we desire to send a message.
2249 * We also set the disconnected flag since there is
2250 * no guarantee that our SCB control byte matches
2251 * the version on the card. We don't want the
2252 * sequencer to abort the command thinking an
2253 * unsolicited reselection occurred.
2254 */
2255 pending_scb->hscb->control |= MK_MESSAGE|DISCONNECTED;
2256
2257 /*
2258 * The sequencer will never re-reference the
2259 * in-core SCB. To make sure we are notified
2260 * during reslection, set the MK_MESSAGE flag in
2261 * the card's copy of the SCB.
2262 */
2263 ahd_outb(ahd, SCB_CONTROL,
2264 ahd_inb(ahd, SCB_CONTROL)|MK_MESSAGE);
2265 }
2266
2267 /*
2268 * Clear out any entries in the QINFIFO first
2269 * so we are the next SCB for this target
2270 * to run.
2271 */
2272 ahd_search_qinfifo(ahd, cmd->device->id,
2273 cmd->device->channel + 'A', cmd->device->lun,
2274 SCB_LIST_NULL, ROLE_INITIATOR,
2275 CAM_REQUEUE_REQ, SEARCH_COMPLETE);
2276 ahd_qinfifo_requeue_tail(ahd, pending_scb);
2277 ahd_set_scbptr(ahd, saved_scbptr);
2278 ahd_print_path(ahd, pending_scb);
2279 printf("Device is disconnected, re-queuing SCB\n");
2280 wait = TRUE;
2281 } else {
2282 printf("%s:%d:%d:%d: Unable to deliver message\n",
2283 ahd_name(ahd), cmd->device->channel,
2284 cmd->device->id, cmd->device->lun);
2285 retval = FAILED;
2286 goto done;
2287 }
2288
2289no_cmd:
2290 /*
2291 * Our assumption is that if we don't have the command, no
2292 * recovery action was required, so we return success. Again,
2293 * the semantics of the mid-layer recovery engine are not
2294 * well defined, so this may change in time.
2295 */
2296 retval = SUCCESS;
2297done:
2298 if (paused)
2299 ahd_unpause(ahd);
2300 if (wait) {
2301 struct timer_list timer;
2302 int ret;
2303
2304 ahd->platform_data->flags |= AHD_SCB_UP_EH_SEM;
2305 spin_unlock_irq(&ahd->platform_data->spin_lock);
2306 init_timer(&timer);
2307 timer.data = (u_long)ahd;
2308 timer.expires = jiffies + (5 * HZ);
2309 timer.function = ahd_linux_sem_timeout;
2310 add_timer(&timer);
2311 printf("Recovery code sleeping\n");
2312 down(&ahd->platform_data->eh_sem);
2313 printf("Recovery code awake\n");
2314 ret = del_timer_sync(&timer);
2315 if (ret == 0) {
2316 printf("Timer Expired\n");
2317 retval = FAILED;
2318 }
2319 spin_lock_irq(&ahd->platform_data->spin_lock);
2320 }
2321 spin_unlock_irq(&ahd->platform_data->spin_lock);
2322 return (retval);
4917} 2323}
4918 2324
4919static void 2325static void ahd_linux_set_width(struct scsi_target *starget, int width)
4920ahd_linux_dev_timed_unfreeze(u_long arg)
4921{ 2326{
4922 struct ahd_linux_device *dev; 2327 struct Scsi_Host *shost = dev_to_shost(starget->dev.parent);
4923 struct ahd_softc *ahd; 2328 struct ahd_softc *ahd = *((struct ahd_softc **)shost->hostdata);
4924 u_long s; 2329 struct ahd_devinfo devinfo;
2330 unsigned long flags;
4925 2331
4926 dev = (struct ahd_linux_device *)arg; 2332 ahd_compile_devinfo(&devinfo, shost->this_id, starget->id, 0,
4927 ahd = dev->target->ahd; 2333 starget->channel + 'A', ROLE_INITIATOR);
4928 ahd_lock(ahd, &s); 2334 ahd_lock(ahd, &flags);
4929 dev->flags &= ~AHD_DEV_TIMER_ACTIVE; 2335 ahd_set_width(ahd, &devinfo, width, AHD_TRANS_GOAL, FALSE);
4930 if (dev->qfrozen > 0) 2336 ahd_unlock(ahd, &flags);
4931 dev->qfrozen--;
4932 if (dev->qfrozen == 0
4933 && (dev->flags & AHD_DEV_ON_RUN_LIST) == 0)
4934 ahd_linux_run_device_queue(ahd, dev);
4935 if ((dev->flags & AHD_DEV_UNCONFIGURED) != 0
4936 && dev->active == 0)
4937 ahd_linux_free_device(ahd, dev);
4938 ahd_unlock(ahd, &s);
4939} 2337}
4940 2338
4941void 2339static void ahd_linux_set_period(struct scsi_target *starget, int period)
4942ahd_platform_dump_card_state(struct ahd_softc *ahd)
4943{ 2340{
4944 struct ahd_linux_device *dev; 2341 struct Scsi_Host *shost = dev_to_shost(starget->dev.parent);
4945 int target; 2342 struct ahd_softc *ahd = *((struct ahd_softc **)shost->hostdata);
4946 int maxtarget; 2343 struct ahd_tmode_tstate *tstate;
4947 int lun; 2344 struct ahd_initiator_tinfo *tinfo
4948 int i; 2345 = ahd_fetch_transinfo(ahd,
4949 2346 starget->channel + 'A',
4950 maxtarget = (ahd->features & AHD_WIDE) ? 15 : 7; 2347 shost->this_id, starget->id, &tstate);
4951 for (target = 0; target <=maxtarget; target++) { 2348 struct ahd_devinfo devinfo;
4952 2349 unsigned int ppr_options = tinfo->goal.ppr_options;
4953 for (lun = 0; lun < AHD_NUM_LUNS; lun++) { 2350 unsigned int dt;
4954 struct ahd_cmd *acmd; 2351 unsigned long flags;
4955 2352 unsigned long offset = tinfo->goal.offset;
4956 dev = ahd_linux_get_device(ahd, 0, target, 2353
4957 lun, /*alloc*/FALSE); 2354#ifdef AHD_DEBUG
4958 if (dev == NULL) 2355 if ((ahd_debug & AHD_SHOW_DV) != 0)
4959 continue; 2356 printf("%s: set period to %d\n", ahd_name(ahd), period);
4960 2357#endif
4961 printf("DevQ(%d:%d:%d): ", 0, target, lun); 2358 if (offset == 0)
4962 i = 0; 2359 offset = MAX_OFFSET;
4963 TAILQ_FOREACH(acmd, &dev->busyq, acmd_links.tqe) { 2360
4964 if (i++ > AHD_SCB_MAX) 2361 if (period < 8)
4965 break; 2362 period = 8;
4966 } 2363 if (period < 10) {
4967 printf("%d waiting\n", i); 2364 ppr_options |= MSG_EXT_PPR_DT_REQ;
4968 } 2365 if (period == 8)
2366 ppr_options |= MSG_EXT_PPR_IU_REQ;
4969 } 2367 }
2368
2369 dt = ppr_options & MSG_EXT_PPR_DT_REQ;
2370
2371 ahd_compile_devinfo(&devinfo, shost->this_id, starget->id, 0,
2372 starget->channel + 'A', ROLE_INITIATOR);
2373
2374 /* all PPR requests apart from QAS require wide transfers */
2375 if (ppr_options & ~MSG_EXT_PPR_QAS_REQ) {
2376 if (spi_width(starget) == 0)
2377 ppr_options &= MSG_EXT_PPR_QAS_REQ;
2378 }
2379
2380 ahd_find_syncrate(ahd, &period, &ppr_options,
2381 dt ? AHD_SYNCRATE_MAX : AHD_SYNCRATE_ULTRA2);
2382
2383 ahd_lock(ahd, &flags);
2384 ahd_set_syncrate(ahd, &devinfo, period, offset,
2385 ppr_options, AHD_TRANS_GOAL, FALSE);
2386 ahd_unlock(ahd, &flags);
4970} 2387}
4971 2388
4972static int __init 2389static void ahd_linux_set_offset(struct scsi_target *starget, int offset)
4973ahd_linux_init(void)
4974{ 2390{
4975#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,5,0) 2391 struct Scsi_Host *shost = dev_to_shost(starget->dev.parent);
4976 return ahd_linux_detect(&aic79xx_driver_template); 2392 struct ahd_softc *ahd = *((struct ahd_softc **)shost->hostdata);
4977#else 2393 struct ahd_tmode_tstate *tstate;
4978 scsi_register_module(MODULE_SCSI_HA, &aic79xx_driver_template); 2394 struct ahd_initiator_tinfo *tinfo
4979 if (aic79xx_driver_template.present == 0) { 2395 = ahd_fetch_transinfo(ahd,
4980 scsi_unregister_module(MODULE_SCSI_HA, 2396 starget->channel + 'A',
4981 &aic79xx_driver_template); 2397 shost->this_id, starget->id, &tstate);
4982 return (-ENODEV); 2398 struct ahd_devinfo devinfo;
2399 unsigned int ppr_options = 0;
2400 unsigned int period = 0;
2401 unsigned int dt = ppr_options & MSG_EXT_PPR_DT_REQ;
2402 unsigned long flags;
2403
2404#ifdef AHD_DEBUG
2405 if ((ahd_debug & AHD_SHOW_DV) != 0)
2406 printf("%s: set offset to %d\n", ahd_name(ahd), offset);
2407#endif
2408
2409 ahd_compile_devinfo(&devinfo, shost->this_id, starget->id, 0,
2410 starget->channel + 'A', ROLE_INITIATOR);
2411 if (offset != 0) {
2412 period = tinfo->goal.period;
2413 ppr_options = tinfo->goal.ppr_options;
2414 ahd_find_syncrate(ahd, &period, &ppr_options,
2415 dt ? AHD_SYNCRATE_MAX : AHD_SYNCRATE_ULTRA2);
4983 } 2416 }
4984 2417
4985 return (0); 2418 ahd_lock(ahd, &flags);
2419 ahd_set_syncrate(ahd, &devinfo, period, offset, ppr_options,
2420 AHD_TRANS_GOAL, FALSE);
2421 ahd_unlock(ahd, &flags);
2422}
2423
2424static void ahd_linux_set_dt(struct scsi_target *starget, int dt)
2425{
2426 struct Scsi_Host *shost = dev_to_shost(starget->dev.parent);
2427 struct ahd_softc *ahd = *((struct ahd_softc **)shost->hostdata);
2428 struct ahd_tmode_tstate *tstate;
2429 struct ahd_initiator_tinfo *tinfo
2430 = ahd_fetch_transinfo(ahd,
2431 starget->channel + 'A',
2432 shost->this_id, starget->id, &tstate);
2433 struct ahd_devinfo devinfo;
2434 unsigned int ppr_options = tinfo->goal.ppr_options
2435 & ~MSG_EXT_PPR_DT_REQ;
2436 unsigned int period = tinfo->goal.period;
2437 unsigned int width = tinfo->goal.width;
2438 unsigned long flags;
2439
2440#ifdef AHD_DEBUG
2441 if ((ahd_debug & AHD_SHOW_DV) != 0)
2442 printf("%s: %s DT\n", ahd_name(ahd),
2443 dt ? "enabling" : "disabling");
2444#endif
2445 if (dt) {
2446 ppr_options |= MSG_EXT_PPR_DT_REQ;
2447 if (!width)
2448 ahd_linux_set_width(starget, 1);
2449 } else {
2450 if (period <= 9)
2451 period = 10; /* If resetting DT, period must be >= 25ns */
2452 /* IU is invalid without DT set */
2453 ppr_options &= ~MSG_EXT_PPR_IU_REQ;
2454 }
2455 ahd_compile_devinfo(&devinfo, shost->this_id, starget->id, 0,
2456 starget->channel + 'A', ROLE_INITIATOR);
2457 ahd_find_syncrate(ahd, &period, &ppr_options,
2458 dt ? AHD_SYNCRATE_MAX : AHD_SYNCRATE_ULTRA2);
2459
2460 ahd_lock(ahd, &flags);
2461 ahd_set_syncrate(ahd, &devinfo, period, tinfo->goal.offset,
2462 ppr_options, AHD_TRANS_GOAL, FALSE);
2463 ahd_unlock(ahd, &flags);
2464}
2465
2466static void ahd_linux_set_qas(struct scsi_target *starget, int qas)
2467{
2468 struct Scsi_Host *shost = dev_to_shost(starget->dev.parent);
2469 struct ahd_softc *ahd = *((struct ahd_softc **)shost->hostdata);
2470 struct ahd_tmode_tstate *tstate;
2471 struct ahd_initiator_tinfo *tinfo
2472 = ahd_fetch_transinfo(ahd,
2473 starget->channel + 'A',
2474 shost->this_id, starget->id, &tstate);
2475 struct ahd_devinfo devinfo;
2476 unsigned int ppr_options = tinfo->goal.ppr_options
2477 & ~MSG_EXT_PPR_QAS_REQ;
2478 unsigned int period = tinfo->goal.period;
2479 unsigned int dt;
2480 unsigned long flags;
2481
2482#ifdef AHD_DEBUG
2483 if ((ahd_debug & AHD_SHOW_DV) != 0)
2484 printf("%s: %s QAS\n", ahd_name(ahd),
2485 qas ? "enabling" : "disabling");
2486#endif
2487
2488 if (qas) {
2489 ppr_options |= MSG_EXT_PPR_QAS_REQ;
2490 }
2491
2492 dt = ppr_options & MSG_EXT_PPR_DT_REQ;
2493
2494 ahd_compile_devinfo(&devinfo, shost->this_id, starget->id, 0,
2495 starget->channel + 'A', ROLE_INITIATOR);
2496 ahd_find_syncrate(ahd, &period, &ppr_options,
2497 dt ? AHD_SYNCRATE_MAX : AHD_SYNCRATE_ULTRA2);
2498
2499 ahd_lock(ahd, &flags);
2500 ahd_set_syncrate(ahd, &devinfo, period, tinfo->goal.offset,
2501 ppr_options, AHD_TRANS_GOAL, FALSE);
2502 ahd_unlock(ahd, &flags);
2503}
2504
2505static void ahd_linux_set_iu(struct scsi_target *starget, int iu)
2506{
2507 struct Scsi_Host *shost = dev_to_shost(starget->dev.parent);
2508 struct ahd_softc *ahd = *((struct ahd_softc **)shost->hostdata);
2509 struct ahd_tmode_tstate *tstate;
2510 struct ahd_initiator_tinfo *tinfo
2511 = ahd_fetch_transinfo(ahd,
2512 starget->channel + 'A',
2513 shost->this_id, starget->id, &tstate);
2514 struct ahd_devinfo devinfo;
2515 unsigned int ppr_options = tinfo->goal.ppr_options
2516 & ~MSG_EXT_PPR_IU_REQ;
2517 unsigned int period = tinfo->goal.period;
2518 unsigned int dt;
2519 unsigned long flags;
2520
2521#ifdef AHD_DEBUG
2522 if ((ahd_debug & AHD_SHOW_DV) != 0)
2523 printf("%s: %s IU\n", ahd_name(ahd),
2524 iu ? "enabling" : "disabling");
4986#endif 2525#endif
2526
2527 if (iu) {
2528 ppr_options |= MSG_EXT_PPR_IU_REQ;
2529 ppr_options |= MSG_EXT_PPR_DT_REQ; /* IU requires DT */
2530 }
2531
2532 dt = ppr_options & MSG_EXT_PPR_DT_REQ;
2533
2534 ahd_compile_devinfo(&devinfo, shost->this_id, starget->id, 0,
2535 starget->channel + 'A', ROLE_INITIATOR);
2536 ahd_find_syncrate(ahd, &period, &ppr_options,
2537 dt ? AHD_SYNCRATE_MAX : AHD_SYNCRATE_ULTRA2);
2538
2539 ahd_lock(ahd, &flags);
2540 ahd_set_syncrate(ahd, &devinfo, period, tinfo->goal.offset,
2541 ppr_options, AHD_TRANS_GOAL, FALSE);
2542 ahd_unlock(ahd, &flags);
4987} 2543}
4988 2544
4989static void __exit 2545static void ahd_linux_set_rd_strm(struct scsi_target *starget, int rdstrm)
4990ahd_linux_exit(void)
4991{ 2546{
4992 struct ahd_softc *ahd; 2547 struct Scsi_Host *shost = dev_to_shost(starget->dev.parent);
2548 struct ahd_softc *ahd = *((struct ahd_softc **)shost->hostdata);
2549 struct ahd_tmode_tstate *tstate;
2550 struct ahd_initiator_tinfo *tinfo
2551 = ahd_fetch_transinfo(ahd,
2552 starget->channel + 'A',
2553 shost->this_id, starget->id, &tstate);
2554 struct ahd_devinfo devinfo;
2555 unsigned int ppr_options = tinfo->goal.ppr_options
2556 & ~MSG_EXT_PPR_RD_STRM;
2557 unsigned int period = tinfo->goal.period;
2558 unsigned int dt = ppr_options & MSG_EXT_PPR_DT_REQ;
2559 unsigned long flags;
4993 2560
4994 /* 2561#ifdef AHD_DEBUG
4995 * Shutdown DV threads before going into the SCSI mid-layer. 2562 if ((ahd_debug & AHD_SHOW_DV) != 0)
4996 * This avoids situations where the mid-layer locks the entire 2563 printf("%s: %s Read Streaming\n", ahd_name(ahd),
4997 * kernel so that waiting for our DV threads to exit leads 2564 rdstrm ? "enabling" : "disabling");
4998 * to deadlock. 2565#endif
4999 */ 2566
5000 TAILQ_FOREACH(ahd, &ahd_tailq, links) { 2567 if (rdstrm)
2568 ppr_options |= MSG_EXT_PPR_RD_STRM;
2569
2570 ahd_compile_devinfo(&devinfo, shost->this_id, starget->id, 0,
2571 starget->channel + 'A', ROLE_INITIATOR);
2572 ahd_find_syncrate(ahd, &period, &ppr_options,
2573 dt ? AHD_SYNCRATE_MAX : AHD_SYNCRATE_ULTRA2);
5001 2574
5002 ahd_linux_kill_dv_thread(ahd); 2575 ahd_lock(ahd, &flags);
2576 ahd_set_syncrate(ahd, &devinfo, period, tinfo->goal.offset,
2577 ppr_options, AHD_TRANS_GOAL, FALSE);
2578 ahd_unlock(ahd, &flags);
2579}
2580
2581static void ahd_linux_set_wr_flow(struct scsi_target *starget, int wrflow)
2582{
2583 struct Scsi_Host *shost = dev_to_shost(starget->dev.parent);
2584 struct ahd_softc *ahd = *((struct ahd_softc **)shost->hostdata);
2585 struct ahd_tmode_tstate *tstate;
2586 struct ahd_initiator_tinfo *tinfo
2587 = ahd_fetch_transinfo(ahd,
2588 starget->channel + 'A',
2589 shost->this_id, starget->id, &tstate);
2590 struct ahd_devinfo devinfo;
2591 unsigned int ppr_options = tinfo->goal.ppr_options
2592 & ~MSG_EXT_PPR_WR_FLOW;
2593 unsigned int period = tinfo->goal.period;
2594 unsigned int dt = ppr_options & MSG_EXT_PPR_DT_REQ;
2595 unsigned long flags;
2596
2597#ifdef AHD_DEBUG
2598 if ((ahd_debug & AHD_SHOW_DV) != 0)
2599 printf("%s: %s Write Flow Control\n", ahd_name(ahd),
2600 wrflow ? "enabling" : "disabling");
2601#endif
2602
2603 if (wrflow)
2604 ppr_options |= MSG_EXT_PPR_WR_FLOW;
2605
2606 ahd_compile_devinfo(&devinfo, shost->this_id, starget->id, 0,
2607 starget->channel + 'A', ROLE_INITIATOR);
2608 ahd_find_syncrate(ahd, &period, &ppr_options,
2609 dt ? AHD_SYNCRATE_MAX : AHD_SYNCRATE_ULTRA2);
2610
2611 ahd_lock(ahd, &flags);
2612 ahd_set_syncrate(ahd, &devinfo, period, tinfo->goal.offset,
2613 ppr_options, AHD_TRANS_GOAL, FALSE);
2614 ahd_unlock(ahd, &flags);
2615}
2616
2617static void ahd_linux_set_rti(struct scsi_target *starget, int rti)
2618{
2619 struct Scsi_Host *shost = dev_to_shost(starget->dev.parent);
2620 struct ahd_softc *ahd = *((struct ahd_softc **)shost->hostdata);
2621 struct ahd_tmode_tstate *tstate;
2622 struct ahd_initiator_tinfo *tinfo
2623 = ahd_fetch_transinfo(ahd,
2624 starget->channel + 'A',
2625 shost->this_id, starget->id, &tstate);
2626 struct ahd_devinfo devinfo;
2627 unsigned int ppr_options = tinfo->goal.ppr_options
2628 & ~MSG_EXT_PPR_RTI;
2629 unsigned int period = tinfo->goal.period;
2630 unsigned int dt = ppr_options & MSG_EXT_PPR_DT_REQ;
2631 unsigned long flags;
2632
2633 if ((ahd->features & AHD_RTI) == 0) {
2634#ifdef AHD_DEBUG
2635 if ((ahd_debug & AHD_SHOW_DV) != 0)
2636 printf("%s: RTI not available\n", ahd_name(ahd));
2637#endif
2638 return;
5003 } 2639 }
5004 2640
5005#if LINUX_VERSION_CODE < KERNEL_VERSION(2,5,0) 2641#ifdef AHD_DEBUG
2642 if ((ahd_debug & AHD_SHOW_DV) != 0)
2643 printf("%s: %s RTI\n", ahd_name(ahd),
2644 rti ? "enabling" : "disabling");
2645#endif
2646
2647 if (rti)
2648 ppr_options |= MSG_EXT_PPR_RTI;
2649
2650 ahd_compile_devinfo(&devinfo, shost->this_id, starget->id, 0,
2651 starget->channel + 'A', ROLE_INITIATOR);
2652 ahd_find_syncrate(ahd, &period, &ppr_options,
2653 dt ? AHD_SYNCRATE_MAX : AHD_SYNCRATE_ULTRA2);
2654
2655 ahd_lock(ahd, &flags);
2656 ahd_set_syncrate(ahd, &devinfo, period, tinfo->goal.offset,
2657 ppr_options, AHD_TRANS_GOAL, FALSE);
2658 ahd_unlock(ahd, &flags);
2659}
2660
2661static void ahd_linux_set_pcomp_en(struct scsi_target *starget, int pcomp)
2662{
2663 struct Scsi_Host *shost = dev_to_shost(starget->dev.parent);
2664 struct ahd_softc *ahd = *((struct ahd_softc **)shost->hostdata);
2665 struct ahd_tmode_tstate *tstate;
2666 struct ahd_initiator_tinfo *tinfo
2667 = ahd_fetch_transinfo(ahd,
2668 starget->channel + 'A',
2669 shost->this_id, starget->id, &tstate);
2670 struct ahd_devinfo devinfo;
2671 unsigned int ppr_options = tinfo->goal.ppr_options
2672 & ~MSG_EXT_PPR_PCOMP_EN;
2673 unsigned int period = tinfo->goal.period;
2674 unsigned int dt = ppr_options & MSG_EXT_PPR_DT_REQ;
2675 unsigned long flags;
2676
2677#ifdef AHD_DEBUG
2678 if ((ahd_debug & AHD_SHOW_DV) != 0)
2679 printf("%s: %s Precompensation\n", ahd_name(ahd),
2680 pcomp ? "Enable" : "Disable");
2681#endif
2682
2683 if (pcomp)
2684 ppr_options |= MSG_EXT_PPR_PCOMP_EN;
2685
2686 ahd_compile_devinfo(&devinfo, shost->this_id, starget->id, 0,
2687 starget->channel + 'A', ROLE_INITIATOR);
2688 ahd_find_syncrate(ahd, &period, &ppr_options,
2689 dt ? AHD_SYNCRATE_MAX : AHD_SYNCRATE_ULTRA2);
2690
2691 ahd_lock(ahd, &flags);
2692 ahd_set_syncrate(ahd, &devinfo, period, tinfo->goal.offset,
2693 ppr_options, AHD_TRANS_GOAL, FALSE);
2694 ahd_unlock(ahd, &flags);
2695}
2696
2697static void ahd_linux_set_hold_mcs(struct scsi_target *starget, int hold)
2698{
2699 struct Scsi_Host *shost = dev_to_shost(starget->dev.parent);
2700 struct ahd_softc *ahd = *((struct ahd_softc **)shost->hostdata);
2701 struct ahd_tmode_tstate *tstate;
2702 struct ahd_initiator_tinfo *tinfo
2703 = ahd_fetch_transinfo(ahd,
2704 starget->channel + 'A',
2705 shost->this_id, starget->id, &tstate);
2706 struct ahd_devinfo devinfo;
2707 unsigned int ppr_options = tinfo->goal.ppr_options
2708 & ~MSG_EXT_PPR_HOLD_MCS;
2709 unsigned int period = tinfo->goal.period;
2710 unsigned int dt = ppr_options & MSG_EXT_PPR_DT_REQ;
2711 unsigned long flags;
2712
2713 if (hold)
2714 ppr_options |= MSG_EXT_PPR_HOLD_MCS;
2715
2716 ahd_compile_devinfo(&devinfo, shost->this_id, starget->id, 0,
2717 starget->channel + 'A', ROLE_INITIATOR);
2718 ahd_find_syncrate(ahd, &period, &ppr_options,
2719 dt ? AHD_SYNCRATE_MAX : AHD_SYNCRATE_ULTRA2);
2720
2721 ahd_lock(ahd, &flags);
2722 ahd_set_syncrate(ahd, &devinfo, period, tinfo->goal.offset,
2723 ppr_options, AHD_TRANS_GOAL, FALSE);
2724 ahd_unlock(ahd, &flags);
2725}
2726
2727
2728
2729static struct spi_function_template ahd_linux_transport_functions = {
2730 .set_offset = ahd_linux_set_offset,
2731 .show_offset = 1,
2732 .set_period = ahd_linux_set_period,
2733 .show_period = 1,
2734 .set_width = ahd_linux_set_width,
2735 .show_width = 1,
2736 .set_dt = ahd_linux_set_dt,
2737 .show_dt = 1,
2738 .set_iu = ahd_linux_set_iu,
2739 .show_iu = 1,
2740 .set_qas = ahd_linux_set_qas,
2741 .show_qas = 1,
2742 .set_rd_strm = ahd_linux_set_rd_strm,
2743 .show_rd_strm = 1,
2744 .set_wr_flow = ahd_linux_set_wr_flow,
2745 .show_wr_flow = 1,
2746 .set_rti = ahd_linux_set_rti,
2747 .show_rti = 1,
2748 .set_pcomp_en = ahd_linux_set_pcomp_en,
2749 .show_pcomp_en = 1,
2750 .set_hold_mcs = ahd_linux_set_hold_mcs,
2751 .show_hold_mcs = 1,
2752};
2753
2754static int __init
2755ahd_linux_init(void)
2756{
2757 int error = 0;
2758
5006 /* 2759 /*
5007 * In 2.4 we have to unregister from the PCI core _after_ 2760 * If we've been passed any parameters, process them now.
5008 * unregistering from the scsi midlayer to avoid dangling
5009 * references.
5010 */ 2761 */
5011 scsi_unregister_module(MODULE_SCSI_HA, &aic79xx_driver_template); 2762 if (aic79xx)
5012#endif 2763 aic79xx_setup(aic79xx);
2764
2765 ahd_linux_transport_template =
2766 spi_attach_transport(&ahd_linux_transport_functions);
2767 if (!ahd_linux_transport_template)
2768 return -ENODEV;
2769
2770 scsi_transport_reserve_target(ahd_linux_transport_template,
2771 sizeof(struct ahd_linux_target));
2772 scsi_transport_reserve_device(ahd_linux_transport_template,
2773 sizeof(struct ahd_linux_device));
2774
2775 error = ahd_linux_pci_init();
2776 if (error)
2777 spi_release_transport(ahd_linux_transport_template);
2778 return error;
2779}
2780
2781static void __exit
2782ahd_linux_exit(void)
2783{
5013 ahd_linux_pci_exit(); 2784 ahd_linux_pci_exit();
2785 spi_release_transport(ahd_linux_transport_template);
5014} 2786}
5015 2787
5016module_init(ahd_linux_init); 2788module_init(ahd_linux_init);
diff --git a/drivers/scsi/aic7xxx/aic79xx_osm.h b/drivers/scsi/aic7xxx/aic79xx_osm.h
index 7823e52e99a..052c6619acc 100644
--- a/drivers/scsi/aic7xxx/aic79xx_osm.h
+++ b/drivers/scsi/aic7xxx/aic79xx_osm.h
@@ -42,6 +42,7 @@
42#ifndef _AIC79XX_LINUX_H_ 42#ifndef _AIC79XX_LINUX_H_
43#define _AIC79XX_LINUX_H_ 43#define _AIC79XX_LINUX_H_
44 44
45#include <linux/config.h>
45#include <linux/types.h> 46#include <linux/types.h>
46#include <linux/blkdev.h> 47#include <linux/blkdev.h>
47#include <linux/delay.h> 48#include <linux/delay.h>
@@ -49,18 +50,23 @@
49#include <linux/pci.h> 50#include <linux/pci.h>
50#include <linux/smp_lock.h> 51#include <linux/smp_lock.h>
51#include <linux/version.h> 52#include <linux/version.h>
53#include <linux/interrupt.h>
52#include <linux/module.h> 54#include <linux/module.h>
55#include <linux/slab.h>
53#include <asm/byteorder.h> 56#include <asm/byteorder.h>
54#include <asm/io.h> 57#include <asm/io.h>
55 58
56#include <linux/interrupt.h> /* For tasklet support. */ 59#include <scsi/scsi.h>
57#include <linux/config.h> 60#include <scsi/scsi_cmnd.h>
58#include <linux/slab.h> 61#include <scsi/scsi_eh.h>
62#include <scsi/scsi_device.h>
63#include <scsi/scsi_host.h>
64#include <scsi/scsi_tcq.h>
65#include <scsi/scsi_transport.h>
66#include <scsi/scsi_transport_spi.h>
59 67
60/* Core SCSI definitions */ 68/* Core SCSI definitions */
61#define AIC_LIB_PREFIX ahd 69#define AIC_LIB_PREFIX ahd
62#include "scsi.h"
63#include <scsi/scsi_host.h>
64 70
65/* Name space conflict with BSD queue macros */ 71/* Name space conflict with BSD queue macros */
66#ifdef LIST_HEAD 72#ifdef LIST_HEAD
@@ -95,7 +101,7 @@
95/************************* Forward Declarations *******************************/ 101/************************* Forward Declarations *******************************/
96struct ahd_softc; 102struct ahd_softc;
97typedef struct pci_dev *ahd_dev_softc_t; 103typedef struct pci_dev *ahd_dev_softc_t;
98typedef Scsi_Cmnd *ahd_io_ctx_t; 104typedef struct scsi_cmnd *ahd_io_ctx_t;
99 105
100/******************************* Byte Order ***********************************/ 106/******************************* Byte Order ***********************************/
101#define ahd_htobe16(x) cpu_to_be16(x) 107#define ahd_htobe16(x) cpu_to_be16(x)
@@ -114,8 +120,7 @@ typedef Scsi_Cmnd *ahd_io_ctx_t;
114 120
115/************************* Configuration Data *********************************/ 121/************************* Configuration Data *********************************/
116extern uint32_t aic79xx_allow_memio; 122extern uint32_t aic79xx_allow_memio;
117extern int aic79xx_detect_complete; 123extern struct scsi_host_template aic79xx_driver_template;
118extern Scsi_Host_Template aic79xx_driver_template;
119 124
120/***************************** Bus Space/DMA **********************************/ 125/***************************** Bus Space/DMA **********************************/
121 126
@@ -145,11 +150,7 @@ struct ahd_linux_dma_tag
145}; 150};
146typedef struct ahd_linux_dma_tag* bus_dma_tag_t; 151typedef struct ahd_linux_dma_tag* bus_dma_tag_t;
147 152
148struct ahd_linux_dmamap 153typedef dma_addr_t bus_dmamap_t;
149{
150 dma_addr_t bus_addr;
151};
152typedef struct ahd_linux_dmamap* bus_dmamap_t;
153 154
154typedef int bus_dma_filter_t(void*, dma_addr_t); 155typedef int bus_dma_filter_t(void*, dma_addr_t);
155typedef void bus_dmamap_callback_t(void *, bus_dma_segment_t *, int, int); 156typedef void bus_dmamap_callback_t(void *, bus_dma_segment_t *, int, int);
@@ -226,12 +227,12 @@ typedef struct timer_list ahd_timer_t;
226#define ahd_timer_init init_timer 227#define ahd_timer_init init_timer
227#define ahd_timer_stop del_timer_sync 228#define ahd_timer_stop del_timer_sync
228typedef void ahd_linux_callback_t (u_long); 229typedef void ahd_linux_callback_t (u_long);
229static __inline void ahd_timer_reset(ahd_timer_t *timer, u_int usec, 230static __inline void ahd_timer_reset(ahd_timer_t *timer, int usec,
230 ahd_callback_t *func, void *arg); 231 ahd_callback_t *func, void *arg);
231static __inline void ahd_scb_timer_reset(struct scb *scb, u_int usec); 232static __inline void ahd_scb_timer_reset(struct scb *scb, u_int usec);
232 233
233static __inline void 234static __inline void
234ahd_timer_reset(ahd_timer_t *timer, u_int usec, ahd_callback_t *func, void *arg) 235ahd_timer_reset(ahd_timer_t *timer, int usec, ahd_callback_t *func, void *arg)
235{ 236{
236 struct ahd_softc *ahd; 237 struct ahd_softc *ahd;
237 238
@@ -252,43 +253,8 @@ ahd_scb_timer_reset(struct scb *scb, u_int usec)
252/***************************** SMP support ************************************/ 253/***************************** SMP support ************************************/
253#include <linux/spinlock.h> 254#include <linux/spinlock.h>
254 255
255#if (LINUX_VERSION_CODE >= KERNEL_VERSION(2,5,0) || defined(SCSI_HAS_HOST_LOCK))
256#define AHD_SCSI_HAS_HOST_LOCK 1
257#else
258#define AHD_SCSI_HAS_HOST_LOCK 0
259#endif
260
261#define AIC79XX_DRIVER_VERSION "1.3.11" 256#define AIC79XX_DRIVER_VERSION "1.3.11"
262 257
263/**************************** Front End Queues ********************************/
264/*
265 * Data structure used to cast the Linux struct scsi_cmnd to something
266 * that allows us to use the queue macros. The linux structure has
267 * plenty of space to hold the links fields as required by the queue
268 * macros, but the queue macors require them to have the correct type.
269 */
270struct ahd_cmd_internal {
271 /* Area owned by the Linux scsi layer. */
272 uint8_t private[offsetof(struct scsi_cmnd, SCp.Status)];
273 union {
274 STAILQ_ENTRY(ahd_cmd) ste;
275 LIST_ENTRY(ahd_cmd) le;
276 TAILQ_ENTRY(ahd_cmd) tqe;
277 } links;
278 uint32_t end;
279};
280
281struct ahd_cmd {
282 union {
283 struct ahd_cmd_internal icmd;
284 struct scsi_cmnd scsi_cmd;
285 } un;
286};
287
288#define acmd_icmd(cmd) ((cmd)->un.icmd)
289#define acmd_scsi_cmd(cmd) ((cmd)->un.scsi_cmd)
290#define acmd_links un.icmd.links
291
292/*************************** Device Data Structures ***************************/ 258/*************************** Device Data Structures ***************************/
293/* 259/*
294 * A per probed device structure used to deal with some error recovery 260 * A per probed device structure used to deal with some error recovery
@@ -297,22 +263,17 @@ struct ahd_cmd {
297 * after a successfully completed inquiry command to the target when 263 * after a successfully completed inquiry command to the target when
298 * that inquiry data indicates a lun is present. 264 * that inquiry data indicates a lun is present.
299 */ 265 */
300TAILQ_HEAD(ahd_busyq, ahd_cmd); 266
301typedef enum { 267typedef enum {
302 AHD_DEV_UNCONFIGURED = 0x01,
303 AHD_DEV_FREEZE_TIL_EMPTY = 0x02, /* Freeze queue until active == 0 */ 268 AHD_DEV_FREEZE_TIL_EMPTY = 0x02, /* Freeze queue until active == 0 */
304 AHD_DEV_TIMER_ACTIVE = 0x04, /* Our timer is active */
305 AHD_DEV_ON_RUN_LIST = 0x08, /* Queued to be run later */
306 AHD_DEV_Q_BASIC = 0x10, /* Allow basic device queuing */ 269 AHD_DEV_Q_BASIC = 0x10, /* Allow basic device queuing */
307 AHD_DEV_Q_TAGGED = 0x20, /* Allow full SCSI2 command queueing */ 270 AHD_DEV_Q_TAGGED = 0x20, /* Allow full SCSI2 command queueing */
308 AHD_DEV_PERIODIC_OTAG = 0x40, /* Send OTAG to prevent starvation */ 271 AHD_DEV_PERIODIC_OTAG = 0x40, /* Send OTAG to prevent starvation */
309 AHD_DEV_SLAVE_CONFIGURED = 0x80 /* slave_configure() has been called */
310} ahd_linux_dev_flags; 272} ahd_linux_dev_flags;
311 273
312struct ahd_linux_target; 274struct ahd_linux_target;
313struct ahd_linux_device { 275struct ahd_linux_device {
314 TAILQ_ENTRY(ahd_linux_device) links; 276 TAILQ_ENTRY(ahd_linux_device) links;
315 struct ahd_busyq busyq;
316 277
317 /* 278 /*
318 * The number of transactions currently 279 * The number of transactions currently
@@ -388,62 +349,12 @@ struct ahd_linux_device {
388 */ 349 */
389 u_int commands_since_idle_or_otag; 350 u_int commands_since_idle_or_otag;
390#define AHD_OTAG_THRESH 500 351#define AHD_OTAG_THRESH 500
391
392 int lun;
393 Scsi_Device *scsi_device;
394 struct ahd_linux_target *target;
395}; 352};
396 353
397typedef enum {
398 AHD_DV_REQUIRED = 0x01,
399 AHD_INQ_VALID = 0x02,
400 AHD_BASIC_DV = 0x04,
401 AHD_ENHANCED_DV = 0x08
402} ahd_linux_targ_flags;
403
404/* DV States */
405typedef enum {
406 AHD_DV_STATE_EXIT = 0,
407 AHD_DV_STATE_INQ_SHORT_ASYNC,
408 AHD_DV_STATE_INQ_ASYNC,
409 AHD_DV_STATE_INQ_ASYNC_VERIFY,
410 AHD_DV_STATE_TUR,
411 AHD_DV_STATE_REBD,
412 AHD_DV_STATE_INQ_VERIFY,
413 AHD_DV_STATE_WEB,
414 AHD_DV_STATE_REB,
415 AHD_DV_STATE_SU,
416 AHD_DV_STATE_BUSY
417} ahd_dv_state;
418
419struct ahd_linux_target { 354struct ahd_linux_target {
420 struct ahd_linux_device *devices[AHD_NUM_LUNS]; 355 struct scsi_device *sdev[AHD_NUM_LUNS];
421 int channel;
422 int target;
423 int refcount;
424 struct ahd_transinfo last_tinfo; 356 struct ahd_transinfo last_tinfo;
425 struct ahd_softc *ahd; 357 struct ahd_softc *ahd;
426 ahd_linux_targ_flags flags;
427 struct scsi_inquiry_data *inq_data;
428 /*
429 * The next "fallback" period to use for narrow/wide transfers.
430 */
431 uint8_t dv_next_narrow_period;
432 uint8_t dv_next_wide_period;
433 uint8_t dv_max_width;
434 uint8_t dv_max_ppr_options;
435 uint8_t dv_last_ppr_options;
436 u_int dv_echo_size;
437 ahd_dv_state dv_state;
438 u_int dv_state_retry;
439 uint8_t *dv_buffer;
440 uint8_t *dv_buffer1;
441
442 /*
443 * Cumulative counter of errors.
444 */
445 u_long errors_detected;
446 u_long cmds_since_error;
447}; 358};
448 359
449/********************* Definitions Required by the Core ***********************/ 360/********************* Definitions Required by the Core ***********************/
@@ -453,32 +364,16 @@ struct ahd_linux_target {
453 * manner and are allocated below 4GB, the number of S/G segments is 364 * manner and are allocated below 4GB, the number of S/G segments is
454 * unrestricted. 365 * unrestricted.
455 */ 366 */
456#if LINUX_VERSION_CODE < KERNEL_VERSION(2,5,0)
457/*
458 * We dynamically adjust the number of segments in pre-2.5 kernels to
459 * avoid fragmentation issues in the SCSI mid-layer's private memory
460 * allocator. See aic79xx_osm.c ahd_linux_size_nseg() for details.
461 */
462extern u_int ahd_linux_nseg;
463#define AHD_NSEG ahd_linux_nseg
464#define AHD_LINUX_MIN_NSEG 64
465#else
466#define AHD_NSEG 128 367#define AHD_NSEG 128
467#endif
468 368
469/* 369/*
470 * Per-SCB OSM storage. 370 * Per-SCB OSM storage.
471 */ 371 */
472typedef enum {
473 AHD_SCB_UP_EH_SEM = 0x1
474} ahd_linux_scb_flags;
475
476struct scb_platform_data { 372struct scb_platform_data {
477 struct ahd_linux_device *dev; 373 struct ahd_linux_device *dev;
478 dma_addr_t buf_busaddr; 374 dma_addr_t buf_busaddr;
479 uint32_t xfer_len; 375 uint32_t xfer_len;
480 uint32_t sense_resid; /* Auto-Sense residual */ 376 uint32_t sense_resid; /* Auto-Sense residual */
481 ahd_linux_scb_flags flags;
482}; 377};
483 378
484/* 379/*
@@ -487,44 +382,23 @@ struct scb_platform_data {
487 * alignment restrictions of the various platforms supported by 382 * alignment restrictions of the various platforms supported by
488 * this driver. 383 * this driver.
489 */ 384 */
490typedef enum {
491 AHD_DV_WAIT_SIMQ_EMPTY = 0x01,
492 AHD_DV_WAIT_SIMQ_RELEASE = 0x02,
493 AHD_DV_ACTIVE = 0x04,
494 AHD_DV_SHUTDOWN = 0x08,
495 AHD_RUN_CMPLT_Q_TIMER = 0x10
496} ahd_linux_softc_flags;
497
498TAILQ_HEAD(ahd_completeq, ahd_cmd);
499
500struct ahd_platform_data { 385struct ahd_platform_data {
501 /* 386 /*
502 * Fields accessed from interrupt context. 387 * Fields accessed from interrupt context.
503 */ 388 */
504 struct ahd_linux_target *targets[AHD_NUM_TARGETS]; 389 struct scsi_target *starget[AHD_NUM_TARGETS];
505 TAILQ_HEAD(, ahd_linux_device) device_runq;
506 struct ahd_completeq completeq;
507 390
508 spinlock_t spin_lock; 391 spinlock_t spin_lock;
509 struct tasklet_struct runq_tasklet;
510 u_int qfrozen; 392 u_int qfrozen;
511 pid_t dv_pid;
512 struct timer_list completeq_timer;
513 struct timer_list reset_timer; 393 struct timer_list reset_timer;
514 struct timer_list stats_timer;
515 struct semaphore eh_sem; 394 struct semaphore eh_sem;
516 struct semaphore dv_sem;
517 struct semaphore dv_cmd_sem; /* XXX This needs to be in
518 * the target struct
519 */
520 struct scsi_device *dv_scsi_dev;
521 struct Scsi_Host *host; /* pointer to scsi host */ 395 struct Scsi_Host *host; /* pointer to scsi host */
522#define AHD_LINUX_NOIRQ ((uint32_t)~0) 396#define AHD_LINUX_NOIRQ ((uint32_t)~0)
523 uint32_t irq; /* IRQ for this adapter */ 397 uint32_t irq; /* IRQ for this adapter */
524 uint32_t bios_address; 398 uint32_t bios_address;
525 uint32_t mem_busaddr; /* Mem Base Addr */ 399 uint32_t mem_busaddr; /* Mem Base Addr */
526 uint64_t hw_dma_mask; 400#define AHD_SCB_UP_EH_SEM 0x1
527 ahd_linux_softc_flags flags; 401 uint32_t flags;
528}; 402};
529 403
530/************************** OS Utility Wrappers *******************************/ 404/************************** OS Utility Wrappers *******************************/
@@ -641,7 +515,7 @@ ahd_insb(struct ahd_softc * ahd, long port, uint8_t *array, int count)
641 515
642/**************************** Initialization **********************************/ 516/**************************** Initialization **********************************/
643int ahd_linux_register_host(struct ahd_softc *, 517int ahd_linux_register_host(struct ahd_softc *,
644 Scsi_Host_Template *); 518 struct scsi_host_template *);
645 519
646uint64_t ahd_linux_get_memsize(void); 520uint64_t ahd_linux_get_memsize(void);
647 521
@@ -657,28 +531,6 @@ void ahd_format_transinfo(struct info_str *info,
657 struct ahd_transinfo *tinfo); 531 struct ahd_transinfo *tinfo);
658 532
659/******************************** Locking *************************************/ 533/******************************** Locking *************************************/
660/* Lock protecting internal data structures */
661static __inline void ahd_lockinit(struct ahd_softc *);
662static __inline void ahd_lock(struct ahd_softc *, unsigned long *flags);
663static __inline void ahd_unlock(struct ahd_softc *, unsigned long *flags);
664
665/* Lock acquisition and release of the above lock in midlayer entry points. */
666static __inline void ahd_midlayer_entrypoint_lock(struct ahd_softc *,
667 unsigned long *flags);
668static __inline void ahd_midlayer_entrypoint_unlock(struct ahd_softc *,
669 unsigned long *flags);
670
671/* Lock held during command compeletion to the upper layer */
672static __inline void ahd_done_lockinit(struct ahd_softc *);
673static __inline void ahd_done_lock(struct ahd_softc *, unsigned long *flags);
674static __inline void ahd_done_unlock(struct ahd_softc *, unsigned long *flags);
675
676/* Lock held during ahd_list manipulation and ahd softc frees */
677extern spinlock_t ahd_list_spinlock;
678static __inline void ahd_list_lockinit(void);
679static __inline void ahd_list_lock(unsigned long *flags);
680static __inline void ahd_list_unlock(unsigned long *flags);
681
682static __inline void 534static __inline void
683ahd_lockinit(struct ahd_softc *ahd) 535ahd_lockinit(struct ahd_softc *ahd)
684{ 536{
@@ -697,75 +549,6 @@ ahd_unlock(struct ahd_softc *ahd, unsigned long *flags)
697 spin_unlock_irqrestore(&ahd->platform_data->spin_lock, *flags); 549 spin_unlock_irqrestore(&ahd->platform_data->spin_lock, *flags);
698} 550}
699 551
700static __inline void
701ahd_midlayer_entrypoint_lock(struct ahd_softc *ahd, unsigned long *flags)
702{
703 /*
704 * In 2.5.X and some 2.4.X versions, the midlayer takes our
705 * lock just before calling us, so we avoid locking again.
706 * For other kernel versions, the io_request_lock is taken
707 * just before our entry point is called. In this case, we
708 * trade the io_request_lock for our per-softc lock.
709 */
710#if AHD_SCSI_HAS_HOST_LOCK == 0
711 spin_unlock(&io_request_lock);
712 spin_lock(&ahd->platform_data->spin_lock);
713#endif
714}
715
716static __inline void
717ahd_midlayer_entrypoint_unlock(struct ahd_softc *ahd, unsigned long *flags)
718{
719#if AHD_SCSI_HAS_HOST_LOCK == 0
720 spin_unlock(&ahd->platform_data->spin_lock);
721 spin_lock(&io_request_lock);
722#endif
723}
724
725static __inline void
726ahd_done_lockinit(struct ahd_softc *ahd)
727{
728 /*
729 * In 2.5.X, our own lock is held during completions.
730 * In previous versions, the io_request_lock is used.
731 * In either case, we can't initialize this lock again.
732 */
733}
734
735static __inline void
736ahd_done_lock(struct ahd_softc *ahd, unsigned long *flags)
737{
738#if AHD_SCSI_HAS_HOST_LOCK == 0
739 spin_lock(&io_request_lock);
740#endif
741}
742
743static __inline void
744ahd_done_unlock(struct ahd_softc *ahd, unsigned long *flags)
745{
746#if AHD_SCSI_HAS_HOST_LOCK == 0
747 spin_unlock(&io_request_lock);
748#endif
749}
750
751static __inline void
752ahd_list_lockinit(void)
753{
754 spin_lock_init(&ahd_list_spinlock);
755}
756
757static __inline void
758ahd_list_lock(unsigned long *flags)
759{
760 spin_lock_irqsave(&ahd_list_spinlock, *flags);
761}
762
763static __inline void
764ahd_list_unlock(unsigned long *flags)
765{
766 spin_unlock_irqrestore(&ahd_list_spinlock, *flags);
767}
768
769/******************************* PCI Definitions ******************************/ 552/******************************* PCI Definitions ******************************/
770/* 553/*
771 * PCIM_xxx: mask to locate subfield in register 554 * PCIM_xxx: mask to locate subfield in register
@@ -925,27 +708,17 @@ ahd_flush_device_writes(struct ahd_softc *ahd)
925} 708}
926 709
927/**************************** Proc FS Support *********************************/ 710/**************************** Proc FS Support *********************************/
928#if LINUX_VERSION_CODE < KERNEL_VERSION(2,5,0)
929int ahd_linux_proc_info(char *, char **, off_t, int, int, int);
930#else
931int ahd_linux_proc_info(struct Scsi_Host *, char *, char **, 711int ahd_linux_proc_info(struct Scsi_Host *, char *, char **,
932 off_t, int, int); 712 off_t, int, int);
933#endif
934
935/*************************** Domain Validation ********************************/
936#define AHD_DV_CMD(cmd) ((cmd)->scsi_done == ahd_linux_dv_complete)
937#define AHD_DV_SIMQ_FROZEN(ahd) \
938 ((((ahd)->platform_data->flags & AHD_DV_ACTIVE) != 0) \
939 && (ahd)->platform_data->qfrozen == 1)
940 713
941/*********************** Transaction Access Wrappers **************************/ 714/*********************** Transaction Access Wrappers **************************/
942static __inline void ahd_cmd_set_transaction_status(Scsi_Cmnd *, uint32_t); 715static __inline void ahd_cmd_set_transaction_status(struct scsi_cmnd *, uint32_t);
943static __inline void ahd_set_transaction_status(struct scb *, uint32_t); 716static __inline void ahd_set_transaction_status(struct scb *, uint32_t);
944static __inline void ahd_cmd_set_scsi_status(Scsi_Cmnd *, uint32_t); 717static __inline void ahd_cmd_set_scsi_status(struct scsi_cmnd *, uint32_t);
945static __inline void ahd_set_scsi_status(struct scb *, uint32_t); 718static __inline void ahd_set_scsi_status(struct scb *, uint32_t);
946static __inline uint32_t ahd_cmd_get_transaction_status(Scsi_Cmnd *cmd); 719static __inline uint32_t ahd_cmd_get_transaction_status(struct scsi_cmnd *cmd);
947static __inline uint32_t ahd_get_transaction_status(struct scb *); 720static __inline uint32_t ahd_get_transaction_status(struct scb *);
948static __inline uint32_t ahd_cmd_get_scsi_status(Scsi_Cmnd *cmd); 721static __inline uint32_t ahd_cmd_get_scsi_status(struct scsi_cmnd *cmd);
949static __inline uint32_t ahd_get_scsi_status(struct scb *); 722static __inline uint32_t ahd_get_scsi_status(struct scb *);
950static __inline void ahd_set_transaction_tag(struct scb *, int, u_int); 723static __inline void ahd_set_transaction_tag(struct scb *, int, u_int);
951static __inline u_long ahd_get_transfer_length(struct scb *); 724static __inline u_long ahd_get_transfer_length(struct scb *);
@@ -964,7 +737,7 @@ static __inline void ahd_platform_scb_free(struct ahd_softc *ahd,
964static __inline void ahd_freeze_scb(struct scb *scb); 737static __inline void ahd_freeze_scb(struct scb *scb);
965 738
966static __inline 739static __inline
967void ahd_cmd_set_transaction_status(Scsi_Cmnd *cmd, uint32_t status) 740void ahd_cmd_set_transaction_status(struct scsi_cmnd *cmd, uint32_t status)
968{ 741{
969 cmd->result &= ~(CAM_STATUS_MASK << 16); 742 cmd->result &= ~(CAM_STATUS_MASK << 16);
970 cmd->result |= status << 16; 743 cmd->result |= status << 16;
@@ -977,7 +750,7 @@ void ahd_set_transaction_status(struct scb *scb, uint32_t status)
977} 750}
978 751
979static __inline 752static __inline
980void ahd_cmd_set_scsi_status(Scsi_Cmnd *cmd, uint32_t status) 753void ahd_cmd_set_scsi_status(struct scsi_cmnd *cmd, uint32_t status)
981{ 754{
982 cmd->result &= ~0xFFFF; 755 cmd->result &= ~0xFFFF;
983 cmd->result |= status; 756 cmd->result |= status;
@@ -990,7 +763,7 @@ void ahd_set_scsi_status(struct scb *scb, uint32_t status)
990} 763}
991 764
992static __inline 765static __inline
993uint32_t ahd_cmd_get_transaction_status(Scsi_Cmnd *cmd) 766uint32_t ahd_cmd_get_transaction_status(struct scsi_cmnd *cmd)
994{ 767{
995 return ((cmd->result >> 16) & CAM_STATUS_MASK); 768 return ((cmd->result >> 16) & CAM_STATUS_MASK);
996} 769}
@@ -1002,7 +775,7 @@ uint32_t ahd_get_transaction_status(struct scb *scb)
1002} 775}
1003 776
1004static __inline 777static __inline
1005uint32_t ahd_cmd_get_scsi_status(Scsi_Cmnd *cmd) 778uint32_t ahd_cmd_get_scsi_status(struct scsi_cmnd *cmd)
1006{ 779{
1007 return (cmd->result & 0xFFFF); 780 return (cmd->result & 0xFFFF);
1008} 781}
@@ -1117,7 +890,6 @@ void ahd_done(struct ahd_softc*, struct scb*);
1117void ahd_send_async(struct ahd_softc *, char channel, 890void ahd_send_async(struct ahd_softc *, char channel,
1118 u_int target, u_int lun, ac_code, void *); 891 u_int target, u_int lun, ac_code, void *);
1119void ahd_print_path(struct ahd_softc *, struct scb *); 892void ahd_print_path(struct ahd_softc *, struct scb *);
1120void ahd_platform_dump_card_state(struct ahd_softc *ahd);
1121 893
1122#ifdef CONFIG_PCI 894#ifdef CONFIG_PCI
1123#define AHD_PCI_CONFIG 1 895#define AHD_PCI_CONFIG 1
diff --git a/drivers/scsi/aic7xxx/aic79xx_osm_pci.c b/drivers/scsi/aic7xxx/aic79xx_osm_pci.c
index 91daf0c7fb1..390b53852d4 100644
--- a/drivers/scsi/aic7xxx/aic79xx_osm_pci.c
+++ b/drivers/scsi/aic7xxx/aic79xx_osm_pci.c
@@ -92,27 +92,31 @@ struct pci_driver aic79xx_pci_driver = {
92static void 92static void
93ahd_linux_pci_dev_remove(struct pci_dev *pdev) 93ahd_linux_pci_dev_remove(struct pci_dev *pdev)
94{ 94{
95 struct ahd_softc *ahd; 95 struct ahd_softc *ahd = pci_get_drvdata(pdev);
96 u_long l; 96 u_long s;
97 97
98 /* 98 ahd_lock(ahd, &s);
99 * We should be able to just perform 99 ahd_intr_enable(ahd, FALSE);
100 * the free directly, but check our 100 ahd_unlock(ahd, &s);
101 * list for extra sanity. 101 ahd_free(ahd);
102 */ 102}
103 ahd_list_lock(&l); 103
104 ahd = ahd_find_softc((struct ahd_softc *)pci_get_drvdata(pdev)); 104static void
105 if (ahd != NULL) { 105ahd_linux_pci_inherit_flags(struct ahd_softc *ahd)
106 u_long s; 106{
107 107 struct pci_dev *pdev = ahd->dev_softc, *master_pdev;
108 TAILQ_REMOVE(&ahd_tailq, ahd, links); 108 unsigned int master_devfn = PCI_DEVFN(PCI_SLOT(pdev->devfn), 0);
109 ahd_list_unlock(&l); 109
110 ahd_lock(ahd, &s); 110 master_pdev = pci_get_slot(pdev->bus, master_devfn);
111 ahd_intr_enable(ahd, FALSE); 111 if (master_pdev) {
112 ahd_unlock(ahd, &s); 112 struct ahd_softc *master = pci_get_drvdata(master_pdev);
113 ahd_free(ahd); 113 if (master) {
114 } else 114 ahd->flags &= ~AHD_BIOS_ENABLED;
115 ahd_list_unlock(&l); 115 ahd->flags |= master->flags & AHD_BIOS_ENABLED;
116 } else
117 printk(KERN_ERR "aic79xx: no multichannel peer found!\n");
118 pci_dev_put(master_pdev);
119 }
116} 120}
117 121
118static int 122static int
@@ -125,22 +129,6 @@ ahd_linux_pci_dev_probe(struct pci_dev *pdev, const struct pci_device_id *ent)
125 char *name; 129 char *name;
126 int error; 130 int error;
127 131
128 /*
129 * Some BIOSen report the same device multiple times.
130 */
131 TAILQ_FOREACH(ahd, &ahd_tailq, links) {
132 struct pci_dev *probed_pdev;
133
134 probed_pdev = ahd->dev_softc;
135 if (probed_pdev->bus->number == pdev->bus->number
136 && probed_pdev->devfn == pdev->devfn)
137 break;
138 }
139 if (ahd != NULL) {
140 /* Skip duplicate. */
141 return (-ENODEV);
142 }
143
144 pci = pdev; 132 pci = pdev;
145 entry = ahd_find_pci_device(pci); 133 entry = ahd_find_pci_device(pci);
146 if (entry == NULL) 134 if (entry == NULL)
@@ -177,15 +165,12 @@ ahd_linux_pci_dev_probe(struct pci_dev *pdev, const struct pci_device_id *ent)
177 if (memsize >= 0x8000000000ULL 165 if (memsize >= 0x8000000000ULL
178 && pci_set_dma_mask(pdev, DMA_64BIT_MASK) == 0) { 166 && pci_set_dma_mask(pdev, DMA_64BIT_MASK) == 0) {
179 ahd->flags |= AHD_64BIT_ADDRESSING; 167 ahd->flags |= AHD_64BIT_ADDRESSING;
180 ahd->platform_data->hw_dma_mask = DMA_64BIT_MASK;
181 } else if (memsize > 0x80000000 168 } else if (memsize > 0x80000000
182 && pci_set_dma_mask(pdev, mask_39bit) == 0) { 169 && pci_set_dma_mask(pdev, mask_39bit) == 0) {
183 ahd->flags |= AHD_39BIT_ADDRESSING; 170 ahd->flags |= AHD_39BIT_ADDRESSING;
184 ahd->platform_data->hw_dma_mask = mask_39bit;
185 } 171 }
186 } else { 172 } else {
187 pci_set_dma_mask(pdev, DMA_32BIT_MASK); 173 pci_set_dma_mask(pdev, DMA_32BIT_MASK);
188 ahd->platform_data->hw_dma_mask = DMA_32BIT_MASK;
189 } 174 }
190 ahd->dev_softc = pci; 175 ahd->dev_softc = pci;
191 error = ahd_pci_config(ahd, entry); 176 error = ahd_pci_config(ahd, entry);
@@ -193,16 +178,17 @@ ahd_linux_pci_dev_probe(struct pci_dev *pdev, const struct pci_device_id *ent)
193 ahd_free(ahd); 178 ahd_free(ahd);
194 return (-error); 179 return (-error);
195 } 180 }
181
182 /*
183 * Second Function PCI devices need to inherit some
184 * * settings from function 0.
185 */
186 if ((ahd->features & AHD_MULTI_FUNC) && PCI_FUNC(pdev->devfn) != 0)
187 ahd_linux_pci_inherit_flags(ahd);
188
196 pci_set_drvdata(pdev, ahd); 189 pci_set_drvdata(pdev, ahd);
197 if (aic79xx_detect_complete) { 190
198#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,5,0) 191 ahd_linux_register_host(ahd, &aic79xx_driver_template);
199 ahd_linux_register_host(ahd, &aic79xx_driver_template);
200#else
201 printf("aic79xx: ignoring PCI device found after "
202 "initialization\n");
203 return (-ENODEV);
204#endif
205 }
206 return (0); 192 return (0);
207} 193}
208 194
diff --git a/drivers/scsi/aic7xxx/aic79xx_pci.c b/drivers/scsi/aic7xxx/aic79xx_pci.c
index 703f6e44889..2131db60018 100644
--- a/drivers/scsi/aic7xxx/aic79xx_pci.c
+++ b/drivers/scsi/aic7xxx/aic79xx_pci.c
@@ -283,7 +283,6 @@ int
283ahd_pci_config(struct ahd_softc *ahd, struct ahd_pci_identity *entry) 283ahd_pci_config(struct ahd_softc *ahd, struct ahd_pci_identity *entry)
284{ 284{
285 struct scb_data *shared_scb_data; 285 struct scb_data *shared_scb_data;
286 u_long l;
287 u_int command; 286 u_int command;
288 uint32_t devconfig; 287 uint32_t devconfig;
289 uint16_t subvendor; 288 uint16_t subvendor;
@@ -373,16 +372,9 @@ ahd_pci_config(struct ahd_softc *ahd, struct ahd_pci_identity *entry)
373 * Allow interrupts now that we are completely setup. 372 * Allow interrupts now that we are completely setup.
374 */ 373 */
375 error = ahd_pci_map_int(ahd); 374 error = ahd_pci_map_int(ahd);
376 if (error != 0) 375 if (!error)
377 return (error); 376 ahd->init_level++;
378 377 return error;
379 ahd_list_lock(&l);
380 /*
381 * Link this softc in with all other ahd instances.
382 */
383 ahd_softc_insert(ahd);
384 ahd_list_unlock(&l);
385 return (0);
386} 378}
387 379
388/* 380/*
diff --git a/drivers/scsi/aic7xxx/aic79xx_proc.c b/drivers/scsi/aic7xxx/aic79xx_proc.c
index e01cd6175e3..39a27840fce 100644
--- a/drivers/scsi/aic7xxx/aic79xx_proc.c
+++ b/drivers/scsi/aic7xxx/aic79xx_proc.c
@@ -49,10 +49,53 @@ static void ahd_dump_target_state(struct ahd_softc *ahd,
49 u_int our_id, char channel, 49 u_int our_id, char channel,
50 u_int target_id, u_int target_offset); 50 u_int target_id, u_int target_offset);
51static void ahd_dump_device_state(struct info_str *info, 51static void ahd_dump_device_state(struct info_str *info,
52 struct ahd_linux_device *dev); 52 struct scsi_device *sdev);
53static int ahd_proc_write_seeprom(struct ahd_softc *ahd, 53static int ahd_proc_write_seeprom(struct ahd_softc *ahd,
54 char *buffer, int length); 54 char *buffer, int length);
55 55
56/*
57 * Table of syncrates that don't follow the "divisible by 4"
58 * rule. This table will be expanded in future SCSI specs.
59 */
60static struct {
61 u_int period_factor;
62 u_int period; /* in 100ths of ns */
63} scsi_syncrates[] = {
64 { 0x08, 625 }, /* FAST-160 */
65 { 0x09, 1250 }, /* FAST-80 */
66 { 0x0a, 2500 }, /* FAST-40 40MHz */
67 { 0x0b, 3030 }, /* FAST-40 33MHz */
68 { 0x0c, 5000 } /* FAST-20 */
69};
70
71/*
72 * Return the frequency in kHz corresponding to the given
73 * sync period factor.
74 */
75static u_int
76ahd_calc_syncsrate(u_int period_factor)
77{
78 int i;
79 int num_syncrates;
80
81 num_syncrates = sizeof(scsi_syncrates) / sizeof(scsi_syncrates[0]);
82 /* See if the period is in the "exception" table */
83 for (i = 0; i < num_syncrates; i++) {
84
85 if (period_factor == scsi_syncrates[i].period_factor) {
86 /* Period in kHz */
87 return (100000000 / scsi_syncrates[i].period);
88 }
89 }
90
91 /*
92 * Wasn't in the table, so use the standard
93 * 4 times conversion.
94 */
95 return (10000000 / (period_factor * 4 * 10));
96}
97
98
56static void 99static void
57copy_mem_info(struct info_str *info, char *data, int len) 100copy_mem_info(struct info_str *info, char *data, int len)
58{ 101{
@@ -109,7 +152,7 @@ ahd_format_transinfo(struct info_str *info, struct ahd_transinfo *tinfo)
109 speed = 3300; 152 speed = 3300;
110 freq = 0; 153 freq = 0;
111 if (tinfo->offset != 0) { 154 if (tinfo->offset != 0) {
112 freq = aic_calc_syncsrate(tinfo->period); 155 freq = ahd_calc_syncsrate(tinfo->period);
113 speed = freq; 156 speed = freq;
114 } 157 }
115 speed *= (0x01 << tinfo->width); 158 speed *= (0x01 << tinfo->width);
@@ -167,6 +210,7 @@ ahd_dump_target_state(struct ahd_softc *ahd, struct info_str *info,
167 u_int target_offset) 210 u_int target_offset)
168{ 211{
169 struct ahd_linux_target *targ; 212 struct ahd_linux_target *targ;
213 struct scsi_target *starget;
170 struct ahd_initiator_tinfo *tinfo; 214 struct ahd_initiator_tinfo *tinfo;
171 struct ahd_tmode_tstate *tstate; 215 struct ahd_tmode_tstate *tstate;
172 int lun; 216 int lun;
@@ -176,20 +220,20 @@ ahd_dump_target_state(struct ahd_softc *ahd, struct info_str *info,
176 copy_info(info, "Target %d Negotiation Settings\n", target_id); 220 copy_info(info, "Target %d Negotiation Settings\n", target_id);
177 copy_info(info, "\tUser: "); 221 copy_info(info, "\tUser: ");
178 ahd_format_transinfo(info, &tinfo->user); 222 ahd_format_transinfo(info, &tinfo->user);
179 targ = ahd->platform_data->targets[target_offset]; 223 starget = ahd->platform_data->starget[target_offset];
180 if (targ == NULL) 224 if (starget == NULL)
181 return; 225 return;
226 targ = scsi_transport_target_data(starget);
182 227
183 copy_info(info, "\tGoal: "); 228 copy_info(info, "\tGoal: ");
184 ahd_format_transinfo(info, &tinfo->goal); 229 ahd_format_transinfo(info, &tinfo->goal);
185 copy_info(info, "\tCurr: "); 230 copy_info(info, "\tCurr: ");
186 ahd_format_transinfo(info, &tinfo->curr); 231 ahd_format_transinfo(info, &tinfo->curr);
187 copy_info(info, "\tTransmission Errors %ld\n", targ->errors_detected);
188 232
189 for (lun = 0; lun < AHD_NUM_LUNS; lun++) { 233 for (lun = 0; lun < AHD_NUM_LUNS; lun++) {
190 struct ahd_linux_device *dev; 234 struct scsi_device *dev;
191 235
192 dev = targ->devices[lun]; 236 dev = targ->sdev[lun];
193 237
194 if (dev == NULL) 238 if (dev == NULL)
195 continue; 239 continue;
@@ -199,10 +243,13 @@ ahd_dump_target_state(struct ahd_softc *ahd, struct info_str *info,
199} 243}
200 244
201static void 245static void
202ahd_dump_device_state(struct info_str *info, struct ahd_linux_device *dev) 246ahd_dump_device_state(struct info_str *info, struct scsi_device *sdev)
203{ 247{
248 struct ahd_linux_device *dev = scsi_transport_device_data(sdev);
249
204 copy_info(info, "\tChannel %c Target %d Lun %d Settings\n", 250 copy_info(info, "\tChannel %c Target %d Lun %d Settings\n",
205 dev->target->channel + 'A', dev->target->target, dev->lun); 251 sdev->sdev_target->channel + 'A',
252 sdev->sdev_target->id, sdev->lun);
206 253
207 copy_info(info, "\t\tCommands Queued %ld\n", dev->commands_issued); 254 copy_info(info, "\t\tCommands Queued %ld\n", dev->commands_issued);
208 copy_info(info, "\t\tCommands Active %d\n", dev->active); 255 copy_info(info, "\t\tCommands Active %d\n", dev->active);
@@ -278,36 +325,16 @@ done:
278 * Return information to handle /proc support for the driver. 325 * Return information to handle /proc support for the driver.
279 */ 326 */
280int 327int
281#if LINUX_VERSION_CODE < KERNEL_VERSION(2,5,0)
282ahd_linux_proc_info(char *buffer, char **start, off_t offset,
283 int length, int hostno, int inout)
284#else
285ahd_linux_proc_info(struct Scsi_Host *shost, char *buffer, char **start, 328ahd_linux_proc_info(struct Scsi_Host *shost, char *buffer, char **start,
286 off_t offset, int length, int inout) 329 off_t offset, int length, int inout)
287#endif
288{ 330{
289 struct ahd_softc *ahd; 331 struct ahd_softc *ahd = *(struct ahd_softc **)shost->hostdata;
290 struct info_str info; 332 struct info_str info;
291 char ahd_info[256]; 333 char ahd_info[256];
292 u_long l;
293 u_int max_targ; 334 u_int max_targ;
294 u_int i; 335 u_int i;
295 int retval; 336 int retval;
296 337
297 retval = -EINVAL;
298 ahd_list_lock(&l);
299#if LINUX_VERSION_CODE < KERNEL_VERSION(2,5,0)
300 TAILQ_FOREACH(ahd, &ahd_tailq, links) {
301 if (ahd->platform_data->host->host_no == hostno)
302 break;
303 }
304#else
305 ahd = ahd_find_softc(*(struct ahd_softc **)shost->hostdata);
306#endif
307
308 if (ahd == NULL)
309 goto done;
310
311 /* Has data been written to the file? */ 338 /* Has data been written to the file? */
312 if (inout == TRUE) { 339 if (inout == TRUE) {
313 retval = ahd_proc_write_seeprom(ahd, buffer, length); 340 retval = ahd_proc_write_seeprom(ahd, buffer, length);
@@ -357,6 +384,5 @@ ahd_linux_proc_info(struct Scsi_Host *shost, char *buffer, char **start,
357 } 384 }
358 retval = info.pos > info.offset ? info.pos - info.offset : 0; 385 retval = info.pos > info.offset ? info.pos - info.offset : 0;
359done: 386done:
360 ahd_list_unlock(&l);
361 return (retval); 387 return (retval);
362} 388}
diff --git a/drivers/scsi/aic7xxx/aic7xxx.h b/drivers/scsi/aic7xxx/aic7xxx.h
index 088cbc23743..91d294c6334 100644
--- a/drivers/scsi/aic7xxx/aic7xxx.h
+++ b/drivers/scsi/aic7xxx/aic7xxx.h
@@ -37,7 +37,7 @@
37 * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 37 * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
38 * POSSIBILITY OF SUCH DAMAGES. 38 * POSSIBILITY OF SUCH DAMAGES.
39 * 39 *
40 * $Id: //depot/aic7xxx/aic7xxx/aic7xxx.h#79 $ 40 * $Id: //depot/aic7xxx/aic7xxx/aic7xxx.h#85 $
41 * 41 *
42 * $FreeBSD$ 42 * $FreeBSD$
43 */ 43 */
@@ -243,7 +243,7 @@ typedef enum {
243 */ 243 */
244 AHC_AIC7850_FE = AHC_SPIOCAP|AHC_AUTOPAUSE|AHC_TARGETMODE|AHC_ULTRA, 244 AHC_AIC7850_FE = AHC_SPIOCAP|AHC_AUTOPAUSE|AHC_TARGETMODE|AHC_ULTRA,
245 AHC_AIC7860_FE = AHC_AIC7850_FE, 245 AHC_AIC7860_FE = AHC_AIC7850_FE,
246 AHC_AIC7870_FE = AHC_TARGETMODE, 246 AHC_AIC7870_FE = AHC_TARGETMODE|AHC_AUTOPAUSE,
247 AHC_AIC7880_FE = AHC_AIC7870_FE|AHC_ULTRA, 247 AHC_AIC7880_FE = AHC_AIC7870_FE|AHC_ULTRA,
248 /* 248 /*
249 * Although we have space for both the initiator and 249 * Although we have space for both the initiator and
diff --git a/drivers/scsi/aic7xxx/aic7xxx.reg b/drivers/scsi/aic7xxx/aic7xxx.reg
index 810ec700d9f..e196d83b93c 100644
--- a/drivers/scsi/aic7xxx/aic7xxx.reg
+++ b/drivers/scsi/aic7xxx/aic7xxx.reg
@@ -39,7 +39,7 @@
39 * 39 *
40 * $FreeBSD$ 40 * $FreeBSD$
41 */ 41 */
42VERSION = "$Id: //depot/aic7xxx/aic7xxx/aic7xxx.reg#39 $" 42VERSION = "$Id: //depot/aic7xxx/aic7xxx/aic7xxx.reg#40 $"
43 43
44/* 44/*
45 * This file is processed by the aic7xxx_asm utility for use in assembling 45 * This file is processed by the aic7xxx_asm utility for use in assembling
@@ -1306,7 +1306,6 @@ scratch_ram {
1306 */ 1306 */
1307 MWI_RESIDUAL { 1307 MWI_RESIDUAL {
1308 size 1 1308 size 1
1309 alias TARG_IMMEDIATE_SCB
1310 } 1309 }
1311 /* 1310 /*
1312 * SCBID of the next SCB to be started by the controller. 1311 * SCBID of the next SCB to be started by the controller.
@@ -1461,6 +1460,7 @@ scratch_ram {
1461 */ 1460 */
1462 LAST_MSG { 1461 LAST_MSG {
1463 size 1 1462 size 1
1463 alias TARG_IMMEDIATE_SCB
1464 } 1464 }
1465 1465
1466 /* 1466 /*
diff --git a/drivers/scsi/aic7xxx/aic7xxx.seq b/drivers/scsi/aic7xxx/aic7xxx.seq
index d84b741fbab..15196390e28 100644
--- a/drivers/scsi/aic7xxx/aic7xxx.seq
+++ b/drivers/scsi/aic7xxx/aic7xxx.seq
@@ -40,7 +40,7 @@
40 * $FreeBSD$ 40 * $FreeBSD$
41 */ 41 */
42 42
43VERSION = "$Id: //depot/aic7xxx/aic7xxx/aic7xxx.seq#56 $" 43VERSION = "$Id: //depot/aic7xxx/aic7xxx/aic7xxx.seq#58 $"
44PATCH_ARG_LIST = "struct ahc_softc *ahc" 44PATCH_ARG_LIST = "struct ahc_softc *ahc"
45PREFIX = "ahc_" 45PREFIX = "ahc_"
46 46
@@ -679,6 +679,7 @@ await_busfree:
679 clr SCSIBUSL; /* Prevent bit leakage durint SELTO */ 679 clr SCSIBUSL; /* Prevent bit leakage durint SELTO */
680 } 680 }
681 and SXFRCTL0, ~SPIOEN; 681 and SXFRCTL0, ~SPIOEN;
682 mvi SEQ_FLAGS, NOT_IDENTIFIED|NO_CDB_SENT;
682 test SSTAT1,REQINIT|BUSFREE jz .; 683 test SSTAT1,REQINIT|BUSFREE jz .;
683 test SSTAT1, BUSFREE jnz poll_for_work; 684 test SSTAT1, BUSFREE jnz poll_for_work;
684 mvi MISSED_BUSFREE call set_seqint; 685 mvi MISSED_BUSFREE call set_seqint;
@@ -1097,7 +1098,7 @@ ultra2_dmahalt:
1097 test SCB_RESIDUAL_DATACNT[3], SG_LAST_SEG jz dma_mid_sg; 1098 test SCB_RESIDUAL_DATACNT[3], SG_LAST_SEG jz dma_mid_sg;
1098 if ((ahc->flags & AHC_TARGETROLE) != 0) { 1099 if ((ahc->flags & AHC_TARGETROLE) != 0) {
1099 test SSTAT0, TARGET jz dma_last_sg; 1100 test SSTAT0, TARGET jz dma_last_sg;
1100 if ((ahc->flags & AHC_TMODE_WIDEODD_BUG) != 0) { 1101 if ((ahc->bugs & AHC_TMODE_WIDEODD_BUG) != 0) {
1101 test DMAPARAMS, DIRECTION jz dma_mid_sg; 1102 test DMAPARAMS, DIRECTION jz dma_mid_sg;
1102 } 1103 }
1103 } 1104 }
diff --git a/drivers/scsi/aic7xxx/aic7xxx_93cx6.c b/drivers/scsi/aic7xxx/aic7xxx_93cx6.c
index 468d612a44f..3cb07e114e8 100644
--- a/drivers/scsi/aic7xxx/aic7xxx_93cx6.c
+++ b/drivers/scsi/aic7xxx/aic7xxx_93cx6.c
@@ -28,9 +28,7 @@
28 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 28 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
29 * SUCH DAMAGE. 29 * SUCH DAMAGE.
30 * 30 *
31 * $Id: //depot/aic7xxx/aic7xxx/aic7xxx_93cx6.c#17 $ 31 * $Id: //depot/aic7xxx/aic7xxx/aic7xxx_93cx6.c#19 $
32 *
33 * $FreeBSD$
34 */ 32 */
35 33
36/* 34/*
@@ -64,7 +62,6 @@
64 * is preceded by an initial zero (leading 0, followed by 16-bits, MSB 62 * is preceded by an initial zero (leading 0, followed by 16-bits, MSB
65 * first). The clock cycling from low to high initiates the next data 63 * first). The clock cycling from low to high initiates the next data
66 * bit to be sent from the chip. 64 * bit to be sent from the chip.
67 *
68 */ 65 */
69 66
70#ifdef __linux__ 67#ifdef __linux__
@@ -81,14 +78,22 @@
81 * Right now, we only have to read the SEEPROM. But we make it easier to 78 * Right now, we only have to read the SEEPROM. But we make it easier to
82 * add other 93Cx6 functions. 79 * add other 93Cx6 functions.
83 */ 80 */
84static struct seeprom_cmd { 81struct seeprom_cmd {
85 uint8_t len; 82 uint8_t len;
86 uint8_t bits[9]; 83 uint8_t bits[11];
87} seeprom_read = {3, {1, 1, 0}}; 84};
88 85
86/* Short opcodes for the c46 */
89static struct seeprom_cmd seeprom_ewen = {9, {1, 0, 0, 1, 1, 0, 0, 0, 0}}; 87static struct seeprom_cmd seeprom_ewen = {9, {1, 0, 0, 1, 1, 0, 0, 0, 0}};
90static struct seeprom_cmd seeprom_ewds = {9, {1, 0, 0, 0, 0, 0, 0, 0, 0}}; 88static struct seeprom_cmd seeprom_ewds = {9, {1, 0, 0, 0, 0, 0, 0, 0, 0}};
89
90/* Long opcodes for the C56/C66 */
91static struct seeprom_cmd seeprom_long_ewen = {11, {1, 0, 0, 1, 1, 0, 0, 0, 0}};
92static struct seeprom_cmd seeprom_long_ewds = {11, {1, 0, 0, 0, 0, 0, 0, 0, 0}};
93
94/* Common opcodes */
91static struct seeprom_cmd seeprom_write = {3, {1, 0, 1}}; 95static struct seeprom_cmd seeprom_write = {3, {1, 0, 1}};
96static struct seeprom_cmd seeprom_read = {3, {1, 1, 0}};
92 97
93/* 98/*
94 * Wait for the SEERDY to go high; about 800 ns. 99 * Wait for the SEERDY to go high; about 800 ns.
@@ -222,12 +227,25 @@ int
222ahc_write_seeprom(struct seeprom_descriptor *sd, uint16_t *buf, 227ahc_write_seeprom(struct seeprom_descriptor *sd, uint16_t *buf,
223 u_int start_addr, u_int count) 228 u_int start_addr, u_int count)
224{ 229{
230 struct seeprom_cmd *ewen, *ewds;
225 uint16_t v; 231 uint16_t v;
226 uint8_t temp; 232 uint8_t temp;
227 int i, k; 233 int i, k;
228 234
229 /* Place the chip into write-enable mode */ 235 /* Place the chip into write-enable mode */
230 send_seeprom_cmd(sd, &seeprom_ewen); 236 if (sd->sd_chip == C46) {
237 ewen = &seeprom_ewen;
238 ewds = &seeprom_ewds;
239 } else if (sd->sd_chip == C56_66) {
240 ewen = &seeprom_long_ewen;
241 ewds = &seeprom_long_ewds;
242 } else {
243 printf("ahc_write_seeprom: unsupported seeprom type %d\n",
244 sd->sd_chip);
245 return (0);
246 }
247
248 send_seeprom_cmd(sd, ewen);
231 reset_seeprom(sd); 249 reset_seeprom(sd);
232 250
233 /* Write all requested data out to the seeprom. */ 251 /* Write all requested data out to the seeprom. */
@@ -277,7 +295,7 @@ ahc_write_seeprom(struct seeprom_descriptor *sd, uint16_t *buf,
277 } 295 }
278 296
279 /* Put the chip back into write-protect mode */ 297 /* Put the chip back into write-protect mode */
280 send_seeprom_cmd(sd, &seeprom_ewds); 298 send_seeprom_cmd(sd, ewds);
281 reset_seeprom(sd); 299 reset_seeprom(sd);
282 300
283 return (1); 301 return (1);
diff --git a/drivers/scsi/aic7xxx/aic7xxx_core.c b/drivers/scsi/aic7xxx/aic7xxx_core.c
index 7bc01e41bcc..58ac46103eb 100644
--- a/drivers/scsi/aic7xxx/aic7xxx_core.c
+++ b/drivers/scsi/aic7xxx/aic7xxx_core.c
@@ -37,9 +37,7 @@
37 * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 37 * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
38 * POSSIBILITY OF SUCH DAMAGES. 38 * POSSIBILITY OF SUCH DAMAGES.
39 * 39 *
40 * $Id: //depot/aic7xxx/aic7xxx/aic7xxx.c#134 $ 40 * $Id: //depot/aic7xxx/aic7xxx/aic7xxx.c#155 $
41 *
42 * $FreeBSD$
43 */ 41 */
44 42
45#ifdef __linux__ 43#ifdef __linux__
@@ -287,10 +285,19 @@ ahc_restart(struct ahc_softc *ahc)
287 ahc_outb(ahc, SEQ_FLAGS2, 285 ahc_outb(ahc, SEQ_FLAGS2,
288 ahc_inb(ahc, SEQ_FLAGS2) & ~SCB_DMA); 286 ahc_inb(ahc, SEQ_FLAGS2) & ~SCB_DMA);
289 } 287 }
288
289 /*
290 * Clear any pending sequencer interrupt. It is no
291 * longer relevant since we're resetting the Program
292 * Counter.
293 */
294 ahc_outb(ahc, CLRINT, CLRSEQINT);
295
290 ahc_outb(ahc, MWI_RESIDUAL, 0); 296 ahc_outb(ahc, MWI_RESIDUAL, 0);
291 ahc_outb(ahc, SEQCTL, ahc->seqctl); 297 ahc_outb(ahc, SEQCTL, ahc->seqctl);
292 ahc_outb(ahc, SEQADDR0, 0); 298 ahc_outb(ahc, SEQADDR0, 0);
293 ahc_outb(ahc, SEQADDR1, 0); 299 ahc_outb(ahc, SEQADDR1, 0);
300
294 ahc_unpause(ahc); 301 ahc_unpause(ahc);
295} 302}
296 303
@@ -1174,19 +1181,20 @@ ahc_handle_scsiint(struct ahc_softc *ahc, u_int intstat)
1174 scb_index); 1181 scb_index);
1175 } 1182 }
1176#endif 1183#endif
1177 /*
1178 * Force a renegotiation with this target just in
1179 * case the cable was pulled and will later be
1180 * re-attached. The target may forget its negotiation
1181 * settings with us should it attempt to reselect
1182 * during the interruption. The target will not issue
1183 * a unit attention in this case, so we must always
1184 * renegotiate.
1185 */
1186 ahc_scb_devinfo(ahc, &devinfo, scb); 1184 ahc_scb_devinfo(ahc, &devinfo, scb);
1187 ahc_force_renegotiation(ahc, &devinfo);
1188 ahc_set_transaction_status(scb, CAM_SEL_TIMEOUT); 1185 ahc_set_transaction_status(scb, CAM_SEL_TIMEOUT);
1189 ahc_freeze_devq(ahc, scb); 1186 ahc_freeze_devq(ahc, scb);
1187
1188 /*
1189 * Cancel any pending transactions on the device
1190 * now that it seems to be missing. This will
1191 * also revert us to async/narrow transfers until
1192 * we can renegotiate with the device.
1193 */
1194 ahc_handle_devreset(ahc, &devinfo,
1195 CAM_SEL_TIMEOUT,
1196 "Selection Timeout",
1197 /*verbose_level*/1);
1190 } 1198 }
1191 ahc_outb(ahc, CLRINT, CLRSCSIINT); 1199 ahc_outb(ahc, CLRINT, CLRSCSIINT);
1192 ahc_restart(ahc); 1200 ahc_restart(ahc);
@@ -3763,8 +3771,9 @@ ahc_handle_devreset(struct ahc_softc *ahc, struct ahc_devinfo *devinfo,
3763 /*period*/0, /*offset*/0, /*ppr_options*/0, 3771 /*period*/0, /*offset*/0, /*ppr_options*/0,
3764 AHC_TRANS_CUR, /*paused*/TRUE); 3772 AHC_TRANS_CUR, /*paused*/TRUE);
3765 3773
3766 ahc_send_async(ahc, devinfo->channel, devinfo->target, 3774 if (status != CAM_SEL_TIMEOUT)
3767 CAM_LUN_WILDCARD, AC_SENT_BDR, NULL); 3775 ahc_send_async(ahc, devinfo->channel, devinfo->target,
3776 CAM_LUN_WILDCARD, AC_SENT_BDR, NULL);
3768 3777
3769 if (message != NULL 3778 if (message != NULL
3770 && (verbose_level <= bootverbose)) 3779 && (verbose_level <= bootverbose))
@@ -4003,14 +4012,6 @@ ahc_reset(struct ahc_softc *ahc, int reinit)
4003 * to disturb the integrity of the bus. 4012 * to disturb the integrity of the bus.
4004 */ 4013 */
4005 ahc_pause(ahc); 4014 ahc_pause(ahc);
4006 if ((ahc_inb(ahc, HCNTRL) & CHIPRST) != 0) {
4007 /*
4008 * The chip has not been initialized since
4009 * PCI/EISA/VLB bus reset. Don't trust
4010 * "left over BIOS data".
4011 */
4012 ahc->flags |= AHC_NO_BIOS_INIT;
4013 }
4014 sxfrctl1_b = 0; 4015 sxfrctl1_b = 0;
4015 if ((ahc->chip & AHC_CHIPID_MASK) == AHC_AIC7770) { 4016 if ((ahc->chip & AHC_CHIPID_MASK) == AHC_AIC7770) {
4016 u_int sblkctl; 4017 u_int sblkctl;
@@ -5036,14 +5037,23 @@ ahc_pause_and_flushwork(struct ahc_softc *ahc)
5036 ahc->flags |= AHC_ALL_INTERRUPTS; 5037 ahc->flags |= AHC_ALL_INTERRUPTS;
5037 paused = FALSE; 5038 paused = FALSE;
5038 do { 5039 do {
5039 if (paused) 5040 if (paused) {
5040 ahc_unpause(ahc); 5041 ahc_unpause(ahc);
5042 /*
5043 * Give the sequencer some time to service
5044 * any active selections.
5045 */
5046 ahc_delay(500);
5047 }
5041 ahc_intr(ahc); 5048 ahc_intr(ahc);
5042 ahc_pause(ahc); 5049 ahc_pause(ahc);
5043 paused = TRUE; 5050 paused = TRUE;
5044 ahc_outb(ahc, SCSISEQ, ahc_inb(ahc, SCSISEQ) & ~ENSELO); 5051 ahc_outb(ahc, SCSISEQ, ahc_inb(ahc, SCSISEQ) & ~ENSELO);
5045 ahc_clear_critical_section(ahc);
5046 intstat = ahc_inb(ahc, INTSTAT); 5052 intstat = ahc_inb(ahc, INTSTAT);
5053 if ((intstat & INT_PEND) == 0) {
5054 ahc_clear_critical_section(ahc);
5055 intstat = ahc_inb(ahc, INTSTAT);
5056 }
5047 } while (--maxloops 5057 } while (--maxloops
5048 && (intstat != 0xFF || (ahc->features & AHC_REMOVABLE) == 0) 5058 && (intstat != 0xFF || (ahc->features & AHC_REMOVABLE) == 0)
5049 && ((intstat & INT_PEND) != 0 5059 && ((intstat & INT_PEND) != 0
diff --git a/drivers/scsi/aic7xxx/aic7xxx_osm.c b/drivers/scsi/aic7xxx/aic7xxx_osm.c
index 687f19e9cf0..c932b3b9449 100644
--- a/drivers/scsi/aic7xxx/aic7xxx_osm.c
+++ b/drivers/scsi/aic7xxx/aic7xxx_osm.c
@@ -125,12 +125,6 @@
125 125
126static struct scsi_transport_template *ahc_linux_transport_template = NULL; 126static struct scsi_transport_template *ahc_linux_transport_template = NULL;
127 127
128/*
129 * Include aiclib.c as part of our
130 * "module dependencies are hard" work around.
131 */
132#include "aiclib.c"
133
134#include <linux/init.h> /* __setup */ 128#include <linux/init.h> /* __setup */
135#include <linux/mm.h> /* For fetching system memory size */ 129#include <linux/mm.h> /* For fetching system memory size */
136#include <linux/blkdev.h> /* For block_size() */ 130#include <linux/blkdev.h> /* For block_size() */
@@ -391,7 +385,6 @@ static int ahc_linux_run_command(struct ahc_softc*,
391 struct ahc_linux_device *, 385 struct ahc_linux_device *,
392 struct scsi_cmnd *); 386 struct scsi_cmnd *);
393static void ahc_linux_setup_tag_info_global(char *p); 387static void ahc_linux_setup_tag_info_global(char *p);
394static aic_option_callback_t ahc_linux_setup_tag_info;
395static int aic7xxx_setup(char *s); 388static int aic7xxx_setup(char *s);
396 389
397static int ahc_linux_unit; 390static int ahc_linux_unit;
@@ -635,6 +628,8 @@ ahc_linux_slave_alloc(struct scsi_device *sdev)
635 628
636 targ->sdev[sdev->lun] = sdev; 629 targ->sdev[sdev->lun] = sdev;
637 630
631 spi_period(starget) = 0;
632
638 return 0; 633 return 0;
639} 634}
640 635
@@ -918,6 +913,86 @@ ahc_linux_setup_tag_info(u_long arg, int instance, int targ, int32_t value)
918 } 913 }
919} 914}
920 915
916static char *
917ahc_parse_brace_option(char *opt_name, char *opt_arg, char *end, int depth,
918 void (*callback)(u_long, int, int, int32_t),
919 u_long callback_arg)
920{
921 char *tok_end;
922 char *tok_end2;
923 int i;
924 int instance;
925 int targ;
926 int done;
927 char tok_list[] = {'.', ',', '{', '}', '\0'};
928
929 /* All options use a ':' name/arg separator */
930 if (*opt_arg != ':')
931 return (opt_arg);
932 opt_arg++;
933 instance = -1;
934 targ = -1;
935 done = FALSE;
936 /*
937 * Restore separator that may be in
938 * the middle of our option argument.
939 */
940 tok_end = strchr(opt_arg, '\0');
941 if (tok_end < end)
942 *tok_end = ',';
943 while (!done) {
944 switch (*opt_arg) {
945 case '{':
946 if (instance == -1) {
947 instance = 0;
948 } else {
949 if (depth > 1) {
950 if (targ == -1)
951 targ = 0;
952 } else {
953 printf("Malformed Option %s\n",
954 opt_name);
955 done = TRUE;
956 }
957 }
958 opt_arg++;
959 break;
960 case '}':
961 if (targ != -1)
962 targ = -1;
963 else if (instance != -1)
964 instance = -1;
965 opt_arg++;
966 break;
967 case ',':
968 case '.':
969 if (instance == -1)
970 done = TRUE;
971 else if (targ >= 0)
972 targ++;
973 else if (instance >= 0)
974 instance++;
975 opt_arg++;
976 break;
977 case '\0':
978 done = TRUE;
979 break;
980 default:
981 tok_end = end;
982 for (i = 0; tok_list[i]; i++) {
983 tok_end2 = strchr(opt_arg, tok_list[i]);
984 if ((tok_end2) && (tok_end2 < tok_end))
985 tok_end = tok_end2;
986 }
987 callback(callback_arg, instance, targ,
988 simple_strtol(opt_arg, NULL, 0));
989 opt_arg = tok_end;
990 break;
991 }
992 }
993 return (opt_arg);
994}
995
921/* 996/*
922 * Handle Linux boot parameters. This routine allows for assigning a value 997 * Handle Linux boot parameters. This routine allows for assigning a value
923 * to a parameter with a ':' between the parameter and the value. 998 * to a parameter with a ':' between the parameter and the value.
@@ -972,7 +1047,7 @@ aic7xxx_setup(char *s)
972 if (strncmp(p, "global_tag_depth", n) == 0) { 1047 if (strncmp(p, "global_tag_depth", n) == 0) {
973 ahc_linux_setup_tag_info_global(p + n); 1048 ahc_linux_setup_tag_info_global(p + n);
974 } else if (strncmp(p, "tag_info", n) == 0) { 1049 } else if (strncmp(p, "tag_info", n) == 0) {
975 s = aic_parse_brace_option("tag_info", p + n, end, 1050 s = ahc_parse_brace_option("tag_info", p + n, end,
976 2, ahc_linux_setup_tag_info, 0); 1051 2, ahc_linux_setup_tag_info, 0);
977 } else if (p[n] == ':') { 1052 } else if (p[n] == ':') {
978 *(options[i].flag) = simple_strtoul(p + n + 1, NULL, 0); 1053 *(options[i].flag) = simple_strtoul(p + n + 1, NULL, 0);
@@ -1612,9 +1687,9 @@ ahc_send_async(struct ahc_softc *ahc, char channel,
1612 if (channel == 'B') 1687 if (channel == 'B')
1613 target_offset += 8; 1688 target_offset += 8;
1614 starget = ahc->platform_data->starget[target_offset]; 1689 starget = ahc->platform_data->starget[target_offset];
1615 targ = scsi_transport_target_data(starget); 1690 if (starget == NULL)
1616 if (targ == NULL)
1617 break; 1691 break;
1692 targ = scsi_transport_target_data(starget);
1618 1693
1619 target_ppr_options = 1694 target_ppr_options =
1620 (spi_dt(starget) ? MSG_EXT_PPR_DT_REQ : 0) 1695 (spi_dt(starget) ? MSG_EXT_PPR_DT_REQ : 0)
@@ -2329,8 +2404,6 @@ ahc_platform_dump_card_state(struct ahc_softc *ahc)
2329{ 2404{
2330} 2405}
2331 2406
2332static void ahc_linux_exit(void);
2333
2334static void ahc_linux_set_width(struct scsi_target *starget, int width) 2407static void ahc_linux_set_width(struct scsi_target *starget, int width)
2335{ 2408{
2336 struct Scsi_Host *shost = dev_to_shost(starget->dev.parent); 2409 struct Scsi_Host *shost = dev_to_shost(starget->dev.parent);
diff --git a/drivers/scsi/aic7xxx/aic7xxx_osm.h b/drivers/scsi/aic7xxx/aic7xxx_osm.h
index 0e47ac21754..c5299626924 100644
--- a/drivers/scsi/aic7xxx/aic7xxx_osm.h
+++ b/drivers/scsi/aic7xxx/aic7xxx_osm.h
@@ -265,7 +265,7 @@ ahc_scb_timer_reset(struct scb *scb, u_int usec)
265/***************************** SMP support ************************************/ 265/***************************** SMP support ************************************/
266#include <linux/spinlock.h> 266#include <linux/spinlock.h>
267 267
268#define AIC7XXX_DRIVER_VERSION "6.2.36" 268#define AIC7XXX_DRIVER_VERSION "7.0"
269 269
270/*************************** Device Data Structures ***************************/ 270/*************************** Device Data Structures ***************************/
271/* 271/*
diff --git a/drivers/scsi/aic7xxx/aic7xxx_osm_pci.c b/drivers/scsi/aic7xxx/aic7xxx_osm_pci.c
index 9d318ce2c99..0d44a6907dd 100644
--- a/drivers/scsi/aic7xxx/aic7xxx_osm_pci.c
+++ b/drivers/scsi/aic7xxx/aic7xxx_osm_pci.c
@@ -149,6 +149,27 @@ ahc_linux_pci_dev_remove(struct pci_dev *pdev)
149 ahc_free(ahc); 149 ahc_free(ahc);
150} 150}
151 151
152static void
153ahc_linux_pci_inherit_flags(struct ahc_softc *ahc)
154{
155 struct pci_dev *pdev = ahc->dev_softc, *master_pdev;
156 unsigned int master_devfn = PCI_DEVFN(PCI_SLOT(pdev->devfn), 0);
157
158 master_pdev = pci_get_slot(pdev->bus, master_devfn);
159 if (master_pdev) {
160 struct ahc_softc *master = pci_get_drvdata(master_pdev);
161 if (master) {
162 ahc->flags &= ~AHC_BIOS_ENABLED;
163 ahc->flags |= master->flags & AHC_BIOS_ENABLED;
164
165 ahc->flags &= ~AHC_PRIMARY_CHANNEL;
166 ahc->flags |= master->flags & AHC_PRIMARY_CHANNEL;
167 } else
168 printk(KERN_ERR "aic7xxx: no multichannel peer found!\n");
169 pci_dev_put(master_pdev);
170 }
171}
172
152static int 173static int
153ahc_linux_pci_dev_probe(struct pci_dev *pdev, const struct pci_device_id *ent) 174ahc_linux_pci_dev_probe(struct pci_dev *pdev, const struct pci_device_id *ent)
154{ 175{
@@ -203,6 +224,14 @@ ahc_linux_pci_dev_probe(struct pci_dev *pdev, const struct pci_device_id *ent)
203 ahc_free(ahc); 224 ahc_free(ahc);
204 return (-error); 225 return (-error);
205 } 226 }
227
228 /*
229 * Second Function PCI devices need to inherit some
230 * settings from function 0.
231 */
232 if ((ahc->features & AHC_MULTI_FUNC) && PCI_FUNC(pdev->devfn) != 0)
233 ahc_linux_pci_inherit_flags(ahc);
234
206 pci_set_drvdata(pdev, ahc); 235 pci_set_drvdata(pdev, ahc);
207 ahc_linux_register_host(ahc, &aic7xxx_driver_template); 236 ahc_linux_register_host(ahc, &aic7xxx_driver_template);
208 return (0); 237 return (0);
diff --git a/drivers/scsi/aic7xxx/aic7xxx_proc.c b/drivers/scsi/aic7xxx/aic7xxx_proc.c
index 3802c91f0b0..04a3506cf34 100644
--- a/drivers/scsi/aic7xxx/aic7xxx_proc.c
+++ b/drivers/scsi/aic7xxx/aic7xxx_proc.c
@@ -54,6 +54,49 @@ static void ahc_dump_device_state(struct info_str *info,
54static int ahc_proc_write_seeprom(struct ahc_softc *ahc, 54static int ahc_proc_write_seeprom(struct ahc_softc *ahc,
55 char *buffer, int length); 55 char *buffer, int length);
56 56
57/*
58 * Table of syncrates that don't follow the "divisible by 4"
59 * rule. This table will be expanded in future SCSI specs.
60 */
61static struct {
62 u_int period_factor;
63 u_int period; /* in 100ths of ns */
64} scsi_syncrates[] = {
65 { 0x08, 625 }, /* FAST-160 */
66 { 0x09, 1250 }, /* FAST-80 */
67 { 0x0a, 2500 }, /* FAST-40 40MHz */
68 { 0x0b, 3030 }, /* FAST-40 33MHz */
69 { 0x0c, 5000 } /* FAST-20 */
70};
71
72/*
73 * Return the frequency in kHz corresponding to the given
74 * sync period factor.
75 */
76static u_int
77ahc_calc_syncsrate(u_int period_factor)
78{
79 int i;
80 int num_syncrates;
81
82 num_syncrates = sizeof(scsi_syncrates) / sizeof(scsi_syncrates[0]);
83 /* See if the period is in the "exception" table */
84 for (i = 0; i < num_syncrates; i++) {
85
86 if (period_factor == scsi_syncrates[i].period_factor) {
87 /* Period in kHz */
88 return (100000000 / scsi_syncrates[i].period);
89 }
90 }
91
92 /*
93 * Wasn't in the table, so use the standard
94 * 4 times conversion.
95 */
96 return (10000000 / (period_factor * 4 * 10));
97}
98
99
57static void 100static void
58copy_mem_info(struct info_str *info, char *data, int len) 101copy_mem_info(struct info_str *info, char *data, int len)
59{ 102{
@@ -106,7 +149,7 @@ ahc_format_transinfo(struct info_str *info, struct ahc_transinfo *tinfo)
106 speed = 3300; 149 speed = 3300;
107 freq = 0; 150 freq = 0;
108 if (tinfo->offset != 0) { 151 if (tinfo->offset != 0) {
109 freq = aic_calc_syncsrate(tinfo->period); 152 freq = ahc_calc_syncsrate(tinfo->period);
110 speed = freq; 153 speed = freq;
111 } 154 }
112 speed *= (0x01 << tinfo->width); 155 speed *= (0x01 << tinfo->width);
diff --git a/drivers/scsi/aic7xxx/aic7xxx_reg.h_shipped b/drivers/scsi/aic7xxx/aic7xxx_reg.h_shipped
index 7c1390ed117..2ce1febca20 100644
--- a/drivers/scsi/aic7xxx/aic7xxx_reg.h_shipped
+++ b/drivers/scsi/aic7xxx/aic7xxx_reg.h_shipped
@@ -2,8 +2,8 @@
2 * DO NOT EDIT - This file is automatically generated 2 * DO NOT EDIT - This file is automatically generated
3 * from the following source files: 3 * from the following source files:
4 * 4 *
5 * $Id: //depot/aic7xxx/aic7xxx/aic7xxx.seq#56 $ 5 * $Id: //depot/aic7xxx/aic7xxx/aic7xxx.seq#58 $
6 * $Id: //depot/aic7xxx/aic7xxx/aic7xxx.reg#39 $ 6 * $Id: //depot/aic7xxx/aic7xxx/aic7xxx.reg#40 $
7 */ 7 */
8typedef int (ahc_reg_print_t)(u_int, u_int *, u_int); 8typedef int (ahc_reg_print_t)(u_int, u_int *, u_int);
9typedef struct ahc_reg_parse_entry { 9typedef struct ahc_reg_parse_entry {
@@ -1298,7 +1298,6 @@ ahc_reg_print_t ahc_sg_cache_pre_print;
1298#define CMDSIZE_TABLE_TAIL 0x34 1298#define CMDSIZE_TABLE_TAIL 0x34
1299 1299
1300#define MWI_RESIDUAL 0x38 1300#define MWI_RESIDUAL 0x38
1301#define TARG_IMMEDIATE_SCB 0x38
1302 1301
1303#define NEXT_QUEUED_SCB 0x39 1302#define NEXT_QUEUED_SCB 0x39
1304 1303
@@ -1380,6 +1379,7 @@ ahc_reg_print_t ahc_sg_cache_pre_print;
1380#define RETURN_2 0x52 1379#define RETURN_2 0x52
1381 1380
1382#define LAST_MSG 0x53 1381#define LAST_MSG 0x53
1382#define TARG_IMMEDIATE_SCB 0x53
1383 1383
1384#define SCSISEQ_TEMPLATE 0x54 1384#define SCSISEQ_TEMPLATE 0x54
1385#define ENSELO 0x40 1385#define ENSELO 0x40
diff --git a/drivers/scsi/aic7xxx/aic7xxx_reg_print.c_shipped b/drivers/scsi/aic7xxx/aic7xxx_reg_print.c_shipped
index 9c713775d44..88bfd767c51 100644
--- a/drivers/scsi/aic7xxx/aic7xxx_reg_print.c_shipped
+++ b/drivers/scsi/aic7xxx/aic7xxx_reg_print.c_shipped
@@ -2,8 +2,8 @@
2 * DO NOT EDIT - This file is automatically generated 2 * DO NOT EDIT - This file is automatically generated
3 * from the following source files: 3 * from the following source files:
4 * 4 *
5 * $Id: //depot/aic7xxx/aic7xxx/aic7xxx.seq#56 $ 5 * $Id: //depot/aic7xxx/aic7xxx/aic7xxx.seq#58 $
6 * $Id: //depot/aic7xxx/aic7xxx/aic7xxx.reg#39 $ 6 * $Id: //depot/aic7xxx/aic7xxx/aic7xxx.reg#40 $
7 */ 7 */
8 8
9#include "aic7xxx_osm.h" 9#include "aic7xxx_osm.h"
diff --git a/drivers/scsi/aic7xxx/aic7xxx_seq.h_shipped b/drivers/scsi/aic7xxx/aic7xxx_seq.h_shipped
index cf411368a87..4cee08521e7 100644
--- a/drivers/scsi/aic7xxx/aic7xxx_seq.h_shipped
+++ b/drivers/scsi/aic7xxx/aic7xxx_seq.h_shipped
@@ -2,13 +2,13 @@
2 * DO NOT EDIT - This file is automatically generated 2 * DO NOT EDIT - This file is automatically generated
3 * from the following source files: 3 * from the following source files:
4 * 4 *
5 * $Id: //depot/aic7xxx/aic7xxx/aic7xxx.seq#56 $ 5 * $Id: //depot/aic7xxx/aic7xxx/aic7xxx.seq#58 $
6 * $Id: //depot/aic7xxx/aic7xxx/aic7xxx.reg#39 $ 6 * $Id: //depot/aic7xxx/aic7xxx/aic7xxx.reg#40 $
7 */ 7 */
8static uint8_t seqprog[] = { 8static uint8_t seqprog[] = {
9 0xb2, 0x00, 0x00, 0x08, 9 0xb2, 0x00, 0x00, 0x08,
10 0xf7, 0x11, 0x22, 0x08, 10 0xf7, 0x11, 0x22, 0x08,
11 0x00, 0x65, 0xec, 0x59, 11 0x00, 0x65, 0xee, 0x59,
12 0xf7, 0x01, 0x02, 0x08, 12 0xf7, 0x01, 0x02, 0x08,
13 0xff, 0x6a, 0x24, 0x08, 13 0xff, 0x6a, 0x24, 0x08,
14 0x40, 0x00, 0x40, 0x68, 14 0x40, 0x00, 0x40, 0x68,
@@ -21,15 +21,15 @@ static uint8_t seqprog[] = {
21 0x01, 0x4d, 0xc8, 0x30, 21 0x01, 0x4d, 0xc8, 0x30,
22 0x00, 0x4c, 0x12, 0x70, 22 0x00, 0x4c, 0x12, 0x70,
23 0x01, 0x39, 0xa2, 0x30, 23 0x01, 0x39, 0xa2, 0x30,
24 0x00, 0x6a, 0xc0, 0x5e, 24 0x00, 0x6a, 0xc2, 0x5e,
25 0x01, 0x51, 0x20, 0x31, 25 0x01, 0x51, 0x20, 0x31,
26 0x01, 0x57, 0xae, 0x00, 26 0x01, 0x57, 0xae, 0x00,
27 0x0d, 0x6a, 0x76, 0x00, 27 0x0d, 0x6a, 0x76, 0x00,
28 0x00, 0x51, 0x12, 0x5e, 28 0x00, 0x51, 0x14, 0x5e,
29 0x01, 0x51, 0xc8, 0x30, 29 0x01, 0x51, 0xc8, 0x30,
30 0x00, 0x39, 0xc8, 0x60, 30 0x00, 0x39, 0xc8, 0x60,
31 0x00, 0xbb, 0x30, 0x70, 31 0x00, 0xbb, 0x30, 0x70,
32 0xc1, 0x6a, 0xd8, 0x5e, 32 0xc1, 0x6a, 0xda, 0x5e,
33 0x01, 0xbf, 0x72, 0x30, 33 0x01, 0xbf, 0x72, 0x30,
34 0x01, 0x40, 0x7e, 0x31, 34 0x01, 0x40, 0x7e, 0x31,
35 0x01, 0x90, 0x80, 0x30, 35 0x01, 0x90, 0x80, 0x30,
@@ -49,10 +49,10 @@ static uint8_t seqprog[] = {
49 0x08, 0x6a, 0x78, 0x00, 49 0x08, 0x6a, 0x78, 0x00,
50 0x01, 0x50, 0xc8, 0x30, 50 0x01, 0x50, 0xc8, 0x30,
51 0xe0, 0x6a, 0xcc, 0x00, 51 0xe0, 0x6a, 0xcc, 0x00,
52 0x48, 0x6a, 0xfc, 0x5d, 52 0x48, 0x6a, 0xfe, 0x5d,
53 0x01, 0x6a, 0xdc, 0x01, 53 0x01, 0x6a, 0xdc, 0x01,
54 0x88, 0x6a, 0xcc, 0x00, 54 0x88, 0x6a, 0xcc, 0x00,
55 0x48, 0x6a, 0xfc, 0x5d, 55 0x48, 0x6a, 0xfe, 0x5d,
56 0x01, 0x6a, 0x26, 0x01, 56 0x01, 0x6a, 0x26, 0x01,
57 0xf0, 0x19, 0x7a, 0x08, 57 0xf0, 0x19, 0x7a, 0x08,
58 0x0f, 0x18, 0xc8, 0x08, 58 0x0f, 0x18, 0xc8, 0x08,
@@ -93,7 +93,7 @@ static uint8_t seqprog[] = {
93 0x00, 0x65, 0x20, 0x41, 93 0x00, 0x65, 0x20, 0x41,
94 0x02, 0x57, 0xae, 0x00, 94 0x02, 0x57, 0xae, 0x00,
95 0x00, 0x65, 0x9e, 0x40, 95 0x00, 0x65, 0x9e, 0x40,
96 0x61, 0x6a, 0xd8, 0x5e, 96 0x61, 0x6a, 0xda, 0x5e,
97 0x08, 0x51, 0x20, 0x71, 97 0x08, 0x51, 0x20, 0x71,
98 0x02, 0x0b, 0xb2, 0x78, 98 0x02, 0x0b, 0xb2, 0x78,
99 0x00, 0x65, 0xae, 0x40, 99 0x00, 0x65, 0xae, 0x40,
@@ -106,7 +106,7 @@ static uint8_t seqprog[] = {
106 0x80, 0x3d, 0x7a, 0x00, 106 0x80, 0x3d, 0x7a, 0x00,
107 0x20, 0x6a, 0x16, 0x00, 107 0x20, 0x6a, 0x16, 0x00,
108 0x00, 0x65, 0xcc, 0x41, 108 0x00, 0x65, 0xcc, 0x41,
109 0x00, 0x65, 0xb2, 0x5e, 109 0x00, 0x65, 0xb4, 0x5e,
110 0x00, 0x65, 0x12, 0x40, 110 0x00, 0x65, 0x12, 0x40,
111 0x20, 0x11, 0xd2, 0x68, 111 0x20, 0x11, 0xd2, 0x68,
112 0x20, 0x6a, 0x18, 0x00, 112 0x20, 0x6a, 0x18, 0x00,
@@ -140,27 +140,27 @@ static uint8_t seqprog[] = {
140 0x80, 0x0b, 0xc4, 0x79, 140 0x80, 0x0b, 0xc4, 0x79,
141 0x12, 0x01, 0x02, 0x00, 141 0x12, 0x01, 0x02, 0x00,
142 0x01, 0xab, 0xac, 0x30, 142 0x01, 0xab, 0xac, 0x30,
143 0xe4, 0x6a, 0x6e, 0x5d, 143 0xe4, 0x6a, 0x70, 0x5d,
144 0x40, 0x6a, 0x16, 0x00, 144 0x40, 0x6a, 0x16, 0x00,
145 0x80, 0x3e, 0x84, 0x5d, 145 0x80, 0x3e, 0x86, 0x5d,
146 0x20, 0xb8, 0x18, 0x79, 146 0x20, 0xb8, 0x18, 0x79,
147 0x20, 0x6a, 0x84, 0x5d, 147 0x20, 0x6a, 0x86, 0x5d,
148 0x00, 0xab, 0x84, 0x5d, 148 0x00, 0xab, 0x86, 0x5d,
149 0x01, 0xa9, 0x78, 0x30, 149 0x01, 0xa9, 0x78, 0x30,
150 0x10, 0xb8, 0x20, 0x79, 150 0x10, 0xb8, 0x20, 0x79,
151 0xe4, 0x6a, 0x6e, 0x5d, 151 0xe4, 0x6a, 0x70, 0x5d,
152 0x00, 0x65, 0xae, 0x40, 152 0x00, 0x65, 0xae, 0x40,
153 0x10, 0x03, 0x3c, 0x69, 153 0x10, 0x03, 0x3c, 0x69,
154 0x08, 0x3c, 0x5a, 0x69, 154 0x08, 0x3c, 0x5a, 0x69,
155 0x04, 0x3c, 0x92, 0x69, 155 0x04, 0x3c, 0x92, 0x69,
156 0x02, 0x3c, 0x98, 0x69, 156 0x02, 0x3c, 0x98, 0x69,
157 0x01, 0x3c, 0x44, 0x79, 157 0x01, 0x3c, 0x44, 0x79,
158 0xff, 0x6a, 0x70, 0x00, 158 0xff, 0x6a, 0xa6, 0x00,
159 0x00, 0x65, 0xa4, 0x59, 159 0x00, 0x65, 0xa4, 0x59,
160 0x00, 0x6a, 0xc0, 0x5e, 160 0x00, 0x6a, 0xc2, 0x5e,
161 0xff, 0x38, 0x30, 0x71, 161 0xff, 0x53, 0x30, 0x71,
162 0x0d, 0x6a, 0x76, 0x00, 162 0x0d, 0x6a, 0x76, 0x00,
163 0x00, 0x38, 0x12, 0x5e, 163 0x00, 0x53, 0x14, 0x5e,
164 0x00, 0x65, 0xea, 0x58, 164 0x00, 0x65, 0xea, 0x58,
165 0x12, 0x01, 0x02, 0x00, 165 0x12, 0x01, 0x02, 0x00,
166 0x00, 0x65, 0x18, 0x41, 166 0x00, 0x65, 0x18, 0x41,
@@ -168,10 +168,10 @@ static uint8_t seqprog[] = {
168 0x00, 0x65, 0xf2, 0x58, 168 0x00, 0x65, 0xf2, 0x58,
169 0xfd, 0x57, 0xae, 0x08, 169 0xfd, 0x57, 0xae, 0x08,
170 0x00, 0x65, 0xae, 0x40, 170 0x00, 0x65, 0xae, 0x40,
171 0xe4, 0x6a, 0x6e, 0x5d, 171 0xe4, 0x6a, 0x70, 0x5d,
172 0x20, 0x3c, 0x4a, 0x79, 172 0x20, 0x3c, 0x4a, 0x79,
173 0x02, 0x6a, 0x84, 0x5d, 173 0x02, 0x6a, 0x86, 0x5d,
174 0x04, 0x6a, 0x84, 0x5d, 174 0x04, 0x6a, 0x86, 0x5d,
175 0x01, 0x03, 0x4c, 0x69, 175 0x01, 0x03, 0x4c, 0x69,
176 0xf7, 0x11, 0x22, 0x08, 176 0xf7, 0x11, 0x22, 0x08,
177 0xff, 0x6a, 0x24, 0x08, 177 0xff, 0x6a, 0x24, 0x08,
@@ -182,13 +182,13 @@ static uint8_t seqprog[] = {
182 0x80, 0x86, 0xc8, 0x08, 182 0x80, 0x86, 0xc8, 0x08,
183 0x01, 0x4f, 0xc8, 0x30, 183 0x01, 0x4f, 0xc8, 0x30,
184 0x00, 0x50, 0x6c, 0x61, 184 0x00, 0x50, 0x6c, 0x61,
185 0xc4, 0x6a, 0x6e, 0x5d, 185 0xc4, 0x6a, 0x70, 0x5d,
186 0x40, 0x3c, 0x68, 0x79, 186 0x40, 0x3c, 0x68, 0x79,
187 0x28, 0x6a, 0x84, 0x5d, 187 0x28, 0x6a, 0x86, 0x5d,
188 0x00, 0x65, 0x4c, 0x41, 188 0x00, 0x65, 0x4c, 0x41,
189 0x08, 0x6a, 0x84, 0x5d, 189 0x08, 0x6a, 0x86, 0x5d,
190 0x00, 0x65, 0x4c, 0x41, 190 0x00, 0x65, 0x4c, 0x41,
191 0x84, 0x6a, 0x6e, 0x5d, 191 0x84, 0x6a, 0x70, 0x5d,
192 0x00, 0x65, 0xf2, 0x58, 192 0x00, 0x65, 0xf2, 0x58,
193 0x01, 0x66, 0xc8, 0x30, 193 0x01, 0x66, 0xc8, 0x30,
194 0x01, 0x64, 0xd8, 0x31, 194 0x01, 0x64, 0xd8, 0x31,
@@ -208,16 +208,16 @@ static uint8_t seqprog[] = {
208 0xf7, 0x3c, 0x78, 0x08, 208 0xf7, 0x3c, 0x78, 0x08,
209 0x00, 0x65, 0x20, 0x41, 209 0x00, 0x65, 0x20, 0x41,
210 0x40, 0xaa, 0x7e, 0x10, 210 0x40, 0xaa, 0x7e, 0x10,
211 0x04, 0xaa, 0x6e, 0x5d, 211 0x04, 0xaa, 0x70, 0x5d,
212 0x00, 0x65, 0x56, 0x42, 212 0x00, 0x65, 0x58, 0x42,
213 0xc4, 0x6a, 0x6e, 0x5d, 213 0xc4, 0x6a, 0x70, 0x5d,
214 0xc0, 0x6a, 0x7e, 0x00, 214 0xc0, 0x6a, 0x7e, 0x00,
215 0x00, 0xa8, 0x84, 0x5d, 215 0x00, 0xa8, 0x86, 0x5d,
216 0xe4, 0x6a, 0x06, 0x00, 216 0xe4, 0x6a, 0x06, 0x00,
217 0x00, 0x6a, 0x84, 0x5d, 217 0x00, 0x6a, 0x86, 0x5d,
218 0x00, 0x65, 0x4c, 0x41, 218 0x00, 0x65, 0x4c, 0x41,
219 0x10, 0x3c, 0xa8, 0x69, 219 0x10, 0x3c, 0xa8, 0x69,
220 0x00, 0xbb, 0x8a, 0x44, 220 0x00, 0xbb, 0x8c, 0x44,
221 0x18, 0x6a, 0xda, 0x01, 221 0x18, 0x6a, 0xda, 0x01,
222 0x01, 0x69, 0xd8, 0x31, 222 0x01, 0x69, 0xd8, 0x31,
223 0x1c, 0x6a, 0xd0, 0x01, 223 0x1c, 0x6a, 0xd0, 0x01,
@@ -227,31 +227,32 @@ static uint8_t seqprog[] = {
227 0x01, 0x93, 0x26, 0x01, 227 0x01, 0x93, 0x26, 0x01,
228 0x03, 0x6a, 0x2a, 0x01, 228 0x03, 0x6a, 0x2a, 0x01,
229 0x01, 0x69, 0x32, 0x31, 229 0x01, 0x69, 0x32, 0x31,
230 0x1c, 0x6a, 0xe0, 0x5d, 230 0x1c, 0x6a, 0xe2, 0x5d,
231 0x0a, 0x93, 0x26, 0x01, 231 0x0a, 0x93, 0x26, 0x01,
232 0x00, 0x65, 0xa8, 0x5e, 232 0x00, 0x65, 0xaa, 0x5e,
233 0x01, 0x50, 0xa0, 0x18, 233 0x01, 0x50, 0xa0, 0x18,
234 0x02, 0x6a, 0x22, 0x05, 234 0x02, 0x6a, 0x22, 0x05,
235 0x1a, 0x01, 0x02, 0x00, 235 0x1a, 0x01, 0x02, 0x00,
236 0x80, 0x6a, 0x74, 0x00, 236 0x80, 0x6a, 0x74, 0x00,
237 0x40, 0x6a, 0x78, 0x00, 237 0x40, 0x6a, 0x78, 0x00,
238 0x40, 0x6a, 0x16, 0x00, 238 0x40, 0x6a, 0x16, 0x00,
239 0x00, 0x65, 0xd8, 0x5d, 239 0x00, 0x65, 0xda, 0x5d,
240 0x01, 0x3f, 0xc8, 0x30, 240 0x01, 0x3f, 0xc8, 0x30,
241 0xbf, 0x64, 0x56, 0x7a, 241 0xbf, 0x64, 0x58, 0x7a,
242 0x80, 0x64, 0x9e, 0x73, 242 0x80, 0x64, 0xa0, 0x73,
243 0xa0, 0x64, 0x00, 0x74, 243 0xa0, 0x64, 0x02, 0x74,
244 0xc0, 0x64, 0xf4, 0x73, 244 0xc0, 0x64, 0xf6, 0x73,
245 0xe0, 0x64, 0x30, 0x74, 245 0xe0, 0x64, 0x32, 0x74,
246 0x01, 0x6a, 0xd8, 0x5e, 246 0x01, 0x6a, 0xda, 0x5e,
247 0x00, 0x65, 0xcc, 0x41, 247 0x00, 0x65, 0xcc, 0x41,
248 0xf7, 0x11, 0x22, 0x08, 248 0xf7, 0x11, 0x22, 0x08,
249 0x01, 0x06, 0xd4, 0x30, 249 0x01, 0x06, 0xd4, 0x30,
250 0xff, 0x6a, 0x24, 0x08, 250 0xff, 0x6a, 0x24, 0x08,
251 0xf7, 0x01, 0x02, 0x08, 251 0xf7, 0x01, 0x02, 0x08,
252 0x09, 0x0c, 0xe6, 0x79, 252 0xc0, 0x6a, 0x78, 0x00,
253 0x09, 0x0c, 0xe8, 0x79,
253 0x08, 0x0c, 0x04, 0x68, 254 0x08, 0x0c, 0x04, 0x68,
254 0xb1, 0x6a, 0xd8, 0x5e, 255 0xb1, 0x6a, 0xda, 0x5e,
255 0xff, 0x6a, 0x26, 0x09, 256 0xff, 0x6a, 0x26, 0x09,
256 0x12, 0x01, 0x02, 0x00, 257 0x12, 0x01, 0x02, 0x00,
257 0x02, 0x6a, 0x08, 0x30, 258 0x02, 0x6a, 0x08, 0x30,
@@ -264,29 +265,29 @@ static uint8_t seqprog[] = {
264 0x00, 0xa5, 0x4a, 0x21, 265 0x00, 0xa5, 0x4a, 0x21,
265 0x00, 0xa6, 0x4c, 0x21, 266 0x00, 0xa6, 0x4c, 0x21,
266 0x00, 0xa7, 0x4e, 0x25, 267 0x00, 0xa7, 0x4e, 0x25,
267 0x08, 0xeb, 0xdc, 0x7e, 268 0x08, 0xeb, 0xde, 0x7e,
268 0x80, 0xeb, 0x06, 0x7a, 269 0x80, 0xeb, 0x08, 0x7a,
269 0xff, 0x6a, 0xd6, 0x09, 270 0xff, 0x6a, 0xd6, 0x09,
270 0x08, 0xeb, 0x0a, 0x6a, 271 0x08, 0xeb, 0x0c, 0x6a,
271 0xff, 0x6a, 0xd4, 0x0c, 272 0xff, 0x6a, 0xd4, 0x0c,
272 0x80, 0xa3, 0xdc, 0x6e, 273 0x80, 0xa3, 0xde, 0x6e,
273 0x88, 0xeb, 0x20, 0x72, 274 0x88, 0xeb, 0x22, 0x72,
274 0x08, 0xeb, 0xdc, 0x6e, 275 0x08, 0xeb, 0xde, 0x6e,
275 0x04, 0xea, 0x24, 0xe2, 276 0x04, 0xea, 0x26, 0xe2,
276 0x08, 0xee, 0xdc, 0x6e, 277 0x08, 0xee, 0xde, 0x6e,
277 0x04, 0x6a, 0xd0, 0x81, 278 0x04, 0x6a, 0xd0, 0x81,
278 0x05, 0xa4, 0xc0, 0x89, 279 0x05, 0xa4, 0xc0, 0x89,
279 0x03, 0xa5, 0xc2, 0x31, 280 0x03, 0xa5, 0xc2, 0x31,
280 0x09, 0x6a, 0xd6, 0x05, 281 0x09, 0x6a, 0xd6, 0x05,
281 0x00, 0x65, 0x08, 0x5a, 282 0x00, 0x65, 0x0a, 0x5a,
282 0x06, 0xa4, 0xd4, 0x89, 283 0x06, 0xa4, 0xd4, 0x89,
283 0x80, 0x94, 0xdc, 0x7e, 284 0x80, 0x94, 0xde, 0x7e,
284 0x07, 0xe9, 0x10, 0x31, 285 0x07, 0xe9, 0x10, 0x31,
285 0x01, 0xe9, 0x46, 0x31, 286 0x01, 0xe9, 0x46, 0x31,
286 0x00, 0xa3, 0xba, 0x5e, 287 0x00, 0xa3, 0xbc, 0x5e,
287 0x00, 0x65, 0xfa, 0x59, 288 0x00, 0x65, 0xfc, 0x59,
288 0x01, 0xa4, 0xca, 0x30, 289 0x01, 0xa4, 0xca, 0x30,
289 0x80, 0xa3, 0x34, 0x7a, 290 0x80, 0xa3, 0x36, 0x7a,
290 0x02, 0x65, 0xca, 0x00, 291 0x02, 0x65, 0xca, 0x00,
291 0x01, 0x65, 0xf8, 0x31, 292 0x01, 0x65, 0xf8, 0x31,
292 0x80, 0x93, 0x26, 0x01, 293 0x80, 0x93, 0x26, 0x01,
@@ -294,162 +295,162 @@ static uint8_t seqprog[] = {
294 0x01, 0x8c, 0xc8, 0x30, 295 0x01, 0x8c, 0xc8, 0x30,
295 0x00, 0x88, 0xc8, 0x18, 296 0x00, 0x88, 0xc8, 0x18,
296 0x02, 0x64, 0xc8, 0x88, 297 0x02, 0x64, 0xc8, 0x88,
297 0xff, 0x64, 0xdc, 0x7e, 298 0xff, 0x64, 0xde, 0x7e,
298 0xff, 0x8d, 0x4a, 0x6a, 299 0xff, 0x8d, 0x4c, 0x6a,
299 0xff, 0x8e, 0x4a, 0x6a, 300 0xff, 0x8e, 0x4c, 0x6a,
300 0x03, 0x8c, 0xd4, 0x98, 301 0x03, 0x8c, 0xd4, 0x98,
301 0x00, 0x65, 0xdc, 0x56, 302 0x00, 0x65, 0xde, 0x56,
302 0x01, 0x64, 0x70, 0x30, 303 0x01, 0x64, 0x70, 0x30,
303 0xff, 0x64, 0xc8, 0x10, 304 0xff, 0x64, 0xc8, 0x10,
304 0x01, 0x64, 0xc8, 0x18, 305 0x01, 0x64, 0xc8, 0x18,
305 0x00, 0x8c, 0x18, 0x19, 306 0x00, 0x8c, 0x18, 0x19,
306 0xff, 0x8d, 0x1a, 0x21, 307 0xff, 0x8d, 0x1a, 0x21,
307 0xff, 0x8e, 0x1c, 0x25, 308 0xff, 0x8e, 0x1c, 0x25,
308 0xc0, 0x3c, 0x5a, 0x7a, 309 0xc0, 0x3c, 0x5c, 0x7a,
309 0x21, 0x6a, 0xd8, 0x5e, 310 0x21, 0x6a, 0xda, 0x5e,
310 0xa8, 0x6a, 0x76, 0x00, 311 0xa8, 0x6a, 0x76, 0x00,
311 0x79, 0x6a, 0x76, 0x00, 312 0x79, 0x6a, 0x76, 0x00,
312 0x40, 0x3f, 0x62, 0x6a, 313 0x40, 0x3f, 0x64, 0x6a,
313 0x04, 0x3b, 0x76, 0x00, 314 0x04, 0x3b, 0x76, 0x00,
314 0x04, 0x6a, 0xd4, 0x81, 315 0x04, 0x6a, 0xd4, 0x81,
315 0x20, 0x3c, 0x6a, 0x7a, 316 0x20, 0x3c, 0x6c, 0x7a,
316 0x51, 0x6a, 0xd8, 0x5e, 317 0x51, 0x6a, 0xda, 0x5e,
317 0x00, 0x65, 0x82, 0x42, 318 0x00, 0x65, 0x84, 0x42,
318 0x20, 0x3c, 0x78, 0x00, 319 0x20, 0x3c, 0x78, 0x00,
319 0x00, 0xb3, 0xba, 0x5e, 320 0x00, 0xb3, 0xbc, 0x5e,
320 0x07, 0xac, 0x10, 0x31, 321 0x07, 0xac, 0x10, 0x31,
321 0x05, 0xb3, 0x46, 0x31, 322 0x05, 0xb3, 0x46, 0x31,
322 0x88, 0x6a, 0xcc, 0x00, 323 0x88, 0x6a, 0xcc, 0x00,
323 0xac, 0x6a, 0xee, 0x5d, 324 0xac, 0x6a, 0xf0, 0x5d,
324 0xa3, 0x6a, 0xcc, 0x00, 325 0xa3, 0x6a, 0xcc, 0x00,
325 0xb3, 0x6a, 0xf2, 0x5d, 326 0xb3, 0x6a, 0xf4, 0x5d,
326 0x00, 0x65, 0x3a, 0x5a, 327 0x00, 0x65, 0x3c, 0x5a,
327 0xfd, 0xa4, 0x48, 0x09, 328 0xfd, 0xa4, 0x48, 0x09,
328 0x03, 0x8c, 0x10, 0x30, 329 0x03, 0x8c, 0x10, 0x30,
329 0x00, 0x65, 0xe6, 0x5d, 330 0x00, 0x65, 0xe8, 0x5d,
330 0x01, 0xa4, 0x94, 0x7a, 331 0x01, 0xa4, 0x96, 0x7a,
331 0x04, 0x3b, 0x76, 0x08, 332 0x04, 0x3b, 0x76, 0x08,
332 0x01, 0x3b, 0x26, 0x31, 333 0x01, 0x3b, 0x26, 0x31,
333 0x80, 0x02, 0x04, 0x00, 334 0x80, 0x02, 0x04, 0x00,
334 0x10, 0x0c, 0x8a, 0x7a, 335 0x10, 0x0c, 0x8c, 0x7a,
335 0x03, 0x9e, 0x8c, 0x6a, 336 0x03, 0x9e, 0x8e, 0x6a,
336 0x7f, 0x02, 0x04, 0x08, 337 0x7f, 0x02, 0x04, 0x08,
337 0x91, 0x6a, 0xd8, 0x5e, 338 0x91, 0x6a, 0xda, 0x5e,
338 0x00, 0x65, 0xcc, 0x41, 339 0x00, 0x65, 0xcc, 0x41,
339 0x01, 0xa4, 0xca, 0x30, 340 0x01, 0xa4, 0xca, 0x30,
340 0x80, 0xa3, 0x9a, 0x7a, 341 0x80, 0xa3, 0x9c, 0x7a,
341 0x02, 0x65, 0xca, 0x00, 342 0x02, 0x65, 0xca, 0x00,
342 0x01, 0x65, 0xf8, 0x31, 343 0x01, 0x65, 0xf8, 0x31,
343 0x01, 0x3b, 0x26, 0x31, 344 0x01, 0x3b, 0x26, 0x31,
344 0x00, 0x65, 0x0e, 0x5a, 345 0x00, 0x65, 0x10, 0x5a,
345 0x01, 0xfc, 0xa8, 0x6a, 346 0x01, 0xfc, 0xaa, 0x6a,
346 0x80, 0x0b, 0x9e, 0x6a, 347 0x80, 0x0b, 0xa0, 0x6a,
347 0x10, 0x0c, 0x9e, 0x7a, 348 0x10, 0x0c, 0xa0, 0x7a,
348 0x20, 0x93, 0x9e, 0x6a, 349 0x20, 0x93, 0xa0, 0x6a,
349 0x02, 0x93, 0x26, 0x01, 350 0x02, 0x93, 0x26, 0x01,
350 0x02, 0xfc, 0xb2, 0x7a, 351 0x02, 0xfc, 0xb4, 0x7a,
351 0x40, 0x0d, 0xc6, 0x6a, 352 0x40, 0x0d, 0xc8, 0x6a,
352 0x01, 0xa4, 0x48, 0x01, 353 0x01, 0xa4, 0x48, 0x01,
353 0x00, 0x65, 0xc6, 0x42, 354 0x00, 0x65, 0xc8, 0x42,
354 0x40, 0x0d, 0xb8, 0x6a, 355 0x40, 0x0d, 0xba, 0x6a,
355 0x00, 0x65, 0x0e, 0x5a, 356 0x00, 0x65, 0x10, 0x5a,
356 0x00, 0x65, 0xaa, 0x42, 357 0x00, 0x65, 0xac, 0x42,
357 0x80, 0xfc, 0xc2, 0x7a, 358 0x80, 0xfc, 0xc4, 0x7a,
358 0x80, 0xa4, 0xc2, 0x6a, 359 0x80, 0xa4, 0xc4, 0x6a,
359 0xff, 0xa5, 0x4a, 0x19, 360 0xff, 0xa5, 0x4a, 0x19,
360 0xff, 0xa6, 0x4c, 0x21, 361 0xff, 0xa6, 0x4c, 0x21,
361 0xff, 0xa7, 0x4e, 0x21, 362 0xff, 0xa7, 0x4e, 0x21,
362 0xf8, 0xfc, 0x48, 0x09, 363 0xf8, 0xfc, 0x48, 0x09,
363 0x7f, 0xa3, 0x46, 0x09, 364 0x7f, 0xa3, 0x46, 0x09,
364 0x04, 0x3b, 0xe2, 0x6a, 365 0x04, 0x3b, 0xe4, 0x6a,
365 0x02, 0x93, 0x26, 0x01, 366 0x02, 0x93, 0x26, 0x01,
366 0x01, 0x94, 0xc8, 0x7a, 367 0x01, 0x94, 0xca, 0x7a,
367 0x01, 0x94, 0xc8, 0x7a, 368 0x01, 0x94, 0xca, 0x7a,
368 0x01, 0x94, 0xc8, 0x7a, 369 0x01, 0x94, 0xca, 0x7a,
369 0x01, 0x94, 0xc8, 0x7a, 370 0x01, 0x94, 0xca, 0x7a,
370 0x01, 0x94, 0xc8, 0x7a, 371 0x01, 0x94, 0xca, 0x7a,
371 0x01, 0xa4, 0xe0, 0x7a, 372 0x01, 0xa4, 0xe2, 0x7a,
372 0x01, 0xfc, 0xd6, 0x7a, 373 0x01, 0xfc, 0xd8, 0x7a,
373 0x01, 0x94, 0xe2, 0x6a, 374 0x01, 0x94, 0xe4, 0x6a,
374 0x01, 0x94, 0xe2, 0x6a, 375 0x01, 0x94, 0xe4, 0x6a,
375 0x01, 0x94, 0xe2, 0x6a, 376 0x01, 0x94, 0xe4, 0x6a,
376 0x00, 0x65, 0x82, 0x42, 377 0x00, 0x65, 0x84, 0x42,
377 0x01, 0x94, 0xe0, 0x7a, 378 0x01, 0x94, 0xe2, 0x7a,
378 0x10, 0x94, 0xe2, 0x6a, 379 0x10, 0x94, 0xe4, 0x6a,
379 0xd7, 0x93, 0x26, 0x09, 380 0xd7, 0x93, 0x26, 0x09,
380 0x28, 0x93, 0xe6, 0x6a, 381 0x28, 0x93, 0xe8, 0x6a,
381 0x01, 0x85, 0x0a, 0x01, 382 0x01, 0x85, 0x0a, 0x01,
382 0x02, 0xfc, 0xee, 0x6a, 383 0x02, 0xfc, 0xf0, 0x6a,
383 0x01, 0x14, 0x46, 0x31, 384 0x01, 0x14, 0x46, 0x31,
384 0xff, 0x6a, 0x10, 0x09, 385 0xff, 0x6a, 0x10, 0x09,
385 0xfe, 0x85, 0x0a, 0x09, 386 0xfe, 0x85, 0x0a, 0x09,
386 0xff, 0x38, 0xfc, 0x6a, 387 0xff, 0x38, 0xfe, 0x6a,
387 0x80, 0xa3, 0xfc, 0x7a, 388 0x80, 0xa3, 0xfe, 0x7a,
388 0x80, 0x0b, 0xfa, 0x7a, 389 0x80, 0x0b, 0xfc, 0x7a,
389 0x04, 0x3b, 0xfc, 0x7a, 390 0x04, 0x3b, 0xfe, 0x7a,
390 0xbf, 0x3b, 0x76, 0x08, 391 0xbf, 0x3b, 0x76, 0x08,
391 0x01, 0x3b, 0x26, 0x31, 392 0x01, 0x3b, 0x26, 0x31,
392 0x00, 0x65, 0x0e, 0x5a, 393 0x00, 0x65, 0x10, 0x5a,
393 0x01, 0x0b, 0x0a, 0x6b, 394 0x01, 0x0b, 0x0c, 0x6b,
394 0x10, 0x0c, 0xfe, 0x7a, 395 0x10, 0x0c, 0x00, 0x7b,
395 0x04, 0x93, 0x08, 0x6b, 396 0x04, 0x93, 0x0a, 0x6b,
396 0x01, 0x94, 0x06, 0x7b, 397 0x01, 0x94, 0x08, 0x7b,
397 0x10, 0x94, 0x08, 0x6b, 398 0x10, 0x94, 0x0a, 0x6b,
398 0xc7, 0x93, 0x26, 0x09, 399 0xc7, 0x93, 0x26, 0x09,
399 0x01, 0x99, 0xd4, 0x30, 400 0x01, 0x99, 0xd4, 0x30,
400 0x38, 0x93, 0x0c, 0x6b, 401 0x38, 0x93, 0x0e, 0x6b,
401 0xff, 0x08, 0x5a, 0x6b, 402 0xff, 0x08, 0x5c, 0x6b,
402 0xff, 0x09, 0x5a, 0x6b, 403 0xff, 0x09, 0x5c, 0x6b,
403 0xff, 0x0a, 0x5a, 0x6b, 404 0xff, 0x0a, 0x5c, 0x6b,
404 0xff, 0x38, 0x28, 0x7b, 405 0xff, 0x38, 0x2a, 0x7b,
405 0x04, 0x14, 0x10, 0x31, 406 0x04, 0x14, 0x10, 0x31,
406 0x01, 0x38, 0x18, 0x31, 407 0x01, 0x38, 0x18, 0x31,
407 0x02, 0x6a, 0x1a, 0x31, 408 0x02, 0x6a, 0x1a, 0x31,
408 0x88, 0x6a, 0xcc, 0x00, 409 0x88, 0x6a, 0xcc, 0x00,
409 0x14, 0x6a, 0xf4, 0x5d, 410 0x14, 0x6a, 0xf6, 0x5d,
410 0x00, 0x38, 0xe0, 0x5d, 411 0x00, 0x38, 0xe2, 0x5d,
411 0xff, 0x6a, 0x70, 0x08, 412 0xff, 0x6a, 0x70, 0x08,
412 0x00, 0x65, 0x54, 0x43, 413 0x00, 0x65, 0x56, 0x43,
413 0x80, 0xa3, 0x2e, 0x7b, 414 0x80, 0xa3, 0x30, 0x7b,
414 0x01, 0xa4, 0x48, 0x01, 415 0x01, 0xa4, 0x48, 0x01,
415 0x00, 0x65, 0x5a, 0x43, 416 0x00, 0x65, 0x5c, 0x43,
416 0x08, 0xeb, 0x34, 0x7b, 417 0x08, 0xeb, 0x36, 0x7b,
417 0x00, 0x65, 0x0e, 0x5a, 418 0x00, 0x65, 0x10, 0x5a,
418 0x08, 0xeb, 0x30, 0x6b, 419 0x08, 0xeb, 0x32, 0x6b,
419 0x07, 0xe9, 0x10, 0x31, 420 0x07, 0xe9, 0x10, 0x31,
420 0x01, 0xe9, 0xca, 0x30, 421 0x01, 0xe9, 0xca, 0x30,
421 0x01, 0x65, 0x46, 0x31, 422 0x01, 0x65, 0x46, 0x31,
422 0x00, 0x6a, 0xba, 0x5e, 423 0x00, 0x6a, 0xbc, 0x5e,
423 0x88, 0x6a, 0xcc, 0x00, 424 0x88, 0x6a, 0xcc, 0x00,
424 0xa4, 0x6a, 0xf4, 0x5d, 425 0xa4, 0x6a, 0xf6, 0x5d,
425 0x08, 0x6a, 0xe0, 0x5d, 426 0x08, 0x6a, 0xe2, 0x5d,
426 0x0d, 0x93, 0x26, 0x01, 427 0x0d, 0x93, 0x26, 0x01,
427 0x00, 0x65, 0xa8, 0x5e, 428 0x00, 0x65, 0xaa, 0x5e,
428 0x88, 0x6a, 0xcc, 0x00, 429 0x88, 0x6a, 0xcc, 0x00,
429 0x00, 0x65, 0x8a, 0x5e, 430 0x00, 0x65, 0x8c, 0x5e,
430 0x01, 0x99, 0x46, 0x31, 431 0x01, 0x99, 0x46, 0x31,
431 0x00, 0xa3, 0xba, 0x5e, 432 0x00, 0xa3, 0xbc, 0x5e,
432 0x01, 0x88, 0x10, 0x31, 433 0x01, 0x88, 0x10, 0x31,
433 0x00, 0x65, 0x3a, 0x5a, 434 0x00, 0x65, 0x3c, 0x5a,
434 0x00, 0x65, 0xfa, 0x59, 435 0x00, 0x65, 0xfc, 0x59,
435 0x03, 0x8c, 0x10, 0x30, 436 0x03, 0x8c, 0x10, 0x30,
436 0x00, 0x65, 0xe6, 0x5d, 437 0x00, 0x65, 0xe8, 0x5d,
437 0x80, 0x0b, 0x82, 0x6a, 438 0x80, 0x0b, 0x84, 0x6a,
438 0x80, 0x0b, 0x62, 0x6b, 439 0x80, 0x0b, 0x64, 0x6b,
439 0x01, 0x0c, 0x5c, 0x7b, 440 0x01, 0x0c, 0x5e, 0x7b,
440 0x10, 0x0c, 0x82, 0x7a, 441 0x10, 0x0c, 0x84, 0x7a,
441 0x03, 0x9e, 0x82, 0x6a, 442 0x03, 0x9e, 0x84, 0x6a,
442 0x00, 0x65, 0x04, 0x5a, 443 0x00, 0x65, 0x06, 0x5a,
443 0x00, 0x6a, 0xba, 0x5e, 444 0x00, 0x6a, 0xbc, 0x5e,
444 0x01, 0xa4, 0x82, 0x6b, 445 0x01, 0xa4, 0x84, 0x6b,
445 0xff, 0x38, 0x78, 0x7b, 446 0xff, 0x38, 0x7a, 0x7b,
446 0x01, 0x38, 0xc8, 0x30, 447 0x01, 0x38, 0xc8, 0x30,
447 0x00, 0x08, 0x40, 0x19, 448 0x00, 0x08, 0x40, 0x19,
448 0xff, 0x6a, 0xc8, 0x08, 449 0xff, 0x6a, 0xc8, 0x08,
449 0x00, 0x09, 0x42, 0x21, 450 0x00, 0x09, 0x42, 0x21,
450 0x00, 0x0a, 0x44, 0x21, 451 0x00, 0x0a, 0x44, 0x21,
451 0xff, 0x6a, 0x70, 0x08, 452 0xff, 0x6a, 0x70, 0x08,
452 0x00, 0x65, 0x7a, 0x43, 453 0x00, 0x65, 0x7c, 0x43,
453 0x03, 0x08, 0x40, 0x31, 454 0x03, 0x08, 0x40, 0x31,
454 0x03, 0x08, 0x40, 0x31, 455 0x03, 0x08, 0x40, 0x31,
455 0x01, 0x08, 0x40, 0x31, 456 0x01, 0x08, 0x40, 0x31,
@@ -461,16 +462,16 @@ static uint8_t seqprog[] = {
461 0x04, 0x3c, 0xcc, 0x79, 462 0x04, 0x3c, 0xcc, 0x79,
462 0xfb, 0x3c, 0x78, 0x08, 463 0xfb, 0x3c, 0x78, 0x08,
463 0x04, 0x93, 0x20, 0x79, 464 0x04, 0x93, 0x20, 0x79,
464 0x01, 0x0c, 0x8e, 0x6b, 465 0x01, 0x0c, 0x90, 0x6b,
465 0x80, 0xba, 0x20, 0x79, 466 0x80, 0xba, 0x20, 0x79,
466 0x80, 0x04, 0x20, 0x79, 467 0x80, 0x04, 0x20, 0x79,
467 0xe4, 0x6a, 0x6e, 0x5d, 468 0xe4, 0x6a, 0x70, 0x5d,
468 0x23, 0x6a, 0x84, 0x5d, 469 0x23, 0x6a, 0x86, 0x5d,
469 0x01, 0x6a, 0x84, 0x5d, 470 0x01, 0x6a, 0x86, 0x5d,
470 0x00, 0x65, 0x20, 0x41, 471 0x00, 0x65, 0x20, 0x41,
471 0x00, 0x65, 0xcc, 0x41, 472 0x00, 0x65, 0xcc, 0x41,
472 0x80, 0x3c, 0xa2, 0x7b, 473 0x80, 0x3c, 0xa4, 0x7b,
473 0x21, 0x6a, 0xd8, 0x5e, 474 0x21, 0x6a, 0xda, 0x5e,
474 0x01, 0xbc, 0x18, 0x31, 475 0x01, 0xbc, 0x18, 0x31,
475 0x02, 0x6a, 0x1a, 0x31, 476 0x02, 0x6a, 0x1a, 0x31,
476 0x02, 0x6a, 0xf8, 0x01, 477 0x02, 0x6a, 0xf8, 0x01,
@@ -480,16 +481,16 @@ static uint8_t seqprog[] = {
480 0xff, 0x6a, 0x12, 0x08, 481 0xff, 0x6a, 0x12, 0x08,
481 0xff, 0x6a, 0x14, 0x08, 482 0xff, 0x6a, 0x14, 0x08,
482 0xf3, 0xbc, 0xd4, 0x18, 483 0xf3, 0xbc, 0xd4, 0x18,
483 0xa0, 0x6a, 0xc8, 0x53, 484 0xa0, 0x6a, 0xca, 0x53,
484 0x04, 0xa0, 0x10, 0x31, 485 0x04, 0xa0, 0x10, 0x31,
485 0xac, 0x6a, 0x26, 0x01, 486 0xac, 0x6a, 0x26, 0x01,
486 0x04, 0xa0, 0x10, 0x31, 487 0x04, 0xa0, 0x10, 0x31,
487 0x03, 0x08, 0x18, 0x31, 488 0x03, 0x08, 0x18, 0x31,
488 0x88, 0x6a, 0xcc, 0x00, 489 0x88, 0x6a, 0xcc, 0x00,
489 0xa0, 0x6a, 0xf4, 0x5d, 490 0xa0, 0x6a, 0xf6, 0x5d,
490 0x00, 0xbc, 0xe0, 0x5d, 491 0x00, 0xbc, 0xe2, 0x5d,
491 0x3d, 0x6a, 0x26, 0x01, 492 0x3d, 0x6a, 0x26, 0x01,
492 0x00, 0x65, 0xe0, 0x43, 493 0x00, 0x65, 0xe2, 0x43,
493 0xff, 0x6a, 0x10, 0x09, 494 0xff, 0x6a, 0x10, 0x09,
494 0xa4, 0x6a, 0x26, 0x01, 495 0xa4, 0x6a, 0x26, 0x01,
495 0x0c, 0xa0, 0x32, 0x31, 496 0x0c, 0xa0, 0x32, 0x31,
@@ -499,128 +500,128 @@ static uint8_t seqprog[] = {
499 0x36, 0x6a, 0x26, 0x01, 500 0x36, 0x6a, 0x26, 0x01,
500 0x02, 0x93, 0x26, 0x01, 501 0x02, 0x93, 0x26, 0x01,
501 0x35, 0x6a, 0x26, 0x01, 502 0x35, 0x6a, 0x26, 0x01,
502 0x00, 0x65, 0x9c, 0x5e, 503 0x00, 0x65, 0x9e, 0x5e,
503 0x00, 0x65, 0x9c, 0x5e, 504 0x00, 0x65, 0x9e, 0x5e,
504 0x02, 0x93, 0x26, 0x01, 505 0x02, 0x93, 0x26, 0x01,
505 0xbf, 0x3c, 0x78, 0x08, 506 0xbf, 0x3c, 0x78, 0x08,
506 0x04, 0x0b, 0xe6, 0x6b, 507 0x04, 0x0b, 0xe8, 0x6b,
507 0x10, 0x0c, 0xe2, 0x7b, 508 0x10, 0x0c, 0xe4, 0x7b,
508 0x01, 0x03, 0xe6, 0x6b, 509 0x01, 0x03, 0xe8, 0x6b,
509 0x20, 0x93, 0xe8, 0x6b, 510 0x20, 0x93, 0xea, 0x6b,
510 0x04, 0x0b, 0xee, 0x6b, 511 0x04, 0x0b, 0xf0, 0x6b,
511 0x40, 0x3c, 0x78, 0x00, 512 0x40, 0x3c, 0x78, 0x00,
512 0xc7, 0x93, 0x26, 0x09, 513 0xc7, 0x93, 0x26, 0x09,
513 0x38, 0x93, 0xf0, 0x6b, 514 0x38, 0x93, 0xf2, 0x6b,
514 0x00, 0x65, 0xcc, 0x41, 515 0x00, 0x65, 0xcc, 0x41,
515 0x80, 0x3c, 0x56, 0x6c, 516 0x80, 0x3c, 0x58, 0x6c,
516 0x01, 0x06, 0x50, 0x31, 517 0x01, 0x06, 0x50, 0x31,
517 0x80, 0xb8, 0x70, 0x01, 518 0x80, 0xb8, 0x70, 0x01,
518 0x00, 0x65, 0xcc, 0x41, 519 0x00, 0x65, 0xcc, 0x41,
519 0x10, 0x3f, 0x06, 0x00, 520 0x10, 0x3f, 0x06, 0x00,
520 0x10, 0x6a, 0x06, 0x00, 521 0x10, 0x6a, 0x06, 0x00,
521 0x01, 0x3a, 0xca, 0x30, 522 0x01, 0x3a, 0xca, 0x30,
522 0x80, 0x65, 0x1c, 0x64, 523 0x80, 0x65, 0x1e, 0x64,
523 0x10, 0xb8, 0x40, 0x6c, 524 0x10, 0xb8, 0x42, 0x6c,
524 0xc0, 0x3e, 0xca, 0x00, 525 0xc0, 0x3e, 0xca, 0x00,
525 0x40, 0xb8, 0x0c, 0x6c, 526 0x40, 0xb8, 0x0e, 0x6c,
526 0xbf, 0x65, 0xca, 0x08, 527 0xbf, 0x65, 0xca, 0x08,
527 0x20, 0xb8, 0x20, 0x7c, 528 0x20, 0xb8, 0x22, 0x7c,
528 0x01, 0x65, 0x0c, 0x30, 529 0x01, 0x65, 0x0c, 0x30,
529 0x00, 0x65, 0xd8, 0x5d, 530 0x00, 0x65, 0xda, 0x5d,
530 0xa0, 0x3f, 0x28, 0x64, 531 0xa0, 0x3f, 0x2a, 0x64,
531 0x23, 0xb8, 0x0c, 0x08, 532 0x23, 0xb8, 0x0c, 0x08,
532 0x00, 0x65, 0xd8, 0x5d, 533 0x00, 0x65, 0xda, 0x5d,
533 0xa0, 0x3f, 0x28, 0x64, 534 0xa0, 0x3f, 0x2a, 0x64,
534 0x00, 0xbb, 0x20, 0x44, 535 0x00, 0xbb, 0x22, 0x44,
535 0xff, 0x65, 0x20, 0x64, 536 0xff, 0x65, 0x22, 0x64,
536 0x00, 0x65, 0x40, 0x44, 537 0x00, 0x65, 0x42, 0x44,
537 0x40, 0x6a, 0x18, 0x00, 538 0x40, 0x6a, 0x18, 0x00,
538 0x01, 0x65, 0x0c, 0x30, 539 0x01, 0x65, 0x0c, 0x30,
539 0x00, 0x65, 0xd8, 0x5d, 540 0x00, 0x65, 0xda, 0x5d,
540 0xa0, 0x3f, 0xfc, 0x73, 541 0xa0, 0x3f, 0xfe, 0x73,
541 0x40, 0x6a, 0x18, 0x00, 542 0x40, 0x6a, 0x18, 0x00,
542 0x01, 0x3a, 0xa6, 0x30, 543 0x01, 0x3a, 0xa6, 0x30,
543 0x08, 0x6a, 0x74, 0x00, 544 0x08, 0x6a, 0x74, 0x00,
544 0x00, 0x65, 0xcc, 0x41, 545 0x00, 0x65, 0xcc, 0x41,
545 0x64, 0x6a, 0x68, 0x5d, 546 0x64, 0x6a, 0x6a, 0x5d,
546 0x80, 0x64, 0xd8, 0x6c, 547 0x80, 0x64, 0xda, 0x6c,
547 0x04, 0x64, 0x9a, 0x74, 548 0x04, 0x64, 0x9c, 0x74,
548 0x02, 0x64, 0xaa, 0x74, 549 0x02, 0x64, 0xac, 0x74,
549 0x00, 0x6a, 0x60, 0x74, 550 0x00, 0x6a, 0x62, 0x74,
550 0x03, 0x64, 0xc8, 0x74, 551 0x03, 0x64, 0xca, 0x74,
551 0x23, 0x64, 0x48, 0x74, 552 0x23, 0x64, 0x4a, 0x74,
552 0x08, 0x64, 0x5c, 0x74, 553 0x08, 0x64, 0x5e, 0x74,
553 0x61, 0x6a, 0xd8, 0x5e, 554 0x61, 0x6a, 0xda, 0x5e,
554 0x00, 0x65, 0xd8, 0x5d, 555 0x00, 0x65, 0xda, 0x5d,
555 0x08, 0x51, 0xce, 0x71, 556 0x08, 0x51, 0xce, 0x71,
556 0x00, 0x65, 0x40, 0x44, 557 0x00, 0x65, 0x42, 0x44,
557 0x80, 0x04, 0x5a, 0x7c, 558 0x80, 0x04, 0x5c, 0x7c,
558 0x51, 0x6a, 0x5e, 0x5d, 559 0x51, 0x6a, 0x60, 0x5d,
559 0x01, 0x51, 0x5a, 0x64, 560 0x01, 0x51, 0x5c, 0x64,
560 0x01, 0xa4, 0x52, 0x7c, 561 0x01, 0xa4, 0x54, 0x7c,
561 0x80, 0xba, 0x5c, 0x6c, 562 0x80, 0xba, 0x5e, 0x6c,
562 0x41, 0x6a, 0xd8, 0x5e, 563 0x41, 0x6a, 0xda, 0x5e,
563 0x00, 0x65, 0x5c, 0x44, 564 0x00, 0x65, 0x5e, 0x44,
564 0x21, 0x6a, 0xd8, 0x5e, 565 0x21, 0x6a, 0xda, 0x5e,
565 0x00, 0x65, 0x5c, 0x44, 566 0x00, 0x65, 0x5e, 0x44,
566 0x07, 0x6a, 0x54, 0x5d, 567 0x07, 0x6a, 0x56, 0x5d,
567 0x01, 0x06, 0xd4, 0x30, 568 0x01, 0x06, 0xd4, 0x30,
568 0x00, 0x65, 0xcc, 0x41, 569 0x00, 0x65, 0xcc, 0x41,
569 0x80, 0xb8, 0x56, 0x7c, 570 0x80, 0xb8, 0x58, 0x7c,
570 0xc0, 0x3c, 0x6a, 0x7c, 571 0xc0, 0x3c, 0x6c, 0x7c,
571 0x80, 0x3c, 0x56, 0x6c, 572 0x80, 0x3c, 0x58, 0x6c,
572 0xff, 0xa8, 0x6a, 0x6c, 573 0xff, 0xa8, 0x6c, 0x6c,
573 0x40, 0x3c, 0x56, 0x6c, 574 0x40, 0x3c, 0x58, 0x6c,
574 0x10, 0xb8, 0x6e, 0x7c, 575 0x10, 0xb8, 0x70, 0x7c,
575 0xa1, 0x6a, 0xd8, 0x5e, 576 0xa1, 0x6a, 0xda, 0x5e,
576 0x01, 0xb4, 0x74, 0x6c, 577 0x01, 0xb4, 0x76, 0x6c,
577 0x02, 0xb4, 0x76, 0x6c, 578 0x02, 0xb4, 0x78, 0x6c,
578 0x01, 0xa4, 0x76, 0x7c, 579 0x01, 0xa4, 0x78, 0x7c,
579 0xff, 0xa8, 0x86, 0x7c, 580 0xff, 0xa8, 0x88, 0x7c,
580 0x04, 0xb4, 0x68, 0x01, 581 0x04, 0xb4, 0x68, 0x01,
581 0x01, 0x6a, 0x76, 0x00, 582 0x01, 0x6a, 0x76, 0x00,
582 0x00, 0xbb, 0x12, 0x5e, 583 0x00, 0xbb, 0x14, 0x5e,
583 0xff, 0xa8, 0x86, 0x7c, 584 0xff, 0xa8, 0x88, 0x7c,
584 0x71, 0x6a, 0xd8, 0x5e, 585 0x71, 0x6a, 0xda, 0x5e,
585 0x40, 0x51, 0x86, 0x64, 586 0x40, 0x51, 0x88, 0x64,
586 0x00, 0x65, 0xb2, 0x5e, 587 0x00, 0x65, 0xb4, 0x5e,
587 0x00, 0x65, 0xde, 0x41, 588 0x00, 0x65, 0xde, 0x41,
588 0x00, 0xbb, 0x8a, 0x5c, 589 0x00, 0xbb, 0x8c, 0x5c,
589 0x00, 0x65, 0xde, 0x41, 590 0x00, 0x65, 0xde, 0x41,
590 0x00, 0x65, 0xb2, 0x5e, 591 0x00, 0x65, 0xb4, 0x5e,
591 0x01, 0x65, 0xa2, 0x30, 592 0x01, 0x65, 0xa2, 0x30,
592 0x01, 0xf8, 0xc8, 0x30, 593 0x01, 0xf8, 0xc8, 0x30,
593 0x01, 0x4e, 0xc8, 0x30, 594 0x01, 0x4e, 0xc8, 0x30,
594 0x00, 0x6a, 0xb6, 0xdd, 595 0x00, 0x6a, 0xb8, 0xdd,
595 0x00, 0x51, 0xc8, 0x5d, 596 0x00, 0x51, 0xca, 0x5d,
596 0x01, 0x4e, 0x9c, 0x18, 597 0x01, 0x4e, 0x9c, 0x18,
597 0x02, 0x6a, 0x22, 0x05, 598 0x02, 0x6a, 0x22, 0x05,
598 0xc0, 0x3c, 0x56, 0x6c, 599 0xc0, 0x3c, 0x58, 0x6c,
599 0x04, 0xb8, 0x70, 0x01, 600 0x04, 0xb8, 0x70, 0x01,
600 0x00, 0x65, 0xd4, 0x5e, 601 0x00, 0x65, 0xd6, 0x5e,
601 0x20, 0xb8, 0xde, 0x69, 602 0x20, 0xb8, 0xde, 0x69,
602 0x01, 0xbb, 0xa2, 0x30, 603 0x01, 0xbb, 0xa2, 0x30,
603 0x3f, 0xba, 0x7c, 0x08, 604 0x3f, 0xba, 0x7c, 0x08,
604 0x00, 0xb9, 0xce, 0x5c, 605 0x00, 0xb9, 0xd0, 0x5c,
605 0x00, 0x65, 0xde, 0x41, 606 0x00, 0x65, 0xde, 0x41,
606 0x01, 0x06, 0xd4, 0x30, 607 0x01, 0x06, 0xd4, 0x30,
607 0x20, 0x3c, 0xcc, 0x79, 608 0x20, 0x3c, 0xcc, 0x79,
608 0x20, 0x3c, 0x5c, 0x7c, 609 0x20, 0x3c, 0x5e, 0x7c,
609 0x01, 0xa4, 0xb8, 0x7c, 610 0x01, 0xa4, 0xba, 0x7c,
610 0x01, 0xb4, 0x68, 0x01, 611 0x01, 0xb4, 0x68, 0x01,
611 0x00, 0x65, 0xcc, 0x41, 612 0x00, 0x65, 0xcc, 0x41,
612 0x00, 0x65, 0x5c, 0x44, 613 0x00, 0x65, 0x5e, 0x44,
613 0x04, 0x14, 0x58, 0x31, 614 0x04, 0x14, 0x58, 0x31,
614 0x01, 0x06, 0xd4, 0x30, 615 0x01, 0x06, 0xd4, 0x30,
615 0x08, 0xa0, 0x60, 0x31, 616 0x08, 0xa0, 0x60, 0x31,
616 0xac, 0x6a, 0xcc, 0x00, 617 0xac, 0x6a, 0xcc, 0x00,
617 0x14, 0x6a, 0xf4, 0x5d, 618 0x14, 0x6a, 0xf6, 0x5d,
618 0x01, 0x06, 0xd4, 0x30, 619 0x01, 0x06, 0xd4, 0x30,
619 0xa0, 0x6a, 0xec, 0x5d, 620 0xa0, 0x6a, 0xee, 0x5d,
620 0x00, 0x65, 0xcc, 0x41, 621 0x00, 0x65, 0xcc, 0x41,
621 0xdf, 0x3c, 0x78, 0x08, 622 0xdf, 0x3c, 0x78, 0x08,
622 0x12, 0x01, 0x02, 0x00, 623 0x12, 0x01, 0x02, 0x00,
623 0x00, 0x65, 0x5c, 0x44, 624 0x00, 0x65, 0x5e, 0x44,
624 0x4c, 0x65, 0xcc, 0x28, 625 0x4c, 0x65, 0xcc, 0x28,
625 0x01, 0x3e, 0x20, 0x31, 626 0x01, 0x3e, 0x20, 0x31,
626 0xd0, 0x66, 0xcc, 0x18, 627 0xd0, 0x66, 0xcc, 0x18,
@@ -631,102 +632,102 @@ static uint8_t seqprog[] = {
631 0xd0, 0x65, 0xca, 0x18, 632 0xd0, 0x65, 0xca, 0x18,
632 0x01, 0x3e, 0x20, 0x31, 633 0x01, 0x3e, 0x20, 0x31,
633 0x30, 0x65, 0xd4, 0x18, 634 0x30, 0x65, 0xd4, 0x18,
634 0x00, 0x65, 0xe6, 0x4c, 635 0x00, 0x65, 0xe8, 0x4c,
635 0xe1, 0x6a, 0x22, 0x01, 636 0xe1, 0x6a, 0x22, 0x01,
636 0xff, 0x6a, 0xd4, 0x08, 637 0xff, 0x6a, 0xd4, 0x08,
637 0x20, 0x65, 0xd4, 0x18, 638 0x20, 0x65, 0xd4, 0x18,
638 0x00, 0x65, 0xee, 0x54, 639 0x00, 0x65, 0xf0, 0x54,
639 0xe1, 0x6a, 0x22, 0x01, 640 0xe1, 0x6a, 0x22, 0x01,
640 0xff, 0x6a, 0xd4, 0x08, 641 0xff, 0x6a, 0xd4, 0x08,
641 0x20, 0x65, 0xca, 0x18, 642 0x20, 0x65, 0xca, 0x18,
642 0xe0, 0x65, 0xd4, 0x18, 643 0xe0, 0x65, 0xd4, 0x18,
643 0x00, 0x65, 0xf8, 0x4c, 644 0x00, 0x65, 0xfa, 0x4c,
644 0xe1, 0x6a, 0x22, 0x01, 645 0xe1, 0x6a, 0x22, 0x01,
645 0xff, 0x6a, 0xd4, 0x08, 646 0xff, 0x6a, 0xd4, 0x08,
646 0xd0, 0x65, 0xd4, 0x18, 647 0xd0, 0x65, 0xd4, 0x18,
647 0x00, 0x65, 0x00, 0x55, 648 0x00, 0x65, 0x02, 0x55,
648 0xe1, 0x6a, 0x22, 0x01, 649 0xe1, 0x6a, 0x22, 0x01,
649 0xff, 0x6a, 0xd4, 0x08, 650 0xff, 0x6a, 0xd4, 0x08,
650 0x01, 0x6c, 0xa2, 0x30, 651 0x01, 0x6c, 0xa2, 0x30,
651 0xff, 0x51, 0x12, 0x75, 652 0xff, 0x51, 0x14, 0x75,
652 0x00, 0x51, 0x8e, 0x5d, 653 0x00, 0x51, 0x90, 0x5d,
653 0x01, 0x51, 0x20, 0x31, 654 0x01, 0x51, 0x20, 0x31,
654 0x00, 0x65, 0x34, 0x45, 655 0x00, 0x65, 0x36, 0x45,
655 0x3f, 0xba, 0xc8, 0x08, 656 0x3f, 0xba, 0xc8, 0x08,
656 0x00, 0x3e, 0x34, 0x75, 657 0x00, 0x3e, 0x36, 0x75,
657 0x00, 0x65, 0xb0, 0x5e, 658 0x00, 0x65, 0xb2, 0x5e,
658 0x80, 0x3c, 0x78, 0x00, 659 0x80, 0x3c, 0x78, 0x00,
659 0x01, 0x06, 0xd4, 0x30, 660 0x01, 0x06, 0xd4, 0x30,
660 0x00, 0x65, 0xd8, 0x5d, 661 0x00, 0x65, 0xda, 0x5d,
661 0x01, 0x3c, 0x78, 0x00, 662 0x01, 0x3c, 0x78, 0x00,
662 0xe0, 0x3f, 0x50, 0x65, 663 0xe0, 0x3f, 0x52, 0x65,
663 0x02, 0x3c, 0x78, 0x00, 664 0x02, 0x3c, 0x78, 0x00,
664 0x20, 0x12, 0x50, 0x65, 665 0x20, 0x12, 0x52, 0x65,
665 0x51, 0x6a, 0x5e, 0x5d, 666 0x51, 0x6a, 0x60, 0x5d,
666 0x00, 0x51, 0x8e, 0x5d, 667 0x00, 0x51, 0x90, 0x5d,
667 0x51, 0x6a, 0x5e, 0x5d, 668 0x51, 0x6a, 0x60, 0x5d,
668 0x01, 0x51, 0x20, 0x31, 669 0x01, 0x51, 0x20, 0x31,
669 0x04, 0x3c, 0x78, 0x00, 670 0x04, 0x3c, 0x78, 0x00,
670 0x01, 0xb9, 0xc8, 0x30, 671 0x01, 0xb9, 0xc8, 0x30,
671 0x00, 0x3d, 0x4e, 0x65, 672 0x00, 0x3d, 0x50, 0x65,
672 0x08, 0x3c, 0x78, 0x00, 673 0x08, 0x3c, 0x78, 0x00,
673 0x3f, 0xba, 0xc8, 0x08, 674 0x3f, 0xba, 0xc8, 0x08,
674 0x00, 0x3e, 0x4e, 0x65, 675 0x00, 0x3e, 0x50, 0x65,
675 0x10, 0x3c, 0x78, 0x00, 676 0x10, 0x3c, 0x78, 0x00,
676 0x04, 0xb8, 0x4e, 0x7d, 677 0x04, 0xb8, 0x50, 0x7d,
677 0xfb, 0xb8, 0x70, 0x09, 678 0xfb, 0xb8, 0x70, 0x09,
678 0x20, 0xb8, 0x44, 0x6d, 679 0x20, 0xb8, 0x46, 0x6d,
679 0x01, 0x90, 0xc8, 0x30, 680 0x01, 0x90, 0xc8, 0x30,
680 0xff, 0x6a, 0xa2, 0x00, 681 0xff, 0x6a, 0xa2, 0x00,
681 0x00, 0x3d, 0xce, 0x5c, 682 0x00, 0x3d, 0xd0, 0x5c,
682 0x01, 0x64, 0x20, 0x31, 683 0x01, 0x64, 0x20, 0x31,
683 0xff, 0x6a, 0x78, 0x08, 684 0xff, 0x6a, 0x78, 0x08,
684 0x00, 0x65, 0xea, 0x58, 685 0x00, 0x65, 0xea, 0x58,
685 0x10, 0xb8, 0x5c, 0x7c, 686 0x10, 0xb8, 0x5e, 0x7c,
686 0xff, 0x6a, 0x54, 0x5d, 687 0xff, 0x6a, 0x56, 0x5d,
687 0x00, 0x65, 0x5c, 0x44, 688 0x00, 0x65, 0x5e, 0x44,
688 0x00, 0x65, 0xb0, 0x5e, 689 0x00, 0x65, 0xb2, 0x5e,
689 0x31, 0x6a, 0xd8, 0x5e, 690 0x31, 0x6a, 0xda, 0x5e,
690 0x00, 0x65, 0x5c, 0x44, 691 0x00, 0x65, 0x5e, 0x44,
691 0x10, 0x3f, 0x06, 0x00, 692 0x10, 0x3f, 0x06, 0x00,
692 0x10, 0x6a, 0x06, 0x00, 693 0x10, 0x6a, 0x06, 0x00,
693 0x01, 0x65, 0x74, 0x34, 694 0x01, 0x65, 0x74, 0x34,
694 0x81, 0x6a, 0xd8, 0x5e, 695 0x81, 0x6a, 0xda, 0x5e,
695 0x00, 0x65, 0x60, 0x45, 696 0x00, 0x65, 0x62, 0x45,
696 0x01, 0x06, 0xd4, 0x30, 697 0x01, 0x06, 0xd4, 0x30,
697 0x01, 0x0c, 0x60, 0x7d, 698 0x01, 0x0c, 0x62, 0x7d,
698 0x04, 0x0c, 0x5a, 0x6d, 699 0x04, 0x0c, 0x5c, 0x6d,
699 0xe0, 0x03, 0x7e, 0x08, 700 0xe0, 0x03, 0x7e, 0x08,
700 0xe0, 0x3f, 0xcc, 0x61, 701 0xe0, 0x3f, 0xcc, 0x61,
701 0x01, 0x65, 0xcc, 0x30, 702 0x01, 0x65, 0xcc, 0x30,
702 0x01, 0x12, 0xda, 0x34, 703 0x01, 0x12, 0xda, 0x34,
703 0x01, 0x06, 0xd4, 0x34, 704 0x01, 0x06, 0xd4, 0x34,
704 0x01, 0x03, 0x6e, 0x6d, 705 0x01, 0x03, 0x70, 0x6d,
705 0x40, 0x03, 0xcc, 0x08, 706 0x40, 0x03, 0xcc, 0x08,
706 0x01, 0x65, 0x06, 0x30, 707 0x01, 0x65, 0x06, 0x30,
707 0x40, 0x65, 0xc8, 0x08, 708 0x40, 0x65, 0xc8, 0x08,
708 0x00, 0x66, 0x7c, 0x75, 709 0x00, 0x66, 0x7e, 0x75,
709 0x40, 0x65, 0x7c, 0x7d, 710 0x40, 0x65, 0x7e, 0x7d,
710 0x00, 0x65, 0x7c, 0x5d, 711 0x00, 0x65, 0x7e, 0x5d,
711 0xff, 0x6a, 0xd4, 0x08, 712 0xff, 0x6a, 0xd4, 0x08,
712 0xff, 0x6a, 0xd4, 0x08, 713 0xff, 0x6a, 0xd4, 0x08,
713 0xff, 0x6a, 0xd4, 0x08, 714 0xff, 0x6a, 0xd4, 0x08,
714 0xff, 0x6a, 0xd4, 0x0c, 715 0xff, 0x6a, 0xd4, 0x0c,
715 0x08, 0x01, 0x02, 0x00, 716 0x08, 0x01, 0x02, 0x00,
716 0x02, 0x0b, 0x86, 0x7d, 717 0x02, 0x0b, 0x88, 0x7d,
717 0x01, 0x65, 0x0c, 0x30, 718 0x01, 0x65, 0x0c, 0x30,
718 0x02, 0x0b, 0x8a, 0x7d, 719 0x02, 0x0b, 0x8c, 0x7d,
719 0xf7, 0x01, 0x02, 0x0c, 720 0xf7, 0x01, 0x02, 0x0c,
720 0x01, 0x65, 0xc8, 0x30, 721 0x01, 0x65, 0xc8, 0x30,
721 0xff, 0x41, 0xae, 0x75, 722 0xff, 0x41, 0xb0, 0x75,
722 0x01, 0x41, 0x20, 0x31, 723 0x01, 0x41, 0x20, 0x31,
723 0xff, 0x6a, 0xa4, 0x00, 724 0xff, 0x6a, 0xa4, 0x00,
724 0x00, 0x65, 0x9e, 0x45, 725 0x00, 0x65, 0xa0, 0x45,
725 0xff, 0xbf, 0xae, 0x75, 726 0xff, 0xbf, 0xb0, 0x75,
726 0x01, 0x90, 0xa4, 0x30, 727 0x01, 0x90, 0xa4, 0x30,
727 0x01, 0xbf, 0x20, 0x31, 728 0x01, 0xbf, 0x20, 0x31,
728 0x00, 0xbb, 0x98, 0x65, 729 0x00, 0xbb, 0x9a, 0x65,
729 0xff, 0x52, 0xac, 0x75, 730 0xff, 0x52, 0xae, 0x75,
730 0x01, 0xbf, 0xcc, 0x30, 731 0x01, 0xbf, 0xcc, 0x30,
731 0x01, 0x90, 0xca, 0x30, 732 0x01, 0x90, 0xca, 0x30,
732 0x01, 0x52, 0x20, 0x31, 733 0x01, 0x52, 0x20, 0x31,
@@ -734,28 +735,28 @@ static uint8_t seqprog[] = {
734 0x01, 0x65, 0x20, 0x35, 735 0x01, 0x65, 0x20, 0x35,
735 0x01, 0xbf, 0x82, 0x34, 736 0x01, 0xbf, 0x82, 0x34,
736 0x01, 0x64, 0xa2, 0x30, 737 0x01, 0x64, 0xa2, 0x30,
737 0x00, 0x6a, 0xc0, 0x5e, 738 0x00, 0x6a, 0xc2, 0x5e,
738 0x0d, 0x6a, 0x76, 0x00, 739 0x0d, 0x6a, 0x76, 0x00,
739 0x00, 0x51, 0x12, 0x46, 740 0x00, 0x51, 0x14, 0x46,
740 0x01, 0x65, 0xa4, 0x30, 741 0x01, 0x65, 0xa4, 0x30,
741 0xe0, 0x6a, 0xcc, 0x00, 742 0xe0, 0x6a, 0xcc, 0x00,
742 0x48, 0x6a, 0x06, 0x5e, 743 0x48, 0x6a, 0x08, 0x5e,
743 0x01, 0x6a, 0xd0, 0x01, 744 0x01, 0x6a, 0xd0, 0x01,
744 0x01, 0x6a, 0xdc, 0x05, 745 0x01, 0x6a, 0xdc, 0x05,
745 0x88, 0x6a, 0xcc, 0x00, 746 0x88, 0x6a, 0xcc, 0x00,
746 0x48, 0x6a, 0x06, 0x5e, 747 0x48, 0x6a, 0x08, 0x5e,
747 0x01, 0x6a, 0xe0, 0x5d, 748 0x01, 0x6a, 0xe2, 0x5d,
748 0x01, 0x6a, 0x26, 0x05, 749 0x01, 0x6a, 0x26, 0x05,
749 0x01, 0x65, 0xd8, 0x31, 750 0x01, 0x65, 0xd8, 0x31,
750 0x09, 0xee, 0xdc, 0x01, 751 0x09, 0xee, 0xdc, 0x01,
751 0x80, 0xee, 0xcc, 0x7d, 752 0x80, 0xee, 0xce, 0x7d,
752 0xff, 0x6a, 0xdc, 0x0d, 753 0xff, 0x6a, 0xdc, 0x0d,
753 0x01, 0x65, 0x32, 0x31, 754 0x01, 0x65, 0x32, 0x31,
754 0x0a, 0x93, 0x26, 0x01, 755 0x0a, 0x93, 0x26, 0x01,
755 0x00, 0x65, 0xa8, 0x46, 756 0x00, 0x65, 0xaa, 0x46,
756 0x81, 0x6a, 0xd8, 0x5e, 757 0x81, 0x6a, 0xda, 0x5e,
757 0x01, 0x0c, 0xd8, 0x7d, 758 0x01, 0x0c, 0xda, 0x7d,
758 0x04, 0x0c, 0xd6, 0x6d, 759 0x04, 0x0c, 0xd8, 0x6d,
759 0xe0, 0x03, 0x06, 0x08, 760 0xe0, 0x03, 0x06, 0x08,
760 0xe0, 0x03, 0x7e, 0x0c, 761 0xe0, 0x03, 0x7e, 0x0c,
761 0x01, 0x65, 0x18, 0x31, 762 0x01, 0x65, 0x18, 0x31,
@@ -774,7 +775,7 @@ static uint8_t seqprog[] = {
774 0x01, 0x6c, 0xda, 0x34, 775 0x01, 0x6c, 0xda, 0x34,
775 0x3d, 0x64, 0xa4, 0x28, 776 0x3d, 0x64, 0xa4, 0x28,
776 0x55, 0x64, 0xc8, 0x28, 777 0x55, 0x64, 0xc8, 0x28,
777 0x00, 0x65, 0x06, 0x46, 778 0x00, 0x65, 0x08, 0x46,
778 0x2e, 0x64, 0xa4, 0x28, 779 0x2e, 0x64, 0xa4, 0x28,
779 0x66, 0x64, 0xc8, 0x28, 780 0x66, 0x64, 0xc8, 0x28,
780 0x00, 0x6c, 0xda, 0x18, 781 0x00, 0x6c, 0xda, 0x18,
@@ -785,63 +786,63 @@ static uint8_t seqprog[] = {
785 0x00, 0x6c, 0xda, 0x24, 786 0x00, 0x6c, 0xda, 0x24,
786 0x01, 0x65, 0xc8, 0x30, 787 0x01, 0x65, 0xc8, 0x30,
787 0xe0, 0x6a, 0xcc, 0x00, 788 0xe0, 0x6a, 0xcc, 0x00,
788 0x44, 0x6a, 0x02, 0x5e, 789 0x44, 0x6a, 0x04, 0x5e,
789 0x01, 0x90, 0xe2, 0x31, 790 0x01, 0x90, 0xe2, 0x31,
790 0x04, 0x3b, 0x26, 0x7e, 791 0x04, 0x3b, 0x28, 0x7e,
791 0x30, 0x6a, 0xd0, 0x01, 792 0x30, 0x6a, 0xd0, 0x01,
792 0x20, 0x6a, 0xd0, 0x01, 793 0x20, 0x6a, 0xd0, 0x01,
793 0x1d, 0x6a, 0xdc, 0x01, 794 0x1d, 0x6a, 0xdc, 0x01,
794 0xdc, 0xee, 0x22, 0x66, 795 0xdc, 0xee, 0x24, 0x66,
795 0x00, 0x65, 0x3e, 0x46, 796 0x00, 0x65, 0x40, 0x46,
796 0x20, 0x6a, 0xd0, 0x01, 797 0x20, 0x6a, 0xd0, 0x01,
797 0x01, 0x6a, 0xdc, 0x01, 798 0x01, 0x6a, 0xdc, 0x01,
798 0x20, 0xa0, 0xd8, 0x31, 799 0x20, 0xa0, 0xd8, 0x31,
799 0x09, 0xee, 0xdc, 0x01, 800 0x09, 0xee, 0xdc, 0x01,
800 0x80, 0xee, 0x2e, 0x7e, 801 0x80, 0xee, 0x30, 0x7e,
801 0x11, 0x6a, 0xdc, 0x01, 802 0x11, 0x6a, 0xdc, 0x01,
802 0x50, 0xee, 0x32, 0x66, 803 0x50, 0xee, 0x34, 0x66,
803 0x20, 0x6a, 0xd0, 0x01, 804 0x20, 0x6a, 0xd0, 0x01,
804 0x09, 0x6a, 0xdc, 0x01, 805 0x09, 0x6a, 0xdc, 0x01,
805 0x88, 0xee, 0x38, 0x66, 806 0x88, 0xee, 0x3a, 0x66,
806 0x19, 0x6a, 0xdc, 0x01, 807 0x19, 0x6a, 0xdc, 0x01,
807 0xd8, 0xee, 0x3c, 0x66, 808 0xd8, 0xee, 0x3e, 0x66,
808 0xff, 0x6a, 0xdc, 0x09, 809 0xff, 0x6a, 0xdc, 0x09,
809 0x18, 0xee, 0x40, 0x6e, 810 0x18, 0xee, 0x42, 0x6e,
810 0xff, 0x6a, 0xd4, 0x0c, 811 0xff, 0x6a, 0xd4, 0x0c,
811 0x88, 0x6a, 0xcc, 0x00, 812 0x88, 0x6a, 0xcc, 0x00,
812 0x44, 0x6a, 0x02, 0x5e, 813 0x44, 0x6a, 0x04, 0x5e,
813 0x20, 0x6a, 0xe0, 0x5d, 814 0x20, 0x6a, 0xe2, 0x5d,
814 0x01, 0x3b, 0x26, 0x31, 815 0x01, 0x3b, 0x26, 0x31,
815 0x04, 0x3b, 0x5a, 0x6e, 816 0x04, 0x3b, 0x5c, 0x6e,
816 0xa0, 0x6a, 0xca, 0x00, 817 0xa0, 0x6a, 0xca, 0x00,
817 0x20, 0x65, 0xc8, 0x18, 818 0x20, 0x65, 0xc8, 0x18,
818 0x00, 0x65, 0x98, 0x5e, 819 0x00, 0x65, 0x9a, 0x5e,
819 0x00, 0x65, 0x52, 0x66, 820 0x00, 0x65, 0x54, 0x66,
820 0x0a, 0x93, 0x26, 0x01, 821 0x0a, 0x93, 0x26, 0x01,
821 0x00, 0x65, 0xa8, 0x46, 822 0x00, 0x65, 0xaa, 0x46,
822 0xa0, 0x6a, 0xcc, 0x00, 823 0xa0, 0x6a, 0xcc, 0x00,
823 0xff, 0x6a, 0xc8, 0x08, 824 0xff, 0x6a, 0xc8, 0x08,
824 0x20, 0x94, 0x5e, 0x6e, 825 0x20, 0x94, 0x60, 0x6e,
825 0x10, 0x94, 0x60, 0x6e, 826 0x10, 0x94, 0x62, 0x6e,
826 0x08, 0x94, 0x7a, 0x6e, 827 0x08, 0x94, 0x7c, 0x6e,
827 0x08, 0x94, 0x7a, 0x6e, 828 0x08, 0x94, 0x7c, 0x6e,
828 0x08, 0x94, 0x7a, 0x6e, 829 0x08, 0x94, 0x7c, 0x6e,
829 0xff, 0x8c, 0xc8, 0x10, 830 0xff, 0x8c, 0xc8, 0x10,
830 0xc1, 0x64, 0xc8, 0x18, 831 0xc1, 0x64, 0xc8, 0x18,
831 0xf8, 0x64, 0xc8, 0x08, 832 0xf8, 0x64, 0xc8, 0x08,
832 0x01, 0x99, 0xda, 0x30, 833 0x01, 0x99, 0xda, 0x30,
833 0x00, 0x66, 0x6e, 0x66, 834 0x00, 0x66, 0x70, 0x66,
834 0xc0, 0x66, 0xaa, 0x76, 835 0xc0, 0x66, 0xac, 0x76,
835 0x60, 0x66, 0xc8, 0x18, 836 0x60, 0x66, 0xc8, 0x18,
836 0x3d, 0x64, 0xc8, 0x28, 837 0x3d, 0x64, 0xc8, 0x28,
837 0x00, 0x65, 0x5e, 0x46, 838 0x00, 0x65, 0x60, 0x46,
838 0xf7, 0x93, 0x26, 0x09, 839 0xf7, 0x93, 0x26, 0x09,
839 0x08, 0x93, 0x7c, 0x6e, 840 0x08, 0x93, 0x7e, 0x6e,
840 0x00, 0x62, 0xc4, 0x18, 841 0x00, 0x62, 0xc4, 0x18,
841 0x00, 0x65, 0xa8, 0x5e, 842 0x00, 0x65, 0xaa, 0x5e,
842 0x00, 0x65, 0x88, 0x5e, 843 0x00, 0x65, 0x8a, 0x5e,
843 0x00, 0x65, 0x88, 0x5e, 844 0x00, 0x65, 0x8a, 0x5e,
844 0x00, 0x65, 0x88, 0x5e, 845 0x00, 0x65, 0x8a, 0x5e,
845 0x01, 0x99, 0xda, 0x30, 846 0x01, 0x99, 0xda, 0x30,
846 0x01, 0x99, 0xda, 0x30, 847 0x01, 0x99, 0xda, 0x30,
847 0x01, 0x99, 0xda, 0x30, 848 0x01, 0x99, 0xda, 0x30,
@@ -858,11 +859,11 @@ static uint8_t seqprog[] = {
858 0x01, 0x6c, 0x32, 0x31, 859 0x01, 0x6c, 0x32, 0x31,
859 0x01, 0x6c, 0x32, 0x31, 860 0x01, 0x6c, 0x32, 0x31,
860 0x01, 0x6c, 0x32, 0x35, 861 0x01, 0x6c, 0x32, 0x35,
861 0x08, 0x94, 0xa8, 0x7e, 862 0x08, 0x94, 0xaa, 0x7e,
862 0xf7, 0x93, 0x26, 0x09, 863 0xf7, 0x93, 0x26, 0x09,
863 0x08, 0x93, 0xac, 0x6e, 864 0x08, 0x93, 0xae, 0x6e,
864 0xff, 0x6a, 0xd4, 0x0c, 865 0xff, 0x6a, 0xd4, 0x0c,
865 0x04, 0xb8, 0xd4, 0x6e, 866 0x04, 0xb8, 0xd6, 0x6e,
866 0x01, 0x42, 0x7e, 0x31, 867 0x01, 0x42, 0x7e, 0x31,
867 0xff, 0x6a, 0x76, 0x01, 868 0xff, 0x6a, 0x76, 0x01,
868 0x01, 0x90, 0x84, 0x34, 869 0x01, 0x90, 0x84, 0x34,
@@ -870,14 +871,14 @@ static uint8_t seqprog[] = {
870 0x01, 0x85, 0x0a, 0x01, 871 0x01, 0x85, 0x0a, 0x01,
871 0x7f, 0x65, 0x10, 0x09, 872 0x7f, 0x65, 0x10, 0x09,
872 0xfe, 0x85, 0x0a, 0x0d, 873 0xfe, 0x85, 0x0a, 0x0d,
873 0xff, 0x42, 0xd0, 0x66, 874 0xff, 0x42, 0xd2, 0x66,
874 0xff, 0x41, 0xc8, 0x66, 875 0xff, 0x41, 0xca, 0x66,
875 0xd1, 0x6a, 0xd8, 0x5e, 876 0xd1, 0x6a, 0xda, 0x5e,
876 0xff, 0x6a, 0xca, 0x04, 877 0xff, 0x6a, 0xca, 0x04,
877 0x01, 0x41, 0x20, 0x31, 878 0x01, 0x41, 0x20, 0x31,
878 0x01, 0xbf, 0x82, 0x30, 879 0x01, 0xbf, 0x82, 0x30,
879 0x01, 0x6a, 0x76, 0x00, 880 0x01, 0x6a, 0x76, 0x00,
880 0x00, 0xbb, 0x12, 0x46, 881 0x00, 0xbb, 0x14, 0x46,
881 0x01, 0x42, 0x20, 0x31, 882 0x01, 0x42, 0x20, 0x31,
882 0x01, 0xbf, 0x84, 0x34, 883 0x01, 0xbf, 0x84, 0x34,
883 0x01, 0x41, 0x7e, 0x31, 884 0x01, 0x41, 0x7e, 0x31,
@@ -941,7 +942,7 @@ static ahc_patch_func_t ahc_patch17_func;
941static int 942static int
942ahc_patch17_func(struct ahc_softc *ahc) 943ahc_patch17_func(struct ahc_softc *ahc)
943{ 944{
944 return ((ahc->flags & AHC_TMODE_WIDEODD_BUG) != 0); 945 return ((ahc->bugs & AHC_TMODE_WIDEODD_BUG) != 0);
945} 946}
946 947
947static ahc_patch_func_t ahc_patch16_func; 948static ahc_patch_func_t ahc_patch16_func;
@@ -1142,152 +1143,152 @@ static struct patch {
1142 { ahc_patch0_func, 196, 1, 1 }, 1143 { ahc_patch0_func, 196, 1, 1 },
1143 { ahc_patch9_func, 212, 6, 2 }, 1144 { ahc_patch9_func, 212, 6, 2 },
1144 { ahc_patch0_func, 218, 6, 1 }, 1145 { ahc_patch0_func, 218, 6, 1 },
1145 { ahc_patch8_func, 226, 20, 2 }, 1146 { ahc_patch8_func, 226, 21, 2 },
1146 { ahc_patch1_func, 241, 1, 1 }, 1147 { ahc_patch1_func, 241, 1, 1 },
1147 { ahc_patch1_func, 248, 1, 2 }, 1148 { ahc_patch1_func, 249, 1, 2 },
1148 { ahc_patch0_func, 249, 2, 2 }, 1149 { ahc_patch0_func, 250, 2, 2 },
1149 { ahc_patch11_func, 250, 1, 1 }, 1150 { ahc_patch11_func, 251, 1, 1 },
1150 { ahc_patch9_func, 258, 27, 3 }, 1151 { ahc_patch9_func, 259, 27, 3 },
1151 { ahc_patch1_func, 274, 10, 2 }, 1152 { ahc_patch1_func, 275, 10, 2 },
1152 { ahc_patch13_func, 277, 1, 1 }, 1153 { ahc_patch13_func, 278, 1, 1 },
1153 { ahc_patch14_func, 285, 14, 1 }, 1154 { ahc_patch14_func, 286, 14, 1 },
1154 { ahc_patch1_func, 301, 1, 2 }, 1155 { ahc_patch1_func, 302, 1, 2 },
1155 { ahc_patch0_func, 302, 1, 1 }, 1156 { ahc_patch0_func, 303, 1, 1 },
1156 { ahc_patch9_func, 305, 1, 1 }, 1157 { ahc_patch9_func, 306, 1, 1 },
1157 { ahc_patch13_func, 310, 1, 1 }, 1158 { ahc_patch13_func, 311, 1, 1 },
1158 { ahc_patch9_func, 311, 2, 2 }, 1159 { ahc_patch9_func, 312, 2, 2 },
1159 { ahc_patch0_func, 313, 4, 1 }, 1160 { ahc_patch0_func, 314, 4, 1 },
1160 { ahc_patch14_func, 317, 1, 1 }, 1161 { ahc_patch14_func, 318, 1, 1 },
1161 { ahc_patch15_func, 319, 2, 3 }, 1162 { ahc_patch15_func, 320, 2, 3 },
1162 { ahc_patch9_func, 319, 1, 2 }, 1163 { ahc_patch9_func, 320, 1, 2 },
1163 { ahc_patch0_func, 320, 1, 1 }, 1164 { ahc_patch0_func, 321, 1, 1 },
1164 { ahc_patch6_func, 325, 1, 2 }, 1165 { ahc_patch6_func, 326, 1, 2 },
1165 { ahc_patch0_func, 326, 1, 1 }, 1166 { ahc_patch0_func, 327, 1, 1 },
1166 { ahc_patch1_func, 330, 47, 11 }, 1167 { ahc_patch1_func, 331, 47, 11 },
1167 { ahc_patch6_func, 337, 2, 4 }, 1168 { ahc_patch6_func, 338, 2, 4 },
1168 { ahc_patch7_func, 337, 1, 1 }, 1169 { ahc_patch7_func, 338, 1, 1 },
1169 { ahc_patch8_func, 338, 1, 1 }, 1170 { ahc_patch8_func, 339, 1, 1 },
1170 { ahc_patch0_func, 339, 1, 1 }, 1171 { ahc_patch0_func, 340, 1, 1 },
1171 { ahc_patch16_func, 340, 1, 1 }, 1172 { ahc_patch16_func, 341, 1, 1 },
1172 { ahc_patch6_func, 356, 6, 3 }, 1173 { ahc_patch6_func, 357, 6, 3 },
1173 { ahc_patch16_func, 356, 5, 1 }, 1174 { ahc_patch16_func, 357, 5, 1 },
1174 { ahc_patch0_func, 362, 7, 1 }, 1175 { ahc_patch0_func, 363, 7, 1 },
1175 { ahc_patch13_func, 372, 5, 1 }, 1176 { ahc_patch13_func, 373, 5, 1 },
1176 { ahc_patch0_func, 377, 52, 17 }, 1177 { ahc_patch0_func, 378, 52, 17 },
1177 { ahc_patch14_func, 377, 1, 1 }, 1178 { ahc_patch14_func, 378, 1, 1 },
1178 { ahc_patch7_func, 379, 2, 2 }, 1179 { ahc_patch7_func, 380, 2, 2 },
1179 { ahc_patch17_func, 380, 1, 1 }, 1180 { ahc_patch17_func, 381, 1, 1 },
1180 { ahc_patch9_func, 383, 1, 1 }, 1181 { ahc_patch9_func, 384, 1, 1 },
1181 { ahc_patch18_func, 390, 1, 1 }, 1182 { ahc_patch18_func, 391, 1, 1 },
1182 { ahc_patch14_func, 395, 9, 3 }, 1183 { ahc_patch14_func, 396, 9, 3 },
1183 { ahc_patch9_func, 396, 3, 2 }, 1184 { ahc_patch9_func, 397, 3, 2 },
1184 { ahc_patch0_func, 399, 3, 1 }, 1185 { ahc_patch0_func, 400, 3, 1 },
1185 { ahc_patch9_func, 407, 6, 2 }, 1186 { ahc_patch9_func, 408, 6, 2 },
1186 { ahc_patch0_func, 413, 9, 2 }, 1187 { ahc_patch0_func, 414, 9, 2 },
1187 { ahc_patch13_func, 413, 1, 1 }, 1188 { ahc_patch13_func, 414, 1, 1 },
1188 { ahc_patch13_func, 422, 2, 1 }, 1189 { ahc_patch13_func, 423, 2, 1 },
1189 { ahc_patch14_func, 424, 1, 1 }, 1190 { ahc_patch14_func, 425, 1, 1 },
1190 { ahc_patch9_func, 426, 1, 2 }, 1191 { ahc_patch9_func, 427, 1, 2 },
1191 { ahc_patch0_func, 427, 1, 1 }, 1192 { ahc_patch0_func, 428, 1, 1 },
1192 { ahc_patch7_func, 428, 1, 1 },
1193 { ahc_patch7_func, 429, 1, 1 }, 1193 { ahc_patch7_func, 429, 1, 1 },
1194 { ahc_patch8_func, 430, 3, 3 }, 1194 { ahc_patch7_func, 430, 1, 1 },
1195 { ahc_patch6_func, 431, 1, 2 }, 1195 { ahc_patch8_func, 431, 3, 3 },
1196 { ahc_patch0_func, 432, 1, 1 }, 1196 { ahc_patch6_func, 432, 1, 2 },
1197 { ahc_patch9_func, 433, 1, 1 }, 1197 { ahc_patch0_func, 433, 1, 1 },
1198 { ahc_patch15_func, 434, 1, 2 }, 1198 { ahc_patch9_func, 434, 1, 1 },
1199 { ahc_patch13_func, 434, 1, 1 }, 1199 { ahc_patch15_func, 435, 1, 2 },
1200 { ahc_patch14_func, 436, 9, 4 }, 1200 { ahc_patch13_func, 435, 1, 1 },
1201 { ahc_patch9_func, 436, 1, 1 }, 1201 { ahc_patch14_func, 437, 9, 4 },
1202 { ahc_patch9_func, 443, 2, 1 }, 1202 { ahc_patch9_func, 437, 1, 1 },
1203 { ahc_patch0_func, 445, 4, 3 }, 1203 { ahc_patch9_func, 444, 2, 1 },
1204 { ahc_patch9_func, 445, 1, 2 }, 1204 { ahc_patch0_func, 446, 4, 3 },
1205 { ahc_patch0_func, 446, 3, 1 }, 1205 { ahc_patch9_func, 446, 1, 2 },
1206 { ahc_patch1_func, 450, 2, 1 }, 1206 { ahc_patch0_func, 447, 3, 1 },
1207 { ahc_patch7_func, 452, 10, 2 }, 1207 { ahc_patch1_func, 451, 2, 1 },
1208 { ahc_patch0_func, 462, 1, 1 }, 1208 { ahc_patch7_func, 453, 10, 2 },
1209 { ahc_patch8_func, 463, 118, 22 }, 1209 { ahc_patch0_func, 463, 1, 1 },
1210 { ahc_patch1_func, 465, 3, 2 }, 1210 { ahc_patch8_func, 464, 118, 22 },
1211 { ahc_patch0_func, 468, 5, 3 }, 1211 { ahc_patch1_func, 466, 3, 2 },
1212 { ahc_patch9_func, 468, 2, 2 }, 1212 { ahc_patch0_func, 469, 5, 3 },
1213 { ahc_patch0_func, 470, 3, 1 }, 1213 { ahc_patch9_func, 469, 2, 2 },
1214 { ahc_patch1_func, 475, 2, 2 }, 1214 { ahc_patch0_func, 471, 3, 1 },
1215 { ahc_patch0_func, 477, 6, 3 }, 1215 { ahc_patch1_func, 476, 2, 2 },
1216 { ahc_patch9_func, 477, 2, 2 }, 1216 { ahc_patch0_func, 478, 6, 3 },
1217 { ahc_patch0_func, 479, 3, 1 }, 1217 { ahc_patch9_func, 478, 2, 2 },
1218 { ahc_patch1_func, 485, 2, 2 }, 1218 { ahc_patch0_func, 480, 3, 1 },
1219 { ahc_patch0_func, 487, 9, 7 }, 1219 { ahc_patch1_func, 486, 2, 2 },
1220 { ahc_patch9_func, 487, 5, 6 }, 1220 { ahc_patch0_func, 488, 9, 7 },
1221 { ahc_patch19_func, 487, 1, 2 }, 1221 { ahc_patch9_func, 488, 5, 6 },
1222 { ahc_patch0_func, 488, 1, 1 }, 1222 { ahc_patch19_func, 488, 1, 2 },
1223 { ahc_patch19_func, 490, 1, 2 }, 1223 { ahc_patch0_func, 489, 1, 1 },
1224 { ahc_patch0_func, 491, 1, 1 }, 1224 { ahc_patch19_func, 491, 1, 2 },
1225 { ahc_patch0_func, 492, 4, 1 }, 1225 { ahc_patch0_func, 492, 1, 1 },
1226 { ahc_patch6_func, 497, 3, 2 }, 1226 { ahc_patch0_func, 493, 4, 1 },
1227 { ahc_patch0_func, 500, 1, 1 }, 1227 { ahc_patch6_func, 498, 3, 2 },
1228 { ahc_patch6_func, 510, 1, 2 }, 1228 { ahc_patch0_func, 501, 1, 1 },
1229 { ahc_patch0_func, 511, 1, 1 }, 1229 { ahc_patch6_func, 511, 1, 2 },
1230 { ahc_patch20_func, 548, 7, 1 }, 1230 { ahc_patch0_func, 512, 1, 1 },
1231 { ahc_patch3_func, 583, 1, 2 }, 1231 { ahc_patch20_func, 549, 7, 1 },
1232 { ahc_patch0_func, 584, 1, 1 }, 1232 { ahc_patch3_func, 584, 1, 2 },
1233 { ahc_patch21_func, 587, 1, 1 }, 1233 { ahc_patch0_func, 585, 1, 1 },
1234 { ahc_patch8_func, 589, 106, 33 }, 1234 { ahc_patch21_func, 588, 1, 1 },
1235 { ahc_patch4_func, 591, 1, 1 }, 1235 { ahc_patch8_func, 590, 106, 33 },
1236 { ahc_patch1_func, 597, 2, 2 }, 1236 { ahc_patch4_func, 592, 1, 1 },
1237 { ahc_patch0_func, 599, 1, 1 }, 1237 { ahc_patch1_func, 598, 2, 2 },
1238 { ahc_patch1_func, 602, 1, 2 }, 1238 { ahc_patch0_func, 600, 1, 1 },
1239 { ahc_patch0_func, 603, 1, 1 }, 1239 { ahc_patch1_func, 603, 1, 2 },
1240 { ahc_patch9_func, 604, 3, 3 }, 1240 { ahc_patch0_func, 604, 1, 1 },
1241 { ahc_patch15_func, 605, 1, 1 }, 1241 { ahc_patch9_func, 605, 3, 3 },
1242 { ahc_patch0_func, 607, 4, 1 }, 1242 { ahc_patch15_func, 606, 1, 1 },
1243 { ahc_patch19_func, 616, 2, 2 }, 1243 { ahc_patch0_func, 608, 4, 1 },
1244 { ahc_patch0_func, 618, 1, 1 }, 1244 { ahc_patch19_func, 617, 2, 2 },
1245 { ahc_patch19_func, 622, 10, 3 }, 1245 { ahc_patch0_func, 619, 1, 1 },
1246 { ahc_patch5_func, 624, 8, 1 }, 1246 { ahc_patch19_func, 623, 10, 3 },
1247 { ahc_patch0_func, 632, 9, 2 }, 1247 { ahc_patch5_func, 625, 8, 1 },
1248 { ahc_patch5_func, 633, 8, 1 }, 1248 { ahc_patch0_func, 633, 9, 2 },
1249 { ahc_patch4_func, 643, 1, 2 }, 1249 { ahc_patch5_func, 634, 8, 1 },
1250 { ahc_patch0_func, 644, 1, 1 }, 1250 { ahc_patch4_func, 644, 1, 2 },
1251 { ahc_patch19_func, 645, 1, 2 }, 1251 { ahc_patch0_func, 645, 1, 1 },
1252 { ahc_patch0_func, 646, 3, 2 }, 1252 { ahc_patch19_func, 646, 1, 2 },
1253 { ahc_patch4_func, 648, 1, 1 }, 1253 { ahc_patch0_func, 647, 3, 2 },
1254 { ahc_patch5_func, 649, 1, 1 }, 1254 { ahc_patch4_func, 649, 1, 1 },
1255 { ahc_patch5_func, 652, 1, 1 }, 1255 { ahc_patch5_func, 650, 1, 1 },
1256 { ahc_patch5_func, 654, 1, 1 }, 1256 { ahc_patch5_func, 653, 1, 1 },
1257 { ahc_patch4_func, 656, 2, 2 }, 1257 { ahc_patch5_func, 655, 1, 1 },
1258 { ahc_patch0_func, 658, 2, 1 }, 1258 { ahc_patch4_func, 657, 2, 2 },
1259 { ahc_patch5_func, 660, 1, 1 }, 1259 { ahc_patch0_func, 659, 2, 1 },
1260 { ahc_patch5_func, 663, 1, 1 }, 1260 { ahc_patch5_func, 661, 1, 1 },
1261 { ahc_patch5_func, 666, 1, 1 }, 1261 { ahc_patch5_func, 664, 1, 1 },
1262 { ahc_patch19_func, 670, 1, 1 }, 1262 { ahc_patch5_func, 667, 1, 1 },
1263 { ahc_patch19_func, 673, 1, 1 }, 1263 { ahc_patch19_func, 671, 1, 1 },
1264 { ahc_patch4_func, 679, 1, 1 }, 1264 { ahc_patch19_func, 674, 1, 1 },
1265 { ahc_patch6_func, 682, 1, 2 }, 1265 { ahc_patch4_func, 680, 1, 1 },
1266 { ahc_patch0_func, 683, 1, 1 }, 1266 { ahc_patch6_func, 683, 1, 2 },
1267 { ahc_patch7_func, 695, 16, 1 }, 1267 { ahc_patch0_func, 684, 1, 1 },
1268 { ahc_patch4_func, 711, 20, 1 }, 1268 { ahc_patch7_func, 696, 16, 1 },
1269 { ahc_patch9_func, 732, 4, 2 }, 1269 { ahc_patch4_func, 712, 20, 1 },
1270 { ahc_patch0_func, 736, 4, 1 }, 1270 { ahc_patch9_func, 733, 4, 2 },
1271 { ahc_patch9_func, 740, 4, 2 }, 1271 { ahc_patch0_func, 737, 4, 1 },
1272 { ahc_patch0_func, 744, 3, 1 }, 1272 { ahc_patch9_func, 741, 4, 2 },
1273 { ahc_patch6_func, 750, 1, 1 }, 1273 { ahc_patch0_func, 745, 3, 1 },
1274 { ahc_patch22_func, 752, 14, 1 }, 1274 { ahc_patch6_func, 751, 1, 1 },
1275 { ahc_patch7_func, 766, 3, 1 }, 1275 { ahc_patch22_func, 753, 14, 1 },
1276 { ahc_patch9_func, 778, 24, 8 }, 1276 { ahc_patch7_func, 767, 3, 1 },
1277 { ahc_patch19_func, 782, 1, 2 }, 1277 { ahc_patch9_func, 779, 24, 8 },
1278 { ahc_patch0_func, 783, 1, 1 }, 1278 { ahc_patch19_func, 783, 1, 2 },
1279 { ahc_patch15_func, 788, 4, 2 }, 1279 { ahc_patch0_func, 784, 1, 1 },
1280 { ahc_patch0_func, 792, 7, 3 }, 1280 { ahc_patch15_func, 789, 4, 2 },
1281 { ahc_patch23_func, 792, 5, 2 }, 1281 { ahc_patch0_func, 793, 7, 3 },
1282 { ahc_patch0_func, 797, 2, 1 }, 1282 { ahc_patch23_func, 793, 5, 2 },
1283 { ahc_patch0_func, 802, 42, 3 }, 1283 { ahc_patch0_func, 798, 2, 1 },
1284 { ahc_patch18_func, 814, 18, 2 }, 1284 { ahc_patch0_func, 803, 42, 3 },
1285 { ahc_patch0_func, 832, 1, 1 }, 1285 { ahc_patch18_func, 815, 18, 2 },
1286 { ahc_patch4_func, 856, 1, 1 }, 1286 { ahc_patch0_func, 833, 1, 1 },
1287 { ahc_patch4_func, 857, 3, 2 }, 1287 { ahc_patch4_func, 857, 1, 1 },
1288 { ahc_patch0_func, 860, 1, 1 }, 1288 { ahc_patch4_func, 858, 3, 2 },
1289 { ahc_patch13_func, 861, 3, 1 }, 1289 { ahc_patch0_func, 861, 1, 1 },
1290 { ahc_patch4_func, 864, 12, 1 } 1290 { ahc_patch13_func, 862, 3, 1 },
1291 { ahc_patch4_func, 865, 12, 1 }
1291}; 1292};
1292 1293
1293static struct cs { 1294static struct cs {
@@ -1296,11 +1297,11 @@ static struct cs {
1296} critical_sections[] = { 1297} critical_sections[] = {
1297 { 11, 18 }, 1298 { 11, 18 },
1298 { 21, 30 }, 1299 { 21, 30 },
1299 { 711, 727 }, 1300 { 712, 728 },
1300 { 857, 860 }, 1301 { 858, 861 },
1301 { 864, 870 }, 1302 { 865, 871 },
1302 { 872, 874 }, 1303 { 873, 875 },
1303 { 874, 876 } 1304 { 875, 877 }
1304}; 1305};
1305 1306
1306static const int num_critical_sections = sizeof(critical_sections) 1307static const int num_critical_sections = sizeof(critical_sections)
diff --git a/drivers/scsi/aic7xxx/aiclib.c b/drivers/scsi/aic7xxx/aiclib.c
index 7c5a6db0e67..828ae3d9a51 100644
--- a/drivers/scsi/aic7xxx/aiclib.c
+++ b/drivers/scsi/aic7xxx/aiclib.c
@@ -30,1382 +30,5 @@
30 * $Id$ 30 * $Id$
31 */ 31 */
32 32
33#include <linux/blkdev.h>
34#include <linux/delay.h>
35#include <linux/version.h>
36
37/* Core SCSI definitions */
38#include <scsi/scsi_host.h>
39#include "aiclib.h" 33#include "aiclib.h"
40#include "cam.h"
41
42#ifndef FALSE
43#define FALSE 0
44#endif /* FALSE */
45#ifndef TRUE
46#define TRUE 1
47#endif /* TRUE */
48#ifndef ERESTART
49#define ERESTART -1 /* restart syscall */
50#endif
51#ifndef EJUSTRETURN
52#define EJUSTRETURN -2 /* don't modify regs, just return */
53#endif
54
55static int ascentrycomp(const void *key, const void *member);
56static int senseentrycomp(const void *key, const void *member);
57static void fetchtableentries(int sense_key, int asc, int ascq,
58 struct scsi_inquiry_data *,
59 const struct sense_key_table_entry **,
60 const struct asc_table_entry **);
61static void * scsibsearch(const void *key, const void *base, size_t nmemb,
62 size_t size,
63 int (*compar)(const void *, const void *));
64typedef int (cam_quirkmatch_t)(caddr_t, caddr_t);
65static int cam_strmatch(const u_int8_t *str, const u_int8_t *pattern,
66 int str_len);
67static caddr_t cam_quirkmatch(caddr_t target, caddr_t quirk_table,
68 int num_entries, int entry_size,
69 cam_quirkmatch_t *comp_func);
70
71#define SCSI_NO_SENSE_STRINGS 1
72#if !defined(SCSI_NO_SENSE_STRINGS)
73#define SST(asc, ascq, action, desc) \
74 asc, ascq, action, desc
75#else
76static const char empty_string[] = "";
77
78#define SST(asc, ascq, action, desc) \
79 asc, ascq, action, empty_string
80#endif
81
82static const struct sense_key_table_entry sense_key_table[] =
83{
84 { SSD_KEY_NO_SENSE, SS_NOP, "NO SENSE" },
85 { SSD_KEY_RECOVERED_ERROR, SS_NOP|SSQ_PRINT_SENSE, "RECOVERED ERROR" },
86 {
87 SSD_KEY_NOT_READY, SS_TUR|SSQ_MANY|SSQ_DECREMENT_COUNT|EBUSY,
88 "NOT READY"
89 },
90 { SSD_KEY_MEDIUM_ERROR, SS_RDEF, "MEDIUM ERROR" },
91 { SSD_KEY_HARDWARE_ERROR, SS_RDEF, "HARDWARE FAILURE" },
92 { SSD_KEY_ILLEGAL_REQUEST, SS_FATAL|EINVAL, "ILLEGAL REQUEST" },
93 { SSD_KEY_UNIT_ATTENTION, SS_FATAL|ENXIO, "UNIT ATTENTION" },
94 { SSD_KEY_DATA_PROTECT, SS_FATAL|EACCES, "DATA PROTECT" },
95 { SSD_KEY_BLANK_CHECK, SS_FATAL|ENOSPC, "BLANK CHECK" },
96 { SSD_KEY_Vendor_Specific, SS_FATAL|EIO, "Vendor Specific" },
97 { SSD_KEY_COPY_ABORTED, SS_FATAL|EIO, "COPY ABORTED" },
98 { SSD_KEY_ABORTED_COMMAND, SS_RDEF, "ABORTED COMMAND" },
99 { SSD_KEY_EQUAL, SS_NOP, "EQUAL" },
100 { SSD_KEY_VOLUME_OVERFLOW, SS_FATAL|EIO, "VOLUME OVERFLOW" },
101 { SSD_KEY_MISCOMPARE, SS_NOP, "MISCOMPARE" },
102 { SSD_KEY_RESERVED, SS_FATAL|EIO, "RESERVED" }
103};
104
105static const int sense_key_table_size =
106 sizeof(sense_key_table)/sizeof(sense_key_table[0]);
107
108static struct asc_table_entry quantum_fireball_entries[] = {
109 {SST(0x04, 0x0b, SS_START|SSQ_DECREMENT_COUNT|ENXIO,
110 "Logical unit not ready, initializing cmd. required")}
111};
112
113static struct asc_table_entry sony_mo_entries[] = {
114 {SST(0x04, 0x00, SS_START|SSQ_DECREMENT_COUNT|ENXIO,
115 "Logical unit not ready, cause not reportable")}
116};
117
118static struct scsi_sense_quirk_entry sense_quirk_table[] = {
119 {
120 /*
121 * The Quantum Fireball ST and SE like to return 0x04 0x0b when
122 * they really should return 0x04 0x02. 0x04,0x0b isn't
123 * defined in any SCSI spec, and it isn't mentioned in the
124 * hardware manual for these drives.
125 */
126 {T_DIRECT, SIP_MEDIA_FIXED, "QUANTUM", "FIREBALL S*", "*"},
127 /*num_sense_keys*/0,
128 sizeof(quantum_fireball_entries)/sizeof(struct asc_table_entry),
129 /*sense key entries*/NULL,
130 quantum_fireball_entries
131 },
132 {
133 /*
134 * This Sony MO drive likes to return 0x04, 0x00 when it
135 * isn't spun up.
136 */
137 {T_DIRECT, SIP_MEDIA_REMOVABLE, "SONY", "SMO-*", "*"},
138 /*num_sense_keys*/0,
139 sizeof(sony_mo_entries)/sizeof(struct asc_table_entry),
140 /*sense key entries*/NULL,
141 sony_mo_entries
142 }
143};
144
145static const int sense_quirk_table_size =
146 sizeof(sense_quirk_table)/sizeof(sense_quirk_table[0]);
147
148static struct asc_table_entry asc_table[] = {
149/*
150 * From File: ASC-NUM.TXT
151 * SCSI ASC/ASCQ Assignments
152 * Numeric Sorted Listing
153 * as of 5/12/97
154 *
155 * D - DIRECT ACCESS DEVICE (SBC) device column key
156 * .T - SEQUENTIAL ACCESS DEVICE (SSC) -------------------
157 * . L - PRINTER DEVICE (SSC) blank = reserved
158 * . P - PROCESSOR DEVICE (SPC) not blank = allowed
159 * . .W - WRITE ONCE READ MULTIPLE DEVICE (SBC)
160 * . . R - CD DEVICE (MMC)
161 * . . S - SCANNER DEVICE (SGC)
162 * . . .O - OPTICAL MEMORY DEVICE (SBC)
163 * . . . M - MEDIA CHANGER DEVICE (SMC)
164 * . . . C - COMMUNICATION DEVICE (SSC)
165 * . . . .A - STORAGE ARRAY DEVICE (SCC)
166 * . . . . E - ENCLOSURE SERVICES DEVICE (SES)
167 * DTLPWRSOMCAE ASC ASCQ Action Description
168 * ------------ ---- ---- ------ -----------------------------------*/
169/* DTLPWRSOMCAE */{SST(0x00, 0x00, SS_NOP,
170 "No additional sense information") },
171/* T S */{SST(0x00, 0x01, SS_RDEF,
172 "Filemark detected") },
173/* T S */{SST(0x00, 0x02, SS_RDEF,
174 "End-of-partition/medium detected") },
175/* T */{SST(0x00, 0x03, SS_RDEF,
176 "Setmark detected") },
177/* T S */{SST(0x00, 0x04, SS_RDEF,
178 "Beginning-of-partition/medium detected") },
179/* T S */{SST(0x00, 0x05, SS_RDEF,
180 "End-of-data detected") },
181/* DTLPWRSOMCAE */{SST(0x00, 0x06, SS_RDEF,
182 "I/O process terminated") },
183/* R */{SST(0x00, 0x11, SS_FATAL|EBUSY,
184 "Audio play operation in progress") },
185/* R */{SST(0x00, 0x12, SS_NOP,
186 "Audio play operation paused") },
187/* R */{SST(0x00, 0x13, SS_NOP,
188 "Audio play operation successfully completed") },
189/* R */{SST(0x00, 0x14, SS_RDEF,
190 "Audio play operation stopped due to error") },
191/* R */{SST(0x00, 0x15, SS_NOP,
192 "No current audio status to return") },
193/* DTLPWRSOMCAE */{SST(0x00, 0x16, SS_FATAL|EBUSY,
194 "Operation in progress") },
195/* DTL WRSOM AE */{SST(0x00, 0x17, SS_RDEF,
196 "Cleaning requested") },
197/* D W O */{SST(0x01, 0x00, SS_RDEF,
198 "No index/sector signal") },
199/* D WR OM */{SST(0x02, 0x00, SS_RDEF,
200 "No seek complete") },
201/* DTL W SO */{SST(0x03, 0x00, SS_RDEF,
202 "Peripheral device write fault") },
203/* T */{SST(0x03, 0x01, SS_RDEF,
204 "No write current") },
205/* T */{SST(0x03, 0x02, SS_RDEF,
206 "Excessive write errors") },
207/* DTLPWRSOMCAE */{SST(0x04, 0x00,
208 SS_TUR|SSQ_DELAY|SSQ_MANY|SSQ_DECREMENT_COUNT|EIO,
209 "Logical unit not ready, cause not reportable") },
210/* DTLPWRSOMCAE */{SST(0x04, 0x01,
211 SS_TUR|SSQ_DELAY|SSQ_MANY|SSQ_DECREMENT_COUNT|EBUSY,
212 "Logical unit is in process of becoming ready") },
213/* DTLPWRSOMCAE */{SST(0x04, 0x02, SS_START|SSQ_DECREMENT_COUNT|ENXIO,
214 "Logical unit not ready, initializing cmd. required") },
215/* DTLPWRSOMCAE */{SST(0x04, 0x03, SS_FATAL|ENXIO,
216 "Logical unit not ready, manual intervention required")},
217/* DTL O */{SST(0x04, 0x04, SS_FATAL|EBUSY,
218 "Logical unit not ready, format in progress") },
219/* DT W OMCA */{SST(0x04, 0x05, SS_FATAL|EBUSY,
220 "Logical unit not ready, rebuild in progress") },
221/* DT W OMCA */{SST(0x04, 0x06, SS_FATAL|EBUSY,
222 "Logical unit not ready, recalculation in progress") },
223/* DTLPWRSOMCAE */{SST(0x04, 0x07, SS_FATAL|EBUSY,
224 "Logical unit not ready, operation in progress") },
225/* R */{SST(0x04, 0x08, SS_FATAL|EBUSY,
226 "Logical unit not ready, long write in progress") },
227/* DTL WRSOMCAE */{SST(0x05, 0x00, SS_RDEF,
228 "Logical unit does not respond to selection") },
229/* D WR OM */{SST(0x06, 0x00, SS_RDEF,
230 "No reference position found") },
231/* DTL WRSOM */{SST(0x07, 0x00, SS_RDEF,
232 "Multiple peripheral devices selected") },
233/* DTL WRSOMCAE */{SST(0x08, 0x00, SS_RDEF,
234 "Logical unit communication failure") },
235/* DTL WRSOMCAE */{SST(0x08, 0x01, SS_RDEF,
236 "Logical unit communication time-out") },
237/* DTL WRSOMCAE */{SST(0x08, 0x02, SS_RDEF,
238 "Logical unit communication parity error") },
239/* DT R OM */{SST(0x08, 0x03, SS_RDEF,
240 "Logical unit communication crc error (ultra-dma/32)")},
241/* DT WR O */{SST(0x09, 0x00, SS_RDEF,
242 "Track following error") },
243/* WR O */{SST(0x09, 0x01, SS_RDEF,
244 "Tracking servo failure") },
245/* WR O */{SST(0x09, 0x02, SS_RDEF,
246 "Focus servo failure") },
247/* WR O */{SST(0x09, 0x03, SS_RDEF,
248 "Spindle servo failure") },
249/* DT WR O */{SST(0x09, 0x04, SS_RDEF,
250 "Head select fault") },
251/* DTLPWRSOMCAE */{SST(0x0A, 0x00, SS_FATAL|ENOSPC,
252 "Error log overflow") },
253/* DTLPWRSOMCAE */{SST(0x0B, 0x00, SS_RDEF,
254 "Warning") },
255/* DTLPWRSOMCAE */{SST(0x0B, 0x01, SS_RDEF,
256 "Specified temperature exceeded") },
257/* DTLPWRSOMCAE */{SST(0x0B, 0x02, SS_RDEF,
258 "Enclosure degraded") },
259/* T RS */{SST(0x0C, 0x00, SS_RDEF,
260 "Write error") },
261/* D W O */{SST(0x0C, 0x01, SS_NOP|SSQ_PRINT_SENSE,
262 "Write error - recovered with auto reallocation") },
263/* D W O */{SST(0x0C, 0x02, SS_RDEF,
264 "Write error - auto reallocation failed") },
265/* D W O */{SST(0x0C, 0x03, SS_RDEF,
266 "Write error - recommend reassignment") },
267/* DT W O */{SST(0x0C, 0x04, SS_RDEF,
268 "Compression check miscompare error") },
269/* DT W O */{SST(0x0C, 0x05, SS_RDEF,
270 "Data expansion occurred during compression") },
271/* DT W O */{SST(0x0C, 0x06, SS_RDEF,
272 "Block not compressible") },
273/* R */{SST(0x0C, 0x07, SS_RDEF,
274 "Write error - recovery needed") },
275/* R */{SST(0x0C, 0x08, SS_RDEF,
276 "Write error - recovery failed") },
277/* R */{SST(0x0C, 0x09, SS_RDEF,
278 "Write error - loss of streaming") },
279/* R */{SST(0x0C, 0x0A, SS_RDEF,
280 "Write error - padding blocks added") },
281/* D W O */{SST(0x10, 0x00, SS_RDEF,
282 "ID CRC or ECC error") },
283/* DT WRSO */{SST(0x11, 0x00, SS_RDEF,
284 "Unrecovered read error") },
285/* DT W SO */{SST(0x11, 0x01, SS_RDEF,
286 "Read retries exhausted") },
287/* DT W SO */{SST(0x11, 0x02, SS_RDEF,
288 "Error too long to correct") },
289/* DT W SO */{SST(0x11, 0x03, SS_RDEF,
290 "Multiple read errors") },
291/* D W O */{SST(0x11, 0x04, SS_RDEF,
292 "Unrecovered read error - auto reallocate failed") },
293/* WR O */{SST(0x11, 0x05, SS_RDEF,
294 "L-EC uncorrectable error") },
295/* WR O */{SST(0x11, 0x06, SS_RDEF,
296 "CIRC unrecovered error") },
297/* W O */{SST(0x11, 0x07, SS_RDEF,
298 "Data re-synchronization error") },
299/* T */{SST(0x11, 0x08, SS_RDEF,
300 "Incomplete block read") },
301/* T */{SST(0x11, 0x09, SS_RDEF,
302 "No gap found") },
303/* DT O */{SST(0x11, 0x0A, SS_RDEF,
304 "Miscorrected error") },
305/* D W O */{SST(0x11, 0x0B, SS_RDEF,
306 "Unrecovered read error - recommend reassignment") },
307/* D W O */{SST(0x11, 0x0C, SS_RDEF,
308 "Unrecovered read error - recommend rewrite the data")},
309/* DT WR O */{SST(0x11, 0x0D, SS_RDEF,
310 "De-compression CRC error") },
311/* DT WR O */{SST(0x11, 0x0E, SS_RDEF,
312 "Cannot decompress using declared algorithm") },
313/* R */{SST(0x11, 0x0F, SS_RDEF,
314 "Error reading UPC/EAN number") },
315/* R */{SST(0x11, 0x10, SS_RDEF,
316 "Error reading ISRC number") },
317/* R */{SST(0x11, 0x11, SS_RDEF,
318 "Read error - loss of streaming") },
319/* D W O */{SST(0x12, 0x00, SS_RDEF,
320 "Address mark not found for id field") },
321/* D W O */{SST(0x13, 0x00, SS_RDEF,
322 "Address mark not found for data field") },
323/* DTL WRSO */{SST(0x14, 0x00, SS_RDEF,
324 "Recorded entity not found") },
325/* DT WR O */{SST(0x14, 0x01, SS_RDEF,
326 "Record not found") },
327/* T */{SST(0x14, 0x02, SS_RDEF,
328 "Filemark or setmark not found") },
329/* T */{SST(0x14, 0x03, SS_RDEF,
330 "End-of-data not found") },
331/* T */{SST(0x14, 0x04, SS_RDEF,
332 "Block sequence error") },
333/* DT W O */{SST(0x14, 0x05, SS_RDEF,
334 "Record not found - recommend reassignment") },
335/* DT W O */{SST(0x14, 0x06, SS_RDEF,
336 "Record not found - data auto-reallocated") },
337/* DTL WRSOM */{SST(0x15, 0x00, SS_RDEF,
338 "Random positioning error") },
339/* DTL WRSOM */{SST(0x15, 0x01, SS_RDEF,
340 "Mechanical positioning error") },
341/* DT WR O */{SST(0x15, 0x02, SS_RDEF,
342 "Positioning error detected by read of medium") },
343/* D W O */{SST(0x16, 0x00, SS_RDEF,
344 "Data synchronization mark error") },
345/* D W O */{SST(0x16, 0x01, SS_RDEF,
346 "Data sync error - data rewritten") },
347/* D W O */{SST(0x16, 0x02, SS_RDEF,
348 "Data sync error - recommend rewrite") },
349/* D W O */{SST(0x16, 0x03, SS_NOP|SSQ_PRINT_SENSE,
350 "Data sync error - data auto-reallocated") },
351/* D W O */{SST(0x16, 0x04, SS_RDEF,
352 "Data sync error - recommend reassignment") },
353/* DT WRSO */{SST(0x17, 0x00, SS_NOP|SSQ_PRINT_SENSE,
354 "Recovered data with no error correction applied") },
355/* DT WRSO */{SST(0x17, 0x01, SS_NOP|SSQ_PRINT_SENSE,
356 "Recovered data with retries") },
357/* DT WR O */{SST(0x17, 0x02, SS_NOP|SSQ_PRINT_SENSE,
358 "Recovered data with positive head offset") },
359/* DT WR O */{SST(0x17, 0x03, SS_NOP|SSQ_PRINT_SENSE,
360 "Recovered data with negative head offset") },
361/* WR O */{SST(0x17, 0x04, SS_NOP|SSQ_PRINT_SENSE,
362 "Recovered data with retries and/or CIRC applied") },
363/* D WR O */{SST(0x17, 0x05, SS_NOP|SSQ_PRINT_SENSE,
364 "Recovered data using previous sector id") },
365/* D W O */{SST(0x17, 0x06, SS_NOP|SSQ_PRINT_SENSE,
366 "Recovered data without ECC - data auto-reallocated") },
367/* D W O */{SST(0x17, 0x07, SS_NOP|SSQ_PRINT_SENSE,
368 "Recovered data without ECC - recommend reassignment")},
369/* D W O */{SST(0x17, 0x08, SS_NOP|SSQ_PRINT_SENSE,
370 "Recovered data without ECC - recommend rewrite") },
371/* D W O */{SST(0x17, 0x09, SS_NOP|SSQ_PRINT_SENSE,
372 "Recovered data without ECC - data rewritten") },
373/* D W O */{SST(0x18, 0x00, SS_NOP|SSQ_PRINT_SENSE,
374 "Recovered data with error correction applied") },
375/* D WR O */{SST(0x18, 0x01, SS_NOP|SSQ_PRINT_SENSE,
376 "Recovered data with error corr. & retries applied") },
377/* D WR O */{SST(0x18, 0x02, SS_NOP|SSQ_PRINT_SENSE,
378 "Recovered data - data auto-reallocated") },
379/* R */{SST(0x18, 0x03, SS_NOP|SSQ_PRINT_SENSE,
380 "Recovered data with CIRC") },
381/* R */{SST(0x18, 0x04, SS_NOP|SSQ_PRINT_SENSE,
382 "Recovered data with L-EC") },
383/* D WR O */{SST(0x18, 0x05, SS_NOP|SSQ_PRINT_SENSE,
384 "Recovered data - recommend reassignment") },
385/* D WR O */{SST(0x18, 0x06, SS_NOP|SSQ_PRINT_SENSE,
386 "Recovered data - recommend rewrite") },
387/* D W O */{SST(0x18, 0x07, SS_NOP|SSQ_PRINT_SENSE,
388 "Recovered data with ECC - data rewritten") },
389/* D O */{SST(0x19, 0x00, SS_RDEF,
390 "Defect list error") },
391/* D O */{SST(0x19, 0x01, SS_RDEF,
392 "Defect list not available") },
393/* D O */{SST(0x19, 0x02, SS_RDEF,
394 "Defect list error in primary list") },
395/* D O */{SST(0x19, 0x03, SS_RDEF,
396 "Defect list error in grown list") },
397/* DTLPWRSOMCAE */{SST(0x1A, 0x00, SS_RDEF,
398 "Parameter list length error") },
399/* DTLPWRSOMCAE */{SST(0x1B, 0x00, SS_RDEF,
400 "Synchronous data transfer error") },
401/* D O */{SST(0x1C, 0x00, SS_RDEF,
402 "Defect list not found") },
403/* D O */{SST(0x1C, 0x01, SS_RDEF,
404 "Primary defect list not found") },
405/* D O */{SST(0x1C, 0x02, SS_RDEF,
406 "Grown defect list not found") },
407/* D W O */{SST(0x1D, 0x00, SS_FATAL,
408 "Miscompare during verify operation" )},
409/* D W O */{SST(0x1E, 0x00, SS_NOP|SSQ_PRINT_SENSE,
410 "Recovered id with ecc correction") },
411/* D O */{SST(0x1F, 0x00, SS_RDEF,
412 "Partial defect list transfer") },
413/* DTLPWRSOMCAE */{SST(0x20, 0x00, SS_FATAL|EINVAL,
414 "Invalid command operation code") },
415/* DT WR OM */{SST(0x21, 0x00, SS_FATAL|EINVAL,
416 "Logical block address out of range" )},
417/* DT WR OM */{SST(0x21, 0x01, SS_FATAL|EINVAL,
418 "Invalid element address") },
419/* D */{SST(0x22, 0x00, SS_FATAL|EINVAL,
420 "Illegal function") }, /* Deprecated. Use 20 00, 24 00, or 26 00 instead */
421/* DTLPWRSOMCAE */{SST(0x24, 0x00, SS_FATAL|EINVAL,
422 "Invalid field in CDB") },
423/* DTLPWRSOMCAE */{SST(0x25, 0x00, SS_FATAL|ENXIO,
424 "Logical unit not supported") },
425/* DTLPWRSOMCAE */{SST(0x26, 0x00, SS_FATAL|EINVAL,
426 "Invalid field in parameter list") },
427/* DTLPWRSOMCAE */{SST(0x26, 0x01, SS_FATAL|EINVAL,
428 "Parameter not supported") },
429/* DTLPWRSOMCAE */{SST(0x26, 0x02, SS_FATAL|EINVAL,
430 "Parameter value invalid") },
431/* DTLPWRSOMCAE */{SST(0x26, 0x03, SS_FATAL|EINVAL,
432 "Threshold parameters not supported") },
433/* DTLPWRSOMCAE */{SST(0x26, 0x04, SS_FATAL|EINVAL,
434 "Invalid release of active persistent reservation") },
435/* DT W O */{SST(0x27, 0x00, SS_FATAL|EACCES,
436 "Write protected") },
437/* DT W O */{SST(0x27, 0x01, SS_FATAL|EACCES,
438 "Hardware write protected") },
439/* DT W O */{SST(0x27, 0x02, SS_FATAL|EACCES,
440 "Logical unit software write protected") },
441/* T */{SST(0x27, 0x03, SS_FATAL|EACCES,
442 "Associated write protect") },
443/* T */{SST(0x27, 0x04, SS_FATAL|EACCES,
444 "Persistent write protect") },
445/* T */{SST(0x27, 0x05, SS_FATAL|EACCES,
446 "Permanent write protect") },
447/* DTLPWRSOMCAE */{SST(0x28, 0x00, SS_RDEF,
448 "Not ready to ready change, medium may have changed") },
449/* DTLPWRSOMCAE */{SST(0x28, 0x01, SS_FATAL|ENXIO,
450 "Import or export element accessed") },
451/*
452 * XXX JGibbs - All of these should use the same errno, but I don't think
453 * ENXIO is the correct choice. Should we borrow from the networking
454 * errnos? ECONNRESET anyone?
455 */
456/* DTLPWRSOMCAE */{SST(0x29, 0x00, SS_RDEF,
457 "Power on, reset, or bus device reset occurred") },
458/* DTLPWRSOMCAE */{SST(0x29, 0x01, SS_RDEF,
459 "Power on occurred") },
460/* DTLPWRSOMCAE */{SST(0x29, 0x02, SS_RDEF,
461 "Scsi bus reset occurred") },
462/* DTLPWRSOMCAE */{SST(0x29, 0x03, SS_RDEF,
463 "Bus device reset function occurred") },
464/* DTLPWRSOMCAE */{SST(0x29, 0x04, SS_RDEF,
465 "Device internal reset") },
466/* DTLPWRSOMCAE */{SST(0x29, 0x05, SS_RDEF,
467 "Transceiver mode changed to single-ended") },
468/* DTLPWRSOMCAE */{SST(0x29, 0x06, SS_RDEF,
469 "Transceiver mode changed to LVD") },
470/* DTL WRSOMCAE */{SST(0x2A, 0x00, SS_RDEF,
471 "Parameters changed") },
472/* DTL WRSOMCAE */{SST(0x2A, 0x01, SS_RDEF,
473 "Mode parameters changed") },
474/* DTL WRSOMCAE */{SST(0x2A, 0x02, SS_RDEF,
475 "Log parameters changed") },
476/* DTLPWRSOMCAE */{SST(0x2A, 0x03, SS_RDEF,
477 "Reservations preempted") },
478/* DTLPWRSO C */{SST(0x2B, 0x00, SS_RDEF,
479 "Copy cannot execute since host cannot disconnect") },
480/* DTLPWRSOMCAE */{SST(0x2C, 0x00, SS_RDEF,
481 "Command sequence error") },
482/* S */{SST(0x2C, 0x01, SS_RDEF,
483 "Too many windows specified") },
484/* S */{SST(0x2C, 0x02, SS_RDEF,
485 "Invalid combination of windows specified") },
486/* R */{SST(0x2C, 0x03, SS_RDEF,
487 "Current program area is not empty") },
488/* R */{SST(0x2C, 0x04, SS_RDEF,
489 "Current program area is empty") },
490/* T */{SST(0x2D, 0x00, SS_RDEF,
491 "Overwrite error on update in place") },
492/* DTLPWRSOMCAE */{SST(0x2F, 0x00, SS_RDEF,
493 "Commands cleared by another initiator") },
494/* DT WR OM */{SST(0x30, 0x00, SS_RDEF,
495 "Incompatible medium installed") },
496/* DT WR O */{SST(0x30, 0x01, SS_RDEF,
497 "Cannot read medium - unknown format") },
498/* DT WR O */{SST(0x30, 0x02, SS_RDEF,
499 "Cannot read medium - incompatible format") },
500/* DT */{SST(0x30, 0x03, SS_RDEF,
501 "Cleaning cartridge installed") },
502/* DT WR O */{SST(0x30, 0x04, SS_RDEF,
503 "Cannot write medium - unknown format") },
504/* DT WR O */{SST(0x30, 0x05, SS_RDEF,
505 "Cannot write medium - incompatible format") },
506/* DT W O */{SST(0x30, 0x06, SS_RDEF,
507 "Cannot format medium - incompatible medium") },
508/* DTL WRSOM AE */{SST(0x30, 0x07, SS_RDEF,
509 "Cleaning failure") },
510/* R */{SST(0x30, 0x08, SS_RDEF,
511 "Cannot write - application code mismatch") },
512/* R */{SST(0x30, 0x09, SS_RDEF,
513 "Current session not fixated for append") },
514/* DT WR O */{SST(0x31, 0x00, SS_RDEF,
515 "Medium format corrupted") },
516/* D L R O */{SST(0x31, 0x01, SS_RDEF,
517 "Format command failed") },
518/* D W O */{SST(0x32, 0x00, SS_RDEF,
519 "No defect spare location available") },
520/* D W O */{SST(0x32, 0x01, SS_RDEF,
521 "Defect list update failure") },
522/* T */{SST(0x33, 0x00, SS_RDEF,
523 "Tape length error") },
524/* DTLPWRSOMCAE */{SST(0x34, 0x00, SS_RDEF,
525 "Enclosure failure") },
526/* DTLPWRSOMCAE */{SST(0x35, 0x00, SS_RDEF,
527 "Enclosure services failure") },
528/* DTLPWRSOMCAE */{SST(0x35, 0x01, SS_RDEF,
529 "Unsupported enclosure function") },
530/* DTLPWRSOMCAE */{SST(0x35, 0x02, SS_RDEF,
531 "Enclosure services unavailable") },
532/* DTLPWRSOMCAE */{SST(0x35, 0x03, SS_RDEF,
533 "Enclosure services transfer failure") },
534/* DTLPWRSOMCAE */{SST(0x35, 0x04, SS_RDEF,
535 "Enclosure services transfer refused") },
536/* L */{SST(0x36, 0x00, SS_RDEF,
537 "Ribbon, ink, or toner failure") },
538/* DTL WRSOMCAE */{SST(0x37, 0x00, SS_RDEF,
539 "Rounded parameter") },
540/* DTL WRSOMCAE */{SST(0x39, 0x00, SS_RDEF,
541 "Saving parameters not supported") },
542/* DTL WRSOM */{SST(0x3A, 0x00, SS_NOP,
543 "Medium not present") },
544/* DT WR OM */{SST(0x3A, 0x01, SS_NOP,
545 "Medium not present - tray closed") },
546/* DT WR OM */{SST(0x3A, 0x01, SS_NOP,
547 "Medium not present - tray open") },
548/* DT WR OM */{SST(0x3A, 0x03, SS_NOP,
549 "Medium not present - Loadable") },
550/* DT WR OM */{SST(0x3A, 0x04, SS_NOP,
551 "Medium not present - medium auxiliary "
552 "memory accessible") },
553/* DT WR OM */{SST(0x3A, 0xFF, SS_NOP, NULL) },/* Range 0x05->0xFF */
554/* TL */{SST(0x3B, 0x00, SS_RDEF,
555 "Sequential positioning error") },
556/* T */{SST(0x3B, 0x01, SS_RDEF,
557 "Tape position error at beginning-of-medium") },
558/* T */{SST(0x3B, 0x02, SS_RDEF,
559 "Tape position error at end-of-medium") },
560/* L */{SST(0x3B, 0x03, SS_RDEF,
561 "Tape or electronic vertical forms unit not ready") },
562/* L */{SST(0x3B, 0x04, SS_RDEF,
563 "Slew failure") },
564/* L */{SST(0x3B, 0x05, SS_RDEF,
565 "Paper jam") },
566/* L */{SST(0x3B, 0x06, SS_RDEF,
567 "Failed to sense top-of-form") },
568/* L */{SST(0x3B, 0x07, SS_RDEF,
569 "Failed to sense bottom-of-form") },
570/* T */{SST(0x3B, 0x08, SS_RDEF,
571 "Reposition error") },
572/* S */{SST(0x3B, 0x09, SS_RDEF,
573 "Read past end of medium") },
574/* S */{SST(0x3B, 0x0A, SS_RDEF,
575 "Read past beginning of medium") },
576/* S */{SST(0x3B, 0x0B, SS_RDEF,
577 "Position past end of medium") },
578/* T S */{SST(0x3B, 0x0C, SS_RDEF,
579 "Position past beginning of medium") },
580/* DT WR OM */{SST(0x3B, 0x0D, SS_FATAL|ENOSPC,
581 "Medium destination element full") },
582/* DT WR OM */{SST(0x3B, 0x0E, SS_RDEF,
583 "Medium source element empty") },
584/* R */{SST(0x3B, 0x0F, SS_RDEF,
585 "End of medium reached") },
586/* DT WR OM */{SST(0x3B, 0x11, SS_RDEF,
587 "Medium magazine not accessible") },
588/* DT WR OM */{SST(0x3B, 0x12, SS_RDEF,
589 "Medium magazine removed") },
590/* DT WR OM */{SST(0x3B, 0x13, SS_RDEF,
591 "Medium magazine inserted") },
592/* DT WR OM */{SST(0x3B, 0x14, SS_RDEF,
593 "Medium magazine locked") },
594/* DT WR OM */{SST(0x3B, 0x15, SS_RDEF,
595 "Medium magazine unlocked") },
596/* DTLPWRSOMCAE */{SST(0x3D, 0x00, SS_RDEF,
597 "Invalid bits in identify message") },
598/* DTLPWRSOMCAE */{SST(0x3E, 0x00, SS_RDEF,
599 "Logical unit has not self-configured yet") },
600/* DTLPWRSOMCAE */{SST(0x3E, 0x01, SS_RDEF,
601 "Logical unit failure") },
602/* DTLPWRSOMCAE */{SST(0x3E, 0x02, SS_RDEF,
603 "Timeout on logical unit") },
604/* DTLPWRSOMCAE */{SST(0x3F, 0x00, SS_RDEF,
605 "Target operating conditions have changed") },
606/* DTLPWRSOMCAE */{SST(0x3F, 0x01, SS_RDEF,
607 "Microcode has been changed") },
608/* DTLPWRSOMC */{SST(0x3F, 0x02, SS_RDEF,
609 "Changed operating definition") },
610/* DTLPWRSOMCAE */{SST(0x3F, 0x03, SS_INQ_REFRESH|SSQ_DECREMENT_COUNT,
611 "Inquiry data has changed") },
612/* DT WR OMCAE */{SST(0x3F, 0x04, SS_RDEF,
613 "Component device attached") },
614/* DT WR OMCAE */{SST(0x3F, 0x05, SS_RDEF,
615 "Device identifier changed") },
616/* DT WR OMCAE */{SST(0x3F, 0x06, SS_RDEF,
617 "Redundancy group created or modified") },
618/* DT WR OMCAE */{SST(0x3F, 0x07, SS_RDEF,
619 "Redundancy group deleted") },
620/* DT WR OMCAE */{SST(0x3F, 0x08, SS_RDEF,
621 "Spare created or modified") },
622/* DT WR OMCAE */{SST(0x3F, 0x09, SS_RDEF,
623 "Spare deleted") },
624/* DT WR OMCAE */{SST(0x3F, 0x0A, SS_RDEF,
625 "Volume set created or modified") },
626/* DT WR OMCAE */{SST(0x3F, 0x0B, SS_RDEF,
627 "Volume set deleted") },
628/* DT WR OMCAE */{SST(0x3F, 0x0C, SS_RDEF,
629 "Volume set deassigned") },
630/* DT WR OMCAE */{SST(0x3F, 0x0D, SS_RDEF,
631 "Volume set reassigned") },
632/* DTLPWRSOMCAE */{SST(0x3F, 0x0E, SS_RDEF,
633 "Reported luns data has changed") },
634/* DTLPWRSOMCAE */{SST(0x3F, 0x0F, SS_RETRY|SSQ_DECREMENT_COUNT
635 | SSQ_DELAY_RANDOM|EBUSY,
636 "Echo buffer overwritten") },
637/* DT WR OM B*/{SST(0x3F, 0x0F, SS_RDEF, "Medium Loadable") },
638/* DT WR OM B*/{SST(0x3F, 0x0F, SS_RDEF,
639 "Medium auxiliary memory accessible") },
640/* D */{SST(0x40, 0x00, SS_RDEF,
641 "Ram failure") }, /* deprecated - use 40 NN instead */
642/* DTLPWRSOMCAE */{SST(0x40, 0x80, SS_RDEF,
643 "Diagnostic failure: ASCQ = Component ID") },
644/* DTLPWRSOMCAE */{SST(0x40, 0xFF, SS_RDEF|SSQ_RANGE,
645 NULL) },/* Range 0x80->0xFF */
646/* D */{SST(0x41, 0x00, SS_RDEF,
647 "Data path failure") }, /* deprecated - use 40 NN instead */
648/* D */{SST(0x42, 0x00, SS_RDEF,
649 "Power-on or self-test failure") }, /* deprecated - use 40 NN instead */
650/* DTLPWRSOMCAE */{SST(0x43, 0x00, SS_RDEF,
651 "Message error") },
652/* DTLPWRSOMCAE */{SST(0x44, 0x00, SS_RDEF,
653 "Internal target failure") },
654/* DTLPWRSOMCAE */{SST(0x45, 0x00, SS_RDEF,
655 "Select or reselect failure") },
656/* DTLPWRSOMC */{SST(0x46, 0x00, SS_RDEF,
657 "Unsuccessful soft reset") },
658/* DTLPWRSOMCAE */{SST(0x47, 0x00, SS_RDEF|SSQ_FALLBACK,
659 "SCSI parity error") },
660/* DTLPWRSOMCAE */{SST(0x47, 0x01, SS_RDEF|SSQ_FALLBACK,
661 "Data Phase CRC error detected") },
662/* DTLPWRSOMCAE */{SST(0x47, 0x02, SS_RDEF|SSQ_FALLBACK,
663 "SCSI parity error detected during ST data phase") },
664/* DTLPWRSOMCAE */{SST(0x47, 0x03, SS_RDEF|SSQ_FALLBACK,
665 "Information Unit iuCRC error") },
666/* DTLPWRSOMCAE */{SST(0x47, 0x04, SS_RDEF|SSQ_FALLBACK,
667 "Asynchronous information protection error detected") },
668/* DTLPWRSOMCAE */{SST(0x47, 0x05, SS_RDEF|SSQ_FALLBACK,
669 "Protocol server CRC error") },
670/* DTLPWRSOMCAE */{SST(0x48, 0x00, SS_RDEF|SSQ_FALLBACK,
671 "Initiator detected error message received") },
672/* DTLPWRSOMCAE */{SST(0x49, 0x00, SS_RDEF,
673 "Invalid message error") },
674/* DTLPWRSOMCAE */{SST(0x4A, 0x00, SS_RDEF,
675 "Command phase error") },
676/* DTLPWRSOMCAE */{SST(0x4B, 0x00, SS_RDEF,
677 "Data phase error") },
678/* DTLPWRSOMCAE */{SST(0x4C, 0x00, SS_RDEF,
679 "Logical unit failed self-configuration") },
680/* DTLPWRSOMCAE */{SST(0x4D, 0x00, SS_RDEF,
681 "Tagged overlapped commands: ASCQ = Queue tag ID") },
682/* DTLPWRSOMCAE */{SST(0x4D, 0xFF, SS_RDEF|SSQ_RANGE,
683 NULL)}, /* Range 0x00->0xFF */
684/* DTLPWRSOMCAE */{SST(0x4E, 0x00, SS_RDEF,
685 "Overlapped commands attempted") },
686/* T */{SST(0x50, 0x00, SS_RDEF,
687 "Write append error") },
688/* T */{SST(0x50, 0x01, SS_RDEF,
689 "Write append position error") },
690/* T */{SST(0x50, 0x02, SS_RDEF,
691 "Position error related to timing") },
692/* T O */{SST(0x51, 0x00, SS_RDEF,
693 "Erase failure") },
694/* T */{SST(0x52, 0x00, SS_RDEF,
695 "Cartridge fault") },
696/* DTL WRSOM */{SST(0x53, 0x00, SS_RDEF,
697 "Media load or eject failed") },
698/* T */{SST(0x53, 0x01, SS_RDEF,
699 "Unload tape failure") },
700/* DT WR OM */{SST(0x53, 0x02, SS_RDEF,
701 "Medium removal prevented") },
702/* P */{SST(0x54, 0x00, SS_RDEF,
703 "Scsi to host system interface failure") },
704/* P */{SST(0x55, 0x00, SS_RDEF,
705 "System resource failure") },
706/* D O */{SST(0x55, 0x01, SS_FATAL|ENOSPC,
707 "System buffer full") },
708/* R */{SST(0x57, 0x00, SS_RDEF,
709 "Unable to recover table-of-contents") },
710/* O */{SST(0x58, 0x00, SS_RDEF,
711 "Generation does not exist") },
712/* O */{SST(0x59, 0x00, SS_RDEF,
713 "Updated block read") },
714/* DTLPWRSOM */{SST(0x5A, 0x00, SS_RDEF,
715 "Operator request or state change input") },
716/* DT WR OM */{SST(0x5A, 0x01, SS_RDEF,
717 "Operator medium removal request") },
718/* DT W O */{SST(0x5A, 0x02, SS_RDEF,
719 "Operator selected write protect") },
720/* DT W O */{SST(0x5A, 0x03, SS_RDEF,
721 "Operator selected write permit") },
722/* DTLPWRSOM */{SST(0x5B, 0x00, SS_RDEF,
723 "Log exception") },
724/* DTLPWRSOM */{SST(0x5B, 0x01, SS_RDEF,
725 "Threshold condition met") },
726/* DTLPWRSOM */{SST(0x5B, 0x02, SS_RDEF,
727 "Log counter at maximum") },
728/* DTLPWRSOM */{SST(0x5B, 0x03, SS_RDEF,
729 "Log list codes exhausted") },
730/* D O */{SST(0x5C, 0x00, SS_RDEF,
731 "RPL status change") },
732/* D O */{SST(0x5C, 0x01, SS_NOP|SSQ_PRINT_SENSE,
733 "Spindles synchronized") },
734/* D O */{SST(0x5C, 0x02, SS_RDEF,
735 "Spindles not synchronized") },
736/* DTLPWRSOMCAE */{SST(0x5D, 0x00, SS_RDEF,
737 "Failure prediction threshold exceeded") },
738/* DTLPWRSOMCAE */{SST(0x5D, 0xFF, SS_RDEF,
739 "Failure prediction threshold exceeded (false)") },
740/* DTLPWRSO CA */{SST(0x5E, 0x00, SS_RDEF,
741 "Low power condition on") },
742/* DTLPWRSO CA */{SST(0x5E, 0x01, SS_RDEF,
743 "Idle condition activated by timer") },
744/* DTLPWRSO CA */{SST(0x5E, 0x02, SS_RDEF,
745 "Standby condition activated by timer") },
746/* DTLPWRSO CA */{SST(0x5E, 0x03, SS_RDEF,
747 "Idle condition activated by command") },
748/* DTLPWRSO CA */{SST(0x5E, 0x04, SS_RDEF,
749 "Standby condition activated by command") },
750/* S */{SST(0x60, 0x00, SS_RDEF,
751 "Lamp failure") },
752/* S */{SST(0x61, 0x00, SS_RDEF,
753 "Video acquisition error") },
754/* S */{SST(0x61, 0x01, SS_RDEF,
755 "Unable to acquire video") },
756/* S */{SST(0x61, 0x02, SS_RDEF,
757 "Out of focus") },
758/* S */{SST(0x62, 0x00, SS_RDEF,
759 "Scan head positioning error") },
760/* R */{SST(0x63, 0x00, SS_RDEF,
761 "End of user area encountered on this track") },
762/* R */{SST(0x63, 0x01, SS_FATAL|ENOSPC,
763 "Packet does not fit in available space") },
764/* R */{SST(0x64, 0x00, SS_RDEF,
765 "Illegal mode for this track") },
766/* R */{SST(0x64, 0x01, SS_RDEF,
767 "Invalid packet size") },
768/* DTLPWRSOMCAE */{SST(0x65, 0x00, SS_RDEF,
769 "Voltage fault") },
770/* S */{SST(0x66, 0x00, SS_RDEF,
771 "Automatic document feeder cover up") },
772/* S */{SST(0x66, 0x01, SS_RDEF,
773 "Automatic document feeder lift up") },
774/* S */{SST(0x66, 0x02, SS_RDEF,
775 "Document jam in automatic document feeder") },
776/* S */{SST(0x66, 0x03, SS_RDEF,
777 "Document miss feed automatic in document feeder") },
778/* A */{SST(0x67, 0x00, SS_RDEF,
779 "Configuration failure") },
780/* A */{SST(0x67, 0x01, SS_RDEF,
781 "Configuration of incapable logical units failed") },
782/* A */{SST(0x67, 0x02, SS_RDEF,
783 "Add logical unit failed") },
784/* A */{SST(0x67, 0x03, SS_RDEF,
785 "Modification of logical unit failed") },
786/* A */{SST(0x67, 0x04, SS_RDEF,
787 "Exchange of logical unit failed") },
788/* A */{SST(0x67, 0x05, SS_RDEF,
789 "Remove of logical unit failed") },
790/* A */{SST(0x67, 0x06, SS_RDEF,
791 "Attachment of logical unit failed") },
792/* A */{SST(0x67, 0x07, SS_RDEF,
793 "Creation of logical unit failed") },
794/* A */{SST(0x68, 0x00, SS_RDEF,
795 "Logical unit not configured") },
796/* A */{SST(0x69, 0x00, SS_RDEF,
797 "Data loss on logical unit") },
798/* A */{SST(0x69, 0x01, SS_RDEF,
799 "Multiple logical unit failures") },
800/* A */{SST(0x69, 0x02, SS_RDEF,
801 "Parity/data mismatch") },
802/* A */{SST(0x6A, 0x00, SS_RDEF,
803 "Informational, refer to log") },
804/* A */{SST(0x6B, 0x00, SS_RDEF,
805 "State change has occurred") },
806/* A */{SST(0x6B, 0x01, SS_RDEF,
807 "Redundancy level got better") },
808/* A */{SST(0x6B, 0x02, SS_RDEF,
809 "Redundancy level got worse") },
810/* A */{SST(0x6C, 0x00, SS_RDEF,
811 "Rebuild failure occurred") },
812/* A */{SST(0x6D, 0x00, SS_RDEF,
813 "Recalculate failure occurred") },
814/* A */{SST(0x6E, 0x00, SS_RDEF,
815 "Command to logical unit failed") },
816/* T */{SST(0x70, 0x00, SS_RDEF,
817 "Decompression exception short: ASCQ = Algorithm ID") },
818/* T */{SST(0x70, 0xFF, SS_RDEF|SSQ_RANGE,
819 NULL) }, /* Range 0x00 -> 0xFF */
820/* T */{SST(0x71, 0x00, SS_RDEF,
821 "Decompression exception long: ASCQ = Algorithm ID") },
822/* T */{SST(0x71, 0xFF, SS_RDEF|SSQ_RANGE,
823 NULL) }, /* Range 0x00 -> 0xFF */
824/* R */{SST(0x72, 0x00, SS_RDEF,
825 "Session fixation error") },
826/* R */{SST(0x72, 0x01, SS_RDEF,
827 "Session fixation error writing lead-in") },
828/* R */{SST(0x72, 0x02, SS_RDEF,
829 "Session fixation error writing lead-out") },
830/* R */{SST(0x72, 0x03, SS_RDEF,
831 "Session fixation error - incomplete track in session") },
832/* R */{SST(0x72, 0x04, SS_RDEF,
833 "Empty or partially written reserved track") },
834/* R */{SST(0x73, 0x00, SS_RDEF,
835 "CD control error") },
836/* R */{SST(0x73, 0x01, SS_RDEF,
837 "Power calibration area almost full") },
838/* R */{SST(0x73, 0x02, SS_FATAL|ENOSPC,
839 "Power calibration area is full") },
840/* R */{SST(0x73, 0x03, SS_RDEF,
841 "Power calibration area error") },
842/* R */{SST(0x73, 0x04, SS_RDEF,
843 "Program memory area update failure") },
844/* R */{SST(0x73, 0x05, SS_RDEF,
845 "program memory area is full") }
846};
847
848static const int asc_table_size = sizeof(asc_table)/sizeof(asc_table[0]);
849
850struct asc_key
851{
852 int asc;
853 int ascq;
854};
855
856static int
857ascentrycomp(const void *key, const void *member)
858{
859 int asc;
860 int ascq;
861 const struct asc_table_entry *table_entry;
862
863 asc = ((const struct asc_key *)key)->asc;
864 ascq = ((const struct asc_key *)key)->ascq;
865 table_entry = (const struct asc_table_entry *)member;
866
867 if (asc >= table_entry->asc) {
868
869 if (asc > table_entry->asc)
870 return (1);
871
872 if (ascq <= table_entry->ascq) {
873 /* Check for ranges */
874 if (ascq == table_entry->ascq
875 || ((table_entry->action & SSQ_RANGE) != 0
876 && ascq >= (table_entry - 1)->ascq))
877 return (0);
878 return (-1);
879 }
880 return (1);
881 }
882 return (-1);
883}
884
885static int
886senseentrycomp(const void *key, const void *member)
887{
888 int sense_key;
889 const struct sense_key_table_entry *table_entry;
890
891 sense_key = *((const int *)key);
892 table_entry = (const struct sense_key_table_entry *)member;
893
894 if (sense_key >= table_entry->sense_key) {
895 if (sense_key == table_entry->sense_key)
896 return (0);
897 return (1);
898 }
899 return (-1);
900}
901
902static void
903fetchtableentries(int sense_key, int asc, int ascq,
904 struct scsi_inquiry_data *inq_data,
905 const struct sense_key_table_entry **sense_entry,
906 const struct asc_table_entry **asc_entry)
907{
908 void *match;
909 const struct asc_table_entry *asc_tables[2];
910 const struct sense_key_table_entry *sense_tables[2];
911 struct asc_key asc_ascq;
912 size_t asc_tables_size[2];
913 size_t sense_tables_size[2];
914 int num_asc_tables;
915 int num_sense_tables;
916 int i;
917
918 /* Default to failure */
919 *sense_entry = NULL;
920 *asc_entry = NULL;
921 match = NULL;
922 if (inq_data != NULL)
923 match = cam_quirkmatch((void *)inq_data,
924 (void *)sense_quirk_table,
925 sense_quirk_table_size,
926 sizeof(*sense_quirk_table),
927 aic_inquiry_match);
928
929 if (match != NULL) {
930 struct scsi_sense_quirk_entry *quirk;
931
932 quirk = (struct scsi_sense_quirk_entry *)match;
933 asc_tables[0] = quirk->asc_info;
934 asc_tables_size[0] = quirk->num_ascs;
935 asc_tables[1] = asc_table;
936 asc_tables_size[1] = asc_table_size;
937 num_asc_tables = 2;
938 sense_tables[0] = quirk->sense_key_info;
939 sense_tables_size[0] = quirk->num_sense_keys;
940 sense_tables[1] = sense_key_table;
941 sense_tables_size[1] = sense_key_table_size;
942 num_sense_tables = 2;
943 } else {
944 asc_tables[0] = asc_table;
945 asc_tables_size[0] = asc_table_size;
946 num_asc_tables = 1;
947 sense_tables[0] = sense_key_table;
948 sense_tables_size[0] = sense_key_table_size;
949 num_sense_tables = 1;
950 }
951
952 asc_ascq.asc = asc;
953 asc_ascq.ascq = ascq;
954 for (i = 0; i < num_asc_tables; i++) {
955 void *found_entry;
956
957 found_entry = scsibsearch(&asc_ascq, asc_tables[i],
958 asc_tables_size[i],
959 sizeof(**asc_tables),
960 ascentrycomp);
961
962 if (found_entry) {
963 *asc_entry = (struct asc_table_entry *)found_entry;
964 break;
965 }
966 }
967
968 for (i = 0; i < num_sense_tables; i++) {
969 void *found_entry;
970
971 found_entry = scsibsearch(&sense_key, sense_tables[i],
972 sense_tables_size[i],
973 sizeof(**sense_tables),
974 senseentrycomp);
975
976 if (found_entry) {
977 *sense_entry =
978 (struct sense_key_table_entry *)found_entry;
979 break;
980 }
981 }
982}
983
984static void *
985scsibsearch(const void *key, const void *base, size_t nmemb, size_t size,
986 int (*compar)(const void *, const void *))
987{
988 const void *entry;
989 u_int l;
990 u_int u;
991 u_int m;
992
993 l = -1;
994 u = nmemb;
995 while (l + 1 != u) {
996 m = (l + u) / 2;
997 entry = base + m * size;
998 if (compar(key, entry) > 0)
999 l = m;
1000 else
1001 u = m;
1002 }
1003
1004 entry = base + u * size;
1005 if (u == nmemb
1006 || compar(key, entry) != 0)
1007 return (NULL);
1008
1009 return ((void *)entry);
1010}
1011
1012/*
1013 * Compare string with pattern, returning 0 on match.
1014 * Short pattern matches trailing blanks in name,
1015 * wildcard '*' in pattern matches rest of name,
1016 * wildcard '?' matches a single non-space character.
1017 */
1018static int
1019cam_strmatch(const uint8_t *str, const uint8_t *pattern, int str_len)
1020{
1021
1022 while (*pattern != '\0'&& str_len > 0) {
1023
1024 if (*pattern == '*') {
1025 return (0);
1026 }
1027 if ((*pattern != *str)
1028 && (*pattern != '?' || *str == ' ')) {
1029 return (1);
1030 }
1031 pattern++;
1032 str++;
1033 str_len--;
1034 }
1035 while (str_len > 0 && *str++ == ' ')
1036 str_len--;
1037
1038 return (str_len);
1039}
1040
1041static caddr_t
1042cam_quirkmatch(caddr_t target, caddr_t quirk_table, int num_entries,
1043 int entry_size, cam_quirkmatch_t *comp_func)
1044{
1045 for (; num_entries > 0; num_entries--, quirk_table += entry_size) {
1046 if ((*comp_func)(target, quirk_table) == 0)
1047 return (quirk_table);
1048 }
1049 return (NULL);
1050}
1051
1052void
1053aic_sense_desc(int sense_key, int asc, int ascq,
1054 struct scsi_inquiry_data *inq_data,
1055 const char **sense_key_desc, const char **asc_desc)
1056{
1057 const struct asc_table_entry *asc_entry;
1058 const struct sense_key_table_entry *sense_entry;
1059
1060 fetchtableentries(sense_key, asc, ascq,
1061 inq_data,
1062 &sense_entry,
1063 &asc_entry);
1064
1065 *sense_key_desc = sense_entry->desc;
1066
1067 if (asc_entry != NULL)
1068 *asc_desc = asc_entry->desc;
1069 else if (asc >= 0x80 && asc <= 0xff)
1070 *asc_desc = "Vendor Specific ASC";
1071 else if (ascq >= 0x80 && ascq <= 0xff)
1072 *asc_desc = "Vendor Specific ASCQ";
1073 else
1074 *asc_desc = "Reserved ASC/ASCQ pair";
1075}
1076
1077/*
1078 * Given sense and device type information, return the appropriate action.
1079 * If we do not understand the specific error as identified by the ASC/ASCQ
1080 * pair, fall back on the more generic actions derived from the sense key.
1081 */
1082aic_sense_action
1083aic_sense_error_action(struct scsi_sense_data *sense_data,
1084 struct scsi_inquiry_data *inq_data, uint32_t sense_flags)
1085{
1086 const struct asc_table_entry *asc_entry;
1087 const struct sense_key_table_entry *sense_entry;
1088 int error_code, sense_key, asc, ascq;
1089 aic_sense_action action;
1090
1091 scsi_extract_sense(sense_data, &error_code, &sense_key, &asc, &ascq);
1092
1093 if (error_code == SSD_DEFERRED_ERROR) {
1094 /*
1095 * XXX dufault@FreeBSD.org
1096 * This error doesn't relate to the command associated
1097 * with this request sense. A deferred error is an error
1098 * for a command that has already returned GOOD status
1099 * (see SCSI2 8.2.14.2).
1100 *
1101 * By my reading of that section, it looks like the current
1102 * command has been cancelled, we should now clean things up
1103 * (hopefully recovering any lost data) and then retry the
1104 * current command. There are two easy choices, both wrong:
1105 *
1106 * 1. Drop through (like we had been doing), thus treating
1107 * this as if the error were for the current command and
1108 * return and stop the current command.
1109 *
1110 * 2. Issue a retry (like I made it do) thus hopefully
1111 * recovering the current transfer, and ignoring the
1112 * fact that we've dropped a command.
1113 *
1114 * These should probably be handled in a device specific
1115 * sense handler or punted back up to a user mode daemon
1116 */
1117 action = SS_RETRY|SSQ_DECREMENT_COUNT|SSQ_PRINT_SENSE;
1118 } else {
1119 fetchtableentries(sense_key, asc, ascq,
1120 inq_data,
1121 &sense_entry,
1122 &asc_entry);
1123
1124 /*
1125 * Override the 'No additional Sense' entry (0,0)
1126 * with the error action of the sense key.
1127 */
1128 if (asc_entry != NULL
1129 && (asc != 0 || ascq != 0))
1130 action = asc_entry->action;
1131 else
1132 action = sense_entry->action;
1133
1134 if (sense_key == SSD_KEY_RECOVERED_ERROR) {
1135 /*
1136 * The action succeeded but the device wants
1137 * the user to know that some recovery action
1138 * was required.
1139 */
1140 action &= ~(SS_MASK|SSQ_MASK|SS_ERRMASK);
1141 action |= SS_NOP|SSQ_PRINT_SENSE;
1142 } else if (sense_key == SSD_KEY_ILLEGAL_REQUEST) {
1143 if ((sense_flags & SF_QUIET_IR) != 0)
1144 action &= ~SSQ_PRINT_SENSE;
1145 } else if (sense_key == SSD_KEY_UNIT_ATTENTION) {
1146 if ((sense_flags & SF_RETRY_UA) != 0
1147 && (action & SS_MASK) == SS_FAIL) {
1148 action &= ~(SS_MASK|SSQ_MASK);
1149 action |= SS_RETRY|SSQ_DECREMENT_COUNT|
1150 SSQ_PRINT_SENSE;
1151 }
1152 }
1153 }
1154
1155 if ((sense_flags & SF_PRINT_ALWAYS) != 0)
1156 action |= SSQ_PRINT_SENSE;
1157 else if ((sense_flags & SF_NO_PRINT) != 0)
1158 action &= ~SSQ_PRINT_SENSE;
1159
1160 return (action);
1161}
1162
1163/*
1164 * Try make as good a match as possible with
1165 * available sub drivers
1166 */
1167int
1168aic_inquiry_match(caddr_t inqbuffer, caddr_t table_entry)
1169{
1170 struct scsi_inquiry_pattern *entry;
1171 struct scsi_inquiry_data *inq;
1172
1173 entry = (struct scsi_inquiry_pattern *)table_entry;
1174 inq = (struct scsi_inquiry_data *)inqbuffer;
1175
1176 if (((SID_TYPE(inq) == entry->type)
1177 || (entry->type == T_ANY))
1178 && (SID_IS_REMOVABLE(inq) ? entry->media_type & SIP_MEDIA_REMOVABLE
1179 : entry->media_type & SIP_MEDIA_FIXED)
1180 && (cam_strmatch(inq->vendor, entry->vendor, sizeof(inq->vendor)) == 0)
1181 && (cam_strmatch(inq->product, entry->product,
1182 sizeof(inq->product)) == 0)
1183 && (cam_strmatch(inq->revision, entry->revision,
1184 sizeof(inq->revision)) == 0)) {
1185 return (0);
1186 }
1187 return (-1);
1188}
1189
1190/*
1191 * Table of syncrates that don't follow the "divisible by 4"
1192 * rule. This table will be expanded in future SCSI specs.
1193 */
1194static struct {
1195 u_int period_factor;
1196 u_int period; /* in 100ths of ns */
1197} scsi_syncrates[] = {
1198 { 0x08, 625 }, /* FAST-160 */
1199 { 0x09, 1250 }, /* FAST-80 */
1200 { 0x0a, 2500 }, /* FAST-40 40MHz */
1201 { 0x0b, 3030 }, /* FAST-40 33MHz */
1202 { 0x0c, 5000 } /* FAST-20 */
1203};
1204
1205/*
1206 * Return the frequency in kHz corresponding to the given
1207 * sync period factor.
1208 */
1209u_int
1210aic_calc_syncsrate(u_int period_factor)
1211{
1212 int i;
1213 int num_syncrates;
1214
1215 num_syncrates = sizeof(scsi_syncrates) / sizeof(scsi_syncrates[0]);
1216 /* See if the period is in the "exception" table */
1217 for (i = 0; i < num_syncrates; i++) {
1218
1219 if (period_factor == scsi_syncrates[i].period_factor) {
1220 /* Period in kHz */
1221 return (100000000 / scsi_syncrates[i].period);
1222 }
1223 }
1224
1225 /*
1226 * Wasn't in the table, so use the standard
1227 * 4 times conversion.
1228 */
1229 return (10000000 / (period_factor * 4 * 10));
1230}
1231
1232/*
1233 * Return speed in KB/s.
1234 */
1235u_int
1236aic_calc_speed(u_int width, u_int period, u_int offset, u_int min_rate)
1237{
1238 u_int freq;
1239
1240 if (offset != 0 && period < min_rate)
1241 freq = aic_calc_syncsrate(period);
1242 else
1243 /* Roughly 3.3MB/s for async */
1244 freq = 3300;
1245 freq <<= width;
1246 return (freq);
1247}
1248
1249uint32_t
1250aic_error_action(struct scsi_cmnd *cmd, struct scsi_inquiry_data *inq_data,
1251 cam_status status, u_int scsi_status)
1252{
1253 aic_sense_action err_action;
1254 int sense;
1255
1256 sense = (cmd->result >> 24) == DRIVER_SENSE;
1257
1258 switch (status) {
1259 case CAM_REQ_CMP:
1260 err_action = SS_NOP;
1261 break;
1262 case CAM_AUTOSENSE_FAIL:
1263 case CAM_SCSI_STATUS_ERROR:
1264
1265 switch (scsi_status) {
1266 case SCSI_STATUS_OK:
1267 case SCSI_STATUS_COND_MET:
1268 case SCSI_STATUS_INTERMED:
1269 case SCSI_STATUS_INTERMED_COND_MET:
1270 err_action = SS_NOP;
1271 break;
1272 case SCSI_STATUS_CMD_TERMINATED:
1273 case SCSI_STATUS_CHECK_COND:
1274 if (sense != 0) {
1275 struct scsi_sense_data *sense;
1276
1277 sense = (struct scsi_sense_data *)
1278 &cmd->sense_buffer;
1279 err_action =
1280 aic_sense_error_action(sense, inq_data, 0);
1281
1282 } else {
1283 err_action = SS_RETRY|SSQ_FALLBACK
1284 | SSQ_DECREMENT_COUNT|EIO;
1285 }
1286 break;
1287 case SCSI_STATUS_QUEUE_FULL:
1288 case SCSI_STATUS_BUSY:
1289 err_action = SS_RETRY|SSQ_DELAY|SSQ_MANY
1290 | SSQ_DECREMENT_COUNT|EBUSY;
1291 break;
1292 case SCSI_STATUS_RESERV_CONFLICT:
1293 default:
1294 err_action = SS_FAIL|EBUSY;
1295 break;
1296 }
1297 break;
1298 case CAM_CMD_TIMEOUT:
1299 case CAM_REQ_CMP_ERR:
1300 case CAM_UNEXP_BUSFREE:
1301 case CAM_UNCOR_PARITY:
1302 case CAM_DATA_RUN_ERR:
1303 err_action = SS_RETRY|SSQ_FALLBACK|EIO;
1304 break;
1305 case CAM_UA_ABORT:
1306 case CAM_UA_TERMIO:
1307 case CAM_MSG_REJECT_REC:
1308 case CAM_SEL_TIMEOUT:
1309 err_action = SS_FAIL|EIO;
1310 break;
1311 case CAM_REQ_INVALID:
1312 case CAM_PATH_INVALID:
1313 case CAM_DEV_NOT_THERE:
1314 case CAM_NO_HBA:
1315 case CAM_PROVIDE_FAIL:
1316 case CAM_REQ_TOO_BIG:
1317 case CAM_RESRC_UNAVAIL:
1318 case CAM_BUSY:
1319 default:
1320 /* panic?? These should never occur in our application. */
1321 err_action = SS_FAIL|EIO;
1322 break;
1323 case CAM_SCSI_BUS_RESET:
1324 case CAM_BDR_SENT:
1325 case CAM_REQUEUE_REQ:
1326 /* Unconditional requeue */
1327 err_action = SS_RETRY;
1328 break;
1329 }
1330
1331 return (err_action);
1332}
1333
1334char *
1335aic_parse_brace_option(char *opt_name, char *opt_arg, char *end, int depth,
1336 aic_option_callback_t *callback, u_long callback_arg)
1337{
1338 char *tok_end;
1339 char *tok_end2;
1340 int i;
1341 int instance;
1342 int targ;
1343 int done;
1344 char tok_list[] = {'.', ',', '{', '}', '\0'};
1345 34
1346 /* All options use a ':' name/arg separator */
1347 if (*opt_arg != ':')
1348 return (opt_arg);
1349 opt_arg++;
1350 instance = -1;
1351 targ = -1;
1352 done = FALSE;
1353 /*
1354 * Restore separator that may be in
1355 * the middle of our option argument.
1356 */
1357 tok_end = strchr(opt_arg, '\0');
1358 if (tok_end < end)
1359 *tok_end = ',';
1360 while (!done) {
1361 switch (*opt_arg) {
1362 case '{':
1363 if (instance == -1) {
1364 instance = 0;
1365 } else {
1366 if (depth > 1) {
1367 if (targ == -1)
1368 targ = 0;
1369 } else {
1370 printf("Malformed Option %s\n",
1371 opt_name);
1372 done = TRUE;
1373 }
1374 }
1375 opt_arg++;
1376 break;
1377 case '}':
1378 if (targ != -1)
1379 targ = -1;
1380 else if (instance != -1)
1381 instance = -1;
1382 opt_arg++;
1383 break;
1384 case ',':
1385 case '.':
1386 if (instance == -1)
1387 done = TRUE;
1388 else if (targ >= 0)
1389 targ++;
1390 else if (instance >= 0)
1391 instance++;
1392 opt_arg++;
1393 break;
1394 case '\0':
1395 done = TRUE;
1396 break;
1397 default:
1398 tok_end = end;
1399 for (i = 0; tok_list[i]; i++) {
1400 tok_end2 = strchr(opt_arg, tok_list[i]);
1401 if ((tok_end2) && (tok_end2 < tok_end))
1402 tok_end = tok_end2;
1403 }
1404 callback(callback_arg, instance, targ,
1405 simple_strtol(opt_arg, NULL, 0));
1406 opt_arg = tok_end;
1407 break;
1408 }
1409 }
1410 return (opt_arg);
1411}
diff --git a/drivers/scsi/aic7xxx/aiclib.h b/drivers/scsi/aic7xxx/aiclib.h
index bfe6f954d3c..3bfbf0fe1ec 100644
--- a/drivers/scsi/aic7xxx/aiclib.h
+++ b/drivers/scsi/aic7xxx/aiclib.h
@@ -57,121 +57,6 @@
57#ifndef _AICLIB_H 57#ifndef _AICLIB_H
58#define _AICLIB_H 58#define _AICLIB_H
59 59
60/*
61 * Linux Interrupt Support.
62 */
63#ifndef IRQ_RETVAL
64typedef void irqreturn_t;
65#define IRQ_RETVAL(x)
66#endif
67
68/*
69 * SCSI command format
70 */
71
72/*
73 * Define dome bits that are in ALL (or a lot of) scsi commands
74 */
75#define SCSI_CTL_LINK 0x01
76#define SCSI_CTL_FLAG 0x02
77#define SCSI_CTL_VENDOR 0xC0
78#define SCSI_CMD_LUN 0xA0 /* these two should not be needed */
79#define SCSI_CMD_LUN_SHIFT 5 /* LUN in the cmd is no longer SCSI */
80
81#define SCSI_MAX_CDBLEN 16 /*
82 * 16 byte commands are in the
83 * SCSI-3 spec
84 */
85/* 6byte CDBs special case 0 length to be 256 */
86#define SCSI_CDB6_LEN(len) ((len) == 0 ? 256 : len)
87
88/*
89 * This type defines actions to be taken when a particular sense code is
90 * received. Right now, these flags are only defined to take up 16 bits,
91 * but can be expanded in the future if necessary.
92 */
93typedef enum {
94 SS_NOP = 0x000000, /* Do nothing */
95 SS_RETRY = 0x010000, /* Retry the command */
96 SS_FAIL = 0x020000, /* Bail out */
97 SS_START = 0x030000, /* Send a Start Unit command to the device,
98 * then retry the original command.
99 */
100 SS_TUR = 0x040000, /* Send a Test Unit Ready command to the
101 * device, then retry the original command.
102 */
103 SS_REQSENSE = 0x050000, /* Send a RequestSense command to the
104 * device, then retry the original command.
105 */
106 SS_INQ_REFRESH = 0x060000,
107 SS_MASK = 0xff0000
108} aic_sense_action;
109
110typedef enum {
111 SSQ_NONE = 0x0000,
112 SSQ_DECREMENT_COUNT = 0x0100, /* Decrement the retry count */
113 SSQ_MANY = 0x0200, /* send lots of recovery commands */
114 SSQ_RANGE = 0x0400, /*
115 * This table entry represents the
116 * end of a range of ASCQs that
117 * have identical error actions
118 * and text.
119 */
120 SSQ_PRINT_SENSE = 0x0800,
121 SSQ_DELAY = 0x1000, /* Delay before retry. */
122 SSQ_DELAY_RANDOM = 0x2000, /* Randomized delay before retry. */
123 SSQ_FALLBACK = 0x4000, /* Do a speed fallback to recover */
124 SSQ_MASK = 0xff00
125} aic_sense_action_qualifier;
126
127/* Mask for error status values */
128#define SS_ERRMASK 0xff
129
130/* The default, retyable, error action */
131#define SS_RDEF SS_RETRY|SSQ_DECREMENT_COUNT|SSQ_PRINT_SENSE|EIO
132
133/* The retyable, error action, with table specified error code */
134#define SS_RET SS_RETRY|SSQ_DECREMENT_COUNT|SSQ_PRINT_SENSE
135
136/* Fatal error action, with table specified error code */
137#define SS_FATAL SS_FAIL|SSQ_PRINT_SENSE
138
139struct scsi_generic
140{
141 uint8_t opcode;
142 uint8_t bytes[11];
143};
144
145struct scsi_request_sense
146{
147 uint8_t opcode;
148 uint8_t byte2;
149 uint8_t unused[2];
150 uint8_t length;
151 uint8_t control;
152};
153
154struct scsi_test_unit_ready
155{
156 uint8_t opcode;
157 uint8_t byte2;
158 uint8_t unused[3];
159 uint8_t control;
160};
161
162struct scsi_send_diag
163{
164 uint8_t opcode;
165 uint8_t byte2;
166#define SSD_UOL 0x01
167#define SSD_DOL 0x02
168#define SSD_SELFTEST 0x04
169#define SSD_PF 0x10
170 uint8_t unused[1];
171 uint8_t paramlen[2];
172 uint8_t control;
173};
174
175struct scsi_sense 60struct scsi_sense
176{ 61{
177 uint8_t opcode; 62 uint8_t opcode;
@@ -181,537 +66,12 @@ struct scsi_sense
181 uint8_t control; 66 uint8_t control;
182}; 67};
183 68
184struct scsi_inquiry
185{
186 uint8_t opcode;
187 uint8_t byte2;
188#define SI_EVPD 0x01
189 uint8_t page_code;
190 uint8_t reserved;
191 uint8_t length;
192 uint8_t control;
193};
194
195struct scsi_mode_sense_6
196{
197 uint8_t opcode;
198 uint8_t byte2;
199#define SMS_DBD 0x08
200 uint8_t page;
201#define SMS_PAGE_CODE 0x3F
202#define SMS_VENDOR_SPECIFIC_PAGE 0x00
203#define SMS_DISCONNECT_RECONNECT_PAGE 0x02
204#define SMS_PERIPHERAL_DEVICE_PAGE 0x09
205#define SMS_CONTROL_MODE_PAGE 0x0A
206#define SMS_ALL_PAGES_PAGE 0x3F
207#define SMS_PAGE_CTRL_MASK 0xC0
208#define SMS_PAGE_CTRL_CURRENT 0x00
209#define SMS_PAGE_CTRL_CHANGEABLE 0x40
210#define SMS_PAGE_CTRL_DEFAULT 0x80
211#define SMS_PAGE_CTRL_SAVED 0xC0
212 uint8_t unused;
213 uint8_t length;
214 uint8_t control;
215};
216
217struct scsi_mode_sense_10
218{
219 uint8_t opcode;
220 uint8_t byte2; /* same bits as small version */
221 uint8_t page; /* same bits as small version */
222 uint8_t unused[4];
223 uint8_t length[2];
224 uint8_t control;
225};
226
227struct scsi_mode_select_6
228{
229 uint8_t opcode;
230 uint8_t byte2;
231#define SMS_SP 0x01
232#define SMS_PF 0x10
233 uint8_t unused[2];
234 uint8_t length;
235 uint8_t control;
236};
237
238struct scsi_mode_select_10
239{
240 uint8_t opcode;
241 uint8_t byte2; /* same bits as small version */
242 uint8_t unused[5];
243 uint8_t length[2];
244 uint8_t control;
245};
246
247/*
248 * When sending a mode select to a tape drive, the medium type must be 0.
249 */
250struct scsi_mode_hdr_6
251{
252 uint8_t datalen;
253 uint8_t medium_type;
254 uint8_t dev_specific;
255 uint8_t block_descr_len;
256};
257
258struct scsi_mode_hdr_10
259{
260 uint8_t datalen[2];
261 uint8_t medium_type;
262 uint8_t dev_specific;
263 uint8_t reserved[2];
264 uint8_t block_descr_len[2];
265};
266
267struct scsi_mode_block_descr
268{
269 uint8_t density_code;
270 uint8_t num_blocks[3];
271 uint8_t reserved;
272 uint8_t block_len[3];
273};
274
275struct scsi_log_sense
276{
277 uint8_t opcode;
278 uint8_t byte2;
279#define SLS_SP 0x01
280#define SLS_PPC 0x02
281 uint8_t page;
282#define SLS_PAGE_CODE 0x3F
283#define SLS_ALL_PAGES_PAGE 0x00
284#define SLS_OVERRUN_PAGE 0x01
285#define SLS_ERROR_WRITE_PAGE 0x02
286#define SLS_ERROR_READ_PAGE 0x03
287#define SLS_ERROR_READREVERSE_PAGE 0x04
288#define SLS_ERROR_VERIFY_PAGE 0x05
289#define SLS_ERROR_NONMEDIUM_PAGE 0x06
290#define SLS_ERROR_LASTN_PAGE 0x07
291#define SLS_PAGE_CTRL_MASK 0xC0
292#define SLS_PAGE_CTRL_THRESHOLD 0x00
293#define SLS_PAGE_CTRL_CUMULATIVE 0x40
294#define SLS_PAGE_CTRL_THRESH_DEFAULT 0x80
295#define SLS_PAGE_CTRL_CUMUL_DEFAULT 0xC0
296 uint8_t reserved[2];
297 uint8_t paramptr[2];
298 uint8_t length[2];
299 uint8_t control;
300};
301
302struct scsi_log_select
303{
304 uint8_t opcode;
305 uint8_t byte2;
306/* SLS_SP 0x01 */
307#define SLS_PCR 0x02
308 uint8_t page;
309/* SLS_PAGE_CTRL_MASK 0xC0 */
310/* SLS_PAGE_CTRL_THRESHOLD 0x00 */
311/* SLS_PAGE_CTRL_CUMULATIVE 0x40 */
312/* SLS_PAGE_CTRL_THRESH_DEFAULT 0x80 */
313/* SLS_PAGE_CTRL_CUMUL_DEFAULT 0xC0 */
314 uint8_t reserved[4];
315 uint8_t length[2];
316 uint8_t control;
317};
318
319struct scsi_log_header
320{
321 uint8_t page;
322 uint8_t reserved;
323 uint8_t datalen[2];
324};
325
326struct scsi_log_param_header {
327 uint8_t param_code[2];
328 uint8_t param_control;
329#define SLP_LP 0x01
330#define SLP_LBIN 0x02
331#define SLP_TMC_MASK 0x0C
332#define SLP_TMC_ALWAYS 0x00
333#define SLP_TMC_EQUAL 0x04
334#define SLP_TMC_NOTEQUAL 0x08
335#define SLP_TMC_GREATER 0x0C
336#define SLP_ETC 0x10
337#define SLP_TSD 0x20
338#define SLP_DS 0x40
339#define SLP_DU 0x80
340 uint8_t param_len;
341};
342
343struct scsi_control_page {
344 uint8_t page_code;
345 uint8_t page_length;
346 uint8_t rlec;
347#define SCB_RLEC 0x01 /*Report Log Exception Cond*/
348 uint8_t queue_flags;
349#define SCP_QUEUE_ALG_MASK 0xF0
350#define SCP_QUEUE_ALG_RESTRICTED 0x00
351#define SCP_QUEUE_ALG_UNRESTRICTED 0x10
352#define SCP_QUEUE_ERR 0x02 /*Queued I/O aborted for CACs*/
353#define SCP_QUEUE_DQUE 0x01 /*Queued I/O disabled*/
354 uint8_t eca_and_aen;
355#define SCP_EECA 0x80 /*Enable Extended CA*/
356#define SCP_RAENP 0x04 /*Ready AEN Permission*/
357#define SCP_UAAENP 0x02 /*UA AEN Permission*/
358#define SCP_EAENP 0x01 /*Error AEN Permission*/
359 uint8_t reserved;
360 uint8_t aen_holdoff_period[2];
361};
362
363struct scsi_reserve
364{
365 uint8_t opcode;
366 uint8_t byte2;
367 uint8_t unused[2];
368 uint8_t length;
369 uint8_t control;
370};
371
372struct scsi_release
373{
374 uint8_t opcode;
375 uint8_t byte2;
376 uint8_t unused[2];
377 uint8_t length;
378 uint8_t control;
379};
380
381struct scsi_prevent
382{
383 uint8_t opcode;
384 uint8_t byte2;
385 uint8_t unused[2];
386 uint8_t how;
387 uint8_t control;
388};
389#define PR_PREVENT 0x01
390#define PR_ALLOW 0x00
391
392struct scsi_sync_cache
393{
394 uint8_t opcode;
395 uint8_t byte2;
396 uint8_t begin_lba[4];
397 uint8_t reserved;
398 uint8_t lb_count[2];
399 uint8_t control;
400};
401
402
403struct scsi_changedef
404{
405 uint8_t opcode;
406 uint8_t byte2;
407 uint8_t unused1;
408 uint8_t how;
409 uint8_t unused[4];
410 uint8_t datalen;
411 uint8_t control;
412};
413
414struct scsi_read_buffer
415{
416 uint8_t opcode;
417 uint8_t byte2;
418#define RWB_MODE 0x07
419#define RWB_MODE_HDR_DATA 0x00
420#define RWB_MODE_DATA 0x02
421#define RWB_MODE_DOWNLOAD 0x04
422#define RWB_MODE_DOWNLOAD_SAVE 0x05
423 uint8_t buffer_id;
424 uint8_t offset[3];
425 uint8_t length[3];
426 uint8_t control;
427};
428
429struct scsi_write_buffer
430{
431 uint8_t opcode;
432 uint8_t byte2;
433 uint8_t buffer_id;
434 uint8_t offset[3];
435 uint8_t length[3];
436 uint8_t control;
437};
438
439struct scsi_rw_6
440{
441 uint8_t opcode;
442 uint8_t addr[3];
443/* only 5 bits are valid in the MSB address byte */
444#define SRW_TOPADDR 0x1F
445 uint8_t length;
446 uint8_t control;
447};
448
449struct scsi_rw_10
450{
451 uint8_t opcode;
452#define SRW10_RELADDR 0x01
453#define SRW10_FUA 0x08
454#define SRW10_DPO 0x10
455 uint8_t byte2;
456 uint8_t addr[4];
457 uint8_t reserved;
458 uint8_t length[2];
459 uint8_t control;
460};
461
462struct scsi_rw_12
463{
464 uint8_t opcode;
465#define SRW12_RELADDR 0x01
466#define SRW12_FUA 0x08
467#define SRW12_DPO 0x10
468 uint8_t byte2;
469 uint8_t addr[4];
470 uint8_t length[4];
471 uint8_t reserved;
472 uint8_t control;
473};
474
475struct scsi_start_stop_unit
476{
477 uint8_t opcode;
478 uint8_t byte2;
479#define SSS_IMMED 0x01
480 uint8_t reserved[2];
481 uint8_t how;
482#define SSS_START 0x01
483#define SSS_LOEJ 0x02
484 uint8_t control;
485};
486
487#define SC_SCSI_1 0x01
488#define SC_SCSI_2 0x03
489
490/*
491 * Opcodes
492 */
493
494#define TEST_UNIT_READY 0x00
495#define REQUEST_SENSE 0x03
496#define READ_6 0x08
497#define WRITE_6 0x0a
498#define INQUIRY 0x12
499#define MODE_SELECT_6 0x15
500#define MODE_SENSE_6 0x1a
501#define START_STOP_UNIT 0x1b
502#define START_STOP 0x1b
503#define RESERVE 0x16
504#define RELEASE 0x17
505#define RECEIVE_DIAGNOSTIC 0x1c
506#define SEND_DIAGNOSTIC 0x1d
507#define PREVENT_ALLOW 0x1e
508#define READ_CAPACITY 0x25
509#define READ_10 0x28
510#define WRITE_10 0x2a
511#define POSITION_TO_ELEMENT 0x2b
512#define SYNCHRONIZE_CACHE 0x35
513#define WRITE_BUFFER 0x3b
514#define READ_BUFFER 0x3c
515#define CHANGE_DEFINITION 0x40
516#define LOG_SELECT 0x4c
517#define LOG_SENSE 0x4d
518#ifdef XXXCAM
519#define MODE_SENSE_10 0x5A
520#endif
521#define MODE_SELECT_10 0x55
522#define MOVE_MEDIUM 0xa5
523#define READ_12 0xa8
524#define WRITE_12 0xaa
525#define READ_ELEMENT_STATUS 0xb8
526
527
528/*
529 * Device Types
530 */
531#define T_DIRECT 0x00
532#define T_SEQUENTIAL 0x01
533#define T_PRINTER 0x02
534#define T_PROCESSOR 0x03
535#define T_WORM 0x04
536#define T_CDROM 0x05
537#define T_SCANNER 0x06
538#define T_OPTICAL 0x07
539#define T_CHANGER 0x08
540#define T_COMM 0x09
541#define T_ASC0 0x0a
542#define T_ASC1 0x0b
543#define T_STORARRAY 0x0c
544#define T_ENCLOSURE 0x0d
545#define T_RBC 0x0e
546#define T_OCRW 0x0f
547#define T_NODEVICE 0x1F
548#define T_ANY 0xFF /* Used in Quirk table matches */
549
550#define T_REMOV 1
551#define T_FIXED 0
552
553/*
554 * This length is the initial inquiry length used by the probe code, as
555 * well as the legnth necessary for aic_print_inquiry() to function
556 * correctly. If either use requires a different length in the future,
557 * the two values should be de-coupled.
558 */
559#define SHORT_INQUIRY_LENGTH 36
560
561struct scsi_inquiry_data
562{
563 uint8_t device;
564#define SID_TYPE(inq_data) ((inq_data)->device & 0x1f)
565#define SID_QUAL(inq_data) (((inq_data)->device & 0xE0) >> 5)
566#define SID_QUAL_LU_CONNECTED 0x00 /*
567 * The specified peripheral device
568 * type is currently connected to
569 * logical unit. If the target cannot
570 * determine whether or not a physical
571 * device is currently connected, it
572 * shall also use this peripheral
573 * qualifier when returning the INQUIRY
574 * data. This peripheral qualifier
575 * does not mean that the device is
576 * ready for access by the initiator.
577 */
578#define SID_QUAL_LU_OFFLINE 0x01 /*
579 * The target is capable of supporting
580 * the specified peripheral device type
581 * on this logical unit; however, the
582 * physical device is not currently
583 * connected to this logical unit.
584 */
585#define SID_QUAL_RSVD 0x02
586#define SID_QUAL_BAD_LU 0x03 /*
587 * The target is not capable of
588 * supporting a physical device on
589 * this logical unit. For this
590 * peripheral qualifier the peripheral
591 * device type shall be set to 1Fh to
592 * provide compatibility with previous
593 * versions of SCSI. All other
594 * peripheral device type values are
595 * reserved for this peripheral
596 * qualifier.
597 */
598#define SID_QUAL_IS_VENDOR_UNIQUE(inq_data) ((SID_QUAL(inq_data) & 0x08) != 0)
599 uint8_t dev_qual2;
600#define SID_QUAL2 0x7F
601#define SID_IS_REMOVABLE(inq_data) (((inq_data)->dev_qual2 & 0x80) != 0)
602 uint8_t version;
603#define SID_ANSI_REV(inq_data) ((inq_data)->version & 0x07)
604#define SCSI_REV_0 0 69#define SCSI_REV_0 0
605#define SCSI_REV_CCS 1 70#define SCSI_REV_CCS 1
606#define SCSI_REV_2 2 71#define SCSI_REV_2 2
607#define SCSI_REV_SPC 3 72#define SCSI_REV_SPC 3
608#define SCSI_REV_SPC2 4 73#define SCSI_REV_SPC2 4
609 74
610#define SID_ECMA 0x38
611#define SID_ISO 0xC0
612 uint8_t response_format;
613#define SID_AENC 0x80
614#define SID_TrmIOP 0x40
615 uint8_t additional_length;
616 uint8_t reserved[2];
617 uint8_t flags;
618#define SID_SftRe 0x01
619#define SID_CmdQue 0x02
620#define SID_Linked 0x08
621#define SID_Sync 0x10
622#define SID_WBus16 0x20
623#define SID_WBus32 0x40
624#define SID_RelAdr 0x80
625#define SID_VENDOR_SIZE 8
626 char vendor[SID_VENDOR_SIZE];
627#define SID_PRODUCT_SIZE 16
628 char product[SID_PRODUCT_SIZE];
629#define SID_REVISION_SIZE 4
630 char revision[SID_REVISION_SIZE];
631 /*
632 * The following fields were taken from SCSI Primary Commands - 2
633 * (SPC-2) Revision 14, Dated 11 November 1999
634 */
635#define SID_VENDOR_SPECIFIC_0_SIZE 20
636 uint8_t vendor_specific0[SID_VENDOR_SPECIFIC_0_SIZE];
637 /*
638 * An extension of SCSI Parallel Specific Values
639 */
640#define SID_SPI_IUS 0x01
641#define SID_SPI_QAS 0x02
642#define SID_SPI_CLOCK_ST 0x00
643#define SID_SPI_CLOCK_DT 0x04
644#define SID_SPI_CLOCK_DT_ST 0x0C
645#define SID_SPI_MASK 0x0F
646 uint8_t spi3data;
647 uint8_t reserved2;
648 /*
649 * Version Descriptors, stored 2 byte values.
650 */
651 uint8_t version1[2];
652 uint8_t version2[2];
653 uint8_t version3[2];
654 uint8_t version4[2];
655 uint8_t version5[2];
656 uint8_t version6[2];
657 uint8_t version7[2];
658 uint8_t version8[2];
659
660 uint8_t reserved3[22];
661
662#define SID_VENDOR_SPECIFIC_1_SIZE 160
663 uint8_t vendor_specific1[SID_VENDOR_SPECIFIC_1_SIZE];
664};
665
666struct scsi_vpd_unit_serial_number
667{
668 uint8_t device;
669 uint8_t page_code;
670#define SVPD_UNIT_SERIAL_NUMBER 0x80
671 uint8_t reserved;
672 uint8_t length; /* serial number length */
673#define SVPD_SERIAL_NUM_SIZE 251
674 uint8_t serial_num[SVPD_SERIAL_NUM_SIZE];
675};
676
677struct scsi_read_capacity
678{
679 uint8_t opcode;
680 uint8_t byte2;
681 uint8_t addr[4];
682 uint8_t unused[3];
683 uint8_t control;
684};
685
686struct scsi_read_capacity_data
687{
688 uint8_t addr[4];
689 uint8_t length[4];
690};
691
692struct scsi_report_luns
693{
694 uint8_t opcode;
695 uint8_t byte2;
696 uint8_t unused[3];
697 uint8_t addr[4];
698 uint8_t control;
699};
700
701struct scsi_report_luns_data {
702 uint8_t length[4]; /* length of LUN inventory, in bytes */
703 uint8_t reserved[4]; /* unused */
704 /*
705 * LUN inventory- we only support the type zero form for now.
706 */
707 struct {
708 uint8_t lundata[8];
709 } luns[1];
710};
711#define RPL_LUNDATA_ATYP_MASK 0xc0 /* MBZ for type 0 lun */
712#define RPL_LUNDATA_T0LUN 1 /* @ lundata[1] */
713
714
715struct scsi_sense_data 75struct scsi_sense_data
716{ 76{
717 uint8_t error_code; 77 uint8_t error_code;
@@ -757,41 +117,6 @@ struct scsi_sense_data
757#define SSD_FULL_SIZE sizeof(struct scsi_sense_data) 117#define SSD_FULL_SIZE sizeof(struct scsi_sense_data)
758}; 118};
759 119
760struct scsi_mode_header_6
761{
762 uint8_t data_length; /* Sense data length */
763 uint8_t medium_type;
764 uint8_t dev_spec;
765 uint8_t blk_desc_len;
766};
767
768struct scsi_mode_header_10
769{
770 uint8_t data_length[2];/* Sense data length */
771 uint8_t medium_type;
772 uint8_t dev_spec;
773 uint8_t unused[2];
774 uint8_t blk_desc_len[2];
775};
776
777struct scsi_mode_page_header
778{
779 uint8_t page_code;
780 uint8_t page_length;
781};
782
783struct scsi_mode_blk_desc
784{
785 uint8_t density;
786 uint8_t nblocks[3];
787 uint8_t reserved;
788 uint8_t blklen[3];
789};
790
791#define SCSI_DEFAULT_DENSITY 0x00 /* use 'default' density */
792#define SCSI_SAME_DENSITY 0x7f /* use 'same' density- >= SCSI-2 only */
793
794
795/* 120/*
796 * Status Byte 121 * Status Byte
797 */ 122 */
@@ -807,76 +132,7 @@ struct scsi_mode_blk_desc
807#define SCSI_STATUS_ACA_ACTIVE 0x30 132#define SCSI_STATUS_ACA_ACTIVE 0x30
808#define SCSI_STATUS_TASK_ABORTED 0x40 133#define SCSI_STATUS_TASK_ABORTED 0x40
809 134
810struct scsi_inquiry_pattern {
811 uint8_t type;
812 uint8_t media_type;
813#define SIP_MEDIA_REMOVABLE 0x01
814#define SIP_MEDIA_FIXED 0x02
815 const char *vendor;
816 const char *product;
817 const char *revision;
818};
819
820struct scsi_static_inquiry_pattern {
821 uint8_t type;
822 uint8_t media_type;
823 char vendor[SID_VENDOR_SIZE+1];
824 char product[SID_PRODUCT_SIZE+1];
825 char revision[SID_REVISION_SIZE+1];
826};
827
828struct scsi_sense_quirk_entry {
829 struct scsi_inquiry_pattern inq_pat;
830 int num_sense_keys;
831 int num_ascs;
832 struct sense_key_table_entry *sense_key_info;
833 struct asc_table_entry *asc_info;
834};
835
836struct sense_key_table_entry {
837 uint8_t sense_key;
838 uint32_t action;
839 const char *desc;
840};
841
842struct asc_table_entry {
843 uint8_t asc;
844 uint8_t ascq;
845 uint32_t action;
846 const char *desc;
847};
848
849struct op_table_entry {
850 uint8_t opcode;
851 uint16_t opmask;
852 const char *desc;
853};
854
855struct scsi_op_quirk_entry {
856 struct scsi_inquiry_pattern inq_pat;
857 int num_ops;
858 struct op_table_entry *op_table;
859};
860
861typedef enum {
862 SSS_FLAG_NONE = 0x00,
863 SSS_FLAG_PRINT_COMMAND = 0x01
864} scsi_sense_string_flags;
865
866extern const char *scsi_sense_key_text[];
867
868/************************* Large Disk Handling ********************************/ 135/************************* Large Disk Handling ********************************/
869#if LINUX_VERSION_CODE < KERNEL_VERSION(2,5,0)
870static __inline int aic_sector_div(u_long capacity, int heads, int sectors);
871
872static __inline int
873aic_sector_div(u_long capacity, int heads, int sectors)
874{
875 return (capacity / (heads * sectors));
876}
877#else
878static __inline int aic_sector_div(sector_t capacity, int heads, int sectors);
879
880static __inline int 136static __inline int
881aic_sector_div(sector_t capacity, int heads, int sectors) 137aic_sector_div(sector_t capacity, int heads, int sectors)
882{ 138{
@@ -884,152 +140,6 @@ aic_sector_div(sector_t capacity, int heads, int sectors)
884 sector_div(capacity, (heads * sectors)); 140 sector_div(capacity, (heads * sectors));
885 return (int)capacity; 141 return (int)capacity;
886} 142}
887#endif
888
889/**************************** Module Library Hack *****************************/
890/*
891 * What we'd like to do is have a single "scsi library" module that both the
892 * aic7xxx and aic79xx drivers could load and depend on. A cursory examination
893 * of implementing module dependencies in Linux (handling the install and
894 * initrd cases) does not look promissing. For now, we just duplicate this
895 * code in both drivers using a simple symbol renaming scheme that hides this
896 * hack from the drivers.
897 */
898#define AIC_LIB_ENTRY_CONCAT(x, prefix) prefix ## x
899#define AIC_LIB_ENTRY_EXPAND(x, prefix) AIC_LIB_ENTRY_CONCAT(x, prefix)
900#define AIC_LIB_ENTRY(x) AIC_LIB_ENTRY_EXPAND(x, AIC_LIB_PREFIX)
901
902#define aic_sense_desc AIC_LIB_ENTRY(_sense_desc)
903#define aic_sense_error_action AIC_LIB_ENTRY(_sense_error_action)
904#define aic_error_action AIC_LIB_ENTRY(_error_action)
905#define aic_op_desc AIC_LIB_ENTRY(_op_desc)
906#define aic_cdb_string AIC_LIB_ENTRY(_cdb_string)
907#define aic_print_inquiry AIC_LIB_ENTRY(_print_inquiry)
908#define aic_calc_syncsrate AIC_LIB_ENTRY(_calc_syncrate)
909#define aic_calc_syncparam AIC_LIB_ENTRY(_calc_syncparam)
910#define aic_calc_speed AIC_LIB_ENTRY(_calc_speed)
911#define aic_inquiry_match AIC_LIB_ENTRY(_inquiry_match)
912#define aic_static_inquiry_match AIC_LIB_ENTRY(_static_inquiry_match)
913#define aic_parse_brace_option AIC_LIB_ENTRY(_parse_brace_option)
914
915/******************************************************************************/
916
917void aic_sense_desc(int /*sense_key*/, int /*asc*/,
918 int /*ascq*/, struct scsi_inquiry_data*,
919 const char** /*sense_key_desc*/,
920 const char** /*asc_desc*/);
921aic_sense_action aic_sense_error_action(struct scsi_sense_data*,
922 struct scsi_inquiry_data*,
923 uint32_t /*sense_flags*/);
924uint32_t aic_error_action(struct scsi_cmnd *,
925 struct scsi_inquiry_data *,
926 cam_status, u_int);
927
928#define SF_RETRY_UA 0x01
929#define SF_NO_PRINT 0x02
930#define SF_QUIET_IR 0x04 /* Be quiet about Illegal Request reponses */
931#define SF_PRINT_ALWAYS 0x08
932
933
934const char * aic_op_desc(uint16_t /*opcode*/, struct scsi_inquiry_data*);
935char * aic_cdb_string(uint8_t* /*cdb_ptr*/, char* /*cdb_string*/,
936 size_t /*len*/);
937void aic_print_inquiry(struct scsi_inquiry_data*);
938
939u_int aic_calc_syncsrate(u_int /*period_factor*/);
940u_int aic_calc_syncparam(u_int /*period*/);
941u_int aic_calc_speed(u_int width, u_int period, u_int offset,
942 u_int min_rate);
943
944int aic_inquiry_match(caddr_t /*inqbuffer*/,
945 caddr_t /*table_entry*/);
946int aic_static_inquiry_match(caddr_t /*inqbuffer*/,
947 caddr_t /*table_entry*/);
948
949typedef void aic_option_callback_t(u_long, int, int, int32_t);
950char * aic_parse_brace_option(char *opt_name, char *opt_arg,
951 char *end, int depth,
952 aic_option_callback_t *, u_long);
953
954static __inline void scsi_extract_sense(struct scsi_sense_data *sense,
955 int *error_code, int *sense_key,
956 int *asc, int *ascq);
957static __inline void scsi_ulto2b(uint32_t val, uint8_t *bytes);
958static __inline void scsi_ulto3b(uint32_t val, uint8_t *bytes);
959static __inline void scsi_ulto4b(uint32_t val, uint8_t *bytes);
960static __inline uint32_t scsi_2btoul(uint8_t *bytes);
961static __inline uint32_t scsi_3btoul(uint8_t *bytes);
962static __inline int32_t scsi_3btol(uint8_t *bytes);
963static __inline uint32_t scsi_4btoul(uint8_t *bytes);
964
965static __inline void scsi_extract_sense(struct scsi_sense_data *sense,
966 int *error_code, int *sense_key,
967 int *asc, int *ascq)
968{
969 *error_code = sense->error_code & SSD_ERRCODE;
970 *sense_key = sense->flags & SSD_KEY;
971 *asc = (sense->extra_len >= 5) ? sense->add_sense_code : 0;
972 *ascq = (sense->extra_len >= 6) ? sense->add_sense_code_qual : 0;
973}
974
975static __inline void
976scsi_ulto2b(uint32_t val, uint8_t *bytes)
977{
978
979 bytes[0] = (val >> 8) & 0xff;
980 bytes[1] = val & 0xff;
981}
982
983static __inline void
984scsi_ulto3b(uint32_t val, uint8_t *bytes)
985{
986
987 bytes[0] = (val >> 16) & 0xff;
988 bytes[1] = (val >> 8) & 0xff;
989 bytes[2] = val & 0xff;
990}
991
992static __inline void
993scsi_ulto4b(uint32_t val, uint8_t *bytes)
994{
995
996 bytes[0] = (val >> 24) & 0xff;
997 bytes[1] = (val >> 16) & 0xff;
998 bytes[2] = (val >> 8) & 0xff;
999 bytes[3] = val & 0xff;
1000}
1001
1002static __inline uint32_t
1003scsi_2btoul(uint8_t *bytes)
1004{
1005 uint32_t rv;
1006
1007 rv = (bytes[0] << 8) |
1008 bytes[1];
1009 return (rv);
1010}
1011
1012static __inline uint32_t
1013scsi_3btoul(uint8_t *bytes)
1014{
1015 uint32_t rv;
1016
1017 rv = (bytes[0] << 16) |
1018 (bytes[1] << 8) |
1019 bytes[2];
1020 return (rv);
1021}
1022
1023static __inline int32_t
1024scsi_3btol(uint8_t *bytes)
1025{
1026 uint32_t rc = scsi_3btoul(bytes);
1027
1028 if (rc & 0x00800000)
1029 rc |= 0xff000000;
1030
1031 return (int32_t) rc;
1032}
1033 143
1034static __inline uint32_t 144static __inline uint32_t
1035scsi_4btoul(uint8_t *bytes) 145scsi_4btoul(uint8_t *bytes)
diff --git a/drivers/scsi/ata_piix.c b/drivers/scsi/ata_piix.c
index fb28c126184..deec0cef88d 100644
--- a/drivers/scsi/ata_piix.c
+++ b/drivers/scsi/ata_piix.c
@@ -583,8 +583,7 @@ static void pci_enable_intx(struct pci_dev *pdev)
583#define AHCI_ENABLE (1 << 31) 583#define AHCI_ENABLE (1 << 31)
584static int piix_disable_ahci(struct pci_dev *pdev) 584static int piix_disable_ahci(struct pci_dev *pdev)
585{ 585{
586 void *mmio; 586 void __iomem *mmio;
587 unsigned long addr;
588 u32 tmp; 587 u32 tmp;
589 int rc = 0; 588 int rc = 0;
590 589
@@ -592,11 +591,11 @@ static int piix_disable_ahci(struct pci_dev *pdev)
592 * works because this device is usually set up by BIOS. 591 * works because this device is usually set up by BIOS.
593 */ 592 */
594 593
595 addr = pci_resource_start(pdev, AHCI_PCI_BAR); 594 if (!pci_resource_start(pdev, AHCI_PCI_BAR) ||
596 if (!addr || !pci_resource_len(pdev, AHCI_PCI_BAR)) 595 !pci_resource_len(pdev, AHCI_PCI_BAR))
597 return 0; 596 return 0;
598 597
599 mmio = ioremap(addr, 64); 598 mmio = pci_iomap(pdev, AHCI_PCI_BAR, 64);
600 if (!mmio) 599 if (!mmio)
601 return -ENOMEM; 600 return -ENOMEM;
602 601
@@ -610,7 +609,7 @@ static int piix_disable_ahci(struct pci_dev *pdev)
610 rc = -EIO; 609 rc = -EIO;
611 } 610 }
612 611
613 iounmap(mmio); 612 pci_iounmap(pdev, mmio);
614 return rc; 613 return rc;
615} 614}
616 615
diff --git a/drivers/scsi/ch.c b/drivers/scsi/ch.c
index 3900e28ac7d..bd0e1b6be1e 100644
--- a/drivers/scsi/ch.c
+++ b/drivers/scsi/ch.c
@@ -20,7 +20,6 @@
20#include <linux/interrupt.h> 20#include <linux/interrupt.h>
21#include <linux/blkdev.h> 21#include <linux/blkdev.h>
22#include <linux/completion.h> 22#include <linux/completion.h>
23#include <linux/devfs_fs_kernel.h>
24#include <linux/ioctl32.h> 23#include <linux/ioctl32.h>
25#include <linux/compat.h> 24#include <linux/compat.h>
26#include <linux/chio.h> /* here are all the ioctls */ 25#include <linux/chio.h> /* here are all the ioctls */
@@ -31,7 +30,7 @@
31#include <scsi/scsi_ioctl.h> 30#include <scsi/scsi_ioctl.h>
32#include <scsi/scsi_host.h> 31#include <scsi/scsi_host.h>
33#include <scsi/scsi_device.h> 32#include <scsi/scsi_device.h>
34#include <scsi/scsi_request.h> 33#include <scsi/scsi_eh.h>
35#include <scsi/scsi_dbg.h> 34#include <scsi/scsi_dbg.h>
36 35
37#define CH_DT_MAX 16 36#define CH_DT_MAX 16
@@ -181,17 +180,17 @@ static struct {
181 180
182/* ------------------------------------------------------------------- */ 181/* ------------------------------------------------------------------- */
183 182
184static int ch_find_errno(unsigned char *sense_buffer) 183static int ch_find_errno(struct scsi_sense_hdr *sshdr)
185{ 184{
186 int i,errno = 0; 185 int i,errno = 0;
187 186
188 /* Check to see if additional sense information is available */ 187 /* Check to see if additional sense information is available */
189 if (sense_buffer[7] > 5 && 188 if (scsi_sense_valid(sshdr) &&
190 sense_buffer[12] != 0) { 189 sshdr->asc != 0) {
191 for (i = 0; err[i].errno != 0; i++) { 190 for (i = 0; err[i].errno != 0; i++) {
192 if (err[i].sense == sense_buffer[ 2] && 191 if (err[i].sense == sshdr->sense_key &&
193 err[i].asc == sense_buffer[12] && 192 err[i].asc == sshdr->asc &&
194 err[i].ascq == sense_buffer[13]) { 193 err[i].ascq == sshdr->ascq) {
195 errno = -err[i].errno; 194 errno = -err[i].errno;
196 break; 195 break;
197 } 196 }
@@ -207,13 +206,9 @@ ch_do_scsi(scsi_changer *ch, unsigned char *cmd,
207 void *buffer, unsigned buflength, 206 void *buffer, unsigned buflength,
208 enum dma_data_direction direction) 207 enum dma_data_direction direction)
209{ 208{
210 int errno, retries = 0, timeout; 209 int errno, retries = 0, timeout, result;
211 struct scsi_request *sr; 210 struct scsi_sense_hdr sshdr;
212 211
213 sr = scsi_allocate_request(ch->device, GFP_KERNEL);
214 if (NULL == sr)
215 return -ENOMEM;
216
217 timeout = (cmd[0] == INITIALIZE_ELEMENT_STATUS) 212 timeout = (cmd[0] == INITIALIZE_ELEMENT_STATUS)
218 ? timeout_init : timeout_move; 213 ? timeout_init : timeout_move;
219 214
@@ -224,16 +219,17 @@ ch_do_scsi(scsi_changer *ch, unsigned char *cmd,
224 __scsi_print_command(cmd); 219 __scsi_print_command(cmd);
225 } 220 }
226 221
227 scsi_wait_req(sr, cmd, buffer, buflength, 222 result = scsi_execute_req(ch->device, cmd, direction, buffer,
228 timeout * HZ, MAX_RETRIES); 223 buflength, &sshdr, timeout * HZ,
224 MAX_RETRIES);
229 225
230 dprintk("result: 0x%x\n",sr->sr_result); 226 dprintk("result: 0x%x\n",result);
231 if (driver_byte(sr->sr_result) & DRIVER_SENSE) { 227 if (driver_byte(result) & DRIVER_SENSE) {
232 if (debug) 228 if (debug)
233 scsi_print_req_sense(ch->name, sr); 229 scsi_print_sense_hdr(ch->name, &sshdr);
234 errno = ch_find_errno(sr->sr_sense_buffer); 230 errno = ch_find_errno(&sshdr);
235 231
236 switch(sr->sr_sense_buffer[2] & 0xf) { 232 switch(sshdr.sense_key) {
237 case UNIT_ATTENTION: 233 case UNIT_ATTENTION:
238 ch->unit_attention = 1; 234 ch->unit_attention = 1;
239 if (retries++ < 3) 235 if (retries++ < 3)
@@ -241,7 +237,6 @@ ch_do_scsi(scsi_changer *ch, unsigned char *cmd,
241 break; 237 break;
242 } 238 }
243 } 239 }
244 scsi_release_request(sr);
245 return errno; 240 return errno;
246} 241}
247 242
@@ -940,8 +935,6 @@ static int ch_probe(struct device *dev)
940 if (init) 935 if (init)
941 ch_init_elem(ch); 936 ch_init_elem(ch);
942 937
943 devfs_mk_cdev(MKDEV(SCSI_CHANGER_MAJOR,ch->minor),
944 S_IFCHR | S_IRUGO | S_IWUGO, ch->name);
945 class_device_create(ch_sysfs_class, 938 class_device_create(ch_sysfs_class,
946 MKDEV(SCSI_CHANGER_MAJOR,ch->minor), 939 MKDEV(SCSI_CHANGER_MAJOR,ch->minor),
947 dev, "s%s", ch->name); 940 dev, "s%s", ch->name);
@@ -974,7 +967,6 @@ static int ch_remove(struct device *dev)
974 967
975 class_device_destroy(ch_sysfs_class, 968 class_device_destroy(ch_sysfs_class,
976 MKDEV(SCSI_CHANGER_MAJOR,ch->minor)); 969 MKDEV(SCSI_CHANGER_MAJOR,ch->minor));
977 devfs_remove(ch->name);
978 kfree(ch->dt); 970 kfree(ch->dt);
979 kfree(ch); 971 kfree(ch);
980 ch_devcount--; 972 ch_devcount--;
diff --git a/drivers/scsi/constants.c b/drivers/scsi/constants.c
index ec161733a82..f6be2c1c394 100644
--- a/drivers/scsi/constants.c
+++ b/drivers/scsi/constants.c
@@ -17,6 +17,7 @@
17#include <scsi/scsi_host.h> 17#include <scsi/scsi_host.h>
18#include <scsi/scsi_request.h> 18#include <scsi/scsi_request.h>
19#include <scsi/scsi_eh.h> 19#include <scsi/scsi_eh.h>
20#include <scsi/scsi_dbg.h>
20 21
21 22
22 23
@@ -1155,6 +1156,31 @@ scsi_show_extd_sense(unsigned char asc, unsigned char ascq)
1155 } 1156 }
1156} 1157}
1157 1158
1159void
1160scsi_print_sense_hdr(const char *name, struct scsi_sense_hdr *sshdr)
1161{
1162 const char *sense_txt;
1163 /* An example of deferred is when an earlier write to disk cache
1164 * succeeded, but now the disk discovers that it cannot write the
1165 * data to the magnetic media.
1166 */
1167 const char *error = scsi_sense_is_deferred(sshdr) ?
1168 "<<DEFERRED>>" : "Current";
1169 printk(KERN_INFO "%s: %s", name, error);
1170 if (sshdr->response_code >= 0x72)
1171 printk(" [descriptor]");
1172
1173 sense_txt = scsi_sense_key_string(sshdr->sense_key);
1174 if (sense_txt)
1175 printk(": sense key: %s\n", sense_txt);
1176 else
1177 printk(": sense key=0x%x\n", sshdr->sense_key);
1178 printk(KERN_INFO " ");
1179 scsi_show_extd_sense(sshdr->asc, sshdr->ascq);
1180 printk("\n");
1181}
1182EXPORT_SYMBOL(scsi_print_sense_hdr);
1183
1158/* Print sense information */ 1184/* Print sense information */
1159void 1185void
1160__scsi_print_sense(const char *name, const unsigned char *sense_buffer, 1186__scsi_print_sense(const char *name, const unsigned char *sense_buffer,
@@ -1162,8 +1188,6 @@ __scsi_print_sense(const char *name, const unsigned char *sense_buffer,
1162{ 1188{
1163 int k, num, res; 1189 int k, num, res;
1164 unsigned int info; 1190 unsigned int info;
1165 const char *error;
1166 const char *sense_txt;
1167 struct scsi_sense_hdr ssh; 1191 struct scsi_sense_hdr ssh;
1168 1192
1169 res = scsi_normalize_sense(sense_buffer, sense_len, &ssh); 1193 res = scsi_normalize_sense(sense_buffer, sense_len, &ssh);
@@ -1181,26 +1205,7 @@ __scsi_print_sense(const char *name, const unsigned char *sense_buffer,
1181 printk("\n"); 1205 printk("\n");
1182 return; 1206 return;
1183 } 1207 }
1184 1208 scsi_print_sense_hdr(name, &ssh);
1185 /* An example of deferred is when an earlier write to disk cache
1186 * succeeded, but now the disk discovers that it cannot write the
1187 * data to the magnetic media.
1188 */
1189 error = scsi_sense_is_deferred(&ssh) ?
1190 "<<DEFERRED>>" : "Current";
1191 printk(KERN_INFO "%s: %s", name, error);
1192 if (ssh.response_code >= 0x72)
1193 printk(" [descriptor]");
1194
1195 sense_txt = scsi_sense_key_string(ssh.sense_key);
1196 if (sense_txt)
1197 printk(": sense key: %s\n", sense_txt);
1198 else
1199 printk(": sense key=0x%x\n", ssh.sense_key);
1200 printk(KERN_INFO " ");
1201 scsi_show_extd_sense(ssh.asc, ssh.ascq);
1202 printk("\n");
1203
1204 if (ssh.response_code < 0x72) { 1209 if (ssh.response_code < 0x72) {
1205 /* only decode extras for "fixed" format now */ 1210 /* only decode extras for "fixed" format now */
1206 char buff[80]; 1211 char buff[80];
diff --git a/drivers/scsi/hosts.c b/drivers/scsi/hosts.c
index 5feb886c339..85503fad789 100644
--- a/drivers/scsi/hosts.c
+++ b/drivers/scsi/hosts.c
@@ -24,6 +24,7 @@
24#include <linux/module.h> 24#include <linux/module.h>
25#include <linux/blkdev.h> 25#include <linux/blkdev.h>
26#include <linux/kernel.h> 26#include <linux/kernel.h>
27#include <linux/kthread.h>
27#include <linux/string.h> 28#include <linux/string.h>
28#include <linux/mm.h> 29#include <linux/mm.h>
29#include <linux/init.h> 30#include <linux/init.h>
@@ -52,21 +53,80 @@ static struct class shost_class = {
52}; 53};
53 54
54/** 55/**
55 * scsi_host_cancel - cancel outstanding IO to this host 56 * scsi_host_set_state - Take the given host through the host
56 * @shost: pointer to struct Scsi_Host 57 * state model.
57 * recovery: recovery requested to run. 58 * @shost: scsi host to change the state of.
59 * @state: state to change to.
60 *
61 * Returns zero if unsuccessful or an error if the requested
62 * transition is illegal.
58 **/ 63 **/
59static void scsi_host_cancel(struct Scsi_Host *shost, int recovery) 64int scsi_host_set_state(struct Scsi_Host *shost, enum scsi_host_state state)
60{ 65{
61 struct scsi_device *sdev; 66 enum scsi_host_state oldstate = shost->shost_state;
67
68 if (state == oldstate)
69 return 0;
70
71 switch (state) {
72 case SHOST_CREATED:
73 /* There are no legal states that come back to
74 * created. This is the manually initialised start
75 * state */
76 goto illegal;
77
78 case SHOST_RUNNING:
79 switch (oldstate) {
80 case SHOST_CREATED:
81 case SHOST_RECOVERY:
82 break;
83 default:
84 goto illegal;
85 }
86 break;
87
88 case SHOST_RECOVERY:
89 switch (oldstate) {
90 case SHOST_RUNNING:
91 break;
92 default:
93 goto illegal;
94 }
95 break;
96
97 case SHOST_CANCEL:
98 switch (oldstate) {
99 case SHOST_CREATED:
100 case SHOST_RUNNING:
101 break;
102 default:
103 goto illegal;
104 }
105 break;
106
107 case SHOST_DEL:
108 switch (oldstate) {
109 case SHOST_CANCEL:
110 break;
111 default:
112 goto illegal;
113 }
114 break;
62 115
63 set_bit(SHOST_CANCEL, &shost->shost_state);
64 shost_for_each_device(sdev, shost) {
65 scsi_device_cancel(sdev, recovery);
66 } 116 }
67 wait_event(shost->host_wait, (!test_bit(SHOST_RECOVERY, 117 shost->shost_state = state;
68 &shost->shost_state))); 118 return 0;
119
120 illegal:
121 SCSI_LOG_ERROR_RECOVERY(1,
122 dev_printk(KERN_ERR, &shost->shost_gendev,
123 "Illegal host state transition"
124 "%s->%s\n",
125 scsi_host_state_name(oldstate),
126 scsi_host_state_name(state)));
127 return -EINVAL;
69} 128}
129EXPORT_SYMBOL(scsi_host_set_state);
70 130
71/** 131/**
72 * scsi_remove_host - remove a scsi host 132 * scsi_remove_host - remove a scsi host
@@ -74,11 +134,13 @@ static void scsi_host_cancel(struct Scsi_Host *shost, int recovery)
74 **/ 134 **/
75void scsi_remove_host(struct Scsi_Host *shost) 135void scsi_remove_host(struct Scsi_Host *shost)
76{ 136{
137 down(&shost->scan_mutex);
138 scsi_host_set_state(shost, SHOST_CANCEL);
139 up(&shost->scan_mutex);
77 scsi_forget_host(shost); 140 scsi_forget_host(shost);
78 scsi_host_cancel(shost, 0);
79 scsi_proc_host_rm(shost); 141 scsi_proc_host_rm(shost);
80 142
81 set_bit(SHOST_DEL, &shost->shost_state); 143 scsi_host_set_state(shost, SHOST_DEL);
82 144
83 transport_unregister_device(&shost->shost_gendev); 145 transport_unregister_device(&shost->shost_gendev);
84 class_device_unregister(&shost->shost_classdev); 146 class_device_unregister(&shost->shost_classdev);
@@ -115,7 +177,7 @@ int scsi_add_host(struct Scsi_Host *shost, struct device *dev)
115 if (error) 177 if (error)
116 goto out; 178 goto out;
117 179
118 set_bit(SHOST_ADD, &shost->shost_state); 180 scsi_host_set_state(shost, SHOST_RUNNING);
119 get_device(shost->shost_gendev.parent); 181 get_device(shost->shost_gendev.parent);
120 182
121 error = class_device_add(&shost->shost_classdev); 183 error = class_device_add(&shost->shost_classdev);
@@ -164,15 +226,8 @@ static void scsi_host_dev_release(struct device *dev)
164 struct Scsi_Host *shost = dev_to_shost(dev); 226 struct Scsi_Host *shost = dev_to_shost(dev);
165 struct device *parent = dev->parent; 227 struct device *parent = dev->parent;
166 228
167 if (shost->ehandler) { 229 if (shost->ehandler)
168 DECLARE_COMPLETION(sem); 230 kthread_stop(shost->ehandler);
169 shost->eh_notify = &sem;
170 shost->eh_kill = 1;
171 up(shost->eh_wait);
172 wait_for_completion(&sem);
173 shost->eh_notify = NULL;
174 }
175
176 if (shost->work_q) 231 if (shost->work_q)
177 destroy_workqueue(shost->work_q); 232 destroy_workqueue(shost->work_q);
178 233
@@ -202,7 +257,6 @@ struct Scsi_Host *scsi_host_alloc(struct scsi_host_template *sht, int privsize)
202{ 257{
203 struct Scsi_Host *shost; 258 struct Scsi_Host *shost;
204 int gfp_mask = GFP_KERNEL, rval; 259 int gfp_mask = GFP_KERNEL, rval;
205 DECLARE_COMPLETION(complete);
206 260
207 if (sht->unchecked_isa_dma && privsize) 261 if (sht->unchecked_isa_dma && privsize)
208 gfp_mask |= __GFP_DMA; 262 gfp_mask |= __GFP_DMA;
@@ -226,6 +280,7 @@ struct Scsi_Host *scsi_host_alloc(struct scsi_host_template *sht, int privsize)
226 280
227 spin_lock_init(&shost->default_lock); 281 spin_lock_init(&shost->default_lock);
228 scsi_assign_lock(shost, &shost->default_lock); 282 scsi_assign_lock(shost, &shost->default_lock);
283 shost->shost_state = SHOST_CREATED;
229 INIT_LIST_HEAD(&shost->__devices); 284 INIT_LIST_HEAD(&shost->__devices);
230 INIT_LIST_HEAD(&shost->__targets); 285 INIT_LIST_HEAD(&shost->__targets);
231 INIT_LIST_HEAD(&shost->eh_cmd_q); 286 INIT_LIST_HEAD(&shost->eh_cmd_q);
@@ -307,12 +362,12 @@ struct Scsi_Host *scsi_host_alloc(struct scsi_host_template *sht, int privsize)
307 snprintf(shost->shost_classdev.class_id, BUS_ID_SIZE, "host%d", 362 snprintf(shost->shost_classdev.class_id, BUS_ID_SIZE, "host%d",
308 shost->host_no); 363 shost->host_no);
309 364
310 shost->eh_notify = &complete; 365 shost->ehandler = kthread_run(scsi_error_handler, shost,
311 rval = kernel_thread(scsi_error_handler, shost, 0); 366 "scsi_eh_%d", shost->host_no);
312 if (rval < 0) 367 if (IS_ERR(shost->ehandler)) {
368 rval = PTR_ERR(shost->ehandler);
313 goto fail_destroy_freelist; 369 goto fail_destroy_freelist;
314 wait_for_completion(&complete); 370 }
315 shost->eh_notify = NULL;
316 371
317 scsi_proc_hostdir_add(shost->hostt); 372 scsi_proc_hostdir_add(shost->hostt);
318 return shost; 373 return shost;
@@ -382,7 +437,7 @@ EXPORT_SYMBOL(scsi_host_lookup);
382 **/ 437 **/
383struct Scsi_Host *scsi_host_get(struct Scsi_Host *shost) 438struct Scsi_Host *scsi_host_get(struct Scsi_Host *shost)
384{ 439{
385 if (test_bit(SHOST_DEL, &shost->shost_state) || 440 if ((shost->shost_state == SHOST_DEL) ||
386 !get_device(&shost->shost_gendev)) 441 !get_device(&shost->shost_gendev))
387 return NULL; 442 return NULL;
388 return shost; 443 return shost;
diff --git a/drivers/scsi/ibmvscsi/ibmvscsi.c b/drivers/scsi/ibmvscsi/ibmvscsi.c
index 2cb3c8340ca..5b14934ba86 100644
--- a/drivers/scsi/ibmvscsi/ibmvscsi.c
+++ b/drivers/scsi/ibmvscsi/ibmvscsi.c
@@ -87,7 +87,7 @@ static int max_channel = 3;
87static int init_timeout = 5; 87static int init_timeout = 5;
88static int max_requests = 50; 88static int max_requests = 50;
89 89
90#define IBMVSCSI_VERSION "1.5.6" 90#define IBMVSCSI_VERSION "1.5.7"
91 91
92MODULE_DESCRIPTION("IBM Virtual SCSI"); 92MODULE_DESCRIPTION("IBM Virtual SCSI");
93MODULE_AUTHOR("Dave Boutcher"); 93MODULE_AUTHOR("Dave Boutcher");
@@ -145,6 +145,8 @@ static int initialize_event_pool(struct event_pool *pool,
145 sizeof(*evt->xfer_iu) * i; 145 sizeof(*evt->xfer_iu) * i;
146 evt->xfer_iu = pool->iu_storage + i; 146 evt->xfer_iu = pool->iu_storage + i;
147 evt->hostdata = hostdata; 147 evt->hostdata = hostdata;
148 evt->ext_list = NULL;
149 evt->ext_list_token = 0;
148 } 150 }
149 151
150 return 0; 152 return 0;
@@ -161,9 +163,16 @@ static void release_event_pool(struct event_pool *pool,
161 struct ibmvscsi_host_data *hostdata) 163 struct ibmvscsi_host_data *hostdata)
162{ 164{
163 int i, in_use = 0; 165 int i, in_use = 0;
164 for (i = 0; i < pool->size; ++i) 166 for (i = 0; i < pool->size; ++i) {
165 if (atomic_read(&pool->events[i].free) != 1) 167 if (atomic_read(&pool->events[i].free) != 1)
166 ++in_use; 168 ++in_use;
169 if (pool->events[i].ext_list) {
170 dma_free_coherent(hostdata->dev,
171 SG_ALL * sizeof(struct memory_descriptor),
172 pool->events[i].ext_list,
173 pool->events[i].ext_list_token);
174 }
175 }
167 if (in_use) 176 if (in_use)
168 printk(KERN_WARNING 177 printk(KERN_WARNING
169 "ibmvscsi: releasing event pool with %d " 178 "ibmvscsi: releasing event pool with %d "
@@ -286,24 +295,41 @@ static void set_srp_direction(struct scsi_cmnd *cmd,
286 } else { 295 } else {
287 if (cmd->sc_data_direction == DMA_TO_DEVICE) { 296 if (cmd->sc_data_direction == DMA_TO_DEVICE) {
288 srp_cmd->data_out_format = SRP_INDIRECT_BUFFER; 297 srp_cmd->data_out_format = SRP_INDIRECT_BUFFER;
289 srp_cmd->data_out_count = numbuf; 298 srp_cmd->data_out_count =
299 numbuf < MAX_INDIRECT_BUFS ?
300 numbuf: MAX_INDIRECT_BUFS;
290 } else { 301 } else {
291 srp_cmd->data_in_format = SRP_INDIRECT_BUFFER; 302 srp_cmd->data_in_format = SRP_INDIRECT_BUFFER;
292 srp_cmd->data_in_count = numbuf; 303 srp_cmd->data_in_count =
304 numbuf < MAX_INDIRECT_BUFS ?
305 numbuf: MAX_INDIRECT_BUFS;
293 } 306 }
294 } 307 }
295} 308}
296 309
310static void unmap_sg_list(int num_entries,
311 struct device *dev,
312 struct memory_descriptor *md)
313{
314 int i;
315
316 for (i = 0; i < num_entries; ++i) {
317 dma_unmap_single(dev,
318 md[i].virtual_address,
319 md[i].length, DMA_BIDIRECTIONAL);
320 }
321}
322
297/** 323/**
298 * unmap_cmd_data: - Unmap data pointed in srp_cmd based on the format 324 * unmap_cmd_data: - Unmap data pointed in srp_cmd based on the format
299 * @cmd: srp_cmd whose additional_data member will be unmapped 325 * @cmd: srp_cmd whose additional_data member will be unmapped
300 * @dev: device for which the memory is mapped 326 * @dev: device for which the memory is mapped
301 * 327 *
302*/ 328*/
303static void unmap_cmd_data(struct srp_cmd *cmd, struct device *dev) 329static void unmap_cmd_data(struct srp_cmd *cmd,
330 struct srp_event_struct *evt_struct,
331 struct device *dev)
304{ 332{
305 int i;
306
307 if ((cmd->data_out_format == SRP_NO_BUFFER) && 333 if ((cmd->data_out_format == SRP_NO_BUFFER) &&
308 (cmd->data_in_format == SRP_NO_BUFFER)) 334 (cmd->data_in_format == SRP_NO_BUFFER))
309 return; 335 return;
@@ -318,15 +344,34 @@ static void unmap_cmd_data(struct srp_cmd *cmd, struct device *dev)
318 (struct indirect_descriptor *)cmd->additional_data; 344 (struct indirect_descriptor *)cmd->additional_data;
319 int num_mapped = indirect->head.length / 345 int num_mapped = indirect->head.length /
320 sizeof(indirect->list[0]); 346 sizeof(indirect->list[0]);
321 for (i = 0; i < num_mapped; ++i) { 347
322 struct memory_descriptor *data = &indirect->list[i]; 348 if (num_mapped <= MAX_INDIRECT_BUFS) {
323 dma_unmap_single(dev, 349 unmap_sg_list(num_mapped, dev, &indirect->list[0]);
324 data->virtual_address, 350 return;
325 data->length, DMA_BIDIRECTIONAL);
326 } 351 }
352
353 unmap_sg_list(num_mapped, dev, evt_struct->ext_list);
327 } 354 }
328} 355}
329 356
357static int map_sg_list(int num_entries,
358 struct scatterlist *sg,
359 struct memory_descriptor *md)
360{
361 int i;
362 u64 total_length = 0;
363
364 for (i = 0; i < num_entries; ++i) {
365 struct memory_descriptor *descr = md + i;
366 struct scatterlist *sg_entry = &sg[i];
367 descr->virtual_address = sg_dma_address(sg_entry);
368 descr->length = sg_dma_len(sg_entry);
369 descr->memory_handle = 0;
370 total_length += sg_dma_len(sg_entry);
371 }
372 return total_length;
373}
374
330/** 375/**
331 * map_sg_data: - Maps dma for a scatterlist and initializes decriptor fields 376 * map_sg_data: - Maps dma for a scatterlist and initializes decriptor fields
332 * @cmd: Scsi_Cmnd with the scatterlist 377 * @cmd: Scsi_Cmnd with the scatterlist
@@ -337,10 +382,11 @@ static void unmap_cmd_data(struct srp_cmd *cmd, struct device *dev)
337 * Returns 1 on success. 382 * Returns 1 on success.
338*/ 383*/
339static int map_sg_data(struct scsi_cmnd *cmd, 384static int map_sg_data(struct scsi_cmnd *cmd,
385 struct srp_event_struct *evt_struct,
340 struct srp_cmd *srp_cmd, struct device *dev) 386 struct srp_cmd *srp_cmd, struct device *dev)
341{ 387{
342 388
343 int i, sg_mapped; 389 int sg_mapped;
344 u64 total_length = 0; 390 u64 total_length = 0;
345 struct scatterlist *sg = cmd->request_buffer; 391 struct scatterlist *sg = cmd->request_buffer;
346 struct memory_descriptor *data = 392 struct memory_descriptor *data =
@@ -363,27 +409,46 @@ static int map_sg_data(struct scsi_cmnd *cmd,
363 return 1; 409 return 1;
364 } 410 }
365 411
366 if (sg_mapped > MAX_INDIRECT_BUFS) { 412 if (sg_mapped > SG_ALL) {
367 printk(KERN_ERR 413 printk(KERN_ERR
368 "ibmvscsi: More than %d mapped sg entries, got %d\n", 414 "ibmvscsi: More than %d mapped sg entries, got %d\n",
369 MAX_INDIRECT_BUFS, sg_mapped); 415 SG_ALL, sg_mapped);
370 return 0; 416 return 0;
371 } 417 }
372 418
373 indirect->head.virtual_address = 0; 419 indirect->head.virtual_address = 0;
374 indirect->head.length = sg_mapped * sizeof(indirect->list[0]); 420 indirect->head.length = sg_mapped * sizeof(indirect->list[0]);
375 indirect->head.memory_handle = 0; 421 indirect->head.memory_handle = 0;
376 for (i = 0; i < sg_mapped; ++i) { 422
377 struct memory_descriptor *descr = &indirect->list[i]; 423 if (sg_mapped <= MAX_INDIRECT_BUFS) {
378 struct scatterlist *sg_entry = &sg[i]; 424 total_length = map_sg_list(sg_mapped, sg, &indirect->list[0]);
379 descr->virtual_address = sg_dma_address(sg_entry); 425 indirect->total_length = total_length;
380 descr->length = sg_dma_len(sg_entry); 426 return 1;
381 descr->memory_handle = 0;
382 total_length += sg_dma_len(sg_entry);
383 } 427 }
384 indirect->total_length = total_length;
385 428
386 return 1; 429 /* get indirect table */
430 if (!evt_struct->ext_list) {
431 evt_struct->ext_list =(struct memory_descriptor*)
432 dma_alloc_coherent(dev,
433 SG_ALL * sizeof(struct memory_descriptor),
434 &evt_struct->ext_list_token, 0);
435 if (!evt_struct->ext_list) {
436 printk(KERN_ERR
437 "ibmvscsi: Can't allocate memory for indirect table\n");
438 return 0;
439
440 }
441 }
442
443 total_length = map_sg_list(sg_mapped, sg, evt_struct->ext_list);
444
445 indirect->total_length = total_length;
446 indirect->head.virtual_address = evt_struct->ext_list_token;
447 indirect->head.length = sg_mapped * sizeof(indirect->list[0]);
448 memcpy(indirect->list, evt_struct->ext_list,
449 MAX_INDIRECT_BUFS * sizeof(struct memory_descriptor));
450
451 return 1;
387} 452}
388 453
389/** 454/**
@@ -428,6 +493,7 @@ static int map_single_data(struct scsi_cmnd *cmd,
428 * Returns 1 on success. 493 * Returns 1 on success.
429*/ 494*/
430static int map_data_for_srp_cmd(struct scsi_cmnd *cmd, 495static int map_data_for_srp_cmd(struct scsi_cmnd *cmd,
496 struct srp_event_struct *evt_struct,
431 struct srp_cmd *srp_cmd, struct device *dev) 497 struct srp_cmd *srp_cmd, struct device *dev)
432{ 498{
433 switch (cmd->sc_data_direction) { 499 switch (cmd->sc_data_direction) {
@@ -450,7 +516,7 @@ static int map_data_for_srp_cmd(struct scsi_cmnd *cmd,
450 if (!cmd->request_buffer) 516 if (!cmd->request_buffer)
451 return 1; 517 return 1;
452 if (cmd->use_sg) 518 if (cmd->use_sg)
453 return map_sg_data(cmd, srp_cmd, dev); 519 return map_sg_data(cmd, evt_struct, srp_cmd, dev);
454 return map_single_data(cmd, srp_cmd, dev); 520 return map_single_data(cmd, srp_cmd, dev);
455} 521}
456 522
@@ -486,6 +552,7 @@ static int ibmvscsi_send_srp_event(struct srp_event_struct *evt_struct,
486 printk(KERN_WARNING 552 printk(KERN_WARNING
487 "ibmvscsi: Warning, request_limit exceeded\n"); 553 "ibmvscsi: Warning, request_limit exceeded\n");
488 unmap_cmd_data(&evt_struct->iu.srp.cmd, 554 unmap_cmd_data(&evt_struct->iu.srp.cmd,
555 evt_struct,
489 hostdata->dev); 556 hostdata->dev);
490 free_event_struct(&hostdata->pool, evt_struct); 557 free_event_struct(&hostdata->pool, evt_struct);
491 return SCSI_MLQUEUE_HOST_BUSY; 558 return SCSI_MLQUEUE_HOST_BUSY;
@@ -513,7 +580,7 @@ static int ibmvscsi_send_srp_event(struct srp_event_struct *evt_struct,
513 return 0; 580 return 0;
514 581
515 send_error: 582 send_error:
516 unmap_cmd_data(&evt_struct->iu.srp.cmd, hostdata->dev); 583 unmap_cmd_data(&evt_struct->iu.srp.cmd, evt_struct, hostdata->dev);
517 584
518 if ((cmnd = evt_struct->cmnd) != NULL) { 585 if ((cmnd = evt_struct->cmnd) != NULL) {
519 cmnd->result = DID_ERROR << 16; 586 cmnd->result = DID_ERROR << 16;
@@ -551,6 +618,7 @@ static void handle_cmd_rsp(struct srp_event_struct *evt_struct)
551 rsp->sense_and_response_data, 618 rsp->sense_and_response_data,
552 rsp->sense_data_list_length); 619 rsp->sense_data_list_length);
553 unmap_cmd_data(&evt_struct->iu.srp.cmd, 620 unmap_cmd_data(&evt_struct->iu.srp.cmd,
621 evt_struct,
554 evt_struct->hostdata->dev); 622 evt_struct->hostdata->dev);
555 623
556 if (rsp->doover) 624 if (rsp->doover)
@@ -583,6 +651,7 @@ static int ibmvscsi_queuecommand(struct scsi_cmnd *cmnd,
583{ 651{
584 struct srp_cmd *srp_cmd; 652 struct srp_cmd *srp_cmd;
585 struct srp_event_struct *evt_struct; 653 struct srp_event_struct *evt_struct;
654 struct indirect_descriptor *indirect;
586 struct ibmvscsi_host_data *hostdata = 655 struct ibmvscsi_host_data *hostdata =
587 (struct ibmvscsi_host_data *)&cmnd->device->host->hostdata; 656 (struct ibmvscsi_host_data *)&cmnd->device->host->hostdata;
588 u16 lun = lun_from_dev(cmnd->device); 657 u16 lun = lun_from_dev(cmnd->device);
@@ -591,14 +660,6 @@ static int ibmvscsi_queuecommand(struct scsi_cmnd *cmnd,
591 if (!evt_struct) 660 if (!evt_struct)
592 return SCSI_MLQUEUE_HOST_BUSY; 661 return SCSI_MLQUEUE_HOST_BUSY;
593 662
594 init_event_struct(evt_struct,
595 handle_cmd_rsp,
596 VIOSRP_SRP_FORMAT,
597 cmnd->timeout);
598
599 evt_struct->cmnd = cmnd;
600 evt_struct->cmnd_done = done;
601
602 /* Set up the actual SRP IU */ 663 /* Set up the actual SRP IU */
603 srp_cmd = &evt_struct->iu.srp.cmd; 664 srp_cmd = &evt_struct->iu.srp.cmd;
604 memset(srp_cmd, 0x00, sizeof(*srp_cmd)); 665 memset(srp_cmd, 0x00, sizeof(*srp_cmd));
@@ -606,17 +667,25 @@ static int ibmvscsi_queuecommand(struct scsi_cmnd *cmnd,
606 memcpy(srp_cmd->cdb, cmnd->cmnd, sizeof(cmnd->cmnd)); 667 memcpy(srp_cmd->cdb, cmnd->cmnd, sizeof(cmnd->cmnd));
607 srp_cmd->lun = ((u64) lun) << 48; 668 srp_cmd->lun = ((u64) lun) << 48;
608 669
609 if (!map_data_for_srp_cmd(cmnd, srp_cmd, hostdata->dev)) { 670 if (!map_data_for_srp_cmd(cmnd, evt_struct, srp_cmd, hostdata->dev)) {
610 printk(KERN_ERR "ibmvscsi: couldn't convert cmd to srp_cmd\n"); 671 printk(KERN_ERR "ibmvscsi: couldn't convert cmd to srp_cmd\n");
611 free_event_struct(&hostdata->pool, evt_struct); 672 free_event_struct(&hostdata->pool, evt_struct);
612 return SCSI_MLQUEUE_HOST_BUSY; 673 return SCSI_MLQUEUE_HOST_BUSY;
613 } 674 }
614 675
676 init_event_struct(evt_struct,
677 handle_cmd_rsp,
678 VIOSRP_SRP_FORMAT,
679 cmnd->timeout_per_command/HZ);
680
681 evt_struct->cmnd = cmnd;
682 evt_struct->cmnd_done = done;
683
615 /* Fix up dma address of the buffer itself */ 684 /* Fix up dma address of the buffer itself */
616 if ((srp_cmd->data_out_format == SRP_INDIRECT_BUFFER) || 685 indirect = (struct indirect_descriptor *)srp_cmd->additional_data;
617 (srp_cmd->data_in_format == SRP_INDIRECT_BUFFER)) { 686 if (((srp_cmd->data_out_format == SRP_INDIRECT_BUFFER) ||
618 struct indirect_descriptor *indirect = 687 (srp_cmd->data_in_format == SRP_INDIRECT_BUFFER)) &&
619 (struct indirect_descriptor *)srp_cmd->additional_data; 688 (indirect->head.virtual_address == 0)) {
620 indirect->head.virtual_address = evt_struct->crq.IU_data_ptr + 689 indirect->head.virtual_address = evt_struct->crq.IU_data_ptr +
621 offsetof(struct srp_cmd, additional_data) + 690 offsetof(struct srp_cmd, additional_data) +
622 offsetof(struct indirect_descriptor, list); 691 offsetof(struct indirect_descriptor, list);
@@ -826,11 +895,13 @@ static int ibmvscsi_eh_abort_handler(struct scsi_cmnd *cmd)
826 struct srp_event_struct *tmp_evt, *found_evt; 895 struct srp_event_struct *tmp_evt, *found_evt;
827 union viosrp_iu srp_rsp; 896 union viosrp_iu srp_rsp;
828 int rsp_rc; 897 int rsp_rc;
898 unsigned long flags;
829 u16 lun = lun_from_dev(cmd->device); 899 u16 lun = lun_from_dev(cmd->device);
830 900
831 /* First, find this command in our sent list so we can figure 901 /* First, find this command in our sent list so we can figure
832 * out the correct tag 902 * out the correct tag
833 */ 903 */
904 spin_lock_irqsave(hostdata->host->host_lock, flags);
834 found_evt = NULL; 905 found_evt = NULL;
835 list_for_each_entry(tmp_evt, &hostdata->sent, list) { 906 list_for_each_entry(tmp_evt, &hostdata->sent, list) {
836 if (tmp_evt->cmnd == cmd) { 907 if (tmp_evt->cmnd == cmd) {
@@ -839,11 +910,14 @@ static int ibmvscsi_eh_abort_handler(struct scsi_cmnd *cmd)
839 } 910 }
840 } 911 }
841 912
842 if (!found_evt) 913 if (!found_evt) {
914 spin_unlock_irqrestore(hostdata->host->host_lock, flags);
843 return FAILED; 915 return FAILED;
916 }
844 917
845 evt = get_event_struct(&hostdata->pool); 918 evt = get_event_struct(&hostdata->pool);
846 if (evt == NULL) { 919 if (evt == NULL) {
920 spin_unlock_irqrestore(hostdata->host->host_lock, flags);
847 printk(KERN_ERR "ibmvscsi: failed to allocate abort event\n"); 921 printk(KERN_ERR "ibmvscsi: failed to allocate abort event\n");
848 return FAILED; 922 return FAILED;
849 } 923 }
@@ -867,7 +941,9 @@ static int ibmvscsi_eh_abort_handler(struct scsi_cmnd *cmd)
867 941
868 evt->sync_srp = &srp_rsp; 942 evt->sync_srp = &srp_rsp;
869 init_completion(&evt->comp); 943 init_completion(&evt->comp);
870 if (ibmvscsi_send_srp_event(evt, hostdata) != 0) { 944 rsp_rc = ibmvscsi_send_srp_event(evt, hostdata);
945 spin_unlock_irqrestore(hostdata->host->host_lock, flags);
946 if (rsp_rc != 0) {
871 printk(KERN_ERR "ibmvscsi: failed to send abort() event\n"); 947 printk(KERN_ERR "ibmvscsi: failed to send abort() event\n");
872 return FAILED; 948 return FAILED;
873 } 949 }
@@ -901,6 +977,7 @@ static int ibmvscsi_eh_abort_handler(struct scsi_cmnd *cmd)
901 * The event is no longer in our list. Make sure it didn't 977 * The event is no longer in our list. Make sure it didn't
902 * complete while we were aborting 978 * complete while we were aborting
903 */ 979 */
980 spin_lock_irqsave(hostdata->host->host_lock, flags);
904 found_evt = NULL; 981 found_evt = NULL;
905 list_for_each_entry(tmp_evt, &hostdata->sent, list) { 982 list_for_each_entry(tmp_evt, &hostdata->sent, list) {
906 if (tmp_evt->cmnd == cmd) { 983 if (tmp_evt->cmnd == cmd) {
@@ -910,6 +987,7 @@ static int ibmvscsi_eh_abort_handler(struct scsi_cmnd *cmd)
910 } 987 }
911 988
912 if (found_evt == NULL) { 989 if (found_evt == NULL) {
990 spin_unlock_irqrestore(hostdata->host->host_lock, flags);
913 printk(KERN_INFO 991 printk(KERN_INFO
914 "ibmvscsi: aborted task tag 0x%lx completed\n", 992 "ibmvscsi: aborted task tag 0x%lx completed\n",
915 tsk_mgmt->managed_task_tag); 993 tsk_mgmt->managed_task_tag);
@@ -922,8 +1000,10 @@ static int ibmvscsi_eh_abort_handler(struct scsi_cmnd *cmd)
922 1000
923 cmd->result = (DID_ABORT << 16); 1001 cmd->result = (DID_ABORT << 16);
924 list_del(&found_evt->list); 1002 list_del(&found_evt->list);
925 unmap_cmd_data(&found_evt->iu.srp.cmd, found_evt->hostdata->dev); 1003 unmap_cmd_data(&found_evt->iu.srp.cmd, found_evt,
1004 found_evt->hostdata->dev);
926 free_event_struct(&found_evt->hostdata->pool, found_evt); 1005 free_event_struct(&found_evt->hostdata->pool, found_evt);
1006 spin_unlock_irqrestore(hostdata->host->host_lock, flags);
927 atomic_inc(&hostdata->request_limit); 1007 atomic_inc(&hostdata->request_limit);
928 return SUCCESS; 1008 return SUCCESS;
929} 1009}
@@ -943,10 +1023,13 @@ static int ibmvscsi_eh_device_reset_handler(struct scsi_cmnd *cmd)
943 struct srp_event_struct *tmp_evt, *pos; 1023 struct srp_event_struct *tmp_evt, *pos;
944 union viosrp_iu srp_rsp; 1024 union viosrp_iu srp_rsp;
945 int rsp_rc; 1025 int rsp_rc;
1026 unsigned long flags;
946 u16 lun = lun_from_dev(cmd->device); 1027 u16 lun = lun_from_dev(cmd->device);
947 1028
1029 spin_lock_irqsave(hostdata->host->host_lock, flags);
948 evt = get_event_struct(&hostdata->pool); 1030 evt = get_event_struct(&hostdata->pool);
949 if (evt == NULL) { 1031 if (evt == NULL) {
1032 spin_unlock_irqrestore(hostdata->host->host_lock, flags);
950 printk(KERN_ERR "ibmvscsi: failed to allocate reset event\n"); 1033 printk(KERN_ERR "ibmvscsi: failed to allocate reset event\n");
951 return FAILED; 1034 return FAILED;
952 } 1035 }
@@ -969,7 +1052,9 @@ static int ibmvscsi_eh_device_reset_handler(struct scsi_cmnd *cmd)
969 1052
970 evt->sync_srp = &srp_rsp; 1053 evt->sync_srp = &srp_rsp;
971 init_completion(&evt->comp); 1054 init_completion(&evt->comp);
972 if (ibmvscsi_send_srp_event(evt, hostdata) != 0) { 1055 rsp_rc = ibmvscsi_send_srp_event(evt, hostdata);
1056 spin_unlock_irqrestore(hostdata->host->host_lock, flags);
1057 if (rsp_rc != 0) {
973 printk(KERN_ERR "ibmvscsi: failed to send reset event\n"); 1058 printk(KERN_ERR "ibmvscsi: failed to send reset event\n");
974 return FAILED; 1059 return FAILED;
975 } 1060 }
@@ -1002,12 +1087,14 @@ static int ibmvscsi_eh_device_reset_handler(struct scsi_cmnd *cmd)
1002 /* We need to find all commands for this LUN that have not yet been 1087 /* We need to find all commands for this LUN that have not yet been
1003 * responded to, and fail them with DID_RESET 1088 * responded to, and fail them with DID_RESET
1004 */ 1089 */
1090 spin_lock_irqsave(hostdata->host->host_lock, flags);
1005 list_for_each_entry_safe(tmp_evt, pos, &hostdata->sent, list) { 1091 list_for_each_entry_safe(tmp_evt, pos, &hostdata->sent, list) {
1006 if ((tmp_evt->cmnd) && (tmp_evt->cmnd->device == cmd->device)) { 1092 if ((tmp_evt->cmnd) && (tmp_evt->cmnd->device == cmd->device)) {
1007 if (tmp_evt->cmnd) 1093 if (tmp_evt->cmnd)
1008 tmp_evt->cmnd->result = (DID_RESET << 16); 1094 tmp_evt->cmnd->result = (DID_RESET << 16);
1009 list_del(&tmp_evt->list); 1095 list_del(&tmp_evt->list);
1010 unmap_cmd_data(&tmp_evt->iu.srp.cmd, tmp_evt->hostdata->dev); 1096 unmap_cmd_data(&tmp_evt->iu.srp.cmd, tmp_evt,
1097 tmp_evt->hostdata->dev);
1011 free_event_struct(&tmp_evt->hostdata->pool, 1098 free_event_struct(&tmp_evt->hostdata->pool,
1012 tmp_evt); 1099 tmp_evt);
1013 atomic_inc(&hostdata->request_limit); 1100 atomic_inc(&hostdata->request_limit);
@@ -1017,6 +1104,7 @@ static int ibmvscsi_eh_device_reset_handler(struct scsi_cmnd *cmd)
1017 tmp_evt->done(tmp_evt); 1104 tmp_evt->done(tmp_evt);
1018 } 1105 }
1019 } 1106 }
1107 spin_unlock_irqrestore(hostdata->host->host_lock, flags);
1020 return SUCCESS; 1108 return SUCCESS;
1021} 1109}
1022 1110
@@ -1035,6 +1123,7 @@ static void purge_requests(struct ibmvscsi_host_data *hostdata)
1035 if (tmp_evt->cmnd) { 1123 if (tmp_evt->cmnd) {
1036 tmp_evt->cmnd->result = (DID_ERROR << 16); 1124 tmp_evt->cmnd->result = (DID_ERROR << 16);
1037 unmap_cmd_data(&tmp_evt->iu.srp.cmd, 1125 unmap_cmd_data(&tmp_evt->iu.srp.cmd,
1126 tmp_evt,
1038 tmp_evt->hostdata->dev); 1127 tmp_evt->hostdata->dev);
1039 if (tmp_evt->cmnd_done) 1128 if (tmp_evt->cmnd_done)
1040 tmp_evt->cmnd_done(tmp_evt->cmnd); 1129 tmp_evt->cmnd_done(tmp_evt->cmnd);
@@ -1339,7 +1428,7 @@ static struct scsi_host_template driver_template = {
1339 .cmd_per_lun = 16, 1428 .cmd_per_lun = 16,
1340 .can_queue = 1, /* Updated after SRP_LOGIN */ 1429 .can_queue = 1, /* Updated after SRP_LOGIN */
1341 .this_id = -1, 1430 .this_id = -1,
1342 .sg_tablesize = MAX_INDIRECT_BUFS, 1431 .sg_tablesize = SG_ALL,
1343 .use_clustering = ENABLE_CLUSTERING, 1432 .use_clustering = ENABLE_CLUSTERING,
1344 .shost_attrs = ibmvscsi_attrs, 1433 .shost_attrs = ibmvscsi_attrs,
1345}; 1434};
diff --git a/drivers/scsi/ibmvscsi/ibmvscsi.h b/drivers/scsi/ibmvscsi/ibmvscsi.h
index 1030b703c30..8bec0438dc8 100644
--- a/drivers/scsi/ibmvscsi/ibmvscsi.h
+++ b/drivers/scsi/ibmvscsi/ibmvscsi.h
@@ -68,6 +68,8 @@ struct srp_event_struct {
68 void (*cmnd_done) (struct scsi_cmnd *); 68 void (*cmnd_done) (struct scsi_cmnd *);
69 struct completion comp; 69 struct completion comp;
70 union viosrp_iu *sync_srp; 70 union viosrp_iu *sync_srp;
71 struct memory_descriptor *ext_list;
72 dma_addr_t ext_list_token;
71}; 73};
72 74
73/* a pool of event structs for use */ 75/* a pool of event structs for use */
diff --git a/drivers/scsi/libata-core.c b/drivers/scsi/libata-core.c
index dee4b12b034..5cc53cd9323 100644
--- a/drivers/scsi/libata-core.c
+++ b/drivers/scsi/libata-core.c
@@ -75,6 +75,10 @@ static void __ata_qc_complete(struct ata_queued_cmd *qc);
75static unsigned int ata_unique_id = 1; 75static unsigned int ata_unique_id = 1;
76static struct workqueue_struct *ata_wq; 76static struct workqueue_struct *ata_wq;
77 77
78int atapi_enabled = 0;
79module_param(atapi_enabled, int, 0444);
80MODULE_PARM_DESC(atapi_enabled, "Enable discovery of ATAPI devices (0=off, 1=on)");
81
78MODULE_AUTHOR("Jeff Garzik"); 82MODULE_AUTHOR("Jeff Garzik");
79MODULE_DESCRIPTION("Library module for ATA devices"); 83MODULE_DESCRIPTION("Library module for ATA devices");
80MODULE_LICENSE("GPL"); 84MODULE_LICENSE("GPL");
@@ -2527,7 +2531,7 @@ void swap_buf_le16(u16 *buf, unsigned int buf_words)
2527 * @ap: port to read/write 2531 * @ap: port to read/write
2528 * @buf: data buffer 2532 * @buf: data buffer
2529 * @buflen: buffer length 2533 * @buflen: buffer length
2530 * @do_write: read/write 2534 * @write_data: read/write
2531 * 2535 *
2532 * Transfer data from/to the device data register by MMIO. 2536 * Transfer data from/to the device data register by MMIO.
2533 * 2537 *
@@ -2573,7 +2577,7 @@ static void ata_mmio_data_xfer(struct ata_port *ap, unsigned char *buf,
2573 * @ap: port to read/write 2577 * @ap: port to read/write
2574 * @buf: data buffer 2578 * @buf: data buffer
2575 * @buflen: buffer length 2579 * @buflen: buffer length
2576 * @do_write: read/write 2580 * @write_data: read/write
2577 * 2581 *
2578 * Transfer data from/to the device data register by PIO. 2582 * Transfer data from/to the device data register by PIO.
2579 * 2583 *
@@ -4200,6 +4204,15 @@ ata_probe_ent_alloc(struct device *dev, struct ata_port_info *port)
4200 4204
4201 4205
4202 4206
4207#ifdef CONFIG_PCI
4208
4209void ata_pci_host_stop (struct ata_host_set *host_set)
4210{
4211 struct pci_dev *pdev = to_pci_dev(host_set->dev);
4212
4213 pci_iounmap(pdev, host_set->mmio_base);
4214}
4215
4203/** 4216/**
4204 * ata_pci_init_native_mode - Initialize native-mode driver 4217 * ata_pci_init_native_mode - Initialize native-mode driver
4205 * @pdev: pci device to be initialized 4218 * @pdev: pci device to be initialized
@@ -4212,7 +4225,6 @@ ata_probe_ent_alloc(struct device *dev, struct ata_port_info *port)
4212 * ata_probe_ent structure should then be freed with kfree(). 4225 * ata_probe_ent structure should then be freed with kfree().
4213 */ 4226 */
4214 4227
4215#ifdef CONFIG_PCI
4216struct ata_probe_ent * 4228struct ata_probe_ent *
4217ata_pci_init_native_mode(struct pci_dev *pdev, struct ata_port_info **port) 4229ata_pci_init_native_mode(struct pci_dev *pdev, struct ata_port_info **port)
4218{ 4230{
@@ -4595,6 +4607,7 @@ EXPORT_SYMBOL_GPL(ata_scsi_simulate);
4595 4607
4596#ifdef CONFIG_PCI 4608#ifdef CONFIG_PCI
4597EXPORT_SYMBOL_GPL(pci_test_config_bits); 4609EXPORT_SYMBOL_GPL(pci_test_config_bits);
4610EXPORT_SYMBOL_GPL(ata_pci_host_stop);
4598EXPORT_SYMBOL_GPL(ata_pci_init_native_mode); 4611EXPORT_SYMBOL_GPL(ata_pci_init_native_mode);
4599EXPORT_SYMBOL_GPL(ata_pci_init_one); 4612EXPORT_SYMBOL_GPL(ata_pci_init_one);
4600EXPORT_SYMBOL_GPL(ata_pci_remove_one); 4613EXPORT_SYMBOL_GPL(ata_pci_remove_one);
diff --git a/drivers/scsi/libata-scsi.c b/drivers/scsi/libata-scsi.c
index 346eb36b1e3..104fd9a63e7 100644
--- a/drivers/scsi/libata-scsi.c
+++ b/drivers/scsi/libata-scsi.c
@@ -1470,10 +1470,10 @@ ata_scsi_find_dev(struct ata_port *ap, struct scsi_device *scsidev)
1470 if (unlikely(!ata_dev_present(dev))) 1470 if (unlikely(!ata_dev_present(dev)))
1471 return NULL; 1471 return NULL;
1472 1472
1473#ifndef ATA_ENABLE_ATAPI 1473 if (!atapi_enabled) {
1474 if (unlikely(dev->class == ATA_DEV_ATAPI)) 1474 if (unlikely(dev->class == ATA_DEV_ATAPI))
1475 return NULL; 1475 return NULL;
1476#endif 1476 }
1477 1477
1478 return dev; 1478 return dev;
1479} 1479}
diff --git a/drivers/scsi/libata.h b/drivers/scsi/libata.h
index 809c634afbc..d608b3a0f6f 100644
--- a/drivers/scsi/libata.h
+++ b/drivers/scsi/libata.h
@@ -38,6 +38,7 @@ struct ata_scsi_args {
38}; 38};
39 39
40/* libata-core.c */ 40/* libata-core.c */
41extern int atapi_enabled;
41extern struct ata_queued_cmd *ata_qc_new_init(struct ata_port *ap, 42extern struct ata_queued_cmd *ata_qc_new_init(struct ata_port *ap,
42 struct ata_device *dev); 43 struct ata_device *dev);
43extern void ata_qc_free(struct ata_queued_cmd *qc); 44extern void ata_qc_free(struct ata_queued_cmd *qc);
diff --git a/drivers/scsi/lpfc/lpfc.h b/drivers/scsi/lpfc/lpfc.h
index 3bb82aae432..adb95674823 100644
--- a/drivers/scsi/lpfc/lpfc.h
+++ b/drivers/scsi/lpfc/lpfc.h
@@ -342,9 +342,6 @@ struct lpfc_hba {
342#define VPD_MASK 0xf /* mask for any vpd data */ 342#define VPD_MASK 0xf /* mask for any vpd data */
343 343
344 struct timer_list els_tmofunc; 344 struct timer_list els_tmofunc;
345
346 void *link_stats;
347
348 /* 345 /*
349 * stat counters 346 * stat counters
350 */ 347 */
@@ -370,6 +367,8 @@ struct lpfc_hba {
370 struct list_head freebufList; 367 struct list_head freebufList;
371 struct list_head ctrspbuflist; 368 struct list_head ctrspbuflist;
372 struct list_head rnidrspbuflist; 369 struct list_head rnidrspbuflist;
370
371 struct fc_host_statistics link_stats;
373}; 372};
374 373
375 374
diff --git a/drivers/scsi/lpfc/lpfc_attr.c b/drivers/scsi/lpfc/lpfc_attr.c
index 3cea9288301..0e089a42c03 100644
--- a/drivers/scsi/lpfc/lpfc_attr.c
+++ b/drivers/scsi/lpfc/lpfc_attr.c
@@ -23,6 +23,7 @@
23#include <linux/pci.h> 23#include <linux/pci.h>
24#include <linux/interrupt.h> 24#include <linux/interrupt.h>
25 25
26#include <scsi/scsi.h>
26#include <scsi/scsi_device.h> 27#include <scsi/scsi_device.h>
27#include <scsi/scsi_host.h> 28#include <scsi/scsi_host.h>
28#include <scsi/scsi_tcq.h> 29#include <scsi/scsi_tcq.h>
@@ -988,8 +989,7 @@ lpfc_get_stats(struct Scsi_Host *shost)
988{ 989{
989 struct lpfc_hba *phba = (struct lpfc_hba *)shost->hostdata[0]; 990 struct lpfc_hba *phba = (struct lpfc_hba *)shost->hostdata[0];
990 struct lpfc_sli *psli = &phba->sli; 991 struct lpfc_sli *psli = &phba->sli;
991 struct fc_host_statistics *hs = 992 struct fc_host_statistics *hs = &phba->link_stats;
992 (struct fc_host_statistics *)phba->link_stats;
993 LPFC_MBOXQ_t *pmboxq; 993 LPFC_MBOXQ_t *pmboxq;
994 MAILBOX_t *pmb; 994 MAILBOX_t *pmb;
995 int rc=0; 995 int rc=0;
@@ -1020,6 +1020,8 @@ lpfc_get_stats(struct Scsi_Host *shost)
1020 return NULL; 1020 return NULL;
1021 } 1021 }
1022 1022
1023 memset(hs, 0, sizeof (struct fc_host_statistics));
1024
1023 hs->tx_frames = pmb->un.varRdStatus.xmitFrameCnt; 1025 hs->tx_frames = pmb->un.varRdStatus.xmitFrameCnt;
1024 hs->tx_words = (pmb->un.varRdStatus.xmitByteCnt * 256); 1026 hs->tx_words = (pmb->un.varRdStatus.xmitByteCnt * 256);
1025 hs->rx_frames = pmb->un.varRdStatus.rcvFrameCnt; 1027 hs->rx_frames = pmb->un.varRdStatus.rcvFrameCnt;
diff --git a/drivers/scsi/lpfc/lpfc_ct.c b/drivers/scsi/lpfc/lpfc_ct.c
index 78adee4699a..1280f0e5463 100644
--- a/drivers/scsi/lpfc/lpfc_ct.c
+++ b/drivers/scsi/lpfc/lpfc_ct.c
@@ -27,8 +27,10 @@
27#include <linux/interrupt.h> 27#include <linux/interrupt.h>
28#include <linux/utsname.h> 28#include <linux/utsname.h>
29 29
30#include <scsi/scsi.h>
30#include <scsi/scsi_device.h> 31#include <scsi/scsi_device.h>
31#include <scsi/scsi_host.h> 32#include <scsi/scsi_host.h>
33#include <scsi/scsi_transport_fc.h>
32 34
33#include "lpfc_hw.h" 35#include "lpfc_hw.h"
34#include "lpfc_sli.h" 36#include "lpfc_sli.h"
diff --git a/drivers/scsi/lpfc/lpfc_els.c b/drivers/scsi/lpfc/lpfc_els.c
index 2b1c9572dae..63caf7fe972 100644
--- a/drivers/scsi/lpfc/lpfc_els.c
+++ b/drivers/scsi/lpfc/lpfc_els.c
@@ -23,6 +23,7 @@
23#include <linux/pci.h> 23#include <linux/pci.h>
24#include <linux/interrupt.h> 24#include <linux/interrupt.h>
25 25
26#include <scsi/scsi.h>
26#include <scsi/scsi_device.h> 27#include <scsi/scsi_device.h>
27#include <scsi/scsi_host.h> 28#include <scsi/scsi_host.h>
28#include <scsi/scsi_transport_fc.h> 29#include <scsi/scsi_transport_fc.h>
diff --git a/drivers/scsi/lpfc/lpfc_hbadisc.c b/drivers/scsi/lpfc/lpfc_hbadisc.c
index 233901e9dfd..0a8269d6b13 100644
--- a/drivers/scsi/lpfc/lpfc_hbadisc.c
+++ b/drivers/scsi/lpfc/lpfc_hbadisc.c
@@ -24,6 +24,7 @@
24#include <linux/kthread.h> 24#include <linux/kthread.h>
25#include <linux/interrupt.h> 25#include <linux/interrupt.h>
26 26
27#include <scsi/scsi.h>
27#include <scsi/scsi_device.h> 28#include <scsi/scsi_device.h>
28#include <scsi/scsi_host.h> 29#include <scsi/scsi_host.h>
29#include <scsi/scsi_transport_fc.h> 30#include <scsi/scsi_transport_fc.h>
@@ -1135,6 +1136,8 @@ lpfc_nlp_list(struct lpfc_hba * phba, struct lpfc_nodelist * nlp, int list)
1135 switch(list) { 1136 switch(list) {
1136 case NLP_NO_LIST: /* No list, just remove it */ 1137 case NLP_NO_LIST: /* No list, just remove it */
1137 lpfc_nlp_remove(phba, nlp); 1138 lpfc_nlp_remove(phba, nlp);
1139 /* as node removed - stop further transport calls */
1140 rport_del = none;
1138 break; 1141 break;
1139 case NLP_UNUSED_LIST: 1142 case NLP_UNUSED_LIST:
1140 spin_lock_irq(phba->host->host_lock); 1143 spin_lock_irq(phba->host->host_lock);
diff --git a/drivers/scsi/lpfc/lpfc_init.c b/drivers/scsi/lpfc/lpfc_init.c
index 34d416d2b00..6f3cb59bf9e 100644
--- a/drivers/scsi/lpfc/lpfc_init.c
+++ b/drivers/scsi/lpfc/lpfc_init.c
@@ -28,6 +28,7 @@
28#include <linux/pci.h> 28#include <linux/pci.h>
29#include <linux/spinlock.h> 29#include <linux/spinlock.h>
30 30
31#include <scsi/scsi.h>
31#include <scsi/scsi_device.h> 32#include <scsi/scsi_device.h>
32#include <scsi/scsi_host.h> 33#include <scsi/scsi_host.h>
33#include <scsi/scsi_transport_fc.h> 34#include <scsi/scsi_transport_fc.h>
@@ -1339,14 +1340,12 @@ lpfc_pci_probe_one(struct pci_dev *pdev, const struct pci_device_id *pid)
1339 if (pci_request_regions(pdev, LPFC_DRIVER_NAME)) 1340 if (pci_request_regions(pdev, LPFC_DRIVER_NAME))
1340 goto out_disable_device; 1341 goto out_disable_device;
1341 1342
1342 host = scsi_host_alloc(&lpfc_template, 1343 host = scsi_host_alloc(&lpfc_template, sizeof (struct lpfc_hba));
1343 sizeof (struct lpfc_hba) + sizeof (unsigned long));
1344 if (!host) 1344 if (!host)
1345 goto out_release_regions; 1345 goto out_release_regions;
1346 1346
1347 phba = (struct lpfc_hba*)host->hostdata; 1347 phba = (struct lpfc_hba*)host->hostdata;
1348 memset(phba, 0, sizeof (struct lpfc_hba)); 1348 memset(phba, 0, sizeof (struct lpfc_hba));
1349 phba->link_stats = (void *)&phba[1];
1350 phba->host = host; 1349 phba->host = host;
1351 1350
1352 phba->fc_flag |= FC_LOADING; 1351 phba->fc_flag |= FC_LOADING;
diff --git a/drivers/scsi/lpfc/lpfc_mbox.c b/drivers/scsi/lpfc/lpfc_mbox.c
index c27cf94795d..73eb89f9159 100644
--- a/drivers/scsi/lpfc/lpfc_mbox.c
+++ b/drivers/scsi/lpfc/lpfc_mbox.c
@@ -23,6 +23,11 @@
23#include <linux/pci.h> 23#include <linux/pci.h>
24#include <linux/interrupt.h> 24#include <linux/interrupt.h>
25 25
26#include <scsi/scsi_device.h>
27#include <scsi/scsi_transport_fc.h>
28
29#include <scsi/scsi.h>
30
26#include "lpfc_hw.h" 31#include "lpfc_hw.h"
27#include "lpfc_sli.h" 32#include "lpfc_sli.h"
28#include "lpfc_disc.h" 33#include "lpfc_disc.h"
diff --git a/drivers/scsi/lpfc/lpfc_mem.c b/drivers/scsi/lpfc/lpfc_mem.c
index a5cfb6421fa..0aba13ceaac 100644
--- a/drivers/scsi/lpfc/lpfc_mem.c
+++ b/drivers/scsi/lpfc/lpfc_mem.c
@@ -23,6 +23,11 @@
23#include <linux/pci.h> 23#include <linux/pci.h>
24#include <linux/interrupt.h> 24#include <linux/interrupt.h>
25 25
26#include <scsi/scsi_device.h>
27#include <scsi/scsi_transport_fc.h>
28
29#include <scsi/scsi.h>
30
26#include "lpfc_hw.h" 31#include "lpfc_hw.h"
27#include "lpfc_sli.h" 32#include "lpfc_sli.h"
28#include "lpfc_disc.h" 33#include "lpfc_disc.h"
diff --git a/drivers/scsi/lpfc/lpfc_nportdisc.c b/drivers/scsi/lpfc/lpfc_nportdisc.c
index 45dc0210fc4..9b35eaac781 100644
--- a/drivers/scsi/lpfc/lpfc_nportdisc.c
+++ b/drivers/scsi/lpfc/lpfc_nportdisc.c
@@ -23,6 +23,7 @@
23#include <linux/pci.h> 23#include <linux/pci.h>
24#include <linux/interrupt.h> 24#include <linux/interrupt.h>
25 25
26#include <scsi/scsi.h>
26#include <scsi/scsi_device.h> 27#include <scsi/scsi_device.h>
27#include <scsi/scsi_host.h> 28#include <scsi/scsi_host.h>
28#include <scsi/scsi_transport_fc.h> 29#include <scsi/scsi_transport_fc.h>
diff --git a/drivers/scsi/lpfc/lpfc_scsi.c b/drivers/scsi/lpfc/lpfc_scsi.c
index 17e4974d444..b5ad1871d34 100644
--- a/drivers/scsi/lpfc/lpfc_scsi.c
+++ b/drivers/scsi/lpfc/lpfc_scsi.c
@@ -40,11 +40,6 @@
40#define LPFC_RESET_WAIT 2 40#define LPFC_RESET_WAIT 2
41#define LPFC_ABORT_WAIT 2 41#define LPFC_ABORT_WAIT 2
42 42
43static inline void lpfc_put_lun(struct fcp_cmnd *fcmd, unsigned int lun)
44{
45 fcmd->fcpLunLsl = 0;
46 fcmd->fcpLunMsl = swab16((uint16_t)lun);
47}
48 43
49/* 44/*
50 * This routine allocates a scsi buffer, which contains all the necessary 45 * This routine allocates a scsi buffer, which contains all the necessary
@@ -238,6 +233,8 @@ lpfc_scsi_prep_dma_buf(struct lpfc_hba * phba, struct lpfc_scsi_buf * lpfc_cmd)
238 bpl->tus.f.bdeSize = scsi_cmnd->request_bufflen; 233 bpl->tus.f.bdeSize = scsi_cmnd->request_bufflen;
239 if (datadir == DMA_TO_DEVICE) 234 if (datadir == DMA_TO_DEVICE)
240 bpl->tus.f.bdeFlags = 0; 235 bpl->tus.f.bdeFlags = 0;
236 else
237 bpl->tus.f.bdeFlags = BUFF_USE_RCV;
241 bpl->tus.w = le32_to_cpu(bpl->tus.w); 238 bpl->tus.w = le32_to_cpu(bpl->tus.w);
242 num_bde = 1; 239 num_bde = 1;
243 bpl++; 240 bpl++;
@@ -245,8 +242,11 @@ lpfc_scsi_prep_dma_buf(struct lpfc_hba * phba, struct lpfc_scsi_buf * lpfc_cmd)
245 242
246 /* 243 /*
247 * Finish initializing those IOCB fields that are dependent on the 244 * Finish initializing those IOCB fields that are dependent on the
248 * scsi_cmnd request_buffer 245 * scsi_cmnd request_buffer. Note that the bdeSize is explicitly
246 * reinitialized since all iocb memory resources are used many times
247 * for transmit, receive, and continuation bpl's.
249 */ 248 */
249 iocb_cmd->un.fcpi64.bdl.bdeSize = (2 * sizeof (struct ulp_bde64));
250 iocb_cmd->un.fcpi64.bdl.bdeSize += 250 iocb_cmd->un.fcpi64.bdl.bdeSize +=
251 (num_bde * sizeof (struct ulp_bde64)); 251 (num_bde * sizeof (struct ulp_bde64));
252 iocb_cmd->ulpBdeCount = 1; 252 iocb_cmd->ulpBdeCount = 1;
@@ -445,8 +445,11 @@ lpfc_scsi_prep_cmnd(struct lpfc_hba * phba, struct lpfc_scsi_buf * lpfc_cmd,
445 int datadir = scsi_cmnd->sc_data_direction; 445 int datadir = scsi_cmnd->sc_data_direction;
446 446
447 lpfc_cmd->fcp_rsp->rspSnsLen = 0; 447 lpfc_cmd->fcp_rsp->rspSnsLen = 0;
448 /* clear task management bits */
449 lpfc_cmd->fcp_cmnd->fcpCntl2 = 0;
448 450
449 lpfc_put_lun(lpfc_cmd->fcp_cmnd, lpfc_cmd->pCmd->device->lun); 451 int_to_scsilun(lpfc_cmd->pCmd->device->lun,
452 &lpfc_cmd->fcp_cmnd->fcp_lun);
450 453
451 memcpy(&fcp_cmnd->fcpCdb[0], scsi_cmnd->cmnd, 16); 454 memcpy(&fcp_cmnd->fcpCdb[0], scsi_cmnd->cmnd, 16);
452 455
@@ -545,7 +548,8 @@ lpfc_scsi_prep_task_mgmt_cmd(struct lpfc_hba *phba,
545 piocb = &piocbq->iocb; 548 piocb = &piocbq->iocb;
546 549
547 fcp_cmnd = lpfc_cmd->fcp_cmnd; 550 fcp_cmnd = lpfc_cmd->fcp_cmnd;
548 lpfc_put_lun(lpfc_cmd->fcp_cmnd, lpfc_cmd->pCmd->device->lun); 551 int_to_scsilun(lpfc_cmd->pCmd->device->lun,
552 &lpfc_cmd->fcp_cmnd->fcp_lun);
549 fcp_cmnd->fcpCntl2 = task_mgmt_cmd; 553 fcp_cmnd->fcpCntl2 = task_mgmt_cmd;
550 554
551 piocb->ulpCommand = CMD_FCP_ICMND64_CR; 555 piocb->ulpCommand = CMD_FCP_ICMND64_CR;
@@ -746,6 +750,10 @@ lpfc_queuecommand(struct scsi_cmnd *cmnd, void (*done) (struct scsi_cmnd *))
746 cmnd->result = ScsiResult(DID_NO_CONNECT, 0); 750 cmnd->result = ScsiResult(DID_NO_CONNECT, 0);
747 goto out_fail_command; 751 goto out_fail_command;
748 } 752 }
753 else if (ndlp->nlp_state == NLP_STE_NPR_NODE) {
754 cmnd->result = ScsiResult(DID_BUS_BUSY, 0);
755 goto out_fail_command;
756 }
749 /* 757 /*
750 * The device is most likely recovered and the driver 758 * The device is most likely recovered and the driver
751 * needs a bit more time to finish. Ask the midlayer 759 * needs a bit more time to finish. Ask the midlayer
diff --git a/drivers/scsi/lpfc/lpfc_scsi.h b/drivers/scsi/lpfc/lpfc_scsi.h
index 0fd9ba14e1b..acd64c49e84 100644
--- a/drivers/scsi/lpfc/lpfc_scsi.h
+++ b/drivers/scsi/lpfc/lpfc_scsi.h
@@ -78,18 +78,7 @@ struct fcp_rsp {
78}; 78};
79 79
80struct fcp_cmnd { 80struct fcp_cmnd {
81 uint32_t fcpLunMsl; /* most significant lun word (32 bits) */ 81 struct scsi_lun fcp_lun;
82 uint32_t fcpLunLsl; /* least significant lun word (32 bits) */
83 /* # of bits to shift lun id to end up in right
84 * payload word, little endian = 8, big = 16.
85 */
86#ifdef __BIG_ENDIAN
87#define FC_LUN_SHIFT 16
88#define FC_ADDR_MODE_SHIFT 24
89#else /* __LITTLE_ENDIAN */
90#define FC_LUN_SHIFT 8
91#define FC_ADDR_MODE_SHIFT 0
92#endif
93 82
94 uint8_t fcpCntl0; /* FCP_CNTL byte 0 (reserved) */ 83 uint8_t fcpCntl0; /* FCP_CNTL byte 0 (reserved) */
95 uint8_t fcpCntl1; /* FCP_CNTL byte 1 task codes */ 84 uint8_t fcpCntl1; /* FCP_CNTL byte 1 task codes */
diff --git a/drivers/scsi/lpfc/lpfc_sli.c b/drivers/scsi/lpfc/lpfc_sli.c
index 1775508ed27..e74e224fd77 100644
--- a/drivers/scsi/lpfc/lpfc_sli.c
+++ b/drivers/scsi/lpfc/lpfc_sli.c
@@ -24,9 +24,11 @@
24#include <linux/interrupt.h> 24#include <linux/interrupt.h>
25#include <linux/delay.h> 25#include <linux/delay.h>
26 26
27#include <scsi/scsi.h>
27#include <scsi/scsi_cmnd.h> 28#include <scsi/scsi_cmnd.h>
28#include <scsi/scsi_device.h> 29#include <scsi/scsi_device.h>
29#include <scsi/scsi_host.h> 30#include <scsi/scsi_host.h>
31#include <scsi/scsi_transport_fc.h>
30 32
31#include "lpfc_hw.h" 33#include "lpfc_hw.h"
32#include "lpfc_sli.h" 34#include "lpfc_sli.h"
diff --git a/drivers/scsi/lpfc/lpfc_version.h b/drivers/scsi/lpfc/lpfc_version.h
index 47dea48ee0e..7e6747b06f9 100644
--- a/drivers/scsi/lpfc/lpfc_version.h
+++ b/drivers/scsi/lpfc/lpfc_version.h
@@ -18,7 +18,7 @@
18 * included with this package. * 18 * included with this package. *
19 *******************************************************************/ 19 *******************************************************************/
20 20
21#define LPFC_DRIVER_VERSION "8.0.29" 21#define LPFC_DRIVER_VERSION "8.0.30"
22 22
23#define LPFC_DRIVER_NAME "lpfc" 23#define LPFC_DRIVER_NAME "lpfc"
24 24
diff --git a/drivers/scsi/mesh.c b/drivers/scsi/mesh.c
index ff1933298da..a4857db4f9b 100644
--- a/drivers/scsi/mesh.c
+++ b/drivers/scsi/mesh.c
@@ -1766,7 +1766,7 @@ static int mesh_suspend(struct macio_dev *mdev, pm_message_t state)
1766 struct mesh_state *ms = (struct mesh_state *)macio_get_drvdata(mdev); 1766 struct mesh_state *ms = (struct mesh_state *)macio_get_drvdata(mdev);
1767 unsigned long flags; 1767 unsigned long flags;
1768 1768
1769 if (state == mdev->ofdev.dev.power.power_state || state < 2) 1769 if (state.event == mdev->ofdev.dev.power.power_state.event || state.event < 2)
1770 return 0; 1770 return 0;
1771 1771
1772 scsi_block_requests(ms->host); 1772 scsi_block_requests(ms->host);
@@ -1791,7 +1791,7 @@ static int mesh_resume(struct macio_dev *mdev)
1791 struct mesh_state *ms = (struct mesh_state *)macio_get_drvdata(mdev); 1791 struct mesh_state *ms = (struct mesh_state *)macio_get_drvdata(mdev);
1792 unsigned long flags; 1792 unsigned long flags;
1793 1793
1794 if (mdev->ofdev.dev.power.power_state == 0) 1794 if (mdev->ofdev.dev.power.power_state.event == PM_EVENT_ON)
1795 return 0; 1795 return 0;
1796 1796
1797 set_mesh_power(ms, 1); 1797 set_mesh_power(ms, 1);
@@ -1802,7 +1802,7 @@ static int mesh_resume(struct macio_dev *mdev)
1802 enable_irq(ms->meshintr); 1802 enable_irq(ms->meshintr);
1803 scsi_unblock_requests(ms->host); 1803 scsi_unblock_requests(ms->host);
1804 1804
1805 mdev->ofdev.dev.power.power_state = 0; 1805 mdev->ofdev.dev.power.power_state.event = PM_EVENT_ON;
1806 1806
1807 return 0; 1807 return 0;
1808} 1808}
diff --git a/drivers/scsi/qla1280.c b/drivers/scsi/qla1280.c
index b993652bfa2..637fb6565d2 100644
--- a/drivers/scsi/qla1280.c
+++ b/drivers/scsi/qla1280.c
@@ -996,7 +996,6 @@ qla1280_error_action(struct scsi_cmnd *cmd, enum action action)
996 break; 996 break;
997 997
998 case ABORT_DEVICE: 998 case ABORT_DEVICE:
999 ha->flags.in_reset = 1;
1000 if (qla1280_verbose) 999 if (qla1280_verbose)
1001 printk(KERN_INFO 1000 printk(KERN_INFO
1002 "scsi(%ld:%d:%d:%d): Queueing abort device " 1001 "scsi(%ld:%d:%d:%d): Queueing abort device "
@@ -1010,7 +1009,6 @@ qla1280_error_action(struct scsi_cmnd *cmd, enum action action)
1010 printk(KERN_INFO 1009 printk(KERN_INFO
1011 "scsi(%ld:%d:%d:%d): Queueing device reset " 1010 "scsi(%ld:%d:%d:%d): Queueing device reset "
1012 "command.\n", ha->host_no, bus, target, lun); 1011 "command.\n", ha->host_no, bus, target, lun);
1013 ha->flags.in_reset = 1;
1014 if (qla1280_device_reset(ha, bus, target) == 0) 1012 if (qla1280_device_reset(ha, bus, target) == 0)
1015 result = SUCCESS; 1013 result = SUCCESS;
1016 break; 1014 break;
@@ -1019,7 +1017,6 @@ qla1280_error_action(struct scsi_cmnd *cmd, enum action action)
1019 if (qla1280_verbose) 1017 if (qla1280_verbose)
1020 printk(KERN_INFO "qla1280(%ld:%d): Issuing BUS " 1018 printk(KERN_INFO "qla1280(%ld:%d): Issuing BUS "
1021 "DEVICE RESET\n", ha->host_no, bus); 1019 "DEVICE RESET\n", ha->host_no, bus);
1022 ha->flags.in_reset = 1;
1023 if (qla1280_bus_reset(ha, bus == 0)) 1020 if (qla1280_bus_reset(ha, bus == 0))
1024 result = SUCCESS; 1021 result = SUCCESS;
1025 1022
@@ -1047,7 +1044,6 @@ qla1280_error_action(struct scsi_cmnd *cmd, enum action action)
1047 1044
1048 if (!list_empty(&ha->done_q)) 1045 if (!list_empty(&ha->done_q))
1049 qla1280_done(ha); 1046 qla1280_done(ha);
1050 ha->flags.in_reset = 0;
1051 1047
1052 /* If we didn't manage to issue the action, or we have no 1048 /* If we didn't manage to issue the action, or we have no
1053 * command to wait for, exit here */ 1049 * command to wait for, exit here */
@@ -1269,6 +1265,22 @@ qla1280_biosparam_old(Disk * disk, kdev_t dev, int geom[])
1269 return qla1280_biosparam(disk->device, NULL, disk->capacity, geom); 1265 return qla1280_biosparam(disk->device, NULL, disk->capacity, geom);
1270} 1266}
1271#endif 1267#endif
1268
1269/* disable risc and host interrupts */
1270static inline void
1271qla1280_disable_intrs(struct scsi_qla_host *ha)
1272{
1273 WRT_REG_WORD(&ha->iobase->ictrl, 0);
1274 RD_REG_WORD(&ha->iobase->ictrl); /* PCI Posted Write flush */
1275}
1276
1277/* enable risc and host interrupts */
1278static inline void
1279qla1280_enable_intrs(struct scsi_qla_host *ha)
1280{
1281 WRT_REG_WORD(&ha->iobase->ictrl, (ISP_EN_INT | ISP_EN_RISC));
1282 RD_REG_WORD(&ha->iobase->ictrl); /* PCI Posted Write flush */
1283}
1272 1284
1273/************************************************************************** 1285/**************************************************************************
1274 * qla1280_intr_handler 1286 * qla1280_intr_handler
@@ -1290,7 +1302,7 @@ qla1280_intr_handler(int irq, void *dev_id, struct pt_regs *regs)
1290 ha->isr_count++; 1302 ha->isr_count++;
1291 reg = ha->iobase; 1303 reg = ha->iobase;
1292 1304
1293 WRT_REG_WORD(&reg->ictrl, 0); /* disable our interrupt. */ 1305 qla1280_disable_intrs(ha);
1294 1306
1295 data = qla1280_debounce_register(&reg->istatus); 1307 data = qla1280_debounce_register(&reg->istatus);
1296 /* Check for pending interrupts. */ 1308 /* Check for pending interrupts. */
@@ -1303,8 +1315,7 @@ qla1280_intr_handler(int irq, void *dev_id, struct pt_regs *regs)
1303 1315
1304 spin_unlock(HOST_LOCK); 1316 spin_unlock(HOST_LOCK);
1305 1317
1306 /* enable our interrupt. */ 1318 qla1280_enable_intrs(ha);
1307 WRT_REG_WORD(&reg->ictrl, (ISP_EN_INT | ISP_EN_RISC));
1308 1319
1309 LEAVE_INTR("qla1280_intr_handler"); 1320 LEAVE_INTR("qla1280_intr_handler");
1310 return IRQ_RETVAL(handled); 1321 return IRQ_RETVAL(handled);
@@ -1317,7 +1328,7 @@ qla1280_set_target_parameters(struct scsi_qla_host *ha, int bus, int target)
1317 uint8_t mr; 1328 uint8_t mr;
1318 uint16_t mb[MAILBOX_REGISTER_COUNT]; 1329 uint16_t mb[MAILBOX_REGISTER_COUNT];
1319 struct nvram *nv; 1330 struct nvram *nv;
1320 int status; 1331 int status, lun;
1321 1332
1322 nv = &ha->nvram; 1333 nv = &ha->nvram;
1323 1334
@@ -1325,24 +1336,38 @@ qla1280_set_target_parameters(struct scsi_qla_host *ha, int bus, int target)
1325 1336
1326 /* Set Target Parameters. */ 1337 /* Set Target Parameters. */
1327 mb[0] = MBC_SET_TARGET_PARAMETERS; 1338 mb[0] = MBC_SET_TARGET_PARAMETERS;
1328 mb[1] = (uint16_t) (bus ? target | BIT_7 : target); 1339 mb[1] = (uint16_t)((bus ? target | BIT_7 : target) << 8);
1329 mb[1] <<= 8; 1340 mb[2] = nv->bus[bus].target[target].parameter.renegotiate_on_error << 8;
1330 1341 mb[2] |= nv->bus[bus].target[target].parameter.stop_queue_on_check << 9;
1331 mb[2] = (nv->bus[bus].target[target].parameter.c << 8); 1342 mb[2] |= nv->bus[bus].target[target].parameter.auto_request_sense << 10;
1343 mb[2] |= nv->bus[bus].target[target].parameter.tag_queuing << 11;
1344 mb[2] |= nv->bus[bus].target[target].parameter.enable_sync << 12;
1345 mb[2] |= nv->bus[bus].target[target].parameter.enable_wide << 13;
1346 mb[2] |= nv->bus[bus].target[target].parameter.parity_checking << 14;
1347 mb[2] |= nv->bus[bus].target[target].parameter.disconnect_allowed << 15;
1332 1348
1333 if (IS_ISP1x160(ha)) { 1349 if (IS_ISP1x160(ha)) {
1334 mb[2] |= nv->bus[bus].target[target].ppr_1x160.flags.enable_ppr << 5; 1350 mb[2] |= nv->bus[bus].target[target].ppr_1x160.flags.enable_ppr << 5;
1335 mb[3] = (nv->bus[bus].target[target].flags.flags1x160.sync_offset << 8) | 1351 mb[3] = (nv->bus[bus].target[target].flags.flags1x160.sync_offset << 8);
1336 nv->bus[bus].target[target].sync_period;
1337 mb[6] = (nv->bus[bus].target[target].ppr_1x160.flags.ppr_options << 8) | 1352 mb[6] = (nv->bus[bus].target[target].ppr_1x160.flags.ppr_options << 8) |
1338 nv->bus[bus].target[target].ppr_1x160.flags.ppr_bus_width; 1353 nv->bus[bus].target[target].ppr_1x160.flags.ppr_bus_width;
1339 mr |= BIT_6; 1354 mr |= BIT_6;
1340 } else { 1355 } else {
1341 mb[3] = (nv->bus[bus].target[target].flags.flags1x80.sync_offset << 8) | 1356 mb[3] = (nv->bus[bus].target[target].flags.flags1x80.sync_offset << 8);
1342 nv->bus[bus].target[target].sync_period;
1343 } 1357 }
1358 mb[3] |= nv->bus[bus].target[target].sync_period;
1344 1359
1345 status = qla1280_mailbox_command(ha, mr, &mb[0]); 1360 status = qla1280_mailbox_command(ha, mr, mb);
1361
1362 /* Set Device Queue Parameters. */
1363 for (lun = 0; lun < MAX_LUNS; lun++) {
1364 mb[0] = MBC_SET_DEVICE_QUEUE;
1365 mb[1] = (uint16_t)((bus ? target | BIT_7 : target) << 8);
1366 mb[1] |= lun;
1367 mb[2] = nv->bus[bus].max_queue_depth;
1368 mb[3] = nv->bus[bus].target[target].execution_throttle;
1369 status |= qla1280_mailbox_command(ha, 0x0f, mb);
1370 }
1346 1371
1347 if (status) 1372 if (status)
1348 printk(KERN_WARNING "scsi(%ld:%i:%i): " 1373 printk(KERN_WARNING "scsi(%ld:%i:%i): "
@@ -1389,19 +1414,19 @@ qla1280_slave_configure(struct scsi_device *device)
1389 } 1414 }
1390 1415
1391#if LINUX_VERSION_CODE > 0x020500 1416#if LINUX_VERSION_CODE > 0x020500
1392 nv->bus[bus].target[target].parameter.f.enable_sync = device->sdtr; 1417 nv->bus[bus].target[target].parameter.enable_sync = device->sdtr;
1393 nv->bus[bus].target[target].parameter.f.enable_wide = device->wdtr; 1418 nv->bus[bus].target[target].parameter.enable_wide = device->wdtr;
1394 nv->bus[bus].target[target].ppr_1x160.flags.enable_ppr = device->ppr; 1419 nv->bus[bus].target[target].ppr_1x160.flags.enable_ppr = device->ppr;
1395#endif 1420#endif
1396 1421
1397 if (driver_setup.no_sync || 1422 if (driver_setup.no_sync ||
1398 (driver_setup.sync_mask && 1423 (driver_setup.sync_mask &&
1399 (~driver_setup.sync_mask & (1 << target)))) 1424 (~driver_setup.sync_mask & (1 << target))))
1400 nv->bus[bus].target[target].parameter.f.enable_sync = 0; 1425 nv->bus[bus].target[target].parameter.enable_sync = 0;
1401 if (driver_setup.no_wide || 1426 if (driver_setup.no_wide ||
1402 (driver_setup.wide_mask && 1427 (driver_setup.wide_mask &&
1403 (~driver_setup.wide_mask & (1 << target)))) 1428 (~driver_setup.wide_mask & (1 << target))))
1404 nv->bus[bus].target[target].parameter.f.enable_wide = 0; 1429 nv->bus[bus].target[target].parameter.enable_wide = 0;
1405 if (IS_ISP1x160(ha)) { 1430 if (IS_ISP1x160(ha)) {
1406 if (driver_setup.no_ppr || 1431 if (driver_setup.no_ppr ||
1407 (driver_setup.ppr_mask && 1432 (driver_setup.ppr_mask &&
@@ -1410,7 +1435,7 @@ qla1280_slave_configure(struct scsi_device *device)
1410 } 1435 }
1411 1436
1412 spin_lock_irqsave(HOST_LOCK, flags); 1437 spin_lock_irqsave(HOST_LOCK, flags);
1413 if (nv->bus[bus].target[target].parameter.f.enable_sync) 1438 if (nv->bus[bus].target[target].parameter.enable_sync)
1414 status = qla1280_set_target_parameters(ha, bus, target); 1439 status = qla1280_set_target_parameters(ha, bus, target);
1415 qla1280_get_target_parameters(ha, device); 1440 qla1280_get_target_parameters(ha, device);
1416 spin_unlock_irqrestore(HOST_LOCK, flags); 1441 spin_unlock_irqrestore(HOST_LOCK, flags);
@@ -1448,7 +1473,6 @@ qla1280_select_queue_depth(struct Scsi_Host *host, struct scsi_device *sdev_q)
1448 * 1473 *
1449 * Input: 1474 * Input:
1450 * ha = adapter block pointer. 1475 * ha = adapter block pointer.
1451 * done_q = done queue.
1452 */ 1476 */
1453static void 1477static void
1454qla1280_done(struct scsi_qla_host *ha) 1478qla1280_done(struct scsi_qla_host *ha)
@@ -1522,7 +1546,7 @@ qla1280_return_status(struct response * sts, struct scsi_cmnd *cp)
1522 int host_status = DID_ERROR; 1546 int host_status = DID_ERROR;
1523 uint16_t comp_status = le16_to_cpu(sts->comp_status); 1547 uint16_t comp_status = le16_to_cpu(sts->comp_status);
1524 uint16_t state_flags = le16_to_cpu(sts->state_flags); 1548 uint16_t state_flags = le16_to_cpu(sts->state_flags);
1525 uint16_t residual_length = le16_to_cpu(sts->residual_length); 1549 uint16_t residual_length = le32_to_cpu(sts->residual_length);
1526 uint16_t scsi_status = le16_to_cpu(sts->scsi_status); 1550 uint16_t scsi_status = le16_to_cpu(sts->scsi_status);
1527#if DEBUG_QLA1280_INTR 1551#if DEBUG_QLA1280_INTR
1528 static char *reason[] = { 1552 static char *reason[] = {
@@ -1582,7 +1606,7 @@ qla1280_return_status(struct response * sts, struct scsi_cmnd *cp)
1582 1606
1583 case CS_DATA_OVERRUN: 1607 case CS_DATA_OVERRUN:
1584 dprintk(2, "Data overrun 0x%x\n", residual_length); 1608 dprintk(2, "Data overrun 0x%x\n", residual_length);
1585 dprintk(2, "qla1280_isr: response packet data\n"); 1609 dprintk(2, "qla1280_return_status: response packet data\n");
1586 qla1280_dump_buffer(2, (char *)sts, RESPONSE_ENTRY_SIZE); 1610 qla1280_dump_buffer(2, (char *)sts, RESPONSE_ENTRY_SIZE);
1587 host_status = DID_ERROR; 1611 host_status = DID_ERROR;
1588 break; 1612 break;
@@ -1617,40 +1641,6 @@ qla1280_return_status(struct response * sts, struct scsi_cmnd *cp)
1617/* QLogic ISP1280 Hardware Support Functions. */ 1641/* QLogic ISP1280 Hardware Support Functions. */
1618/****************************************************************************/ 1642/****************************************************************************/
1619 1643
1620 /*
1621 * qla2100_enable_intrs
1622 * qla2100_disable_intrs
1623 *
1624 * Input:
1625 * ha = adapter block pointer.
1626 *
1627 * Returns:
1628 * None
1629 */
1630static inline void
1631qla1280_enable_intrs(struct scsi_qla_host *ha)
1632{
1633 struct device_reg __iomem *reg;
1634
1635 reg = ha->iobase;
1636 /* enable risc and host interrupts */
1637 WRT_REG_WORD(&reg->ictrl, (ISP_EN_INT | ISP_EN_RISC));
1638 RD_REG_WORD(&reg->ictrl); /* PCI Posted Write flush */
1639 ha->flags.ints_enabled = 1;
1640}
1641
1642static inline void
1643qla1280_disable_intrs(struct scsi_qla_host *ha)
1644{
1645 struct device_reg __iomem *reg;
1646
1647 reg = ha->iobase;
1648 /* disable risc and host interrupts */
1649 WRT_REG_WORD(&reg->ictrl, 0);
1650 RD_REG_WORD(&reg->ictrl); /* PCI Posted Write flush */
1651 ha->flags.ints_enabled = 0;
1652}
1653
1654/* 1644/*
1655 * qla1280_initialize_adapter 1645 * qla1280_initialize_adapter
1656 * Initialize board. 1646 * Initialize board.
@@ -1679,7 +1669,6 @@ qla1280_initialize_adapter(struct scsi_qla_host *ha)
1679 ha->flags.reset_active = 0; 1669 ha->flags.reset_active = 0;
1680 ha->flags.abort_isp_active = 0; 1670 ha->flags.abort_isp_active = 0;
1681 1671
1682 ha->flags.ints_enabled = 0;
1683#if defined(CONFIG_IA64_GENERIC) || defined(CONFIG_IA64_SGI_SN2) 1672#if defined(CONFIG_IA64_GENERIC) || defined(CONFIG_IA64_SGI_SN2)
1684 if (ia64_platform_is("sn2")) { 1673 if (ia64_platform_is("sn2")) {
1685 printk(KERN_INFO "scsi(%li): Enabling SN2 PCI DMA " 1674 printk(KERN_INFO "scsi(%li): Enabling SN2 PCI DMA "
@@ -1758,69 +1747,6 @@ qla1280_initialize_adapter(struct scsi_qla_host *ha)
1758 return status; 1747 return status;
1759} 1748}
1760 1749
1761
1762/*
1763 * ISP Firmware Test
1764 * Checks if present version of RISC firmware is older than
1765 * driver firmware.
1766 *
1767 * Input:
1768 * ha = adapter block pointer.
1769 *
1770 * Returns:
1771 * 0 = firmware does not need to be loaded.
1772 */
1773static int
1774qla1280_isp_firmware(struct scsi_qla_host *ha)
1775{
1776 struct nvram *nv = (struct nvram *) ha->response_ring;
1777 int status = 0; /* dg 2/27 always loads RISC */
1778 uint16_t mb[MAILBOX_REGISTER_COUNT];
1779
1780 ENTER("qla1280_isp_firmware");
1781
1782 dprintk(1, "scsi(%li): Determining if RISC is loaded\n", ha->host_no);
1783
1784 /* Bad NVRAM data, load RISC code. */
1785 if (!ha->nvram_valid) {
1786 ha->flags.disable_risc_code_load = 0;
1787 } else
1788 ha->flags.disable_risc_code_load =
1789 nv->cntr_flags_1.disable_loading_risc_code;
1790
1791 if (ha->flags.disable_risc_code_load) {
1792 dprintk(3, "qla1280_isp_firmware: Telling RISC to verify "
1793 "checksum of loaded BIOS code.\n");
1794
1795 /* Verify checksum of loaded RISC code. */
1796 mb[0] = MBC_VERIFY_CHECKSUM;
1797 /* mb[1] = ql12_risc_code_addr01; */
1798 mb[1] = *ql1280_board_tbl[ha->devnum].fwstart;
1799
1800 if (!(status =
1801 qla1280_mailbox_command(ha, BIT_1 | BIT_0, &mb[0]))) {
1802 /* Start firmware execution. */
1803 dprintk(3, "qla1280_isp_firmware: Startng F/W "
1804 "execution.\n");
1805
1806 mb[0] = MBC_EXECUTE_FIRMWARE;
1807 /* mb[1] = ql12_risc_code_addr01; */
1808 mb[1] = *ql1280_board_tbl[ha->devnum].fwstart;
1809 qla1280_mailbox_command(ha, BIT_1 | BIT_0, &mb[0]);
1810 } else
1811 printk(KERN_INFO "qla1280: RISC checksum failed.\n");
1812 } else {
1813 dprintk(1, "qla1280: NVRAM configured to load RISC load.\n");
1814 status = 1;
1815 }
1816
1817 if (status)
1818 dprintk(2, "qla1280_isp_firmware: **** Load RISC code ****\n");
1819
1820 LEAVE("qla1280_isp_firmware");
1821 return status;
1822}
1823
1824/* 1750/*
1825 * Chip diagnostics 1751 * Chip diagnostics
1826 * Test chip for proper operation. 1752 * Test chip for proper operation.
@@ -2006,7 +1932,7 @@ qla1280_load_firmware_dma(struct scsi_qla_host *ha)
2006 "%d,%d(0x%x)\n", 1932 "%d,%d(0x%x)\n",
2007 risc_code_address, cnt, num, risc_address); 1933 risc_code_address, cnt, num, risc_address);
2008 for(i = 0; i < cnt; i++) 1934 for(i = 0; i < cnt; i++)
2009 ((uint16_t *)ha->request_ring)[i] = 1935 ((__le16 *)ha->request_ring)[i] =
2010 cpu_to_le16(risc_code_address[i]); 1936 cpu_to_le16(risc_code_address[i]);
2011 1937
2012 mb[0] = MBC_LOAD_RAM; 1938 mb[0] = MBC_LOAD_RAM;
@@ -2085,7 +2011,7 @@ qla1280_start_firmware(struct scsi_qla_host *ha)
2085 mb[1] = *ql1280_board_tbl[ha->devnum].fwstart; 2011 mb[1] = *ql1280_board_tbl[ha->devnum].fwstart;
2086 err = qla1280_mailbox_command(ha, BIT_1 | BIT_0, mb); 2012 err = qla1280_mailbox_command(ha, BIT_1 | BIT_0, mb);
2087 if (err) { 2013 if (err) {
2088 printk(KERN_ERR "scsi(%li): Failed checksum\n", ha->host_no); 2014 printk(KERN_ERR "scsi(%li): RISC checksum failed.\n", ha->host_no);
2089 return err; 2015 return err;
2090 } 2016 }
2091 2017
@@ -2105,14 +2031,7 @@ qla1280_start_firmware(struct scsi_qla_host *ha)
2105static int 2031static int
2106qla1280_load_firmware(struct scsi_qla_host *ha) 2032qla1280_load_firmware(struct scsi_qla_host *ha)
2107{ 2033{
2108 int err = -ENODEV; 2034 int err;
2109
2110 /* If firmware needs to be loaded */
2111 if (!qla1280_isp_firmware(ha)) {
2112 printk(KERN_ERR "scsi(%li): isp_firmware() failed!\n",
2113 ha->host_no);
2114 goto out;
2115 }
2116 2035
2117 err = qla1280_chip_diag(ha); 2036 err = qla1280_chip_diag(ha);
2118 if (err) 2037 if (err)
@@ -2246,17 +2165,17 @@ qla1280_set_target_defaults(struct scsi_qla_host *ha, int bus, int target)
2246{ 2165{
2247 struct nvram *nv = &ha->nvram; 2166 struct nvram *nv = &ha->nvram;
2248 2167
2249 nv->bus[bus].target[target].parameter.f.renegotiate_on_error = 1; 2168 nv->bus[bus].target[target].parameter.renegotiate_on_error = 1;
2250 nv->bus[bus].target[target].parameter.f.auto_request_sense = 1; 2169 nv->bus[bus].target[target].parameter.auto_request_sense = 1;
2251 nv->bus[bus].target[target].parameter.f.tag_queuing = 1; 2170 nv->bus[bus].target[target].parameter.tag_queuing = 1;
2252 nv->bus[bus].target[target].parameter.f.enable_sync = 1; 2171 nv->bus[bus].target[target].parameter.enable_sync = 1;
2253#if 1 /* Some SCSI Processors do not seem to like this */ 2172#if 1 /* Some SCSI Processors do not seem to like this */
2254 nv->bus[bus].target[target].parameter.f.enable_wide = 1; 2173 nv->bus[bus].target[target].parameter.enable_wide = 1;
2255#endif 2174#endif
2256 nv->bus[bus].target[target].parameter.f.parity_checking = 1;
2257 nv->bus[bus].target[target].parameter.f.disconnect_allowed = 1;
2258 nv->bus[bus].target[target].execution_throttle = 2175 nv->bus[bus].target[target].execution_throttle =
2259 nv->bus[bus].max_queue_depth - 1; 2176 nv->bus[bus].max_queue_depth - 1;
2177 nv->bus[bus].target[target].parameter.parity_checking = 1;
2178 nv->bus[bus].target[target].parameter.disconnect_allowed = 1;
2260 2179
2261 if (IS_ISP1x160(ha)) { 2180 if (IS_ISP1x160(ha)) {
2262 nv->bus[bus].target[target].flags.flags1x160.device_enable = 1; 2181 nv->bus[bus].target[target].flags.flags1x160.device_enable = 1;
@@ -2284,9 +2203,9 @@ qla1280_set_defaults(struct scsi_qla_host *ha)
2284 /* nv->cntr_flags_1.disable_loading_risc_code = 1; */ 2203 /* nv->cntr_flags_1.disable_loading_risc_code = 1; */
2285 nv->firmware_feature.f.enable_fast_posting = 1; 2204 nv->firmware_feature.f.enable_fast_posting = 1;
2286 nv->firmware_feature.f.disable_synchronous_backoff = 1; 2205 nv->firmware_feature.f.disable_synchronous_backoff = 1;
2287 nv->termination.f.scsi_bus_0_control = 3; 2206 nv->termination.scsi_bus_0_control = 3;
2288 nv->termination.f.scsi_bus_1_control = 3; 2207 nv->termination.scsi_bus_1_control = 3;
2289 nv->termination.f.auto_term_support = 1; 2208 nv->termination.auto_term_support = 1;
2290 2209
2291 /* 2210 /*
2292 * Set default FIFO magic - What appropriate values would be here 2211 * Set default FIFO magic - What appropriate values would be here
@@ -2296,7 +2215,12 @@ qla1280_set_defaults(struct scsi_qla_host *ha)
2296 * header file provided by QLogic seems to be bogus or incomplete 2215 * header file provided by QLogic seems to be bogus or incomplete
2297 * at best. 2216 * at best.
2298 */ 2217 */
2299 nv->isp_config.c = ISP_CFG1_BENAB|ISP_CFG1_F128; 2218 nv->isp_config.burst_enable = 1;
2219 if (IS_ISP1040(ha))
2220 nv->isp_config.fifo_threshold |= 3;
2221 else
2222 nv->isp_config.fifo_threshold |= 4;
2223
2300 if (IS_ISP1x160(ha)) 2224 if (IS_ISP1x160(ha))
2301 nv->isp_parameter = 0x01; /* fast memory enable */ 2225 nv->isp_parameter = 0x01; /* fast memory enable */
2302 2226
@@ -2327,66 +2251,53 @@ qla1280_config_target(struct scsi_qla_host *ha, int bus, int target)
2327 struct nvram *nv = &ha->nvram; 2251 struct nvram *nv = &ha->nvram;
2328 uint16_t mb[MAILBOX_REGISTER_COUNT]; 2252 uint16_t mb[MAILBOX_REGISTER_COUNT];
2329 int status, lun; 2253 int status, lun;
2254 uint16_t flag;
2330 2255
2331 /* Set Target Parameters. */ 2256 /* Set Target Parameters. */
2332 mb[0] = MBC_SET_TARGET_PARAMETERS; 2257 mb[0] = MBC_SET_TARGET_PARAMETERS;
2333 mb[1] = (uint16_t) (bus ? target | BIT_7 : target); 2258 mb[1] = (uint16_t)((bus ? target | BIT_7 : target) << 8);
2334 mb[1] <<= 8;
2335
2336 /*
2337 * Do not enable wide, sync, and ppr for the initial
2338 * INQUIRY run. We enable this later if we determine
2339 * the target actually supports it.
2340 */
2341 nv->bus[bus].target[target].parameter.f.
2342 auto_request_sense = 1;
2343 nv->bus[bus].target[target].parameter.f.
2344 stop_queue_on_check = 0;
2345
2346 if (IS_ISP1x160(ha))
2347 nv->bus[bus].target[target].ppr_1x160.
2348 flags.enable_ppr = 0;
2349 2259
2350 /* 2260 /*
2351 * No sync, wide, etc. while probing 2261 * Do not enable sync and ppr for the initial INQUIRY run. We
2262 * enable this later if we determine the target actually
2263 * supports it.
2352 */ 2264 */
2353 mb[2] = (nv->bus[bus].target[target].parameter.c << 8) & 2265 mb[2] = (TP_RENEGOTIATE | TP_AUTO_REQUEST_SENSE | TP_TAGGED_QUEUE
2354 ~(TP_SYNC /*| TP_WIDE | TP_PPR*/); 2266 | TP_WIDE | TP_PARITY | TP_DISCONNECT);
2355 2267
2356 if (IS_ISP1x160(ha)) 2268 if (IS_ISP1x160(ha))
2357 mb[3] = nv->bus[bus].target[target].flags.flags1x160.sync_offset << 8; 2269 mb[3] = nv->bus[bus].target[target].flags.flags1x160.sync_offset << 8;
2358 else 2270 else
2359 mb[3] = nv->bus[bus].target[target].flags.flags1x80.sync_offset << 8; 2271 mb[3] = nv->bus[bus].target[target].flags.flags1x80.sync_offset << 8;
2360 mb[3] |= nv->bus[bus].target[target].sync_period; 2272 mb[3] |= nv->bus[bus].target[target].sync_period;
2361 2273 status = qla1280_mailbox_command(ha, 0x0f, mb);
2362 status = qla1280_mailbox_command(ha, BIT_3 | BIT_2 | BIT_1 | BIT_0, &mb[0]);
2363 2274
2364 /* Save Tag queuing enable flag. */ 2275 /* Save Tag queuing enable flag. */
2365 mb[0] = BIT_0 << target; 2276 flag = (BIT_0 << target) & mb[0];
2366 if (nv->bus[bus].target[target].parameter.f.tag_queuing) 2277 if (nv->bus[bus].target[target].parameter.tag_queuing)
2367 ha->bus_settings[bus].qtag_enables |= mb[0]; 2278 ha->bus_settings[bus].qtag_enables |= flag;
2368 2279
2369 /* Save Device enable flag. */ 2280 /* Save Device enable flag. */
2370 if (IS_ISP1x160(ha)) { 2281 if (IS_ISP1x160(ha)) {
2371 if (nv->bus[bus].target[target].flags.flags1x160.device_enable) 2282 if (nv->bus[bus].target[target].flags.flags1x160.device_enable)
2372 ha->bus_settings[bus].device_enables |= mb[0]; 2283 ha->bus_settings[bus].device_enables |= flag;
2373 ha->bus_settings[bus].lun_disables |= 0; 2284 ha->bus_settings[bus].lun_disables |= 0;
2374 } else { 2285 } else {
2375 if (nv->bus[bus].target[target].flags.flags1x80.device_enable) 2286 if (nv->bus[bus].target[target].flags.flags1x80.device_enable)
2376 ha->bus_settings[bus].device_enables |= mb[0]; 2287 ha->bus_settings[bus].device_enables |= flag;
2377 /* Save LUN disable flag. */ 2288 /* Save LUN disable flag. */
2378 if (nv->bus[bus].target[target].flags.flags1x80.lun_disable) 2289 if (nv->bus[bus].target[target].flags.flags1x80.lun_disable)
2379 ha->bus_settings[bus].lun_disables |= mb[0]; 2290 ha->bus_settings[bus].lun_disables |= flag;
2380 } 2291 }
2381 2292
2382 /* Set Device Queue Parameters. */ 2293 /* Set Device Queue Parameters. */
2383 for (lun = 0; lun < MAX_LUNS; lun++) { 2294 for (lun = 0; lun < MAX_LUNS; lun++) {
2384 mb[0] = MBC_SET_DEVICE_QUEUE; 2295 mb[0] = MBC_SET_DEVICE_QUEUE;
2385 mb[1] = (uint16_t)(bus ? target | BIT_7 : target); 2296 mb[1] = (uint16_t)((bus ? target | BIT_7 : target) << 8);
2386 mb[1] = mb[1] << 8 | lun; 2297 mb[1] |= lun;
2387 mb[2] = nv->bus[bus].max_queue_depth; 2298 mb[2] = nv->bus[bus].max_queue_depth;
2388 mb[3] = nv->bus[bus].target[target].execution_throttle; 2299 mb[3] = nv->bus[bus].target[target].execution_throttle;
2389 status |= qla1280_mailbox_command(ha, 0x0f, &mb[0]); 2300 status |= qla1280_mailbox_command(ha, 0x0f, mb);
2390 } 2301 }
2391 2302
2392 return status; 2303 return status;
@@ -2431,7 +2342,6 @@ qla1280_nvram_config(struct scsi_qla_host *ha)
2431 struct nvram *nv = &ha->nvram; 2342 struct nvram *nv = &ha->nvram;
2432 int bus, target, status = 0; 2343 int bus, target, status = 0;
2433 uint16_t mb[MAILBOX_REGISTER_COUNT]; 2344 uint16_t mb[MAILBOX_REGISTER_COUNT];
2434 uint16_t mask;
2435 2345
2436 ENTER("qla1280_nvram_config"); 2346 ENTER("qla1280_nvram_config");
2437 2347
@@ -2439,7 +2349,7 @@ qla1280_nvram_config(struct scsi_qla_host *ha)
2439 /* Always force AUTO sense for LINUX SCSI */ 2349 /* Always force AUTO sense for LINUX SCSI */
2440 for (bus = 0; bus < MAX_BUSES; bus++) 2350 for (bus = 0; bus < MAX_BUSES; bus++)
2441 for (target = 0; target < MAX_TARGETS; target++) { 2351 for (target = 0; target < MAX_TARGETS; target++) {
2442 nv->bus[bus].target[target].parameter.f. 2352 nv->bus[bus].target[target].parameter.
2443 auto_request_sense = 1; 2353 auto_request_sense = 1;
2444 } 2354 }
2445 } else { 2355 } else {
@@ -2457,31 +2367,40 @@ qla1280_nvram_config(struct scsi_qla_host *ha)
2457 2367
2458 hwrev = RD_REG_WORD(&reg->cfg_0) & ISP_CFG0_HWMSK; 2368 hwrev = RD_REG_WORD(&reg->cfg_0) & ISP_CFG0_HWMSK;
2459 2369
2460 cfg1 = RD_REG_WORD(&reg->cfg_1); 2370 cfg1 = RD_REG_WORD(&reg->cfg_1) & ~(BIT_4 | BIT_5 | BIT_6);
2461 cdma_conf = RD_REG_WORD(&reg->cdma_cfg); 2371 cdma_conf = RD_REG_WORD(&reg->cdma_cfg);
2462 ddma_conf = RD_REG_WORD(&reg->ddma_cfg); 2372 ddma_conf = RD_REG_WORD(&reg->ddma_cfg);
2463 2373
2464 /* Busted fifo, says mjacob. */ 2374 /* Busted fifo, says mjacob. */
2465 if (hwrev == ISP_CFG0_1040A) 2375 if (hwrev != ISP_CFG0_1040A)
2466 WRT_REG_WORD(&reg->cfg_1, cfg1 | ISP_CFG1_F64); 2376 cfg1 |= nv->isp_config.fifo_threshold << 4;
2467 else 2377
2468 WRT_REG_WORD(&reg->cfg_1, cfg1 | ISP_CFG1_F64 | ISP_CFG1_BENAB); 2378 cfg1 |= nv->isp_config.burst_enable << 2;
2379 WRT_REG_WORD(&reg->cfg_1, cfg1);
2469 2380
2470 WRT_REG_WORD(&reg->cdma_cfg, cdma_conf | CDMA_CONF_BENAB); 2381 WRT_REG_WORD(&reg->cdma_cfg, cdma_conf | CDMA_CONF_BENAB);
2471 WRT_REG_WORD(&reg->ddma_cfg, cdma_conf | DDMA_CONF_BENAB); 2382 WRT_REG_WORD(&reg->ddma_cfg, cdma_conf | DDMA_CONF_BENAB);
2472 } else { 2383 } else {
2384 uint16_t cfg1, term;
2385
2473 /* Set ISP hardware DMA burst */ 2386 /* Set ISP hardware DMA burst */
2474 mb[0] = nv->isp_config.c; 2387 cfg1 = nv->isp_config.fifo_threshold << 4;
2388 cfg1 |= nv->isp_config.burst_enable << 2;
2475 /* Enable DMA arbitration on dual channel controllers */ 2389 /* Enable DMA arbitration on dual channel controllers */
2476 if (ha->ports > 1) 2390 if (ha->ports > 1)
2477 mb[0] |= BIT_13; 2391 cfg1 |= BIT_13;
2478 WRT_REG_WORD(&reg->cfg_1, mb[0]); 2392 WRT_REG_WORD(&reg->cfg_1, cfg1);
2479 2393
2480 /* Set SCSI termination. */ 2394 /* Set SCSI termination. */
2481 WRT_REG_WORD(&reg->gpio_enable, (BIT_3 + BIT_2 + BIT_1 + BIT_0)); 2395 WRT_REG_WORD(&reg->gpio_enable,
2482 mb[0] = nv->termination.c & (BIT_3 + BIT_2 + BIT_1 + BIT_0); 2396 BIT_7 | BIT_3 | BIT_2 | BIT_1 | BIT_0);
2483 WRT_REG_WORD(&reg->gpio_data, mb[0]); 2397 term = nv->termination.scsi_bus_1_control;
2398 term |= nv->termination.scsi_bus_0_control << 2;
2399 term |= nv->termination.auto_term_support << 7;
2400 RD_REG_WORD(&reg->id_l); /* Flush PCI write */
2401 WRT_REG_WORD(&reg->gpio_data, term);
2484 } 2402 }
2403 RD_REG_WORD(&reg->id_l); /* Flush PCI write */
2485 2404
2486 /* ISP parameter word. */ 2405 /* ISP parameter word. */
2487 mb[0] = MBC_SET_SYSTEM_PARAMETER; 2406 mb[0] = MBC_SET_SYSTEM_PARAMETER;
@@ -2497,16 +2416,17 @@ qla1280_nvram_config(struct scsi_qla_host *ha)
2497 2416
2498 /* Firmware feature word. */ 2417 /* Firmware feature word. */
2499 mb[0] = MBC_SET_FIRMWARE_FEATURES; 2418 mb[0] = MBC_SET_FIRMWARE_FEATURES;
2500 mask = BIT_5 | BIT_1 | BIT_0; 2419 mb[1] = nv->firmware_feature.f.enable_fast_posting;
2501 mb[1] = le16_to_cpu(nv->firmware_feature.w) & (mask); 2420 mb[1] |= nv->firmware_feature.f.report_lvd_bus_transition << 1;
2421 mb[1] |= nv->firmware_feature.f.disable_synchronous_backoff << 5;
2502#if defined(CONFIG_IA64_GENERIC) || defined (CONFIG_IA64_SGI_SN2) 2422#if defined(CONFIG_IA64_GENERIC) || defined (CONFIG_IA64_SGI_SN2)
2503 if (ia64_platform_is("sn2")) { 2423 if (ia64_platform_is("sn2")) {
2504 printk(KERN_INFO "scsi(%li): Enabling SN2 PCI DMA " 2424 printk(KERN_INFO "scsi(%li): Enabling SN2 PCI DMA "
2505 "workaround\n", ha->host_no); 2425 "workaround\n", ha->host_no);
2506 mb[1] |= BIT_9; 2426 mb[1] |= nv->firmware_feature.f.unused_9 << 9; /* XXX */
2507 } 2427 }
2508#endif 2428#endif
2509 status |= qla1280_mailbox_command(ha, mask, &mb[0]); 2429 status |= qla1280_mailbox_command(ha, BIT_1 | BIT_0, mb);
2510 2430
2511 /* Retry count and delay. */ 2431 /* Retry count and delay. */
2512 mb[0] = MBC_SET_RETRY_COUNT; 2432 mb[0] = MBC_SET_RETRY_COUNT;
@@ -2535,27 +2455,27 @@ qla1280_nvram_config(struct scsi_qla_host *ha)
2535 mb[2] |= BIT_5; 2455 mb[2] |= BIT_5;
2536 if (nv->bus[1].config_2.data_line_active_negation) 2456 if (nv->bus[1].config_2.data_line_active_negation)
2537 mb[2] |= BIT_4; 2457 mb[2] |= BIT_4;
2538 status |= qla1280_mailbox_command(ha, BIT_2 | BIT_1 | BIT_0, &mb[0]); 2458 status |= qla1280_mailbox_command(ha, BIT_2 | BIT_1 | BIT_0, mb);
2539 2459
2540 mb[0] = MBC_SET_DATA_OVERRUN_RECOVERY; 2460 mb[0] = MBC_SET_DATA_OVERRUN_RECOVERY;
2541 mb[1] = 2; /* Reset SCSI bus and return all outstanding IO */ 2461 mb[1] = 2; /* Reset SCSI bus and return all outstanding IO */
2542 status |= qla1280_mailbox_command(ha, BIT_1 | BIT_0, &mb[0]); 2462 status |= qla1280_mailbox_command(ha, BIT_1 | BIT_0, mb);
2543 2463
2544 /* thingy */ 2464 /* thingy */
2545 mb[0] = MBC_SET_PCI_CONTROL; 2465 mb[0] = MBC_SET_PCI_CONTROL;
2546 mb[1] = 2; /* Data DMA Channel Burst Enable */ 2466 mb[1] = BIT_1; /* Data DMA Channel Burst Enable */
2547 mb[2] = 2; /* Command DMA Channel Burst Enable */ 2467 mb[2] = BIT_1; /* Command DMA Channel Burst Enable */
2548 status |= qla1280_mailbox_command(ha, BIT_2 | BIT_1 | BIT_0, &mb[0]); 2468 status |= qla1280_mailbox_command(ha, BIT_2 | BIT_1 | BIT_0, mb);
2549 2469
2550 mb[0] = MBC_SET_TAG_AGE_LIMIT; 2470 mb[0] = MBC_SET_TAG_AGE_LIMIT;
2551 mb[1] = 8; 2471 mb[1] = 8;
2552 status |= qla1280_mailbox_command(ha, BIT_1 | BIT_0, &mb[0]); 2472 status |= qla1280_mailbox_command(ha, BIT_1 | BIT_0, mb);
2553 2473
2554 /* Selection timeout. */ 2474 /* Selection timeout. */
2555 mb[0] = MBC_SET_SELECTION_TIMEOUT; 2475 mb[0] = MBC_SET_SELECTION_TIMEOUT;
2556 mb[1] = nv->bus[0].selection_timeout; 2476 mb[1] = nv->bus[0].selection_timeout;
2557 mb[2] = nv->bus[1].selection_timeout; 2477 mb[2] = nv->bus[1].selection_timeout;
2558 status |= qla1280_mailbox_command(ha, BIT_2 | BIT_1 | BIT_0, &mb[0]); 2478 status |= qla1280_mailbox_command(ha, BIT_2 | BIT_1 | BIT_0, mb);
2559 2479
2560 for (bus = 0; bus < ha->ports; bus++) 2480 for (bus = 0; bus < ha->ports; bus++)
2561 status |= qla1280_config_bus(ha, bus); 2481 status |= qla1280_config_bus(ha, bus);
@@ -3066,7 +2986,7 @@ qla1280_64bit_start_scsi(struct scsi_qla_host *ha, struct srb * sp)
3066 struct scsi_cmnd *cmd = sp->cmd; 2986 struct scsi_cmnd *cmd = sp->cmd;
3067 cmd_a64_entry_t *pkt; 2987 cmd_a64_entry_t *pkt;
3068 struct scatterlist *sg = NULL; 2988 struct scatterlist *sg = NULL;
3069 u32 *dword_ptr; 2989 __le32 *dword_ptr;
3070 dma_addr_t dma_handle; 2990 dma_addr_t dma_handle;
3071 int status = 0; 2991 int status = 0;
3072 int cnt; 2992 int cnt;
@@ -3104,10 +3024,13 @@ qla1280_64bit_start_scsi(struct scsi_qla_host *ha, struct srb * sp)
3104 REQUEST_ENTRY_CNT - (ha->req_ring_index - cnt); 3024 REQUEST_ENTRY_CNT - (ha->req_ring_index - cnt);
3105 } 3025 }
3106 3026
3027 dprintk(3, "Number of free entries=(%d) seg_cnt=0x%x\n",
3028 ha->req_q_cnt, seg_cnt);
3029
3107 /* If room for request in request ring. */ 3030 /* If room for request in request ring. */
3108 if ((req_cnt + 2) >= ha->req_q_cnt) { 3031 if ((req_cnt + 2) >= ha->req_q_cnt) {
3109 status = 1; 3032 status = 1;
3110 dprintk(2, "qla1280_64bit_start_scsi: in-ptr=0x%x req_q_cnt=" 3033 dprintk(2, "qla1280_start_scsi: in-ptr=0x%x req_q_cnt="
3111 "0x%xreq_cnt=0x%x", ha->req_ring_index, ha->req_q_cnt, 3034 "0x%xreq_cnt=0x%x", ha->req_ring_index, ha->req_q_cnt,
3112 req_cnt); 3035 req_cnt);
3113 goto out; 3036 goto out;
@@ -3119,7 +3042,7 @@ qla1280_64bit_start_scsi(struct scsi_qla_host *ha, struct srb * sp)
3119 3042
3120 if (cnt >= MAX_OUTSTANDING_COMMANDS) { 3043 if (cnt >= MAX_OUTSTANDING_COMMANDS) {
3121 status = 1; 3044 status = 1;
3122 dprintk(2, "qla1280_64bit_start_scsi: NO ROOM IN " 3045 dprintk(2, "qla1280_start_scsi: NO ROOM IN "
3123 "OUTSTANDING ARRAY, req_q_cnt=0x%x", ha->req_q_cnt); 3046 "OUTSTANDING ARRAY, req_q_cnt=0x%x", ha->req_q_cnt);
3124 goto out; 3047 goto out;
3125 } 3048 }
@@ -3128,7 +3051,7 @@ qla1280_64bit_start_scsi(struct scsi_qla_host *ha, struct srb * sp)
3128 ha->req_q_cnt -= req_cnt; 3051 ha->req_q_cnt -= req_cnt;
3129 CMD_HANDLE(sp->cmd) = (unsigned char *)(unsigned long)(cnt + 1); 3052 CMD_HANDLE(sp->cmd) = (unsigned char *)(unsigned long)(cnt + 1);
3130 3053
3131 dprintk(2, "64bit_start: cmd=%p sp=%p CDB=%xm, handle %lx\n", cmd, sp, 3054 dprintk(2, "start: cmd=%p sp=%p CDB=%xm, handle %lx\n", cmd, sp,
3132 cmd->cmnd[0], (long)CMD_HANDLE(sp->cmd)); 3055 cmd->cmnd[0], (long)CMD_HANDLE(sp->cmd));
3133 dprintk(2, " bus %i, target %i, lun %i\n", 3056 dprintk(2, " bus %i, target %i, lun %i\n",
3134 SCSI_BUS_32(cmd), SCSI_TCN_32(cmd), SCSI_LUN_32(cmd)); 3057 SCSI_BUS_32(cmd), SCSI_TCN_32(cmd), SCSI_LUN_32(cmd));
@@ -3350,7 +3273,7 @@ qla1280_32bit_start_scsi(struct scsi_qla_host *ha, struct srb * sp)
3350 struct scsi_cmnd *cmd = sp->cmd; 3273 struct scsi_cmnd *cmd = sp->cmd;
3351 struct cmd_entry *pkt; 3274 struct cmd_entry *pkt;
3352 struct scatterlist *sg = NULL; 3275 struct scatterlist *sg = NULL;
3353 uint32_t *dword_ptr; 3276 __le32 *dword_ptr;
3354 int status = 0; 3277 int status = 0;
3355 int cnt; 3278 int cnt;
3356 int req_cnt; 3279 int req_cnt;
@@ -3993,21 +3916,21 @@ qla1280_get_target_options(struct scsi_cmnd *cmd, struct scsi_qla_host *ha)
3993 result = cmd->request_buffer; 3916 result = cmd->request_buffer;
3994 n = &ha->nvram; 3917 n = &ha->nvram;
3995 3918
3996 n->bus[bus].target[target].parameter.f.enable_wide = 0; 3919 n->bus[bus].target[target].parameter.enable_wide = 0;
3997 n->bus[bus].target[target].parameter.f.enable_sync = 0; 3920 n->bus[bus].target[target].parameter.enable_sync = 0;
3998 n->bus[bus].target[target].ppr_1x160.flags.enable_ppr = 0; 3921 n->bus[bus].target[target].ppr_1x160.flags.enable_ppr = 0;
3999 3922
4000 if (result[7] & 0x60) 3923 if (result[7] & 0x60)
4001 n->bus[bus].target[target].parameter.f.enable_wide = 1; 3924 n->bus[bus].target[target].parameter.enable_wide = 1;
4002 if (result[7] & 0x10) 3925 if (result[7] & 0x10)
4003 n->bus[bus].target[target].parameter.f.enable_sync = 1; 3926 n->bus[bus].target[target].parameter.enable_sync = 1;
4004 if ((result[2] >= 3) && (result[4] + 5 > 56) && 3927 if ((result[2] >= 3) && (result[4] + 5 > 56) &&
4005 (result[56] & 0x4)) 3928 (result[56] & 0x4))
4006 n->bus[bus].target[target].ppr_1x160.flags.enable_ppr = 1; 3929 n->bus[bus].target[target].ppr_1x160.flags.enable_ppr = 1;
4007 3930
4008 dprintk(2, "get_target_options(): wide %i, sync %i, ppr %i\n", 3931 dprintk(2, "get_target_options(): wide %i, sync %i, ppr %i\n",
4009 n->bus[bus].target[target].parameter.f.enable_wide, 3932 n->bus[bus].target[target].parameter.enable_wide,
4010 n->bus[bus].target[target].parameter.f.enable_sync, 3933 n->bus[bus].target[target].parameter.enable_sync,
4011 n->bus[bus].target[target].ppr_1x160.flags.enable_ppr); 3934 n->bus[bus].target[target].ppr_1x160.flags.enable_ppr);
4012} 3935}
4013#endif 3936#endif
@@ -4071,7 +3994,7 @@ qla1280_status_entry(struct scsi_qla_host *ha, struct response *pkt,
4071 /* Save ISP completion status */ 3994 /* Save ISP completion status */
4072 CMD_RESULT(cmd) = qla1280_return_status(pkt, cmd); 3995 CMD_RESULT(cmd) = qla1280_return_status(pkt, cmd);
4073 3996
4074 if (scsi_status & SS_CHECK_CONDITION) { 3997 if (scsi_status & SAM_STAT_CHECK_CONDITION) {
4075 if (comp_status != CS_ARS_FAILED) { 3998 if (comp_status != CS_ARS_FAILED) {
4076 uint16_t req_sense_length = 3999 uint16_t req_sense_length =
4077 le16_to_cpu(pkt->req_sense_length); 4000 le16_to_cpu(pkt->req_sense_length);
@@ -4650,7 +4573,7 @@ qla1280_probe_one(struct pci_dev *pdev, const struct pci_device_id *id)
4650 if (pci_set_dma_mask(ha->pdev, (dma_addr_t) ~ 0ULL)) { 4573 if (pci_set_dma_mask(ha->pdev, (dma_addr_t) ~ 0ULL)) {
4651 if (pci_set_dma_mask(ha->pdev, 0xffffffff)) { 4574 if (pci_set_dma_mask(ha->pdev, 0xffffffff)) {
4652 printk(KERN_WARNING "scsi(%li): Unable to set a " 4575 printk(KERN_WARNING "scsi(%li): Unable to set a "
4653 " suitable DMA mask - aboring\n", ha->host_no); 4576 "suitable DMA mask - aborting\n", ha->host_no);
4654 error = -ENODEV; 4577 error = -ENODEV;
4655 goto error_free_irq; 4578 goto error_free_irq;
4656 } 4579 }
@@ -4660,14 +4583,14 @@ qla1280_probe_one(struct pci_dev *pdev, const struct pci_device_id *id)
4660#else 4583#else
4661 if (pci_set_dma_mask(ha->pdev, 0xffffffff)) { 4584 if (pci_set_dma_mask(ha->pdev, 0xffffffff)) {
4662 printk(KERN_WARNING "scsi(%li): Unable to set a " 4585 printk(KERN_WARNING "scsi(%li): Unable to set a "
4663 " suitable DMA mask - aboring\n", ha->host_no); 4586 "suitable DMA mask - aborting\n", ha->host_no);
4664 error = -ENODEV; 4587 error = -ENODEV;
4665 goto error_free_irq; 4588 goto error_free_irq;
4666 } 4589 }
4667#endif 4590#endif
4668 4591
4669 ha->request_ring = pci_alloc_consistent(ha->pdev, 4592 ha->request_ring = pci_alloc_consistent(ha->pdev,
4670 ((REQUEST_ENTRY_CNT + 1) * (sizeof(request_t))), 4593 ((REQUEST_ENTRY_CNT + 1) * sizeof(request_t)),
4671 &ha->request_dma); 4594 &ha->request_dma);
4672 if (!ha->request_ring) { 4595 if (!ha->request_ring) {
4673 printk(KERN_INFO "qla1280: Failed to get request memory\n"); 4596 printk(KERN_INFO "qla1280: Failed to get request memory\n");
@@ -4675,7 +4598,7 @@ qla1280_probe_one(struct pci_dev *pdev, const struct pci_device_id *id)
4675 } 4598 }
4676 4599
4677 ha->response_ring = pci_alloc_consistent(ha->pdev, 4600 ha->response_ring = pci_alloc_consistent(ha->pdev,
4678 ((RESPONSE_ENTRY_CNT + 1) * (sizeof(struct response))), 4601 ((RESPONSE_ENTRY_CNT + 1) * sizeof(struct response)),
4679 &ha->response_dma); 4602 &ha->response_dma);
4680 if (!ha->response_ring) { 4603 if (!ha->response_ring) {
4681 printk(KERN_INFO "qla1280: Failed to get response memory\n"); 4604 printk(KERN_INFO "qla1280: Failed to get response memory\n");
@@ -4758,7 +4681,7 @@ qla1280_probe_one(struct pci_dev *pdev, const struct pci_device_id *id)
4758 4681
4759#if LINUX_VERSION_CODE >= 0x020600 4682#if LINUX_VERSION_CODE >= 0x020600
4760 error_disable_adapter: 4683 error_disable_adapter:
4761 WRT_REG_WORD(&ha->iobase->ictrl, 0); 4684 qla1280_disable_intrs(ha);
4762#endif 4685#endif
4763 error_free_irq: 4686 error_free_irq:
4764 free_irq(pdev->irq, ha); 4687 free_irq(pdev->irq, ha);
@@ -4770,11 +4693,11 @@ qla1280_probe_one(struct pci_dev *pdev, const struct pci_device_id *id)
4770#endif 4693#endif
4771 error_free_response_ring: 4694 error_free_response_ring:
4772 pci_free_consistent(ha->pdev, 4695 pci_free_consistent(ha->pdev,
4773 ((RESPONSE_ENTRY_CNT + 1) * (sizeof(struct response))), 4696 ((RESPONSE_ENTRY_CNT + 1) * sizeof(struct response)),
4774 ha->response_ring, ha->response_dma); 4697 ha->response_ring, ha->response_dma);
4775 error_free_request_ring: 4698 error_free_request_ring:
4776 pci_free_consistent(ha->pdev, 4699 pci_free_consistent(ha->pdev,
4777 ((REQUEST_ENTRY_CNT + 1) * (sizeof(request_t))), 4700 ((REQUEST_ENTRY_CNT + 1) * sizeof(request_t)),
4778 ha->request_ring, ha->request_dma); 4701 ha->request_ring, ha->request_dma);
4779 error_put_host: 4702 error_put_host:
4780 scsi_host_put(host); 4703 scsi_host_put(host);
@@ -4795,7 +4718,7 @@ qla1280_remove_one(struct pci_dev *pdev)
4795 scsi_remove_host(host); 4718 scsi_remove_host(host);
4796#endif 4719#endif
4797 4720
4798 WRT_REG_WORD(&ha->iobase->ictrl, 0); 4721 qla1280_disable_intrs(ha);
4799 4722
4800 free_irq(pdev->irq, ha); 4723 free_irq(pdev->irq, ha);
4801 4724
diff --git a/drivers/scsi/qla1280.h b/drivers/scsi/qla1280.h
index d245ae07518..59915fb7030 100644
--- a/drivers/scsi/qla1280.h
+++ b/drivers/scsi/qla1280.h
@@ -94,9 +94,6 @@
94#define REQUEST_ENTRY_CNT 256 /* Number of request entries. */ 94#define REQUEST_ENTRY_CNT 256 /* Number of request entries. */
95#define RESPONSE_ENTRY_CNT 16 /* Number of response entries. */ 95#define RESPONSE_ENTRY_CNT 16 /* Number of response entries. */
96 96
97/* Number of segments 1 - 65535 */
98#define SG_SEGMENTS 32 /* Cmd entry + 6 continuations */
99
100/* 97/*
101 * SCSI Request Block structure (sp) that is placed 98 * SCSI Request Block structure (sp) that is placed
102 * on cmd->SCp location of every I/O 99 * on cmd->SCp location of every I/O
@@ -378,29 +375,23 @@ struct nvram {
378 uint16_t unused_12; /* 12, 13 */ 375 uint16_t unused_12; /* 12, 13 */
379 uint16_t unused_14; /* 14, 15 */ 376 uint16_t unused_14; /* 14, 15 */
380 377
381 union { 378 struct {
382 uint8_t c; 379 uint8_t reserved:2;
383 struct { 380 uint8_t burst_enable:1;
384 uint8_t reserved:2; 381 uint8_t reserved_1:1;
385 uint8_t burst_enable:1; 382 uint8_t fifo_threshold:4;
386 uint8_t reserved_1:1;
387 uint8_t fifo_threshold:4;
388 } f;
389 } isp_config; /* 16 */ 383 } isp_config; /* 16 */
390 384
391 /* Termination 385 /* Termination
392 * 0 = Disable, 1 = high only, 3 = Auto term 386 * 0 = Disable, 1 = high only, 3 = Auto term
393 */ 387 */
394 union { 388 struct {
395 uint8_t c; 389 uint8_t scsi_bus_1_control:2;
396 struct { 390 uint8_t scsi_bus_0_control:2;
397 uint8_t scsi_bus_1_control:2; 391 uint8_t unused_0:1;
398 uint8_t scsi_bus_0_control:2; 392 uint8_t unused_1:1;
399 uint8_t unused_0:1; 393 uint8_t unused_2:1;
400 uint8_t unused_1:1; 394 uint8_t auto_term_support:1;
401 uint8_t unused_2:1;
402 uint8_t auto_term_support:1;
403 } f;
404 } termination; /* 17 */ 395 } termination; /* 17 */
405 396
406 uint16_t isp_parameter; /* 18, 19 */ 397 uint16_t isp_parameter; /* 18, 19 */
@@ -460,18 +451,15 @@ struct nvram {
460 uint16_t unused_38; /* 38, 39 */ 451 uint16_t unused_38; /* 38, 39 */
461 452
462 struct { 453 struct {
463 union { 454 struct {
464 uint8_t c; 455 uint8_t renegotiate_on_error:1;
465 struct { 456 uint8_t stop_queue_on_check:1;
466 uint8_t renegotiate_on_error:1; 457 uint8_t auto_request_sense:1;
467 uint8_t stop_queue_on_check:1; 458 uint8_t tag_queuing:1;
468 uint8_t auto_request_sense:1; 459 uint8_t enable_sync:1;
469 uint8_t tag_queuing:1; 460 uint8_t enable_wide:1;
470 uint8_t enable_sync:1; 461 uint8_t parity_checking:1;
471 uint8_t enable_wide:1; 462 uint8_t disconnect_allowed:1;
472 uint8_t parity_checking:1;
473 uint8_t disconnect_allowed:1;
474 } f;
475 } parameter; /* 40 */ 463 } parameter; /* 40 */
476 464
477 uint8_t execution_throttle; /* 41 */ 465 uint8_t execution_throttle; /* 41 */
@@ -528,23 +516,23 @@ struct cmd_entry {
528 uint8_t entry_count; /* Entry count. */ 516 uint8_t entry_count; /* Entry count. */
529 uint8_t sys_define; /* System defined. */ 517 uint8_t sys_define; /* System defined. */
530 uint8_t entry_status; /* Entry Status. */ 518 uint8_t entry_status; /* Entry Status. */
531 uint32_t handle; /* System handle. */ 519 __le32 handle; /* System handle. */
532 uint8_t lun; /* SCSI LUN */ 520 uint8_t lun; /* SCSI LUN */
533 uint8_t target; /* SCSI ID */ 521 uint8_t target; /* SCSI ID */
534 uint16_t cdb_len; /* SCSI command length. */ 522 __le16 cdb_len; /* SCSI command length. */
535 uint16_t control_flags; /* Control flags. */ 523 __le16 control_flags; /* Control flags. */
536 uint16_t reserved; 524 __le16 reserved;
537 uint16_t timeout; /* Command timeout. */ 525 __le16 timeout; /* Command timeout. */
538 uint16_t dseg_count; /* Data segment count. */ 526 __le16 dseg_count; /* Data segment count. */
539 uint8_t scsi_cdb[MAX_CMDSZ]; /* SCSI command words. */ 527 uint8_t scsi_cdb[MAX_CMDSZ]; /* SCSI command words. */
540 uint32_t dseg_0_address; /* Data segment 0 address. */ 528 __le32 dseg_0_address; /* Data segment 0 address. */
541 uint32_t dseg_0_length; /* Data segment 0 length. */ 529 __le32 dseg_0_length; /* Data segment 0 length. */
542 uint32_t dseg_1_address; /* Data segment 1 address. */ 530 __le32 dseg_1_address; /* Data segment 1 address. */
543 uint32_t dseg_1_length; /* Data segment 1 length. */ 531 __le32 dseg_1_length; /* Data segment 1 length. */
544 uint32_t dseg_2_address; /* Data segment 2 address. */ 532 __le32 dseg_2_address; /* Data segment 2 address. */
545 uint32_t dseg_2_length; /* Data segment 2 length. */ 533 __le32 dseg_2_length; /* Data segment 2 length. */
546 uint32_t dseg_3_address; /* Data segment 3 address. */ 534 __le32 dseg_3_address; /* Data segment 3 address. */
547 uint32_t dseg_3_length; /* Data segment 3 length. */ 535 __le32 dseg_3_length; /* Data segment 3 length. */
548}; 536};
549 537
550/* 538/*
@@ -556,21 +544,21 @@ struct cont_entry {
556 uint8_t entry_count; /* Entry count. */ 544 uint8_t entry_count; /* Entry count. */
557 uint8_t sys_define; /* System defined. */ 545 uint8_t sys_define; /* System defined. */
558 uint8_t entry_status; /* Entry Status. */ 546 uint8_t entry_status; /* Entry Status. */
559 uint32_t reserved; /* Reserved */ 547 __le32 reserved; /* Reserved */
560 uint32_t dseg_0_address; /* Data segment 0 address. */ 548 __le32 dseg_0_address; /* Data segment 0 address. */
561 uint32_t dseg_0_length; /* Data segment 0 length. */ 549 __le32 dseg_0_length; /* Data segment 0 length. */
562 uint32_t dseg_1_address; /* Data segment 1 address. */ 550 __le32 dseg_1_address; /* Data segment 1 address. */
563 uint32_t dseg_1_length; /* Data segment 1 length. */ 551 __le32 dseg_1_length; /* Data segment 1 length. */
564 uint32_t dseg_2_address; /* Data segment 2 address. */ 552 __le32 dseg_2_address; /* Data segment 2 address. */
565 uint32_t dseg_2_length; /* Data segment 2 length. */ 553 __le32 dseg_2_length; /* Data segment 2 length. */
566 uint32_t dseg_3_address; /* Data segment 3 address. */ 554 __le32 dseg_3_address; /* Data segment 3 address. */
567 uint32_t dseg_3_length; /* Data segment 3 length. */ 555 __le32 dseg_3_length; /* Data segment 3 length. */
568 uint32_t dseg_4_address; /* Data segment 4 address. */ 556 __le32 dseg_4_address; /* Data segment 4 address. */
569 uint32_t dseg_4_length; /* Data segment 4 length. */ 557 __le32 dseg_4_length; /* Data segment 4 length. */
570 uint32_t dseg_5_address; /* Data segment 5 address. */ 558 __le32 dseg_5_address; /* Data segment 5 address. */
571 uint32_t dseg_5_length; /* Data segment 5 length. */ 559 __le32 dseg_5_length; /* Data segment 5 length. */
572 uint32_t dseg_6_address; /* Data segment 6 address. */ 560 __le32 dseg_6_address; /* Data segment 6 address. */
573 uint32_t dseg_6_length; /* Data segment 6 length. */ 561 __le32 dseg_6_length; /* Data segment 6 length. */
574}; 562};
575 563
576/* 564/*
@@ -586,22 +574,22 @@ struct response {
586#define RF_FULL BIT_1 /* Full */ 574#define RF_FULL BIT_1 /* Full */
587#define RF_BAD_HEADER BIT_2 /* Bad header. */ 575#define RF_BAD_HEADER BIT_2 /* Bad header. */
588#define RF_BAD_PAYLOAD BIT_3 /* Bad payload. */ 576#define RF_BAD_PAYLOAD BIT_3 /* Bad payload. */
589 uint32_t handle; /* System handle. */ 577 __le32 handle; /* System handle. */
590 uint16_t scsi_status; /* SCSI status. */ 578 __le16 scsi_status; /* SCSI status. */
591 uint16_t comp_status; /* Completion status. */ 579 __le16 comp_status; /* Completion status. */
592 uint16_t state_flags; /* State flags. */ 580 __le16 state_flags; /* State flags. */
593#define SF_TRANSFER_CMPL BIT_14 /* Transfer Complete. */ 581#define SF_TRANSFER_CMPL BIT_14 /* Transfer Complete. */
594#define SF_GOT_SENSE BIT_13 /* Got Sense */ 582#define SF_GOT_SENSE BIT_13 /* Got Sense */
595#define SF_GOT_STATUS BIT_12 /* Got Status */ 583#define SF_GOT_STATUS BIT_12 /* Got Status */
596#define SF_TRANSFERRED_DATA BIT_11 /* Transferred data */ 584#define SF_TRANSFERRED_DATA BIT_11 /* Transferred data */
597#define SF_SENT_CDB BIT_10 /* Send CDB */ 585#define SF_SENT_CDB BIT_10 /* Send CDB */
598#define SF_GOT_TARGET BIT_9 /* */ 586#define SF_GOT_TARGET BIT_9 /* */
599#define SF_GOT_BUS BIT_8 /* */ 587#define SF_GOT_BUS BIT_8 /* */
600 uint16_t status_flags; /* Status flags. */ 588 __le16 status_flags; /* Status flags. */
601 uint16_t time; /* Time. */ 589 __le16 time; /* Time. */
602 uint16_t req_sense_length; /* Request sense data length. */ 590 __le16 req_sense_length;/* Request sense data length. */
603 uint32_t residual_length; /* Residual transfer length. */ 591 __le32 residual_length; /* Residual transfer length. */
604 uint16_t reserved[4]; 592 __le16 reserved[4];
605 uint8_t req_sense_data[32]; /* Request sense data. */ 593 uint8_t req_sense_data[32]; /* Request sense data. */
606}; 594};
607 595
@@ -614,7 +602,7 @@ struct mrk_entry {
614 uint8_t entry_count; /* Entry count. */ 602 uint8_t entry_count; /* Entry count. */
615 uint8_t sys_define; /* System defined. */ 603 uint8_t sys_define; /* System defined. */
616 uint8_t entry_status; /* Entry Status. */ 604 uint8_t entry_status; /* Entry Status. */
617 uint32_t reserved; 605 __le32 reserved;
618 uint8_t lun; /* SCSI LUN */ 606 uint8_t lun; /* SCSI LUN */
619 uint8_t target; /* SCSI ID */ 607 uint8_t target; /* SCSI ID */
620 uint8_t modifier; /* Modifier (7-0). */ 608 uint8_t modifier; /* Modifier (7-0). */
@@ -638,11 +626,11 @@ struct ecmd_entry {
638 uint32_t handle; /* System handle. */ 626 uint32_t handle; /* System handle. */
639 uint8_t lun; /* SCSI LUN */ 627 uint8_t lun; /* SCSI LUN */
640 uint8_t target; /* SCSI ID */ 628 uint8_t target; /* SCSI ID */
641 uint16_t cdb_len; /* SCSI command length. */ 629 __le16 cdb_len; /* SCSI command length. */
642 uint16_t control_flags; /* Control flags. */ 630 __le16 control_flags; /* Control flags. */
643 uint16_t reserved; 631 __le16 reserved;
644 uint16_t timeout; /* Command timeout. */ 632 __le16 timeout; /* Command timeout. */
645 uint16_t dseg_count; /* Data segment count. */ 633 __le16 dseg_count; /* Data segment count. */
646 uint8_t scsi_cdb[88]; /* SCSI command words. */ 634 uint8_t scsi_cdb[88]; /* SCSI command words. */
647}; 635};
648 636
@@ -655,20 +643,20 @@ typedef struct {
655 uint8_t entry_count; /* Entry count. */ 643 uint8_t entry_count; /* Entry count. */
656 uint8_t sys_define; /* System defined. */ 644 uint8_t sys_define; /* System defined. */
657 uint8_t entry_status; /* Entry Status. */ 645 uint8_t entry_status; /* Entry Status. */
658 uint32_t handle; /* System handle. */ 646 __le32 handle; /* System handle. */
659 uint8_t lun; /* SCSI LUN */ 647 uint8_t lun; /* SCSI LUN */
660 uint8_t target; /* SCSI ID */ 648 uint8_t target; /* SCSI ID */
661 uint16_t cdb_len; /* SCSI command length. */ 649 __le16 cdb_len; /* SCSI command length. */
662 uint16_t control_flags; /* Control flags. */ 650 __le16 control_flags; /* Control flags. */
663 uint16_t reserved; 651 __le16 reserved;
664 uint16_t timeout; /* Command timeout. */ 652 __le16 timeout; /* Command timeout. */
665 uint16_t dseg_count; /* Data segment count. */ 653 __le16 dseg_count; /* Data segment count. */
666 uint8_t scsi_cdb[MAX_CMDSZ]; /* SCSI command words. */ 654 uint8_t scsi_cdb[MAX_CMDSZ]; /* SCSI command words. */
667 uint32_t reserved_1[2]; /* unused */ 655 __le32 reserved_1[2]; /* unused */
668 uint32_t dseg_0_address[2]; /* Data segment 0 address. */ 656 __le32 dseg_0_address[2]; /* Data segment 0 address. */
669 uint32_t dseg_0_length; /* Data segment 0 length. */ 657 __le32 dseg_0_length; /* Data segment 0 length. */
670 uint32_t dseg_1_address[2]; /* Data segment 1 address. */ 658 __le32 dseg_1_address[2]; /* Data segment 1 address. */
671 uint32_t dseg_1_length; /* Data segment 1 length. */ 659 __le32 dseg_1_length; /* Data segment 1 length. */
672} cmd_a64_entry_t, request_t; 660} cmd_a64_entry_t, request_t;
673 661
674/* 662/*
@@ -680,16 +668,16 @@ struct cont_a64_entry {
680 uint8_t entry_count; /* Entry count. */ 668 uint8_t entry_count; /* Entry count. */
681 uint8_t sys_define; /* System defined. */ 669 uint8_t sys_define; /* System defined. */
682 uint8_t entry_status; /* Entry Status. */ 670 uint8_t entry_status; /* Entry Status. */
683 uint32_t dseg_0_address[2]; /* Data segment 0 address. */ 671 __le32 dseg_0_address[2]; /* Data segment 0 address. */
684 uint32_t dseg_0_length; /* Data segment 0 length. */ 672 __le32 dseg_0_length; /* Data segment 0 length. */
685 uint32_t dseg_1_address[2]; /* Data segment 1 address. */ 673 __le32 dseg_1_address[2]; /* Data segment 1 address. */
686 uint32_t dseg_1_length; /* Data segment 1 length. */ 674 __le32 dseg_1_length; /* Data segment 1 length. */
687 uint32_t dseg_2_address[2]; /* Data segment 2 address. */ 675 __le32 dseg_2_address[2]; /* Data segment 2 address. */
688 uint32_t dseg_2_length; /* Data segment 2 length. */ 676 __le32 dseg_2_length; /* Data segment 2 length. */
689 uint32_t dseg_3_address[2]; /* Data segment 3 address. */ 677 __le32 dseg_3_address[2]; /* Data segment 3 address. */
690 uint32_t dseg_3_length; /* Data segment 3 length. */ 678 __le32 dseg_3_length; /* Data segment 3 length. */
691 uint32_t dseg_4_address[2]; /* Data segment 4 address. */ 679 __le32 dseg_4_address[2]; /* Data segment 4 address. */
692 uint32_t dseg_4_length; /* Data segment 4 length. */ 680 __le32 dseg_4_length; /* Data segment 4 length. */
693}; 681};
694 682
695/* 683/*
@@ -701,10 +689,10 @@ struct elun_entry {
701 uint8_t entry_count; /* Entry count. */ 689 uint8_t entry_count; /* Entry count. */
702 uint8_t reserved_1; 690 uint8_t reserved_1;
703 uint8_t entry_status; /* Entry Status not used. */ 691 uint8_t entry_status; /* Entry Status not used. */
704 uint32_t reserved_2; 692 __le32 reserved_2;
705 uint16_t lun; /* Bit 15 is bus number. */ 693 __le16 lun; /* Bit 15 is bus number. */
706 uint16_t reserved_4; 694 __le16 reserved_4;
707 uint32_t option_flags; 695 __le32 option_flags;
708 uint8_t status; 696 uint8_t status;
709 uint8_t reserved_5; 697 uint8_t reserved_5;
710 uint8_t command_count; /* Number of ATIOs allocated. */ 698 uint8_t command_count; /* Number of ATIOs allocated. */
@@ -714,8 +702,8 @@ struct elun_entry {
714 /* commands (2-26). */ 702 /* commands (2-26). */
715 uint8_t group_7_length; /* SCSI CDB length for group 7 */ 703 uint8_t group_7_length; /* SCSI CDB length for group 7 */
716 /* commands (2-26). */ 704 /* commands (2-26). */
717 uint16_t timeout; /* 0 = 30 seconds, 0xFFFF = disable */ 705 __le16 timeout; /* 0 = 30 seconds, 0xFFFF = disable */
718 uint16_t reserved_6[20]; 706 __le16 reserved_6[20];
719}; 707};
720 708
721/* 709/*
@@ -729,20 +717,20 @@ struct modify_lun_entry {
729 uint8_t entry_count; /* Entry count. */ 717 uint8_t entry_count; /* Entry count. */
730 uint8_t reserved_1; 718 uint8_t reserved_1;
731 uint8_t entry_status; /* Entry Status. */ 719 uint8_t entry_status; /* Entry Status. */
732 uint32_t reserved_2; 720 __le32 reserved_2;
733 uint8_t lun; /* SCSI LUN */ 721 uint8_t lun; /* SCSI LUN */
734 uint8_t reserved_3; 722 uint8_t reserved_3;
735 uint8_t operators; 723 uint8_t operators;
736 uint8_t reserved_4; 724 uint8_t reserved_4;
737 uint32_t option_flags; 725 __le32 option_flags;
738 uint8_t status; 726 uint8_t status;
739 uint8_t reserved_5; 727 uint8_t reserved_5;
740 uint8_t command_count; /* Number of ATIOs allocated. */ 728 uint8_t command_count; /* Number of ATIOs allocated. */
741 uint8_t immed_notify_count; /* Number of Immediate Notify */ 729 uint8_t immed_notify_count; /* Number of Immediate Notify */
742 /* entries allocated. */ 730 /* entries allocated. */
743 uint16_t reserved_6; 731 __le16 reserved_6;
744 uint16_t timeout; /* 0 = 30 seconds, 0xFFFF = disable */ 732 __le16 timeout; /* 0 = 30 seconds, 0xFFFF = disable */
745 uint16_t reserved_7[20]; 733 __le16 reserved_7[20];
746}; 734};
747 735
748/* 736/*
@@ -754,20 +742,20 @@ struct notify_entry {
754 uint8_t entry_count; /* Entry count. */ 742 uint8_t entry_count; /* Entry count. */
755 uint8_t reserved_1; 743 uint8_t reserved_1;
756 uint8_t entry_status; /* Entry Status. */ 744 uint8_t entry_status; /* Entry Status. */
757 uint32_t reserved_2; 745 __le32 reserved_2;
758 uint8_t lun; 746 uint8_t lun;
759 uint8_t initiator_id; 747 uint8_t initiator_id;
760 uint8_t reserved_3; 748 uint8_t reserved_3;
761 uint8_t target_id; 749 uint8_t target_id;
762 uint32_t option_flags; 750 __le32 option_flags;
763 uint8_t status; 751 uint8_t status;
764 uint8_t reserved_4; 752 uint8_t reserved_4;
765 uint8_t tag_value; /* Received queue tag message value */ 753 uint8_t tag_value; /* Received queue tag message value */
766 uint8_t tag_type; /* Received queue tag message type */ 754 uint8_t tag_type; /* Received queue tag message type */
767 /* entries allocated. */ 755 /* entries allocated. */
768 uint16_t seq_id; 756 __le16 seq_id;
769 uint8_t scsi_msg[8]; /* SCSI message not handled by ISP */ 757 uint8_t scsi_msg[8]; /* SCSI message not handled by ISP */
770 uint16_t reserved_5[8]; 758 __le16 reserved_5[8];
771 uint8_t sense_data[18]; 759 uint8_t sense_data[18];
772}; 760};
773 761
@@ -780,16 +768,16 @@ struct nack_entry {
780 uint8_t entry_count; /* Entry count. */ 768 uint8_t entry_count; /* Entry count. */
781 uint8_t reserved_1; 769 uint8_t reserved_1;
782 uint8_t entry_status; /* Entry Status. */ 770 uint8_t entry_status; /* Entry Status. */
783 uint32_t reserved_2; 771 __le32 reserved_2;
784 uint8_t lun; 772 uint8_t lun;
785 uint8_t initiator_id; 773 uint8_t initiator_id;
786 uint8_t reserved_3; 774 uint8_t reserved_3;
787 uint8_t target_id; 775 uint8_t target_id;
788 uint32_t option_flags; 776 __le32 option_flags;
789 uint8_t status; 777 uint8_t status;
790 uint8_t event; 778 uint8_t event;
791 uint16_t seq_id; 779 __le16 seq_id;
792 uint16_t reserved_4[22]; 780 __le16 reserved_4[22];
793}; 781};
794 782
795/* 783/*
@@ -801,12 +789,12 @@ struct atio_entry {
801 uint8_t entry_count; /* Entry count. */ 789 uint8_t entry_count; /* Entry count. */
802 uint8_t reserved_1; 790 uint8_t reserved_1;
803 uint8_t entry_status; /* Entry Status. */ 791 uint8_t entry_status; /* Entry Status. */
804 uint32_t reserved_2; 792 __le32 reserved_2;
805 uint8_t lun; 793 uint8_t lun;
806 uint8_t initiator_id; 794 uint8_t initiator_id;
807 uint8_t cdb_len; 795 uint8_t cdb_len;
808 uint8_t target_id; 796 uint8_t target_id;
809 uint32_t option_flags; 797 __le32 option_flags;
810 uint8_t status; 798 uint8_t status;
811 uint8_t scsi_status; 799 uint8_t scsi_status;
812 uint8_t tag_value; /* Received queue tag message value */ 800 uint8_t tag_value; /* Received queue tag message value */
@@ -824,28 +812,28 @@ struct ctio_entry {
824 uint8_t entry_count; /* Entry count. */ 812 uint8_t entry_count; /* Entry count. */
825 uint8_t reserved_1; 813 uint8_t reserved_1;
826 uint8_t entry_status; /* Entry Status. */ 814 uint8_t entry_status; /* Entry Status. */
827 uint32_t reserved_2; 815 __le32 reserved_2;
828 uint8_t lun; /* SCSI LUN */ 816 uint8_t lun; /* SCSI LUN */
829 uint8_t initiator_id; 817 uint8_t initiator_id;
830 uint8_t reserved_3; 818 uint8_t reserved_3;
831 uint8_t target_id; 819 uint8_t target_id;
832 uint32_t option_flags; 820 __le32 option_flags;
833 uint8_t status; 821 uint8_t status;
834 uint8_t scsi_status; 822 uint8_t scsi_status;
835 uint8_t tag_value; /* Received queue tag message value */ 823 uint8_t tag_value; /* Received queue tag message value */
836 uint8_t tag_type; /* Received queue tag message type */ 824 uint8_t tag_type; /* Received queue tag message type */
837 uint32_t transfer_length; 825 __le32 transfer_length;
838 uint32_t residual; 826 __le32 residual;
839 uint16_t timeout; /* 0 = 30 seconds, 0xFFFF = disable */ 827 __le16 timeout; /* 0 = 30 seconds, 0xFFFF = disable */
840 uint16_t dseg_count; /* Data segment count. */ 828 __le16 dseg_count; /* Data segment count. */
841 uint32_t dseg_0_address; /* Data segment 0 address. */ 829 __le32 dseg_0_address; /* Data segment 0 address. */
842 uint32_t dseg_0_length; /* Data segment 0 length. */ 830 __le32 dseg_0_length; /* Data segment 0 length. */
843 uint32_t dseg_1_address; /* Data segment 1 address. */ 831 __le32 dseg_1_address; /* Data segment 1 address. */
844 uint32_t dseg_1_length; /* Data segment 1 length. */ 832 __le32 dseg_1_length; /* Data segment 1 length. */
845 uint32_t dseg_2_address; /* Data segment 2 address. */ 833 __le32 dseg_2_address; /* Data segment 2 address. */
846 uint32_t dseg_2_length; /* Data segment 2 length. */ 834 __le32 dseg_2_length; /* Data segment 2 length. */
847 uint32_t dseg_3_address; /* Data segment 3 address. */ 835 __le32 dseg_3_address; /* Data segment 3 address. */
848 uint32_t dseg_3_length; /* Data segment 3 length. */ 836 __le32 dseg_3_length; /* Data segment 3 length. */
849}; 837};
850 838
851/* 839/*
@@ -857,24 +845,24 @@ struct ctio_ret_entry {
857 uint8_t entry_count; /* Entry count. */ 845 uint8_t entry_count; /* Entry count. */
858 uint8_t reserved_1; 846 uint8_t reserved_1;
859 uint8_t entry_status; /* Entry Status. */ 847 uint8_t entry_status; /* Entry Status. */
860 uint32_t reserved_2; 848 __le32 reserved_2;
861 uint8_t lun; /* SCSI LUN */ 849 uint8_t lun; /* SCSI LUN */
862 uint8_t initiator_id; 850 uint8_t initiator_id;
863 uint8_t reserved_3; 851 uint8_t reserved_3;
864 uint8_t target_id; 852 uint8_t target_id;
865 uint32_t option_flags; 853 __le32 option_flags;
866 uint8_t status; 854 uint8_t status;
867 uint8_t scsi_status; 855 uint8_t scsi_status;
868 uint8_t tag_value; /* Received queue tag message value */ 856 uint8_t tag_value; /* Received queue tag message value */
869 uint8_t tag_type; /* Received queue tag message type */ 857 uint8_t tag_type; /* Received queue tag message type */
870 uint32_t transfer_length; 858 __le32 transfer_length;
871 uint32_t residual; 859 __le32 residual;
872 uint16_t timeout; /* 0 = 30 seconds, 0xFFFF = disable */ 860 __le16 timeout; /* 0 = 30 seconds, 0xFFFF = disable */
873 uint16_t dseg_count; /* Data segment count. */ 861 __le16 dseg_count; /* Data segment count. */
874 uint32_t dseg_0_address; /* Data segment 0 address. */ 862 __le32 dseg_0_address; /* Data segment 0 address. */
875 uint32_t dseg_0_length; /* Data segment 0 length. */ 863 __le32 dseg_0_length; /* Data segment 0 length. */
876 uint32_t dseg_1_address; /* Data segment 1 address. */ 864 __le32 dseg_1_address; /* Data segment 1 address. */
877 uint16_t dseg_1_length; /* Data segment 1 length. */ 865 __le16 dseg_1_length; /* Data segment 1 length. */
878 uint8_t sense_data[18]; 866 uint8_t sense_data[18];
879}; 867};
880 868
@@ -887,25 +875,25 @@ struct ctio_a64_entry {
887 uint8_t entry_count; /* Entry count. */ 875 uint8_t entry_count; /* Entry count. */
888 uint8_t reserved_1; 876 uint8_t reserved_1;
889 uint8_t entry_status; /* Entry Status. */ 877 uint8_t entry_status; /* Entry Status. */
890 uint32_t reserved_2; 878 __le32 reserved_2;
891 uint8_t lun; /* SCSI LUN */ 879 uint8_t lun; /* SCSI LUN */
892 uint8_t initiator_id; 880 uint8_t initiator_id;
893 uint8_t reserved_3; 881 uint8_t reserved_3;
894 uint8_t target_id; 882 uint8_t target_id;
895 uint32_t option_flags; 883 __le32 option_flags;
896 uint8_t status; 884 uint8_t status;
897 uint8_t scsi_status; 885 uint8_t scsi_status;
898 uint8_t tag_value; /* Received queue tag message value */ 886 uint8_t tag_value; /* Received queue tag message value */
899 uint8_t tag_type; /* Received queue tag message type */ 887 uint8_t tag_type; /* Received queue tag message type */
900 uint32_t transfer_length; 888 __le32 transfer_length;
901 uint32_t residual; 889 __le32 residual;
902 uint16_t timeout; /* 0 = 30 seconds, 0xFFFF = disable */ 890 __le16 timeout; /* 0 = 30 seconds, 0xFFFF = disable */
903 uint16_t dseg_count; /* Data segment count. */ 891 __le16 dseg_count; /* Data segment count. */
904 uint32_t reserved_4[2]; 892 __le32 reserved_4[2];
905 uint32_t dseg_0_address[2]; /* Data segment 0 address. */ 893 __le32 dseg_0_address[2];/* Data segment 0 address. */
906 uint32_t dseg_0_length; /* Data segment 0 length. */ 894 __le32 dseg_0_length; /* Data segment 0 length. */
907 uint32_t dseg_1_address[2]; /* Data segment 1 address. */ 895 __le32 dseg_1_address[2];/* Data segment 1 address. */
908 uint32_t dseg_1_length; /* Data segment 1 length. */ 896 __le32 dseg_1_length; /* Data segment 1 length. */
909}; 897};
910 898
911/* 899/*
@@ -917,21 +905,21 @@ struct ctio_a64_ret_entry {
917 uint8_t entry_count; /* Entry count. */ 905 uint8_t entry_count; /* Entry count. */
918 uint8_t reserved_1; 906 uint8_t reserved_1;
919 uint8_t entry_status; /* Entry Status. */ 907 uint8_t entry_status; /* Entry Status. */
920 uint32_t reserved_2; 908 __le32 reserved_2;
921 uint8_t lun; /* SCSI LUN */ 909 uint8_t lun; /* SCSI LUN */
922 uint8_t initiator_id; 910 uint8_t initiator_id;
923 uint8_t reserved_3; 911 uint8_t reserved_3;
924 uint8_t target_id; 912 uint8_t target_id;
925 uint32_t option_flags; 913 __le32 option_flags;
926 uint8_t status; 914 uint8_t status;
927 uint8_t scsi_status; 915 uint8_t scsi_status;
928 uint8_t tag_value; /* Received queue tag message value */ 916 uint8_t tag_value; /* Received queue tag message value */
929 uint8_t tag_type; /* Received queue tag message type */ 917 uint8_t tag_type; /* Received queue tag message type */
930 uint32_t transfer_length; 918 __le32 transfer_length;
931 uint32_t residual; 919 __le32 residual;
932 uint16_t timeout; /* 0 = 30 seconds, 0xFFFF = disable */ 920 __le16 timeout; /* 0 = 30 seconds, 0xFFFF = disable */
933 uint16_t dseg_count; /* Data segment count. */ 921 __le16 dseg_count; /* Data segment count. */
934 uint16_t reserved_4[7]; 922 __le16 reserved_4[7];
935 uint8_t sense_data[18]; 923 uint8_t sense_data[18];
936}; 924};
937 925
@@ -979,14 +967,6 @@ struct ctio_a64_ret_entry {
979#define CS_RETRY 0x82 /* Driver defined */ 967#define CS_RETRY 0x82 /* Driver defined */
980 968
981/* 969/*
982 * ISP status entry - SCSI status byte bit definitions.
983 */
984#define SS_CHECK_CONDITION BIT_1
985#define SS_CONDITION_MET BIT_2
986#define SS_BUSY_CONDITION BIT_3
987#define SS_RESERVE_CONFLICT (BIT_4 | BIT_3)
988
989/*
990 * ISP target entries - Option flags bit definitions. 970 * ISP target entries - Option flags bit definitions.
991 */ 971 */
992#define OF_ENABLE_TAG BIT_1 /* Tagged queue action enable */ 972#define OF_ENABLE_TAG BIT_1 /* Tagged queue action enable */
@@ -1082,10 +1062,6 @@ struct scsi_qla_host {
1082 uint32_t reset_active:1; /* 3 */ 1062 uint32_t reset_active:1; /* 3 */
1083 uint32_t abort_isp_active:1; /* 4 */ 1063 uint32_t abort_isp_active:1; /* 4 */
1084 uint32_t disable_risc_code_load:1; /* 5 */ 1064 uint32_t disable_risc_code_load:1; /* 5 */
1085 uint32_t enable_64bit_addressing:1; /* 6 */
1086 uint32_t in_reset:1; /* 7 */
1087 uint32_t ints_enabled:1;
1088 uint32_t ignore_nvram:1;
1089#ifdef __ia64__ 1065#ifdef __ia64__
1090 uint32_t use_pci_vchannel:1; 1066 uint32_t use_pci_vchannel:1;
1091#endif 1067#endif
diff --git a/drivers/scsi/qla2xxx/qla_attr.c b/drivers/scsi/qla2xxx/qla_attr.c
index 659a5d63467..fe0fce71adc 100644
--- a/drivers/scsi/qla2xxx/qla_attr.c
+++ b/drivers/scsi/qla2xxx/qla_attr.c
@@ -211,6 +211,138 @@ qla2x00_free_sysfs_attr(scsi_qla_host_t *ha)
211 sysfs_remove_bin_file(&host->shost_gendev.kobj, &sysfs_nvram_attr); 211 sysfs_remove_bin_file(&host->shost_gendev.kobj, &sysfs_nvram_attr);
212} 212}
213 213
214/* Scsi_Host attributes. */
215
216static ssize_t
217qla2x00_drvr_version_show(struct class_device *cdev, char *buf)
218{
219 return snprintf(buf, PAGE_SIZE, "%s\n", qla2x00_version_str);
220}
221
222static ssize_t
223qla2x00_fw_version_show(struct class_device *cdev, char *buf)
224{
225 scsi_qla_host_t *ha = to_qla_host(class_to_shost(cdev));
226 char fw_str[30];
227
228 return snprintf(buf, PAGE_SIZE, "%s\n",
229 ha->isp_ops.fw_version_str(ha, fw_str));
230}
231
232static ssize_t
233qla2x00_serial_num_show(struct class_device *cdev, char *buf)
234{
235 scsi_qla_host_t *ha = to_qla_host(class_to_shost(cdev));
236 uint32_t sn;
237
238 sn = ((ha->serial0 & 0x1f) << 16) | (ha->serial2 << 8) | ha->serial1;
239 return snprintf(buf, PAGE_SIZE, "%c%05d\n", 'A' + sn / 100000,
240 sn % 100000);
241}
242
243static ssize_t
244qla2x00_isp_name_show(struct class_device *cdev, char *buf)
245{
246 scsi_qla_host_t *ha = to_qla_host(class_to_shost(cdev));
247 return snprintf(buf, PAGE_SIZE, "%s\n", ha->brd_info->isp_name);
248}
249
250static ssize_t
251qla2x00_isp_id_show(struct class_device *cdev, char *buf)
252{
253 scsi_qla_host_t *ha = to_qla_host(class_to_shost(cdev));
254 return snprintf(buf, PAGE_SIZE, "%04x %04x %04x %04x\n",
255 ha->product_id[0], ha->product_id[1], ha->product_id[2],
256 ha->product_id[3]);
257}
258
259static ssize_t
260qla2x00_model_name_show(struct class_device *cdev, char *buf)
261{
262 scsi_qla_host_t *ha = to_qla_host(class_to_shost(cdev));
263 return snprintf(buf, PAGE_SIZE, "%s\n", ha->model_number);
264}
265
266static ssize_t
267qla2x00_model_desc_show(struct class_device *cdev, char *buf)
268{
269 scsi_qla_host_t *ha = to_qla_host(class_to_shost(cdev));
270 return snprintf(buf, PAGE_SIZE, "%s\n",
271 ha->model_desc ? ha->model_desc: "");
272}
273
274static ssize_t
275qla2x00_pci_info_show(struct class_device *cdev, char *buf)
276{
277 scsi_qla_host_t *ha = to_qla_host(class_to_shost(cdev));
278 char pci_info[30];
279
280 return snprintf(buf, PAGE_SIZE, "%s\n",
281 ha->isp_ops.pci_info_str(ha, pci_info));
282}
283
284static ssize_t
285qla2x00_state_show(struct class_device *cdev, char *buf)
286{
287 scsi_qla_host_t *ha = to_qla_host(class_to_shost(cdev));
288 int len = 0;
289
290 if (atomic_read(&ha->loop_state) == LOOP_DOWN ||
291 atomic_read(&ha->loop_state) == LOOP_DEAD)
292 len = snprintf(buf, PAGE_SIZE, "Link Down\n");
293 else if (atomic_read(&ha->loop_state) != LOOP_READY ||
294 test_bit(ABORT_ISP_ACTIVE, &ha->dpc_flags) ||
295 test_bit(ISP_ABORT_NEEDED, &ha->dpc_flags))
296 len = snprintf(buf, PAGE_SIZE, "Unknown Link State\n");
297 else {
298 len = snprintf(buf, PAGE_SIZE, "Link Up - ");
299
300 switch (ha->current_topology) {
301 case ISP_CFG_NL:
302 len += snprintf(buf + len, PAGE_SIZE-len, "Loop\n");
303 break;
304 case ISP_CFG_FL:
305 len += snprintf(buf + len, PAGE_SIZE-len, "FL_Port\n");
306 break;
307 case ISP_CFG_N:
308 len += snprintf(buf + len, PAGE_SIZE-len,
309 "N_Port to N_Port\n");
310 break;
311 case ISP_CFG_F:
312 len += snprintf(buf + len, PAGE_SIZE-len, "F_Port\n");
313 break;
314 default:
315 len += snprintf(buf + len, PAGE_SIZE-len, "Loop\n");
316 break;
317 }
318 }
319 return len;
320}
321
322static CLASS_DEVICE_ATTR(driver_version, S_IRUGO, qla2x00_drvr_version_show,
323 NULL);
324static CLASS_DEVICE_ATTR(fw_version, S_IRUGO, qla2x00_fw_version_show, NULL);
325static CLASS_DEVICE_ATTR(serial_num, S_IRUGO, qla2x00_serial_num_show, NULL);
326static CLASS_DEVICE_ATTR(isp_name, S_IRUGO, qla2x00_isp_name_show, NULL);
327static CLASS_DEVICE_ATTR(isp_id, S_IRUGO, qla2x00_isp_id_show, NULL);
328static CLASS_DEVICE_ATTR(model_name, S_IRUGO, qla2x00_model_name_show, NULL);
329static CLASS_DEVICE_ATTR(model_desc, S_IRUGO, qla2x00_model_desc_show, NULL);
330static CLASS_DEVICE_ATTR(pci_info, S_IRUGO, qla2x00_pci_info_show, NULL);
331static CLASS_DEVICE_ATTR(state, S_IRUGO, qla2x00_state_show, NULL);
332
333struct class_device_attribute *qla2x00_host_attrs[] = {
334 &class_device_attr_driver_version,
335 &class_device_attr_fw_version,
336 &class_device_attr_serial_num,
337 &class_device_attr_isp_name,
338 &class_device_attr_isp_id,
339 &class_device_attr_model_name,
340 &class_device_attr_model_desc,
341 &class_device_attr_pci_info,
342 &class_device_attr_state,
343 NULL,
344};
345
214/* Host attributes. */ 346/* Host attributes. */
215 347
216static void 348static void
@@ -304,10 +436,13 @@ struct fc_function_template qla2xxx_transport_functions = {
304 436
305 .show_host_node_name = 1, 437 .show_host_node_name = 1,
306 .show_host_port_name = 1, 438 .show_host_port_name = 1,
439 .show_host_supported_classes = 1,
440
307 .get_host_port_id = qla2x00_get_host_port_id, 441 .get_host_port_id = qla2x00_get_host_port_id,
308 .show_host_port_id = 1, 442 .show_host_port_id = 1,
309 443
310 .dd_fcrport_size = sizeof(struct fc_port *), 444 .dd_fcrport_size = sizeof(struct fc_port *),
445 .show_rport_supported_classes = 1,
311 446
312 .get_starget_node_name = qla2x00_get_starget_node_name, 447 .get_starget_node_name = qla2x00_get_starget_node_name,
313 .show_starget_node_name = 1, 448 .show_starget_node_name = 1,
@@ -329,4 +464,5 @@ qla2x00_init_host_attr(scsi_qla_host_t *ha)
329 be64_to_cpu(*(uint64_t *)ha->init_cb->node_name); 464 be64_to_cpu(*(uint64_t *)ha->init_cb->node_name);
330 fc_host_port_name(ha->host) = 465 fc_host_port_name(ha->host) =
331 be64_to_cpu(*(uint64_t *)ha->init_cb->port_name); 466 be64_to_cpu(*(uint64_t *)ha->init_cb->port_name);
467 fc_host_supported_classes(ha->host) = FC_COS_CLASS3;
332} 468}
diff --git a/drivers/scsi/qla2xxx/qla_dbg.h b/drivers/scsi/qla2xxx/qla_dbg.h
index b8d90e97e01..9684e7a91fa 100644
--- a/drivers/scsi/qla2xxx/qla_dbg.h
+++ b/drivers/scsi/qla2xxx/qla_dbg.h
@@ -81,6 +81,7 @@
81#define DEBUG2_3_11(x) do {x;} while (0); 81#define DEBUG2_3_11(x) do {x;} while (0);
82#define DEBUG2_9_10(x) do {x;} while (0); 82#define DEBUG2_9_10(x) do {x;} while (0);
83#define DEBUG2_11(x) do {x;} while (0); 83#define DEBUG2_11(x) do {x;} while (0);
84#define DEBUG2_13(x) do {x;} while (0);
84#else 85#else
85#define DEBUG2(x) do {} while (0); 86#define DEBUG2(x) do {} while (0);
86#endif 87#endif
@@ -169,8 +170,14 @@
169 170
170#if defined(QL_DEBUG_LEVEL_13) 171#if defined(QL_DEBUG_LEVEL_13)
171#define DEBUG13(x) do {x;} while (0) 172#define DEBUG13(x) do {x;} while (0)
173#if !defined(DEBUG2_13)
174#define DEBUG2_13(x) do {x;} while(0)
175#endif
172#else 176#else
173#define DEBUG13(x) do {} while (0) 177#define DEBUG13(x) do {} while (0)
178#if !defined(QL_DEBUG_LEVEL_2)
179#define DEBUG2_13(x) do {} while(0)
180#endif
174#endif 181#endif
175 182
176#if defined(QL_DEBUG_LEVEL_14) 183#if defined(QL_DEBUG_LEVEL_14)
diff --git a/drivers/scsi/qla2xxx/qla_def.h b/drivers/scsi/qla2xxx/qla_def.h
index 1c6d366f4fa..b455c31405e 100644
--- a/drivers/scsi/qla2xxx/qla_def.h
+++ b/drivers/scsi/qla2xxx/qla_def.h
@@ -214,6 +214,7 @@
214 * valid range of an N-PORT id is 0 through 0x7ef. 214 * valid range of an N-PORT id is 0 through 0x7ef.
215 */ 215 */
216#define NPH_LAST_HANDLE 0x7ef 216#define NPH_LAST_HANDLE 0x7ef
217#define NPH_MGMT_SERVER 0x7fa /* FFFFFA */
217#define NPH_SNS 0x7fc /* FFFFFC */ 218#define NPH_SNS 0x7fc /* FFFFFC */
218#define NPH_FABRIC_CONTROLLER 0x7fd /* FFFFFD */ 219#define NPH_FABRIC_CONTROLLER 0x7fd /* FFFFFD */
219#define NPH_F_PORT 0x7fe /* FFFFFE */ 220#define NPH_F_PORT 0x7fe /* FFFFFE */
@@ -630,6 +631,7 @@ typedef struct {
630#define MBC_WRITE_RAM_WORD_EXTENDED 0xd /* Write RAM word extended */ 631#define MBC_WRITE_RAM_WORD_EXTENDED 0xd /* Write RAM word extended */
631#define MBC_READ_RAM_EXTENDED 0xf /* Read RAM extended. */ 632#define MBC_READ_RAM_EXTENDED 0xf /* Read RAM extended. */
632#define MBC_IOCB_COMMAND 0x12 /* Execute IOCB command. */ 633#define MBC_IOCB_COMMAND 0x12 /* Execute IOCB command. */
634#define MBC_STOP_FIRMWARE 0x14 /* Stop firmware. */
633#define MBC_ABORT_COMMAND 0x15 /* Abort IOCB command. */ 635#define MBC_ABORT_COMMAND 0x15 /* Abort IOCB command. */
634#define MBC_ABORT_DEVICE 0x16 /* Abort device (ID/LUN). */ 636#define MBC_ABORT_DEVICE 0x16 /* Abort device (ID/LUN). */
635#define MBC_ABORT_TARGET 0x17 /* Abort target (ID). */ 637#define MBC_ABORT_TARGET 0x17 /* Abort target (ID). */
@@ -913,7 +915,7 @@ typedef struct {
913 * MSB BIT 1 = 915 * MSB BIT 1 =
914 * MSB BIT 2 = 916 * MSB BIT 2 =
915 * MSB BIT 3 = 917 * MSB BIT 3 =
916 * MSB BIT 4 = 918 * MSB BIT 4 = LED mode
917 * MSB BIT 5 = enable 50 ohm termination 919 * MSB BIT 5 = enable 50 ohm termination
918 * MSB BIT 6 = Data Rate (2300 only) 920 * MSB BIT 6 = Data Rate (2300 only)
919 * MSB BIT 7 = Data Rate (2300 only) 921 * MSB BIT 7 = Data Rate (2300 only)
@@ -1035,7 +1037,7 @@ typedef struct {
1035 * MSB BIT 1 = 1037 * MSB BIT 1 =
1036 * MSB BIT 2 = 1038 * MSB BIT 2 =
1037 * MSB BIT 3 = 1039 * MSB BIT 3 =
1038 * MSB BIT 4 = 1040 * MSB BIT 4 = LED mode
1039 * MSB BIT 5 = enable 50 ohm termination 1041 * MSB BIT 5 = enable 50 ohm termination
1040 * MSB BIT 6 = Data Rate (2300 only) 1042 * MSB BIT 6 = Data Rate (2300 only)
1041 * MSB BIT 7 = Data Rate (2300 only) 1043 * MSB BIT 7 = Data Rate (2300 only)
@@ -1131,10 +1133,7 @@ typedef struct {
1131 1133
1132 uint8_t link_down_timeout; 1134 uint8_t link_down_timeout;
1133 1135
1134 uint8_t adapter_id_0[4]; 1136 uint8_t adapter_id[16];
1135 uint8_t adapter_id_1[4];
1136 uint8_t adapter_id_2[4];
1137 uint8_t adapter_id_3[4];
1138 1137
1139 uint8_t alt1_boot_node_name[WWN_SIZE]; 1138 uint8_t alt1_boot_node_name[WWN_SIZE];
1140 uint16_t alt1_boot_lun_number; 1139 uint16_t alt1_boot_lun_number;
@@ -1673,6 +1672,7 @@ typedef struct fc_port {
1673 uint8_t cur_path; /* current path id */ 1672 uint8_t cur_path; /* current path id */
1674 1673
1675 struct fc_rport *rport; 1674 struct fc_rport *rport;
1675 u32 supported_classes;
1676} fc_port_t; 1676} fc_port_t;
1677 1677
1678/* 1678/*
@@ -1727,6 +1727,8 @@ typedef struct fc_port {
1727 1727
1728#define CT_REJECT_RESPONSE 0x8001 1728#define CT_REJECT_RESPONSE 0x8001
1729#define CT_ACCEPT_RESPONSE 0x8002 1729#define CT_ACCEPT_RESPONSE 0x8002
1730#define CT_REASON_CANNOT_PERFORM 0x09
1731#define CT_EXPL_ALREADY_REGISTERED 0x10
1730 1732
1731#define NS_N_PORT_TYPE 0x01 1733#define NS_N_PORT_TYPE 0x01
1732#define NS_NL_PORT_TYPE 0x02 1734#define NS_NL_PORT_TYPE 0x02
@@ -1768,6 +1770,100 @@ typedef struct fc_port {
1768#define RSNN_NN_REQ_SIZE (16 + 8 + 1 + 255) 1770#define RSNN_NN_REQ_SIZE (16 + 8 + 1 + 255)
1769#define RSNN_NN_RSP_SIZE 16 1771#define RSNN_NN_RSP_SIZE 16
1770 1772
1773/*
1774 * HBA attribute types.
1775 */
1776#define FDMI_HBA_ATTR_COUNT 9
1777#define FDMI_HBA_NODE_NAME 1
1778#define FDMI_HBA_MANUFACTURER 2
1779#define FDMI_HBA_SERIAL_NUMBER 3
1780#define FDMI_HBA_MODEL 4
1781#define FDMI_HBA_MODEL_DESCRIPTION 5
1782#define FDMI_HBA_HARDWARE_VERSION 6
1783#define FDMI_HBA_DRIVER_VERSION 7
1784#define FDMI_HBA_OPTION_ROM_VERSION 8
1785#define FDMI_HBA_FIRMWARE_VERSION 9
1786#define FDMI_HBA_OS_NAME_AND_VERSION 0xa
1787#define FDMI_HBA_MAXIMUM_CT_PAYLOAD_LENGTH 0xb
1788
1789struct ct_fdmi_hba_attr {
1790 uint16_t type;
1791 uint16_t len;
1792 union {
1793 uint8_t node_name[WWN_SIZE];
1794 uint8_t manufacturer[32];
1795 uint8_t serial_num[8];
1796 uint8_t model[16];
1797 uint8_t model_desc[80];
1798 uint8_t hw_version[16];
1799 uint8_t driver_version[32];
1800 uint8_t orom_version[16];
1801 uint8_t fw_version[16];
1802 uint8_t os_version[128];
1803 uint8_t max_ct_len[4];
1804 } a;
1805};
1806
1807struct ct_fdmi_hba_attributes {
1808 uint32_t count;
1809 struct ct_fdmi_hba_attr entry[FDMI_HBA_ATTR_COUNT];
1810};
1811
1812/*
1813 * Port attribute types.
1814 */
1815#define FDMI_PORT_ATTR_COUNT 5
1816#define FDMI_PORT_FC4_TYPES 1
1817#define FDMI_PORT_SUPPORT_SPEED 2
1818#define FDMI_PORT_CURRENT_SPEED 3
1819#define FDMI_PORT_MAX_FRAME_SIZE 4
1820#define FDMI_PORT_OS_DEVICE_NAME 5
1821#define FDMI_PORT_HOST_NAME 6
1822
1823struct ct_fdmi_port_attr {
1824 uint16_t type;
1825 uint16_t len;
1826 union {
1827 uint8_t fc4_types[32];
1828 uint32_t sup_speed;
1829 uint32_t cur_speed;
1830 uint32_t max_frame_size;
1831 uint8_t os_dev_name[32];
1832 uint8_t host_name[32];
1833 } a;
1834};
1835
1836/*
1837 * Port Attribute Block.
1838 */
1839struct ct_fdmi_port_attributes {
1840 uint32_t count;
1841 struct ct_fdmi_port_attr entry[FDMI_PORT_ATTR_COUNT];
1842};
1843
1844/* FDMI definitions. */
1845#define GRHL_CMD 0x100
1846#define GHAT_CMD 0x101
1847#define GRPL_CMD 0x102
1848#define GPAT_CMD 0x110
1849
1850#define RHBA_CMD 0x200
1851#define RHBA_RSP_SIZE 16
1852
1853#define RHAT_CMD 0x201
1854#define RPRT_CMD 0x210
1855
1856#define RPA_CMD 0x211
1857#define RPA_RSP_SIZE 16
1858
1859#define DHBA_CMD 0x300
1860#define DHBA_REQ_SIZE (16 + 8)
1861#define DHBA_RSP_SIZE 16
1862
1863#define DHAT_CMD 0x301
1864#define DPRT_CMD 0x310
1865#define DPA_CMD 0x311
1866
1771/* CT command header -- request/response common fields */ 1867/* CT command header -- request/response common fields */
1772struct ct_cmd_hdr { 1868struct ct_cmd_hdr {
1773 uint8_t revision; 1869 uint8_t revision;
@@ -1825,6 +1921,43 @@ struct ct_sns_req {
1825 uint8_t name_len; 1921 uint8_t name_len;
1826 uint8_t sym_node_name[255]; 1922 uint8_t sym_node_name[255];
1827 } rsnn_nn; 1923 } rsnn_nn;
1924
1925 struct {
1926 uint8_t hba_indentifier[8];
1927 } ghat;
1928
1929 struct {
1930 uint8_t hba_identifier[8];
1931 uint32_t entry_count;
1932 uint8_t port_name[8];
1933 struct ct_fdmi_hba_attributes attrs;
1934 } rhba;
1935
1936 struct {
1937 uint8_t hba_identifier[8];
1938 struct ct_fdmi_hba_attributes attrs;
1939 } rhat;
1940
1941 struct {
1942 uint8_t port_name[8];
1943 struct ct_fdmi_port_attributes attrs;
1944 } rpa;
1945
1946 struct {
1947 uint8_t port_name[8];
1948 } dhba;
1949
1950 struct {
1951 uint8_t port_name[8];
1952 } dhat;
1953
1954 struct {
1955 uint8_t port_name[8];
1956 } dprt;
1957
1958 struct {
1959 uint8_t port_name[8];
1960 } dpa;
1828 } req; 1961 } req;
1829}; 1962};
1830 1963
@@ -1882,6 +2015,12 @@ struct ct_sns_rsp {
1882 struct { 2015 struct {
1883 uint8_t fc4_types[32]; 2016 uint8_t fc4_types[32];
1884 } gft_id; 2017 } gft_id;
2018
2019 struct {
2020 uint32_t entry_count;
2021 uint8_t port_name[8];
2022 struct ct_fdmi_hba_attributes attrs;
2023 } ghat;
1885 } rsp; 2024 } rsp;
1886}; 2025};
1887 2026
@@ -2032,6 +2171,8 @@ struct isp_operations {
2032 uint16_t (*calc_req_entries) (uint16_t); 2171 uint16_t (*calc_req_entries) (uint16_t);
2033 void (*build_iocbs) (srb_t *, cmd_entry_t *, uint16_t); 2172 void (*build_iocbs) (srb_t *, cmd_entry_t *, uint16_t);
2034 void * (*prep_ms_iocb) (struct scsi_qla_host *, uint32_t, uint32_t); 2173 void * (*prep_ms_iocb) (struct scsi_qla_host *, uint32_t, uint32_t);
2174 void * (*prep_ms_fdmi_iocb) (struct scsi_qla_host *, uint32_t,
2175 uint32_t);
2035 2176
2036 uint8_t * (*read_nvram) (struct scsi_qla_host *, uint8_t *, 2177 uint8_t * (*read_nvram) (struct scsi_qla_host *, uint8_t *,
2037 uint32_t, uint32_t); 2178 uint32_t, uint32_t);
@@ -2111,6 +2252,7 @@ typedef struct scsi_qla_host {
2111#define IOCTL_ERROR_RECOVERY 23 2252#define IOCTL_ERROR_RECOVERY 23
2112#define LOOP_RESET_NEEDED 24 2253#define LOOP_RESET_NEEDED 24
2113#define BEACON_BLINK_NEEDED 25 2254#define BEACON_BLINK_NEEDED 25
2255#define REGISTER_FDMI_NEEDED 26
2114 2256
2115 uint32_t device_flags; 2257 uint32_t device_flags;
2116#define DFLG_LOCAL_DEVICES BIT_0 2258#define DFLG_LOCAL_DEVICES BIT_0
@@ -2204,6 +2346,7 @@ typedef struct scsi_qla_host {
2204 int port_down_retry_count; 2346 int port_down_retry_count;
2205 uint8_t mbx_count; 2347 uint8_t mbx_count;
2206 uint16_t last_loop_id; 2348 uint16_t last_loop_id;
2349 uint16_t mgmt_svr_loop_id;
2207 2350
2208 uint32_t login_retry_count; 2351 uint32_t login_retry_count;
2209 2352
@@ -2318,6 +2461,7 @@ typedef struct scsi_qla_host {
2318 uint8_t model_number[16+1]; 2461 uint8_t model_number[16+1];
2319#define BINZERO "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0" 2462#define BINZERO "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0"
2320 char *model_desc; 2463 char *model_desc;
2464 uint8_t adapter_id[16+1];
2321 2465
2322 uint8_t *node_name; 2466 uint8_t *node_name;
2323 uint8_t *port_name; 2467 uint8_t *port_name;
@@ -2377,6 +2521,7 @@ typedef struct scsi_qla_host {
2377#define QLA_SUSPENDED 0x106 2521#define QLA_SUSPENDED 0x106
2378#define QLA_BUSY 0x107 2522#define QLA_BUSY 0x107
2379#define QLA_RSCNS_HANDLED 0x108 2523#define QLA_RSCNS_HANDLED 0x108
2524#define QLA_ALREADY_REGISTERED 0x109
2380 2525
2381/* 2526/*
2382* Stat info for all adpaters 2527* Stat info for all adpaters
diff --git a/drivers/scsi/qla2xxx/qla_gbl.h b/drivers/scsi/qla2xxx/qla_gbl.h
index 665c203e067..1ed32e7b547 100644
--- a/drivers/scsi/qla2xxx/qla_gbl.h
+++ b/drivers/scsi/qla2xxx/qla_gbl.h
@@ -79,6 +79,7 @@ extern int ql2xplogiabsentdevice;
79extern int ql2xenablezio; 79extern int ql2xenablezio;
80extern int ql2xintrdelaytimer; 80extern int ql2xintrdelaytimer;
81extern int ql2xloginretrycount; 81extern int ql2xloginretrycount;
82extern int ql2xfdmienable;
82 83
83extern void qla2x00_sp_compl(scsi_qla_host_t *, srb_t *); 84extern void qla2x00_sp_compl(scsi_qla_host_t *, srb_t *);
84 85
@@ -147,9 +148,6 @@ qla2x00_abort_target(fc_port_t *);
147#endif 148#endif
148 149
149extern int 150extern int
150qla2x00_target_reset(scsi_qla_host_t *, struct fc_port *);
151
152extern int
153qla2x00_get_adapter_id(scsi_qla_host_t *, uint16_t *, uint8_t *, uint8_t *, 151qla2x00_get_adapter_id(scsi_qla_host_t *, uint16_t *, uint8_t *, uint8_t *,
154 uint8_t *, uint16_t *); 152 uint8_t *, uint16_t *);
155 153
@@ -215,6 +213,9 @@ qla2x00_get_serdes_params(scsi_qla_host_t *, uint16_t *, uint16_t *,
215extern int 213extern int
216qla2x00_set_serdes_params(scsi_qla_host_t *, uint16_t, uint16_t, uint16_t); 214qla2x00_set_serdes_params(scsi_qla_host_t *, uint16_t, uint16_t, uint16_t);
217 215
216extern int
217qla2x00_stop_firmware(scsi_qla_host_t *);
218
218/* 219/*
219 * Global Function Prototypes in qla_isr.c source file. 220 * Global Function Prototypes in qla_isr.c source file.
220 */ 221 */
@@ -269,6 +270,9 @@ extern int qla2x00_rft_id(scsi_qla_host_t *);
269extern int qla2x00_rff_id(scsi_qla_host_t *); 270extern int qla2x00_rff_id(scsi_qla_host_t *);
270extern int qla2x00_rnn_id(scsi_qla_host_t *); 271extern int qla2x00_rnn_id(scsi_qla_host_t *);
271extern int qla2x00_rsnn_nn(scsi_qla_host_t *); 272extern int qla2x00_rsnn_nn(scsi_qla_host_t *);
273extern void *qla2x00_prep_ms_fdmi_iocb(scsi_qla_host_t *, uint32_t, uint32_t);
274extern void *qla24xx_prep_ms_fdmi_iocb(scsi_qla_host_t *, uint32_t, uint32_t);
275extern int qla2x00_fdmi_register(scsi_qla_host_t *);
272 276
273/* 277/*
274 * Global Function Prototypes in qla_rscn.c source file. 278 * Global Function Prototypes in qla_rscn.c source file.
@@ -289,6 +293,8 @@ extern void qla2x00_cancel_io_descriptors(scsi_qla_host_t *);
289/* 293/*
290 * Global Function Prototypes in qla_attr.c source file. 294 * Global Function Prototypes in qla_attr.c source file.
291 */ 295 */
296struct class_device_attribute;
297extern struct class_device_attribute *qla2x00_host_attrs[];
292struct fc_function_template; 298struct fc_function_template;
293extern struct fc_function_template qla2xxx_transport_functions; 299extern struct fc_function_template qla2xxx_transport_functions;
294extern void qla2x00_alloc_sysfs_attr(scsi_qla_host_t *); 300extern void qla2x00_alloc_sysfs_attr(scsi_qla_host_t *);
diff --git a/drivers/scsi/qla2xxx/qla_gs.c b/drivers/scsi/qla2xxx/qla_gs.c
index 31ce4f62da1..e7b138c2e33 100644
--- a/drivers/scsi/qla2xxx/qla_gs.c
+++ b/drivers/scsi/qla2xxx/qla_gs.c
@@ -1099,3 +1099,567 @@ qla2x00_sns_rnn_id(scsi_qla_host_t *ha)
1099 1099
1100 return (rval); 1100 return (rval);
1101} 1101}
1102
1103/**
1104 * qla2x00_mgmt_svr_login() - Login to fabric Managment Service.
1105 * @ha: HA context
1106 *
1107 * Returns 0 on success.
1108 */
1109static int
1110qla2x00_mgmt_svr_login(scsi_qla_host_t *ha)
1111{
1112 int ret;
1113 uint16_t mb[MAILBOX_REGISTER_COUNT];
1114
1115 ret = QLA_SUCCESS;
1116 if (ha->flags.management_server_logged_in)
1117 return ret;
1118
1119 ha->isp_ops.fabric_login(ha, ha->mgmt_svr_loop_id, 0xff, 0xff, 0xfa,
1120 mb, BIT_1);
1121 if (mb[0] != MBS_COMMAND_COMPLETE) {
1122 DEBUG2_13(printk("%s(%ld): Failed MANAGEMENT_SERVER login: "
1123 "loop_id=%x mb[0]=%x mb[1]=%x mb[2]=%x mb[6]=%x mb[7]=%x\n",
1124 __func__, ha->host_no, ha->mgmt_svr_loop_id, mb[0], mb[1],
1125 mb[2], mb[6], mb[7]));
1126 ret = QLA_FUNCTION_FAILED;
1127 } else
1128 ha->flags.management_server_logged_in = 1;
1129
1130 return ret;
1131}
1132
1133/**
1134 * qla2x00_prep_ms_fdmi_iocb() - Prepare common MS IOCB fields for FDMI query.
1135 * @ha: HA context
1136 * @req_size: request size in bytes
1137 * @rsp_size: response size in bytes
1138 *
1139 * Returns a pointer to the @ha's ms_iocb.
1140 */
1141void *
1142qla2x00_prep_ms_fdmi_iocb(scsi_qla_host_t *ha, uint32_t req_size,
1143 uint32_t rsp_size)
1144{
1145 ms_iocb_entry_t *ms_pkt;
1146
1147 ms_pkt = ha->ms_iocb;
1148 memset(ms_pkt, 0, sizeof(ms_iocb_entry_t));
1149
1150 ms_pkt->entry_type = MS_IOCB_TYPE;
1151 ms_pkt->entry_count = 1;
1152 SET_TARGET_ID(ha, ms_pkt->loop_id, ha->mgmt_svr_loop_id);
1153 ms_pkt->control_flags = __constant_cpu_to_le16(CF_READ | CF_HEAD_TAG);
1154 ms_pkt->timeout = __constant_cpu_to_le16(59);
1155 ms_pkt->cmd_dsd_count = __constant_cpu_to_le16(1);
1156 ms_pkt->total_dsd_count = __constant_cpu_to_le16(2);
1157 ms_pkt->rsp_bytecount = cpu_to_le32(rsp_size);
1158 ms_pkt->req_bytecount = cpu_to_le32(req_size);
1159
1160 ms_pkt->dseg_req_address[0] = cpu_to_le32(LSD(ha->ct_sns_dma));
1161 ms_pkt->dseg_req_address[1] = cpu_to_le32(MSD(ha->ct_sns_dma));
1162 ms_pkt->dseg_req_length = ms_pkt->req_bytecount;
1163
1164 ms_pkt->dseg_rsp_address[0] = cpu_to_le32(LSD(ha->ct_sns_dma));
1165 ms_pkt->dseg_rsp_address[1] = cpu_to_le32(MSD(ha->ct_sns_dma));
1166 ms_pkt->dseg_rsp_length = ms_pkt->rsp_bytecount;
1167
1168 return ms_pkt;
1169}
1170
1171/**
1172 * qla24xx_prep_ms_fdmi_iocb() - Prepare common MS IOCB fields for FDMI query.
1173 * @ha: HA context
1174 * @req_size: request size in bytes
1175 * @rsp_size: response size in bytes
1176 *
1177 * Returns a pointer to the @ha's ms_iocb.
1178 */
1179void *
1180qla24xx_prep_ms_fdmi_iocb(scsi_qla_host_t *ha, uint32_t req_size,
1181 uint32_t rsp_size)
1182{
1183 struct ct_entry_24xx *ct_pkt;
1184
1185 ct_pkt = (struct ct_entry_24xx *)ha->ms_iocb;
1186 memset(ct_pkt, 0, sizeof(struct ct_entry_24xx));
1187
1188 ct_pkt->entry_type = CT_IOCB_TYPE;
1189 ct_pkt->entry_count = 1;
1190 ct_pkt->nport_handle = cpu_to_le16(ha->mgmt_svr_loop_id);
1191 ct_pkt->timeout = __constant_cpu_to_le16(59);
1192 ct_pkt->cmd_dsd_count = __constant_cpu_to_le16(1);
1193 ct_pkt->rsp_dsd_count = __constant_cpu_to_le16(1);
1194 ct_pkt->rsp_byte_count = cpu_to_le32(rsp_size);
1195 ct_pkt->cmd_byte_count = cpu_to_le32(req_size);
1196
1197 ct_pkt->dseg_0_address[0] = cpu_to_le32(LSD(ha->ct_sns_dma));
1198 ct_pkt->dseg_0_address[1] = cpu_to_le32(MSD(ha->ct_sns_dma));
1199 ct_pkt->dseg_0_len = ct_pkt->cmd_byte_count;
1200
1201 ct_pkt->dseg_1_address[0] = cpu_to_le32(LSD(ha->ct_sns_dma));
1202 ct_pkt->dseg_1_address[1] = cpu_to_le32(MSD(ha->ct_sns_dma));
1203 ct_pkt->dseg_1_len = ct_pkt->rsp_byte_count;
1204
1205 return ct_pkt;
1206}
1207
1208static inline ms_iocb_entry_t *
1209qla2x00_update_ms_fdmi_iocb(scsi_qla_host_t *ha, uint32_t req_size)
1210{
1211 ms_iocb_entry_t *ms_pkt = ha->ms_iocb;
1212 struct ct_entry_24xx *ct_pkt = (struct ct_entry_24xx *)ha->ms_iocb;
1213
1214 if (IS_QLA24XX(ha) || IS_QLA25XX(ha)) {
1215 ct_pkt->cmd_byte_count = cpu_to_le32(req_size);
1216 ct_pkt->dseg_0_len = ct_pkt->cmd_byte_count;
1217 } else {
1218 ms_pkt->req_bytecount = cpu_to_le32(req_size);
1219 ms_pkt->dseg_req_length = ms_pkt->req_bytecount;
1220 }
1221
1222 return ms_pkt;
1223}
1224
1225/**
1226 * qla2x00_prep_ct_req() - Prepare common CT request fields for SNS query.
1227 * @ct_req: CT request buffer
1228 * @cmd: GS command
1229 * @rsp_size: response size in bytes
1230 *
1231 * Returns a pointer to the intitialized @ct_req.
1232 */
1233static inline struct ct_sns_req *
1234qla2x00_prep_ct_fdmi_req(struct ct_sns_req *ct_req, uint16_t cmd,
1235 uint16_t rsp_size)
1236{
1237 memset(ct_req, 0, sizeof(struct ct_sns_pkt));
1238
1239 ct_req->header.revision = 0x01;
1240 ct_req->header.gs_type = 0xFA;
1241 ct_req->header.gs_subtype = 0x10;
1242 ct_req->command = cpu_to_be16(cmd);
1243 ct_req->max_rsp_size = cpu_to_be16((rsp_size - 16) / 4);
1244
1245 return ct_req;
1246}
1247
1248/**
1249 * qla2x00_fdmi_rhba() -
1250 * @ha: HA context
1251 *
1252 * Returns 0 on success.
1253 */
1254static int
1255qla2x00_fdmi_rhba(scsi_qla_host_t *ha)
1256{
1257 int rval, alen;
1258 uint32_t size, sn;
1259
1260 ms_iocb_entry_t *ms_pkt;
1261 struct ct_sns_req *ct_req;
1262 struct ct_sns_rsp *ct_rsp;
1263 uint8_t *entries;
1264 struct ct_fdmi_hba_attr *eiter;
1265
1266 /* Issue RHBA */
1267 /* Prepare common MS IOCB */
1268 /* Request size adjusted after CT preparation */
1269 ms_pkt = ha->isp_ops.prep_ms_fdmi_iocb(ha, 0, RHBA_RSP_SIZE);
1270
1271 /* Prepare CT request */
1272 ct_req = qla2x00_prep_ct_fdmi_req(&ha->ct_sns->p.req, RHBA_CMD,
1273 RHBA_RSP_SIZE);
1274 ct_rsp = &ha->ct_sns->p.rsp;
1275
1276 /* Prepare FDMI command arguments -- attribute block, attributes. */
1277 memcpy(ct_req->req.rhba.hba_identifier, ha->port_name, WWN_SIZE);
1278 ct_req->req.rhba.entry_count = __constant_cpu_to_be32(1);
1279 memcpy(ct_req->req.rhba.port_name, ha->port_name, WWN_SIZE);
1280 size = 2 * WWN_SIZE + 4 + 4;
1281
1282 /* Attributes */
1283 ct_req->req.rhba.attrs.count =
1284 __constant_cpu_to_be32(FDMI_HBA_ATTR_COUNT);
1285 entries = ct_req->req.rhba.hba_identifier;
1286
1287 /* Nodename. */
1288 eiter = (struct ct_fdmi_hba_attr *) (entries + size);
1289 eiter->type = __constant_cpu_to_be16(FDMI_HBA_NODE_NAME);
1290 eiter->len = __constant_cpu_to_be16(4 + WWN_SIZE);
1291 memcpy(eiter->a.node_name, ha->node_name, WWN_SIZE);
1292 size += 4 + WWN_SIZE;
1293
1294 DEBUG13(printk("%s(%ld): NODENAME=%02x%02x%02x%02x%02x%02x%02x%02x.\n",
1295 __func__, ha->host_no,
1296 eiter->a.node_name[0], eiter->a.node_name[1], eiter->a.node_name[2],
1297 eiter->a.node_name[3], eiter->a.node_name[4], eiter->a.node_name[5],
1298 eiter->a.node_name[6], eiter->a.node_name[7]));
1299
1300 /* Manufacturer. */
1301 eiter = (struct ct_fdmi_hba_attr *) (entries + size);
1302 eiter->type = __constant_cpu_to_be16(FDMI_HBA_MANUFACTURER);
1303 strcpy(eiter->a.manufacturer, "QLogic Corporation");
1304 alen = strlen(eiter->a.manufacturer);
1305 alen += (alen & 3) ? (4 - (alen & 3)) : 4;
1306 eiter->len = cpu_to_be16(4 + alen);
1307 size += 4 + alen;
1308
1309 DEBUG13(printk("%s(%ld): MANUFACTURER=%s.\n", __func__, ha->host_no,
1310 eiter->a.manufacturer));
1311
1312 /* Serial number. */
1313 eiter = (struct ct_fdmi_hba_attr *) (entries + size);
1314 eiter->type = __constant_cpu_to_be16(FDMI_HBA_SERIAL_NUMBER);
1315 sn = ((ha->serial0 & 0x1f) << 16) | (ha->serial2 << 8) | ha->serial1;
1316 sprintf(eiter->a.serial_num, "%c%05d", 'A' + sn / 100000, sn % 100000);
1317 alen = strlen(eiter->a.serial_num);
1318 alen += (alen & 3) ? (4 - (alen & 3)) : 4;
1319 eiter->len = cpu_to_be16(4 + alen);
1320 size += 4 + alen;
1321
1322 DEBUG13(printk("%s(%ld): SERIALNO=%s.\n", __func__, ha->host_no,
1323 eiter->a.serial_num));
1324
1325 /* Model name. */
1326 eiter = (struct ct_fdmi_hba_attr *) (entries + size);
1327 eiter->type = __constant_cpu_to_be16(FDMI_HBA_MODEL);
1328 strcpy(eiter->a.model, ha->model_number);
1329 alen = strlen(eiter->a.model);
1330 alen += (alen & 3) ? (4 - (alen & 3)) : 4;
1331 eiter->len = cpu_to_be16(4 + alen);
1332 size += 4 + alen;
1333
1334 DEBUG13(printk("%s(%ld): MODEL_NAME=%s.\n", __func__, ha->host_no,
1335 eiter->a.model));
1336
1337 /* Model description. */
1338 eiter = (struct ct_fdmi_hba_attr *) (entries + size);
1339 eiter->type = __constant_cpu_to_be16(FDMI_HBA_MODEL_DESCRIPTION);
1340 if (ha->model_desc)
1341 strncpy(eiter->a.model_desc, ha->model_desc, 80);
1342 alen = strlen(eiter->a.model_desc);
1343 alen += (alen & 3) ? (4 - (alen & 3)) : 4;
1344 eiter->len = cpu_to_be16(4 + alen);
1345 size += 4 + alen;
1346
1347 DEBUG13(printk("%s(%ld): MODEL_DESC=%s.\n", __func__, ha->host_no,
1348 eiter->a.model_desc));
1349
1350 /* Hardware version. */
1351 eiter = (struct ct_fdmi_hba_attr *) (entries + size);
1352 eiter->type = __constant_cpu_to_be16(FDMI_HBA_HARDWARE_VERSION);
1353 strcpy(eiter->a.hw_version, ha->adapter_id);
1354 alen = strlen(eiter->a.hw_version);
1355 alen += (alen & 3) ? (4 - (alen & 3)) : 4;
1356 eiter->len = cpu_to_be16(4 + alen);
1357 size += 4 + alen;
1358
1359 DEBUG13(printk("%s(%ld): HARDWAREVER=%s.\n", __func__, ha->host_no,
1360 eiter->a.hw_version));
1361
1362 /* Driver version. */
1363 eiter = (struct ct_fdmi_hba_attr *) (entries + size);
1364 eiter->type = __constant_cpu_to_be16(FDMI_HBA_DRIVER_VERSION);
1365 strcpy(eiter->a.driver_version, qla2x00_version_str);
1366 alen = strlen(eiter->a.driver_version);
1367 alen += (alen & 3) ? (4 - (alen & 3)) : 4;
1368 eiter->len = cpu_to_be16(4 + alen);
1369 size += 4 + alen;
1370
1371 DEBUG13(printk("%s(%ld): DRIVERVER=%s.\n", __func__, ha->host_no,
1372 eiter->a.driver_version));
1373
1374 /* Option ROM version. */
1375 eiter = (struct ct_fdmi_hba_attr *) (entries + size);
1376 eiter->type = __constant_cpu_to_be16(FDMI_HBA_OPTION_ROM_VERSION);
1377 strcpy(eiter->a.orom_version, "0.00");
1378 alen = strlen(eiter->a.orom_version);
1379 alen += (alen & 3) ? (4 - (alen & 3)) : 4;
1380 eiter->len = cpu_to_be16(4 + alen);
1381 size += 4 + alen;
1382
1383 DEBUG13(printk("%s(%ld): OPTROMVER=%s.\n", __func__, ha->host_no,
1384 eiter->a.orom_version));
1385
1386 /* Firmware version */
1387 eiter = (struct ct_fdmi_hba_attr *) (entries + size);
1388 eiter->type = __constant_cpu_to_be16(FDMI_HBA_FIRMWARE_VERSION);
1389 ha->isp_ops.fw_version_str(ha, eiter->a.fw_version);
1390 alen = strlen(eiter->a.fw_version);
1391 alen += (alen & 3) ? (4 - (alen & 3)) : 4;
1392 eiter->len = cpu_to_be16(4 + alen);
1393 size += 4 + alen;
1394
1395 DEBUG13(printk("%s(%ld): FIRMWAREVER=%s.\n", __func__, ha->host_no,
1396 eiter->a.fw_version));
1397
1398 /* Update MS request size. */
1399 qla2x00_update_ms_fdmi_iocb(ha, size + 16);
1400
1401 DEBUG13(printk("%s(%ld): RHBA identifier="
1402 "%02x%02x%02x%02x%02x%02x%02x%02x size=%d.\n", __func__,
1403 ha->host_no, ct_req->req.rhba.hba_identifier[0],
1404 ct_req->req.rhba.hba_identifier[1],
1405 ct_req->req.rhba.hba_identifier[2],
1406 ct_req->req.rhba.hba_identifier[3],
1407 ct_req->req.rhba.hba_identifier[4],
1408 ct_req->req.rhba.hba_identifier[5],
1409 ct_req->req.rhba.hba_identifier[6],
1410 ct_req->req.rhba.hba_identifier[7], size));
1411 DEBUG13(qla2x00_dump_buffer(entries, size));
1412
1413 /* Execute MS IOCB */
1414 rval = qla2x00_issue_iocb(ha, ha->ms_iocb, ha->ms_iocb_dma,
1415 sizeof(ms_iocb_entry_t));
1416 if (rval != QLA_SUCCESS) {
1417 /*EMPTY*/
1418 DEBUG2_3(printk("scsi(%ld): RHBA issue IOCB failed (%d).\n",
1419 ha->host_no, rval));
1420 } else if (qla2x00_chk_ms_status(ha, ms_pkt, ct_rsp, "RHBA") !=
1421 QLA_SUCCESS) {
1422 rval = QLA_FUNCTION_FAILED;
1423 if (ct_rsp->header.reason_code == CT_REASON_CANNOT_PERFORM &&
1424 ct_rsp->header.explanation_code ==
1425 CT_EXPL_ALREADY_REGISTERED) {
1426 DEBUG2_13(printk("%s(%ld): HBA already registered.\n",
1427 __func__, ha->host_no));
1428 rval = QLA_ALREADY_REGISTERED;
1429 }
1430 } else {
1431 DEBUG2(printk("scsi(%ld): RHBA exiting normally.\n",
1432 ha->host_no));
1433 }
1434
1435 return rval;
1436}
1437
1438/**
1439 * qla2x00_fdmi_dhba() -
1440 * @ha: HA context
1441 *
1442 * Returns 0 on success.
1443 */
1444static int
1445qla2x00_fdmi_dhba(scsi_qla_host_t *ha)
1446{
1447 int rval;
1448
1449 ms_iocb_entry_t *ms_pkt;
1450 struct ct_sns_req *ct_req;
1451 struct ct_sns_rsp *ct_rsp;
1452
1453 /* Issue RPA */
1454 /* Prepare common MS IOCB */
1455 ms_pkt = ha->isp_ops.prep_ms_fdmi_iocb(ha, DHBA_REQ_SIZE,
1456 DHBA_RSP_SIZE);
1457
1458 /* Prepare CT request */
1459 ct_req = qla2x00_prep_ct_fdmi_req(&ha->ct_sns->p.req, DHBA_CMD,
1460 DHBA_RSP_SIZE);
1461 ct_rsp = &ha->ct_sns->p.rsp;
1462
1463 /* Prepare FDMI command arguments -- portname. */
1464 memcpy(ct_req->req.dhba.port_name, ha->port_name, WWN_SIZE);
1465
1466 DEBUG13(printk("%s(%ld): DHBA portname="
1467 "%02x%02x%02x%02x%02x%02x%02x%02x.\n", __func__, ha->host_no,
1468 ct_req->req.dhba.port_name[0], ct_req->req.dhba.port_name[1],
1469 ct_req->req.dhba.port_name[2], ct_req->req.dhba.port_name[3],
1470 ct_req->req.dhba.port_name[4], ct_req->req.dhba.port_name[5],
1471 ct_req->req.dhba.port_name[6], ct_req->req.dhba.port_name[7]));
1472
1473 /* Execute MS IOCB */
1474 rval = qla2x00_issue_iocb(ha, ha->ms_iocb, ha->ms_iocb_dma,
1475 sizeof(ms_iocb_entry_t));
1476 if (rval != QLA_SUCCESS) {
1477 /*EMPTY*/
1478 DEBUG2_3(printk("scsi(%ld): DHBA issue IOCB failed (%d).\n",
1479 ha->host_no, rval));
1480 } else if (qla2x00_chk_ms_status(ha, ms_pkt, ct_rsp, "DHBA") !=
1481 QLA_SUCCESS) {
1482 rval = QLA_FUNCTION_FAILED;
1483 } else {
1484 DEBUG2(printk("scsi(%ld): DHBA exiting normally.\n",
1485 ha->host_no));
1486 }
1487
1488 return rval;
1489}
1490
1491/**
1492 * qla2x00_fdmi_rpa() -
1493 * @ha: HA context
1494 *
1495 * Returns 0 on success.
1496 */
1497static int
1498qla2x00_fdmi_rpa(scsi_qla_host_t *ha)
1499{
1500 int rval, alen;
1501 uint32_t size, max_frame_size;
1502
1503 ms_iocb_entry_t *ms_pkt;
1504 struct ct_sns_req *ct_req;
1505 struct ct_sns_rsp *ct_rsp;
1506 uint8_t *entries;
1507 struct ct_fdmi_port_attr *eiter;
1508 struct init_cb_24xx *icb24 = (struct init_cb_24xx *)ha->init_cb;
1509
1510 /* Issue RPA */
1511 /* Prepare common MS IOCB */
1512 /* Request size adjusted after CT preparation */
1513 ms_pkt = ha->isp_ops.prep_ms_fdmi_iocb(ha, 0, RPA_RSP_SIZE);
1514
1515 /* Prepare CT request */
1516 ct_req = qla2x00_prep_ct_fdmi_req(&ha->ct_sns->p.req, RPA_CMD,
1517 RPA_RSP_SIZE);
1518 ct_rsp = &ha->ct_sns->p.rsp;
1519
1520 /* Prepare FDMI command arguments -- attribute block, attributes. */
1521 memcpy(ct_req->req.rpa.port_name, ha->port_name, WWN_SIZE);
1522 size = WWN_SIZE + 4;
1523
1524 /* Attributes */
1525 ct_req->req.rpa.attrs.count =
1526 __constant_cpu_to_be32(FDMI_PORT_ATTR_COUNT);
1527 entries = ct_req->req.rpa.port_name;
1528
1529 /* FC4 types. */
1530 eiter = (struct ct_fdmi_port_attr *) (entries + size);
1531 eiter->type = __constant_cpu_to_be16(FDMI_PORT_FC4_TYPES);
1532 eiter->len = __constant_cpu_to_be16(4 + 32);
1533 eiter->a.fc4_types[2] = 0x01;
1534 size += 4 + 32;
1535
1536 DEBUG13(printk("%s(%ld): FC4_TYPES=%02x %02x.\n", __func__, ha->host_no,
1537 eiter->a.fc4_types[2], eiter->a.fc4_types[1]));
1538
1539 /* Supported speed. */
1540 eiter = (struct ct_fdmi_port_attr *) (entries + size);
1541 eiter->type = __constant_cpu_to_be16(FDMI_PORT_SUPPORT_SPEED);
1542 eiter->len = __constant_cpu_to_be16(4 + 4);
1543 if (IS_QLA25XX(ha))
1544 eiter->a.sup_speed = __constant_cpu_to_be32(4);
1545 else if (IS_QLA24XX(ha))
1546 eiter->a.sup_speed = __constant_cpu_to_be32(8);
1547 else if (IS_QLA23XX(ha))
1548 eiter->a.sup_speed = __constant_cpu_to_be32(2);
1549 else
1550 eiter->a.sup_speed = __constant_cpu_to_be32(1);
1551 size += 4 + 4;
1552
1553 DEBUG13(printk("%s(%ld): SUPPORTED_SPEED=%x.\n", __func__, ha->host_no,
1554 eiter->a.sup_speed));
1555
1556 /* Current speed. */
1557 eiter = (struct ct_fdmi_port_attr *) (entries + size);
1558 eiter->type = __constant_cpu_to_be16(FDMI_PORT_CURRENT_SPEED);
1559 eiter->len = __constant_cpu_to_be16(4 + 4);
1560 switch (ha->link_data_rate) {
1561 case 0:
1562 eiter->a.cur_speed = __constant_cpu_to_be32(1);
1563 break;
1564 case 1:
1565 eiter->a.cur_speed = __constant_cpu_to_be32(2);
1566 break;
1567 case 3:
1568 eiter->a.cur_speed = __constant_cpu_to_be32(8);
1569 break;
1570 case 4:
1571 eiter->a.cur_speed = __constant_cpu_to_be32(4);
1572 break;
1573 }
1574 size += 4 + 4;
1575
1576 DEBUG13(printk("%s(%ld): CURRENT_SPEED=%x.\n", __func__, ha->host_no,
1577 eiter->a.cur_speed));
1578
1579 /* Max frame size. */
1580 eiter = (struct ct_fdmi_port_attr *) (entries + size);
1581 eiter->type = __constant_cpu_to_be16(FDMI_PORT_MAX_FRAME_SIZE);
1582 eiter->len = __constant_cpu_to_be16(4 + 4);
1583 max_frame_size = IS_QLA24XX(ha) || IS_QLA25XX(ha) ?
1584 (uint32_t) icb24->frame_payload_size:
1585 (uint32_t) ha->init_cb->frame_payload_size;
1586 eiter->a.max_frame_size = cpu_to_be32(max_frame_size);
1587 size += 4 + 4;
1588
1589 DEBUG13(printk("%s(%ld): MAX_FRAME_SIZE=%x.\n", __func__, ha->host_no,
1590 eiter->a.max_frame_size));
1591
1592 /* OS device name. */
1593 eiter = (struct ct_fdmi_port_attr *) (entries + size);
1594 eiter->type = __constant_cpu_to_be16(FDMI_PORT_OS_DEVICE_NAME);
1595 sprintf(eiter->a.os_dev_name, "/proc/scsi/qla2xxx/%ld", ha->host_no);
1596 alen = strlen(eiter->a.os_dev_name);
1597 alen += (alen & 3) ? (4 - (alen & 3)) : 4;
1598 eiter->len = cpu_to_be16(4 + alen);
1599 size += 4 + alen;
1600
1601 DEBUG13(printk("%s(%ld): OS_DEVICE_NAME=%s.\n", __func__, ha->host_no,
1602 eiter->a.os_dev_name));
1603
1604 /* Update MS request size. */
1605 qla2x00_update_ms_fdmi_iocb(ha, size + 16);
1606
1607 DEBUG13(printk("%s(%ld): RPA portname="
1608 "%02x%02x%02x%02x%02x%02x%02x%02x size=%d.\n", __func__,
1609 ha->host_no, ct_req->req.rpa.port_name[0],
1610 ct_req->req.rpa.port_name[1], ct_req->req.rpa.port_name[2],
1611 ct_req->req.rpa.port_name[3], ct_req->req.rpa.port_name[4],
1612 ct_req->req.rpa.port_name[5], ct_req->req.rpa.port_name[6],
1613 ct_req->req.rpa.port_name[7], size));
1614 DEBUG13(qla2x00_dump_buffer(entries, size));
1615
1616 /* Execute MS IOCB */
1617 rval = qla2x00_issue_iocb(ha, ha->ms_iocb, ha->ms_iocb_dma,
1618 sizeof(ms_iocb_entry_t));
1619 if (rval != QLA_SUCCESS) {
1620 /*EMPTY*/
1621 DEBUG2_3(printk("scsi(%ld): RPA issue IOCB failed (%d).\n",
1622 ha->host_no, rval));
1623 } else if (qla2x00_chk_ms_status(ha, ms_pkt, ct_rsp, "RPA") !=
1624 QLA_SUCCESS) {
1625 rval = QLA_FUNCTION_FAILED;
1626 } else {
1627 DEBUG2(printk("scsi(%ld): RPA exiting normally.\n",
1628 ha->host_no));
1629 }
1630
1631 return rval;
1632}
1633
1634/**
1635 * qla2x00_fdmi_register() -
1636 * @ha: HA context
1637 *
1638 * Returns 0 on success.
1639 */
1640int
1641qla2x00_fdmi_register(scsi_qla_host_t *ha)
1642{
1643 int rval;
1644
1645 rval = qla2x00_mgmt_svr_login(ha);
1646 if (rval)
1647 return rval;
1648
1649 rval = qla2x00_fdmi_rhba(ha);
1650 if (rval) {
1651 if (rval != QLA_ALREADY_REGISTERED)
1652 return rval;
1653
1654 rval = qla2x00_fdmi_dhba(ha);
1655 if (rval)
1656 return rval;
1657
1658 rval = qla2x00_fdmi_rhba(ha);
1659 if (rval)
1660 return rval;
1661 }
1662 rval = qla2x00_fdmi_rpa(ha);
1663
1664 return rval;
1665}
diff --git a/drivers/scsi/qla2xxx/qla_init.c b/drivers/scsi/qla2xxx/qla_init.c
index a6d2559217c..c619583e646 100644
--- a/drivers/scsi/qla2xxx/qla_init.c
+++ b/drivers/scsi/qla2xxx/qla_init.c
@@ -88,6 +88,7 @@ qla2x00_initialize_adapter(scsi_qla_host_t *ha)
88 ha->mbx_flags = 0; 88 ha->mbx_flags = 0;
89 ha->isp_abort_cnt = 0; 89 ha->isp_abort_cnt = 0;
90 ha->beacon_blink_led = 0; 90 ha->beacon_blink_led = 0;
91 set_bit(REGISTER_FDMI_NEEDED, &ha->dpc_flags);
91 92
92 qla_printk(KERN_INFO, ha, "Configuring PCI space...\n"); 93 qla_printk(KERN_INFO, ha, "Configuring PCI space...\n");
93 rval = ha->isp_ops.pci_config(ha); 94 rval = ha->isp_ops.pci_config(ha);
@@ -1563,7 +1564,7 @@ qla2x00_nvram_config(scsi_qla_host_t *ha)
1563 ha->flags.enable_lip_reset = ((nv->host_p[1] & BIT_1) ? 1 : 0); 1564 ha->flags.enable_lip_reset = ((nv->host_p[1] & BIT_1) ? 1 : 0);
1564 ha->flags.enable_lip_full_login = ((nv->host_p[1] & BIT_2) ? 1 : 0); 1565 ha->flags.enable_lip_full_login = ((nv->host_p[1] & BIT_2) ? 1 : 0);
1565 ha->flags.enable_target_reset = ((nv->host_p[1] & BIT_3) ? 1 : 0); 1566 ha->flags.enable_target_reset = ((nv->host_p[1] & BIT_3) ? 1 : 0);
1566 ha->flags.enable_led_scheme = ((nv->efi_parameters & BIT_3) ? 1 : 0); 1567 ha->flags.enable_led_scheme = (nv->special_options[1] & BIT_4) ? 1 : 0;
1567 1568
1568 ha->operating_mode = 1569 ha->operating_mode =
1569 (icb->add_firmware_options[0] & (BIT_6 | BIT_5 | BIT_4)) >> 4; 1570 (icb->add_firmware_options[0] & (BIT_6 | BIT_5 | BIT_4)) >> 4;
@@ -1697,6 +1698,7 @@ qla2x00_alloc_fcport(scsi_qla_host_t *ha, int flags)
1697 fcport->iodesc_idx_sent = IODESC_INVALID_INDEX; 1698 fcport->iodesc_idx_sent = IODESC_INVALID_INDEX;
1698 atomic_set(&fcport->state, FCS_UNCONFIGURED); 1699 atomic_set(&fcport->state, FCS_UNCONFIGURED);
1699 fcport->flags = FCF_RLC_SUPPORT; 1700 fcport->flags = FCF_RLC_SUPPORT;
1701 fcport->supported_classes = FC_COS_UNSPECIFIED;
1700 1702
1701 return (fcport); 1703 return (fcport);
1702} 1704}
@@ -1898,7 +1900,8 @@ qla2x00_configure_local_loop(scsi_qla_host_t *ha)
1898 continue; 1900 continue;
1899 1901
1900 /* Bypass if not same domain and area of adapter. */ 1902 /* Bypass if not same domain and area of adapter. */
1901 if (area != ha->d_id.b.area || domain != ha->d_id.b.domain) 1903 if (area && domain &&
1904 (area != ha->d_id.b.area || domain != ha->d_id.b.domain))
1902 continue; 1905 continue;
1903 1906
1904 /* Bypass invalid local loop ID. */ 1907 /* Bypass invalid local loop ID. */
@@ -2075,6 +2078,7 @@ qla2x00_reg_remote_port(scsi_qla_host_t *ha, fc_port_t *fcport)
2075 return; 2078 return;
2076 } 2079 }
2077 rport->dd_data = fcport; 2080 rport->dd_data = fcport;
2081 rport->supported_classes = fcport->supported_classes;
2078 2082
2079 rport_ids.roles = FC_RPORT_ROLE_UNKNOWN; 2083 rport_ids.roles = FC_RPORT_ROLE_UNKNOWN;
2080 if (fcport->port_type == FCT_INITIATOR) 2084 if (fcport->port_type == FCT_INITIATOR)
@@ -2130,6 +2134,11 @@ qla2x00_configure_fabric(scsi_qla_host_t *ha)
2130 return (QLA_SUCCESS); 2134 return (QLA_SUCCESS);
2131 } 2135 }
2132 do { 2136 do {
2137 /* FDMI support. */
2138 if (ql2xfdmienable &&
2139 test_and_clear_bit(REGISTER_FDMI_NEEDED, &ha->dpc_flags))
2140 qla2x00_fdmi_register(ha);
2141
2133 /* Ensure we are logged into the SNS. */ 2142 /* Ensure we are logged into the SNS. */
2134 if (IS_QLA24XX(ha) || IS_QLA25XX(ha)) 2143 if (IS_QLA24XX(ha) || IS_QLA25XX(ha))
2135 loop_id = NPH_SNS; 2144 loop_id = NPH_SNS;
@@ -2392,6 +2401,12 @@ qla2x00_find_all_fabric_devs(scsi_qla_host_t *ha, struct list_head *new_fcports)
2392 if (new_fcport->d_id.b24 == ha->d_id.b24) 2401 if (new_fcport->d_id.b24 == ha->d_id.b24)
2393 continue; 2402 continue;
2394 2403
2404 /* Bypass if same domain and area of adapter. */
2405 if (((new_fcport->d_id.b24 & 0xffff00) ==
2406 (ha->d_id.b24 & 0xffff00)) && ha->current_topology ==
2407 ISP_CFG_FL)
2408 continue;
2409
2395 /* Bypass reserved domain fields. */ 2410 /* Bypass reserved domain fields. */
2396 if ((new_fcport->d_id.b.domain & 0xf0) == 0xf0) 2411 if ((new_fcport->d_id.b.domain & 0xf0) == 0xf0)
2397 continue; 2412 continue;
@@ -2794,6 +2809,11 @@ qla2x00_fabric_login(scsi_qla_host_t *ha, fc_port_t *fcport,
2794 } 2809 }
2795 } 2810 }
2796 2811
2812 if (mb[10] & BIT_0)
2813 fcport->supported_classes |= FC_COS_CLASS2;
2814 if (mb[10] & BIT_1)
2815 fcport->supported_classes |= FC_COS_CLASS3;
2816
2797 rval = QLA_SUCCESS; 2817 rval = QLA_SUCCESS;
2798 break; 2818 break;
2799 } else if (mb[0] == MBS_LOOP_ID_USED) { 2819 } else if (mb[0] == MBS_LOOP_ID_USED) {
diff --git a/drivers/scsi/qla2xxx/qla_iocb.c b/drivers/scsi/qla2xxx/qla_iocb.c
index ebdc3c54d15..37f82e2cd7f 100644
--- a/drivers/scsi/qla2xxx/qla_iocb.c
+++ b/drivers/scsi/qla2xxx/qla_iocb.c
@@ -810,12 +810,8 @@ qla24xx_start_scsi(srb_t *sp)
810 ha->req_q_cnt = ha->request_q_length - 810 ha->req_q_cnt = ha->request_q_length -
811 (ha->req_ring_index - cnt); 811 (ha->req_ring_index - cnt);
812 } 812 }
813 if (ha->req_q_cnt < (req_cnt + 2)) { 813 if (ha->req_q_cnt < (req_cnt + 2))
814 if (cmd->use_sg)
815 pci_unmap_sg(ha->pdev, sg, cmd->use_sg,
816 cmd->sc_data_direction);
817 goto queuing_error; 814 goto queuing_error;
818 }
819 815
820 /* Build command packet. */ 816 /* Build command packet. */
821 ha->current_outstanding_cmd = handle; 817 ha->current_outstanding_cmd = handle;
diff --git a/drivers/scsi/qla2xxx/qla_isr.c b/drivers/scsi/qla2xxx/qla_isr.c
index f910de6dd43..c255bb0268a 100644
--- a/drivers/scsi/qla2xxx/qla_isr.c
+++ b/drivers/scsi/qla2xxx/qla_isr.c
@@ -451,6 +451,8 @@ qla2x00_async_event(scsi_qla_host_t *ha, uint16_t *mb)
451 451
452 ha->flags.management_server_logged_in = 0; 452 ha->flags.management_server_logged_in = 0;
453 ha->link_data_rate = 0; 453 ha->link_data_rate = 0;
454 if (ql2xfdmienable)
455 set_bit(REGISTER_FDMI_NEEDED, &ha->dpc_flags);
454 456
455 /* Update AEN queue. */ 457 /* Update AEN queue. */
456 qla2x00_enqueue_aen(ha, MBA_LOOP_DOWN, NULL); 458 qla2x00_enqueue_aen(ha, MBA_LOOP_DOWN, NULL);
diff --git a/drivers/scsi/qla2xxx/qla_mbx.c b/drivers/scsi/qla2xxx/qla_mbx.c
index 409ea0ac403..13e1c904707 100644
--- a/drivers/scsi/qla2xxx/qla_mbx.c
+++ b/drivers/scsi/qla2xxx/qla_mbx.c
@@ -19,6 +19,7 @@
19#include "qla_def.h" 19#include "qla_def.h"
20 20
21#include <linux/delay.h> 21#include <linux/delay.h>
22#include <scsi/scsi_transport_fc.h>
22 23
23static void 24static void
24qla2x00_mbx_sem_timeout(unsigned long data) 25qla2x00_mbx_sem_timeout(unsigned long data)
@@ -251,7 +252,7 @@ qla2x00_mailbox_command(scsi_qla_host_t *ha, mbx_cmd_t *mcp)
251 mb0 = RD_REG_WORD(&reg->isp24.mailbox0); 252 mb0 = RD_REG_WORD(&reg->isp24.mailbox0);
252 ictrl = RD_REG_DWORD(&reg->isp24.ictrl); 253 ictrl = RD_REG_DWORD(&reg->isp24.ictrl);
253 } else { 254 } else {
254 mb0 = RD_MAILBOX_REG(ha, reg->isp, 0); 255 mb0 = RD_MAILBOX_REG(ha, &reg->isp, 0);
255 ictrl = RD_REG_WORD(&reg->isp.ictrl); 256 ictrl = RD_REG_WORD(&reg->isp.ictrl);
256 } 257 }
257 printk("%s(%ld): **** MB Command Timeout for cmd %x ****\n", 258 printk("%s(%ld): **** MB Command Timeout for cmd %x ****\n",
@@ -983,58 +984,6 @@ qla2x00_abort_target(fc_port_t *fcport)
983#endif 984#endif
984 985
985/* 986/*
986 * qla2x00_target_reset
987 * Issue target reset mailbox command.
988 *
989 * Input:
990 * ha = adapter block pointer.
991 * TARGET_QUEUE_LOCK must be released.
992 * ADAPTER_STATE_LOCK must be released.
993 *
994 * Returns:
995 * qla2x00 local function return status code.
996 *
997 * Context:
998 * Kernel context.
999 */
1000int
1001qla2x00_target_reset(scsi_qla_host_t *ha, struct fc_port *fcport)
1002{
1003 int rval;
1004 mbx_cmd_t mc;
1005 mbx_cmd_t *mcp = &mc;
1006
1007 DEBUG11(printk("qla2x00_target_reset(%ld): entered.\n", ha->host_no);)
1008
1009 if (atomic_read(&fcport->state) != FCS_ONLINE)
1010 return 0;
1011
1012 mcp->mb[0] = MBC_TARGET_RESET;
1013 if (HAS_EXTENDED_IDS(ha))
1014 mcp->mb[1] = fcport->loop_id;
1015 else
1016 mcp->mb[1] = fcport->loop_id << 8;
1017 mcp->mb[2] = ha->loop_reset_delay;
1018 mcp->out_mb = MBX_2|MBX_1|MBX_0;
1019 mcp->in_mb = MBX_0;
1020 mcp->tov = 30;
1021 mcp->flags = 0;
1022 rval = qla2x00_mailbox_command(ha, mcp);
1023
1024 if (rval != QLA_SUCCESS) {
1025 /*EMPTY*/
1026 DEBUG2_3_11(printk("qla2x00_target_reset(%ld): failed=%x.\n",
1027 ha->host_no, rval);)
1028 } else {
1029 /*EMPTY*/
1030 DEBUG11(printk("qla2x00_target_reset(%ld): done.\n",
1031 ha->host_no);)
1032 }
1033
1034 return rval;
1035}
1036
1037/*
1038 * qla2x00_get_adapter_id 987 * qla2x00_get_adapter_id
1039 * Get adapter ID and topology. 988 * Get adapter ID and topology.
1040 * 989 *
@@ -1326,6 +1275,10 @@ qla2x00_get_port_database(scsi_qla_host_t *ha, fc_port_t *fcport, uint8_t opt)
1326 fcport->port_type = FCT_INITIATOR; 1275 fcport->port_type = FCT_INITIATOR;
1327 else 1276 else
1328 fcport->port_type = FCT_TARGET; 1277 fcport->port_type = FCT_TARGET;
1278
1279 /* Passback COS information. */
1280 fcport->supported_classes = (pd->options & BIT_4) ?
1281 FC_COS_CLASS2: FC_COS_CLASS3;
1329 } 1282 }
1330 1283
1331gpd_error_out: 1284gpd_error_out:
@@ -1661,6 +1614,13 @@ qla24xx_login_fabric(scsi_qla_host_t *ha, uint16_t loop_id, uint8_t domain,
1661 mb[1] |= BIT_1; 1614 mb[1] |= BIT_1;
1662 } else 1615 } else
1663 mb[1] = BIT_0; 1616 mb[1] = BIT_0;
1617
1618 /* Passback COS information. */
1619 mb[10] = 0;
1620 if (lg->io_parameter[7] || lg->io_parameter[8])
1621 mb[10] |= BIT_0; /* Class 2. */
1622 if (lg->io_parameter[9] || lg->io_parameter[10])
1623 mb[10] |= BIT_1; /* Class 3. */
1664 } 1624 }
1665 1625
1666 dma_pool_free(ha->s_dma_pool, lg, lg_dma); 1626 dma_pool_free(ha->s_dma_pool, lg, lg_dma);
@@ -1723,6 +1683,8 @@ qla2x00_login_fabric(scsi_qla_host_t *ha, uint16_t loop_id, uint8_t domain,
1723 mb[2] = mcp->mb[2]; 1683 mb[2] = mcp->mb[2];
1724 mb[6] = mcp->mb[6]; 1684 mb[6] = mcp->mb[6];
1725 mb[7] = mcp->mb[7]; 1685 mb[7] = mcp->mb[7];
1686 /* COS retrieved from Get-Port-Database mailbox command. */
1687 mb[10] = 0;
1726 } 1688 }
1727 1689
1728 if (rval != QLA_SUCCESS) { 1690 if (rval != QLA_SUCCESS) {
@@ -2465,3 +2427,32 @@ qla2x00_set_serdes_params(scsi_qla_host_t *ha, uint16_t sw_em_1g,
2465 2427
2466 return rval; 2428 return rval;
2467} 2429}
2430
2431int
2432qla2x00_stop_firmware(scsi_qla_host_t *ha)
2433{
2434 int rval;
2435 mbx_cmd_t mc;
2436 mbx_cmd_t *mcp = &mc;
2437
2438 if (!IS_QLA24XX(ha) && !IS_QLA25XX(ha))
2439 return QLA_FUNCTION_FAILED;
2440
2441 DEBUG11(printk("%s(%ld): entered.\n", __func__, ha->host_no));
2442
2443 mcp->mb[0] = MBC_STOP_FIRMWARE;
2444 mcp->out_mb = MBX_0;
2445 mcp->in_mb = MBX_0;
2446 mcp->tov = 5;
2447 mcp->flags = 0;
2448 rval = qla2x00_mailbox_command(ha, mcp);
2449
2450 if (rval != QLA_SUCCESS) {
2451 DEBUG2_3_11(printk("%s(%ld): failed=%x.\n", __func__,
2452 ha->host_no, rval));
2453 } else {
2454 DEBUG11(printk("%s(%ld): done.\n", __func__, ha->host_no));
2455 }
2456
2457 return rval;
2458}
diff --git a/drivers/scsi/qla2xxx/qla_os.c b/drivers/scsi/qla2xxx/qla_os.c
index 9000659bfbc..8982978c42f 100644
--- a/drivers/scsi/qla2xxx/qla_os.c
+++ b/drivers/scsi/qla2xxx/qla_os.c
@@ -79,7 +79,7 @@ module_param(ql2xloginretrycount, int, S_IRUGO|S_IRUSR);
79MODULE_PARM_DESC(ql2xloginretrycount, 79MODULE_PARM_DESC(ql2xloginretrycount,
80 "Specify an alternate value for the NVRAM login retry count."); 80 "Specify an alternate value for the NVRAM login retry count.");
81 81
82int ql2xfwloadbin; 82int ql2xfwloadbin=1;
83module_param(ql2xfwloadbin, int, S_IRUGO|S_IRUSR); 83module_param(ql2xfwloadbin, int, S_IRUGO|S_IRUSR);
84MODULE_PARM_DESC(ql2xfwloadbin, 84MODULE_PARM_DESC(ql2xfwloadbin,
85 "Load ISP2xxx firmware image via hotplug."); 85 "Load ISP2xxx firmware image via hotplug.");
@@ -88,6 +88,12 @@ static void qla2x00_free_device(scsi_qla_host_t *);
88 88
89static void qla2x00_config_dma_addressing(scsi_qla_host_t *ha); 89static void qla2x00_config_dma_addressing(scsi_qla_host_t *ha);
90 90
91int ql2xfdmienable;
92module_param(ql2xfdmienable, int, S_IRUGO|S_IRUSR);
93MODULE_PARM_DESC(ql2xfdmienable,
94 "Enables FDMI registratons "
95 "Default is 0 - no FDMI. 1 - perfom FDMI.");
96
91/* 97/*
92 * SCSI host template entry points 98 * SCSI host template entry points
93 */ 99 */
@@ -105,6 +111,9 @@ static int qla2xxx_eh_host_reset(struct scsi_cmnd *);
105static int qla2x00_loop_reset(scsi_qla_host_t *ha); 111static int qla2x00_loop_reset(scsi_qla_host_t *ha);
106static int qla2x00_device_reset(scsi_qla_host_t *, fc_port_t *); 112static int qla2x00_device_reset(scsi_qla_host_t *, fc_port_t *);
107 113
114static int qla2x00_change_queue_depth(struct scsi_device *, int);
115static int qla2x00_change_queue_type(struct scsi_device *, int);
116
108static struct scsi_host_template qla2x00_driver_template = { 117static struct scsi_host_template qla2x00_driver_template = {
109 .module = THIS_MODULE, 118 .module = THIS_MODULE,
110 .name = "qla2xxx", 119 .name = "qla2xxx",
@@ -119,6 +128,8 @@ static struct scsi_host_template qla2x00_driver_template = {
119 128
120 .slave_alloc = qla2xxx_slave_alloc, 129 .slave_alloc = qla2xxx_slave_alloc,
121 .slave_destroy = qla2xxx_slave_destroy, 130 .slave_destroy = qla2xxx_slave_destroy,
131 .change_queue_depth = qla2x00_change_queue_depth,
132 .change_queue_type = qla2x00_change_queue_type,
122 .this_id = -1, 133 .this_id = -1,
123 .cmd_per_lun = 3, 134 .cmd_per_lun = 3,
124 .use_clustering = ENABLE_CLUSTERING, 135 .use_clustering = ENABLE_CLUSTERING,
@@ -129,6 +140,7 @@ static struct scsi_host_template qla2x00_driver_template = {
129 * which equates to 0x800000 sectors. 140 * which equates to 0x800000 sectors.
130 */ 141 */
131 .max_sectors = 0xFFFF, 142 .max_sectors = 0xFFFF,
143 .shost_attrs = qla2x00_host_attrs,
132}; 144};
133 145
134static struct scsi_host_template qla24xx_driver_template = { 146static struct scsi_host_template qla24xx_driver_template = {
@@ -145,12 +157,15 @@ static struct scsi_host_template qla24xx_driver_template = {
145 157
146 .slave_alloc = qla2xxx_slave_alloc, 158 .slave_alloc = qla2xxx_slave_alloc,
147 .slave_destroy = qla2xxx_slave_destroy, 159 .slave_destroy = qla2xxx_slave_destroy,
160 .change_queue_depth = qla2x00_change_queue_depth,
161 .change_queue_type = qla2x00_change_queue_type,
148 .this_id = -1, 162 .this_id = -1,
149 .cmd_per_lun = 3, 163 .cmd_per_lun = 3,
150 .use_clustering = ENABLE_CLUSTERING, 164 .use_clustering = ENABLE_CLUSTERING,
151 .sg_tablesize = SG_ALL, 165 .sg_tablesize = SG_ALL,
152 166
153 .max_sectors = 0xFFFF, 167 .max_sectors = 0xFFFF,
168 .shost_attrs = qla2x00_host_attrs,
154}; 169};
155 170
156static struct scsi_transport_template *qla2xxx_transport_template = NULL; 171static struct scsi_transport_template *qla2xxx_transport_template = NULL;
@@ -487,14 +502,13 @@ qc24_fail_command:
487static int 502static int
488qla2x00_eh_wait_on_command(scsi_qla_host_t *ha, struct scsi_cmnd *cmd) 503qla2x00_eh_wait_on_command(scsi_qla_host_t *ha, struct scsi_cmnd *cmd)
489{ 504{
490#define ABORT_POLLING_PERIOD HZ 505#define ABORT_POLLING_PERIOD 1000
491#define ABORT_WAIT_ITER ((10 * HZ) / (ABORT_POLLING_PERIOD)) 506#define ABORT_WAIT_ITER ((10 * 1000) / (ABORT_POLLING_PERIOD))
492 unsigned long wait_iter = ABORT_WAIT_ITER; 507 unsigned long wait_iter = ABORT_WAIT_ITER;
493 int ret = QLA_SUCCESS; 508 int ret = QLA_SUCCESS;
494 509
495 while (CMD_SP(cmd)) { 510 while (CMD_SP(cmd)) {
496 set_current_state(TASK_UNINTERRUPTIBLE); 511 msleep(ABORT_POLLING_PERIOD);
497 schedule_timeout(ABORT_POLLING_PERIOD);
498 512
499 if (--wait_iter) 513 if (--wait_iter)
500 break; 514 break;
@@ -1016,7 +1030,7 @@ qla2x00_loop_reset(scsi_qla_host_t *ha)
1016 if (fcport->port_type != FCT_TARGET) 1030 if (fcport->port_type != FCT_TARGET)
1017 continue; 1031 continue;
1018 1032
1019 status = qla2x00_target_reset(ha, fcport); 1033 status = qla2x00_device_reset(ha, fcport);
1020 if (status != QLA_SUCCESS) 1034 if (status != QLA_SUCCESS)
1021 break; 1035 break;
1022 } 1036 }
@@ -1103,6 +1117,28 @@ qla2xxx_slave_destroy(struct scsi_device *sdev)
1103 sdev->hostdata = NULL; 1117 sdev->hostdata = NULL;
1104} 1118}
1105 1119
1120static int
1121qla2x00_change_queue_depth(struct scsi_device *sdev, int qdepth)
1122{
1123 scsi_adjust_queue_depth(sdev, scsi_get_tag_type(sdev), qdepth);
1124 return sdev->queue_depth;
1125}
1126
1127static int
1128qla2x00_change_queue_type(struct scsi_device *sdev, int tag_type)
1129{
1130 if (sdev->tagged_supported) {
1131 scsi_set_tag_type(sdev, tag_type);
1132 if (tag_type)
1133 scsi_activate_tcq(sdev, sdev->queue_depth);
1134 else
1135 scsi_deactivate_tcq(sdev, sdev->queue_depth);
1136 } else
1137 tag_type = 0;
1138
1139 return tag_type;
1140}
1141
1106/** 1142/**
1107 * qla2x00_config_dma_addressing() - Configure OS DMA addressing method. 1143 * qla2x00_config_dma_addressing() - Configure OS DMA addressing method.
1108 * @ha: HA context 1144 * @ha: HA context
@@ -1113,36 +1149,23 @@ qla2xxx_slave_destroy(struct scsi_device *sdev)
1113static void 1149static void
1114qla2x00_config_dma_addressing(scsi_qla_host_t *ha) 1150qla2x00_config_dma_addressing(scsi_qla_host_t *ha)
1115{ 1151{
1116 /* Assume 32bit DMA address */ 1152 /* Assume a 32bit DMA mask. */
1117 ha->flags.enable_64bit_addressing = 0; 1153 ha->flags.enable_64bit_addressing = 0;
1118 1154
1119 /* 1155 if (!dma_set_mask(&ha->pdev->dev, DMA_64BIT_MASK)) {
1120 * Given the two variants pci_set_dma_mask(), allow the compiler to 1156 /* Any upper-dword bits set? */
1121 * assist in setting the proper dma mask. 1157 if (MSD(dma_get_required_mask(&ha->pdev->dev)) &&
1122 */ 1158 !pci_set_consistent_dma_mask(ha->pdev, DMA_64BIT_MASK)) {
1123 if (sizeof(dma_addr_t) > 4) { 1159 /* Ok, a 64bit DMA mask is applicable. */
1124 if (pci_set_dma_mask(ha->pdev, DMA_64BIT_MASK) == 0) {
1125 ha->flags.enable_64bit_addressing = 1; 1160 ha->flags.enable_64bit_addressing = 1;
1126 ha->isp_ops.calc_req_entries = qla2x00_calc_iocbs_64; 1161 ha->isp_ops.calc_req_entries = qla2x00_calc_iocbs_64;
1127 ha->isp_ops.build_iocbs = qla2x00_build_scsi_iocbs_64; 1162 ha->isp_ops.build_iocbs = qla2x00_build_scsi_iocbs_64;
1128 1163 return;
1129 if (pci_set_consistent_dma_mask(ha->pdev,
1130 DMA_64BIT_MASK)) {
1131 qla_printk(KERN_DEBUG, ha,
1132 "Failed to set 64 bit PCI consistent mask; "
1133 "using 32 bit.\n");
1134 pci_set_consistent_dma_mask(ha->pdev,
1135 DMA_32BIT_MASK);
1136 }
1137 } else {
1138 qla_printk(KERN_DEBUG, ha,
1139 "Failed to set 64 bit PCI DMA mask, falling back "
1140 "to 32 bit MASK.\n");
1141 pci_set_dma_mask(ha->pdev, DMA_32BIT_MASK);
1142 } 1164 }
1143 } else {
1144 pci_set_dma_mask(ha->pdev, DMA_32BIT_MASK);
1145 } 1165 }
1166
1167 dma_set_mask(&ha->pdev->dev, DMA_32BIT_MASK);
1168 pci_set_consistent_dma_mask(ha->pdev, DMA_32BIT_MASK);
1146} 1169}
1147 1170
1148static int 1171static int
@@ -1316,6 +1339,7 @@ int qla2x00_probe_one(struct pci_dev *pdev, struct qla_board_info *brd_info)
1316 ha->prev_topology = 0; 1339 ha->prev_topology = 0;
1317 ha->ports = MAX_BUSES; 1340 ha->ports = MAX_BUSES;
1318 ha->init_cb_size = sizeof(init_cb_t); 1341 ha->init_cb_size = sizeof(init_cb_t);
1342 ha->mgmt_svr_loop_id = MANAGEMENT_SERVER;
1319 1343
1320 /* Assign ISP specific operations. */ 1344 /* Assign ISP specific operations. */
1321 ha->isp_ops.pci_config = qla2100_pci_config; 1345 ha->isp_ops.pci_config = qla2100_pci_config;
@@ -1338,6 +1362,7 @@ int qla2x00_probe_one(struct pci_dev *pdev, struct qla_board_info *brd_info)
1338 ha->isp_ops.calc_req_entries = qla2x00_calc_iocbs_32; 1362 ha->isp_ops.calc_req_entries = qla2x00_calc_iocbs_32;
1339 ha->isp_ops.build_iocbs = qla2x00_build_scsi_iocbs_32; 1363 ha->isp_ops.build_iocbs = qla2x00_build_scsi_iocbs_32;
1340 ha->isp_ops.prep_ms_iocb = qla2x00_prep_ms_iocb; 1364 ha->isp_ops.prep_ms_iocb = qla2x00_prep_ms_iocb;
1365 ha->isp_ops.prep_ms_fdmi_iocb = qla2x00_prep_ms_fdmi_iocb;
1341 ha->isp_ops.read_nvram = qla2x00_read_nvram_data; 1366 ha->isp_ops.read_nvram = qla2x00_read_nvram_data;
1342 ha->isp_ops.write_nvram = qla2x00_write_nvram_data; 1367 ha->isp_ops.write_nvram = qla2x00_write_nvram_data;
1343 ha->isp_ops.fw_dump = qla2100_fw_dump; 1368 ha->isp_ops.fw_dump = qla2100_fw_dump;
@@ -1375,6 +1400,7 @@ int qla2x00_probe_one(struct pci_dev *pdev, struct qla_board_info *brd_info)
1375 ha->response_q_length = RESPONSE_ENTRY_CNT_2300; 1400 ha->response_q_length = RESPONSE_ENTRY_CNT_2300;
1376 ha->last_loop_id = SNS_LAST_LOOP_ID_2300; 1401 ha->last_loop_id = SNS_LAST_LOOP_ID_2300;
1377 ha->init_cb_size = sizeof(struct init_cb_24xx); 1402 ha->init_cb_size = sizeof(struct init_cb_24xx);
1403 ha->mgmt_svr_loop_id = 10;
1378 ha->isp_ops.pci_config = qla24xx_pci_config; 1404 ha->isp_ops.pci_config = qla24xx_pci_config;
1379 ha->isp_ops.reset_chip = qla24xx_reset_chip; 1405 ha->isp_ops.reset_chip = qla24xx_reset_chip;
1380 ha->isp_ops.chip_diag = qla24xx_chip_diag; 1406 ha->isp_ops.chip_diag = qla24xx_chip_diag;
@@ -1395,6 +1421,7 @@ int qla2x00_probe_one(struct pci_dev *pdev, struct qla_board_info *brd_info)
1395 ha->isp_ops.fabric_login = qla24xx_login_fabric; 1421 ha->isp_ops.fabric_login = qla24xx_login_fabric;
1396 ha->isp_ops.fabric_logout = qla24xx_fabric_logout; 1422 ha->isp_ops.fabric_logout = qla24xx_fabric_logout;
1397 ha->isp_ops.prep_ms_iocb = qla24xx_prep_ms_iocb; 1423 ha->isp_ops.prep_ms_iocb = qla24xx_prep_ms_iocb;
1424 ha->isp_ops.prep_ms_fdmi_iocb = qla24xx_prep_ms_fdmi_iocb;
1398 ha->isp_ops.read_nvram = qla24xx_read_nvram_data; 1425 ha->isp_ops.read_nvram = qla24xx_read_nvram_data;
1399 ha->isp_ops.write_nvram = qla24xx_write_nvram_data; 1426 ha->isp_ops.write_nvram = qla24xx_write_nvram_data;
1400 ha->isp_ops.fw_dump = qla24xx_fw_dump; 1427 ha->isp_ops.fw_dump = qla24xx_fw_dump;
@@ -1558,8 +1585,6 @@ int qla2x00_probe_one(struct pci_dev *pdev, struct qla_board_info *brd_info)
1558 return 0; 1585 return 0;
1559 1586
1560probe_failed: 1587probe_failed:
1561 fc_remove_host(ha->host);
1562
1563 qla2x00_free_device(ha); 1588 qla2x00_free_device(ha);
1564 1589
1565 scsi_host_put(host); 1590 scsi_host_put(host);
@@ -1601,10 +1626,6 @@ qla2x00_free_device(scsi_qla_host_t *ha)
1601 if (!IS_QLA2100(ha) && !IS_QLA2200(ha)) 1626 if (!IS_QLA2100(ha) && !IS_QLA2200(ha))
1602 qla2x00_cancel_io_descriptors(ha); 1627 qla2x00_cancel_io_descriptors(ha);
1603 1628
1604 /* turn-off interrupts on the card */
1605 if (ha->interrupts_on)
1606 ha->isp_ops.disable_intrs(ha);
1607
1608 /* Disable timer */ 1629 /* Disable timer */
1609 if (ha->timer_active) 1630 if (ha->timer_active)
1610 qla2x00_stop_timer(ha); 1631 qla2x00_stop_timer(ha);
@@ -1624,8 +1645,14 @@ qla2x00_free_device(scsi_qla_host_t *ha)
1624 } 1645 }
1625 } 1646 }
1626 1647
1627 qla2x00_mem_free(ha); 1648 /* Stop currently executing firmware. */
1649 qla2x00_stop_firmware(ha);
1650
1651 /* turn-off interrupts on the card */
1652 if (ha->interrupts_on)
1653 ha->isp_ops.disable_intrs(ha);
1628 1654
1655 qla2x00_mem_free(ha);
1629 1656
1630 ha->flags.online = 0; 1657 ha->flags.online = 0;
1631 1658
@@ -1934,7 +1961,7 @@ qla2x00_mem_free(scsi_qla_host_t *ha)
1934{ 1961{
1935 struct list_head *fcpl, *fcptemp; 1962 struct list_head *fcpl, *fcptemp;
1936 fc_port_t *fcport; 1963 fc_port_t *fcport;
1937 unsigned long wtime;/* max wait time if mbx cmd is busy. */ 1964 unsigned int wtime;/* max wait time if mbx cmd is busy. */
1938 1965
1939 if (ha == NULL) { 1966 if (ha == NULL) {
1940 /* error */ 1967 /* error */
@@ -1943,11 +1970,9 @@ qla2x00_mem_free(scsi_qla_host_t *ha)
1943 } 1970 }
1944 1971
1945 /* Make sure all other threads are stopped. */ 1972 /* Make sure all other threads are stopped. */
1946 wtime = 60 * HZ; 1973 wtime = 60 * 1000;
1947 while (ha->dpc_wait && wtime) { 1974 while (ha->dpc_wait && wtime)
1948 set_current_state(TASK_INTERRUPTIBLE); 1975 wtime = msleep_interruptible(wtime);
1949 wtime = schedule_timeout(wtime);
1950 }
1951 1976
1952 /* free ioctl memory */ 1977 /* free ioctl memory */
1953 qla2x00_free_ioctl_mem(ha); 1978 qla2x00_free_ioctl_mem(ha);
@@ -2478,15 +2503,15 @@ qla2x00_timer(scsi_qla_host_t *ha)
2478int 2503int
2479qla2x00_down_timeout(struct semaphore *sema, unsigned long timeout) 2504qla2x00_down_timeout(struct semaphore *sema, unsigned long timeout)
2480{ 2505{
2481 const unsigned int step = HZ/10; 2506 const unsigned int step = 100; /* msecs */
2507 unsigned int iterations = jiffies_to_msecs(timeout)/100;
2482 2508
2483 do { 2509 do {
2484 if (!down_trylock(sema)) 2510 if (!down_trylock(sema))
2485 return 0; 2511 return 0;
2486 set_current_state(TASK_INTERRUPTIBLE); 2512 if (msleep_interruptible(step))
2487 if (schedule_timeout(step))
2488 break; 2513 break;
2489 } while ((timeout -= step) > 0); 2514 } while (--iterations >= 0);
2490 2515
2491 return -ETIMEDOUT; 2516 return -ETIMEDOUT;
2492} 2517}
diff --git a/drivers/scsi/qla2xxx/qla_sup.c b/drivers/scsi/qla2xxx/qla_sup.c
index d7f5c608009..c14abf743b7 100644
--- a/drivers/scsi/qla2xxx/qla_sup.c
+++ b/drivers/scsi/qla2xxx/qla_sup.c
@@ -468,21 +468,12 @@ qla24xx_read_flash_data(scsi_qla_host_t *ha, uint32_t *dwptr, uint32_t faddr,
468 uint32_t dwords) 468 uint32_t dwords)
469{ 469{
470 uint32_t i; 470 uint32_t i;
471 struct device_reg_24xx __iomem *reg = &ha->iobase->isp24;
472
473 /* Pause RISC. */
474 WRT_REG_DWORD(&reg->hccr, HCCRX_SET_RISC_PAUSE);
475 RD_REG_DWORD(&reg->hccr); /* PCI Posting. */
476 471
477 /* Dword reads to flash. */ 472 /* Dword reads to flash. */
478 for (i = 0; i < dwords; i++, faddr++) 473 for (i = 0; i < dwords; i++, faddr++)
479 dwptr[i] = cpu_to_le32(qla24xx_read_flash_dword(ha, 474 dwptr[i] = cpu_to_le32(qla24xx_read_flash_dword(ha,
480 flash_data_to_access_addr(faddr))); 475 flash_data_to_access_addr(faddr)));
481 476
482 /* Release RISC pause. */
483 WRT_REG_DWORD(&reg->hccr, HCCRX_REL_RISC_PAUSE);
484 RD_REG_DWORD(&reg->hccr); /* PCI Posting. */
485
486 return dwptr; 477 return dwptr;
487} 478}
488 479
@@ -532,10 +523,6 @@ qla24xx_write_flash_data(scsi_qla_host_t *ha, uint32_t *dwptr, uint32_t faddr,
532 523
533 ret = QLA_SUCCESS; 524 ret = QLA_SUCCESS;
534 525
535 /* Pause RISC. */
536 WRT_REG_DWORD(&reg->hccr, HCCRX_SET_RISC_PAUSE);
537 RD_REG_DWORD(&reg->hccr); /* PCI Posting. */
538
539 qla24xx_get_flash_manufacturer(ha, &man_id, &flash_id); 526 qla24xx_get_flash_manufacturer(ha, &man_id, &flash_id);
540 DEBUG9(printk("%s(%ld): Flash man_id=%d flash_id=%d\n", __func__, 527 DEBUG9(printk("%s(%ld): Flash man_id=%d flash_id=%d\n", __func__,
541 ha->host_no, man_id, flash_id)); 528 ha->host_no, man_id, flash_id));
@@ -599,10 +586,6 @@ qla24xx_write_flash_data(scsi_qla_host_t *ha, uint32_t *dwptr, uint32_t faddr,
599 RD_REG_DWORD(&reg->ctrl_status) & ~CSRX_FLASH_ENABLE); 586 RD_REG_DWORD(&reg->ctrl_status) & ~CSRX_FLASH_ENABLE);
600 RD_REG_DWORD(&reg->ctrl_status); /* PCI Posting. */ 587 RD_REG_DWORD(&reg->ctrl_status); /* PCI Posting. */
601 588
602 /* Release RISC pause. */
603 WRT_REG_DWORD(&reg->hccr, HCCRX_REL_RISC_PAUSE);
604 RD_REG_DWORD(&reg->hccr); /* PCI Posting. */
605
606 return ret; 589 return ret;
607} 590}
608 591
@@ -630,11 +613,6 @@ qla24xx_read_nvram_data(scsi_qla_host_t *ha, uint8_t *buf, uint32_t naddr,
630{ 613{
631 uint32_t i; 614 uint32_t i;
632 uint32_t *dwptr; 615 uint32_t *dwptr;
633 struct device_reg_24xx __iomem *reg = &ha->iobase->isp24;
634
635 /* Pause RISC. */
636 WRT_REG_DWORD(&reg->hccr, HCCRX_SET_RISC_PAUSE);
637 RD_REG_DWORD(&reg->hccr); /* PCI Posting. */
638 616
639 /* Dword reads to flash. */ 617 /* Dword reads to flash. */
640 dwptr = (uint32_t *)buf; 618 dwptr = (uint32_t *)buf;
@@ -642,10 +620,6 @@ qla24xx_read_nvram_data(scsi_qla_host_t *ha, uint8_t *buf, uint32_t naddr,
642 dwptr[i] = cpu_to_le32(qla24xx_read_flash_dword(ha, 620 dwptr[i] = cpu_to_le32(qla24xx_read_flash_dword(ha,
643 nvram_data_to_access_addr(naddr))); 621 nvram_data_to_access_addr(naddr)));
644 622
645 /* Release RISC pause. */
646 WRT_REG_DWORD(&reg->hccr, HCCRX_REL_RISC_PAUSE);
647 RD_REG_DWORD(&reg->hccr); /* PCI Posting. */
648
649 return buf; 623 return buf;
650} 624}
651 625
@@ -690,10 +664,6 @@ qla24xx_write_nvram_data(scsi_qla_host_t *ha, uint8_t *buf, uint32_t naddr,
690 664
691 ret = QLA_SUCCESS; 665 ret = QLA_SUCCESS;
692 666
693 /* Pause RISC. */
694 WRT_REG_DWORD(&reg->hccr, HCCRX_SET_RISC_PAUSE);
695 RD_REG_DWORD(&reg->hccr); /* PCI Posting. */
696
697 /* Enable flash write. */ 667 /* Enable flash write. */
698 WRT_REG_DWORD(&reg->ctrl_status, 668 WRT_REG_DWORD(&reg->ctrl_status,
699 RD_REG_DWORD(&reg->ctrl_status) | CSRX_FLASH_ENABLE); 669 RD_REG_DWORD(&reg->ctrl_status) | CSRX_FLASH_ENABLE);
@@ -728,9 +698,5 @@ qla24xx_write_nvram_data(scsi_qla_host_t *ha, uint8_t *buf, uint32_t naddr,
728 RD_REG_DWORD(&reg->ctrl_status) & ~CSRX_FLASH_ENABLE); 698 RD_REG_DWORD(&reg->ctrl_status) & ~CSRX_FLASH_ENABLE);
729 RD_REG_DWORD(&reg->ctrl_status); /* PCI Posting. */ 699 RD_REG_DWORD(&reg->ctrl_status); /* PCI Posting. */
730 700
731 /* Release RISC pause. */
732 WRT_REG_DWORD(&reg->hccr, HCCRX_REL_RISC_PAUSE);
733 RD_REG_DWORD(&reg->hccr); /* PCI Posting. */
734
735 return ret; 701 return ret;
736} 702}
diff --git a/drivers/scsi/qla2xxx/qla_version.h b/drivers/scsi/qla2xxx/qla_version.h
index e3cd3618bc5..eae7d6edd53 100644
--- a/drivers/scsi/qla2xxx/qla_version.h
+++ b/drivers/scsi/qla2xxx/qla_version.h
@@ -19,9 +19,9 @@
19/* 19/*
20 * Driver version 20 * Driver version
21 */ 21 */
22#define QLA2XXX_VERSION "8.01.00b5-k" 22#define QLA2XXX_VERSION "8.01.00-k"
23 23
24#define QLA_DRIVER_MAJOR_VER 8 24#define QLA_DRIVER_MAJOR_VER 8
25#define QLA_DRIVER_MINOR_VER 1 25#define QLA_DRIVER_MINOR_VER 1
26#define QLA_DRIVER_PATCH_VER 0 26#define QLA_DRIVER_PATCH_VER 0
27#define QLA_DRIVER_BETA_VER 5 27#define QLA_DRIVER_BETA_VER 0
diff --git a/drivers/scsi/raid_class.c b/drivers/scsi/raid_class.c
new file mode 100644
index 00000000000..f1ea5027865
--- /dev/null
+++ b/drivers/scsi/raid_class.c
@@ -0,0 +1,250 @@
1/*
2 * RAID Attributes
3 */
4#include <linux/init.h>
5#include <linux/module.h>
6#include <linux/list.h>
7#include <linux/raid_class.h>
8#include <scsi/scsi_device.h>
9#include <scsi/scsi_host.h>
10
11#define RAID_NUM_ATTRS 3
12
13struct raid_internal {
14 struct raid_template r;
15 struct raid_function_template *f;
16 /* The actual attributes */
17 struct class_device_attribute private_attrs[RAID_NUM_ATTRS];
18 /* The array of null terminated pointers to attributes
19 * needed by scsi_sysfs.c */
20 struct class_device_attribute *attrs[RAID_NUM_ATTRS + 1];
21};
22
23struct raid_component {
24 struct list_head node;
25 struct device *dev;
26 int num;
27};
28
29#define to_raid_internal(tmpl) container_of(tmpl, struct raid_internal, r)
30
31#define tc_to_raid_internal(tcont) ({ \
32 struct raid_template *r = \
33 container_of(tcont, struct raid_template, raid_attrs); \
34 to_raid_internal(r); \
35})
36
37#define ac_to_raid_internal(acont) ({ \
38 struct transport_container *tc = \
39 container_of(acont, struct transport_container, ac); \
40 tc_to_raid_internal(tc); \
41})
42
43#define class_device_to_raid_internal(cdev) ({ \
44 struct attribute_container *ac = \
45 attribute_container_classdev_to_container(cdev); \
46 ac_to_raid_internal(ac); \
47})
48
49
50static int raid_match(struct attribute_container *cont, struct device *dev)
51{
52 /* We have to look for every subsystem that could house
53 * emulated RAID devices, so start with SCSI */
54 struct raid_internal *i = ac_to_raid_internal(cont);
55
56 if (scsi_is_sdev_device(dev)) {
57 struct scsi_device *sdev = to_scsi_device(dev);
58
59 if (i->f->cookie != sdev->host->hostt)
60 return 0;
61
62 return i->f->is_raid(dev);
63 }
64 /* FIXME: look at other subsystems too */
65 return 0;
66}
67
68static int raid_setup(struct transport_container *tc, struct device *dev,
69 struct class_device *cdev)
70{
71 struct raid_data *rd;
72
73 BUG_ON(class_get_devdata(cdev));
74
75 rd = kmalloc(sizeof(*rd), GFP_KERNEL);
76 if (!rd)
77 return -ENOMEM;
78
79 memset(rd, 0, sizeof(*rd));
80 INIT_LIST_HEAD(&rd->component_list);
81 class_set_devdata(cdev, rd);
82
83 return 0;
84}
85
86static int raid_remove(struct transport_container *tc, struct device *dev,
87 struct class_device *cdev)
88{
89 struct raid_data *rd = class_get_devdata(cdev);
90 struct raid_component *rc, *next;
91 class_set_devdata(cdev, NULL);
92 list_for_each_entry_safe(rc, next, &rd->component_list, node) {
93 char buf[40];
94 snprintf(buf, sizeof(buf), "component-%d", rc->num);
95 list_del(&rc->node);
96 sysfs_remove_link(&cdev->kobj, buf);
97 kfree(rc);
98 }
99 kfree(class_get_devdata(cdev));
100 return 0;
101}
102
103static DECLARE_TRANSPORT_CLASS(raid_class,
104 "raid_devices",
105 raid_setup,
106 raid_remove,
107 NULL);
108
109static struct {
110 enum raid_state value;
111 char *name;
112} raid_states[] = {
113 { RAID_ACTIVE, "active" },
114 { RAID_DEGRADED, "degraded" },
115 { RAID_RESYNCING, "resyncing" },
116 { RAID_OFFLINE, "offline" },
117};
118
119static const char *raid_state_name(enum raid_state state)
120{
121 int i;
122 char *name = NULL;
123
124 for (i = 0; i < sizeof(raid_states)/sizeof(raid_states[0]); i++) {
125 if (raid_states[i].value == state) {
126 name = raid_states[i].name;
127 break;
128 }
129 }
130 return name;
131}
132
133
134#define raid_attr_show_internal(attr, fmt, var, code) \
135static ssize_t raid_show_##attr(struct class_device *cdev, char *buf) \
136{ \
137 struct raid_data *rd = class_get_devdata(cdev); \
138 code \
139 return snprintf(buf, 20, #fmt "\n", var); \
140}
141
142#define raid_attr_ro_states(attr, states, code) \
143raid_attr_show_internal(attr, %s, name, \
144 const char *name; \
145 code \
146 name = raid_##states##_name(rd->attr); \
147) \
148static CLASS_DEVICE_ATTR(attr, S_IRUGO, raid_show_##attr, NULL)
149
150
151#define raid_attr_ro_internal(attr, code) \
152raid_attr_show_internal(attr, %d, rd->attr, code) \
153static CLASS_DEVICE_ATTR(attr, S_IRUGO, raid_show_##attr, NULL)
154
155#define ATTR_CODE(attr) \
156 struct raid_internal *i = class_device_to_raid_internal(cdev); \
157 if (i->f->get_##attr) \
158 i->f->get_##attr(cdev->dev);
159
160#define raid_attr_ro(attr) raid_attr_ro_internal(attr, )
161#define raid_attr_ro_fn(attr) raid_attr_ro_internal(attr, ATTR_CODE(attr))
162#define raid_attr_ro_state(attr) raid_attr_ro_states(attr, attr, ATTR_CODE(attr))
163
164raid_attr_ro(level);
165raid_attr_ro_fn(resync);
166raid_attr_ro_state(state);
167
168void raid_component_add(struct raid_template *r,struct device *raid_dev,
169 struct device *component_dev)
170{
171 struct class_device *cdev =
172 attribute_container_find_class_device(&r->raid_attrs.ac,
173 raid_dev);
174 struct raid_component *rc;
175 struct raid_data *rd = class_get_devdata(cdev);
176 char buf[40];
177
178 rc = kmalloc(sizeof(*rc), GFP_KERNEL);
179 if (!rc)
180 return;
181
182 INIT_LIST_HEAD(&rc->node);
183 rc->dev = component_dev;
184 rc->num = rd->component_count++;
185
186 snprintf(buf, sizeof(buf), "component-%d", rc->num);
187 list_add_tail(&rc->node, &rd->component_list);
188 sysfs_create_link(&cdev->kobj, &component_dev->kobj, buf);
189}
190EXPORT_SYMBOL(raid_component_add);
191
192struct raid_template *
193raid_class_attach(struct raid_function_template *ft)
194{
195 struct raid_internal *i = kmalloc(sizeof(struct raid_internal),
196 GFP_KERNEL);
197 int count = 0;
198
199 if (unlikely(!i))
200 return NULL;
201
202 memset(i, 0, sizeof(*i));
203
204 i->f = ft;
205
206 i->r.raid_attrs.ac.class = &raid_class.class;
207 i->r.raid_attrs.ac.match = raid_match;
208 i->r.raid_attrs.ac.attrs = &i->attrs[0];
209
210 attribute_container_register(&i->r.raid_attrs.ac);
211
212 i->attrs[count++] = &class_device_attr_level;
213 i->attrs[count++] = &class_device_attr_resync;
214 i->attrs[count++] = &class_device_attr_state;
215
216 i->attrs[count] = NULL;
217 BUG_ON(count > RAID_NUM_ATTRS);
218
219 return &i->r;
220}
221EXPORT_SYMBOL(raid_class_attach);
222
223void
224raid_class_release(struct raid_template *r)
225{
226 struct raid_internal *i = to_raid_internal(r);
227
228 attribute_container_unregister(&i->r.raid_attrs.ac);
229
230 kfree(i);
231}
232EXPORT_SYMBOL(raid_class_release);
233
234static __init int raid_init(void)
235{
236 return transport_class_register(&raid_class);
237}
238
239static __exit void raid_exit(void)
240{
241 transport_class_unregister(&raid_class);
242}
243
244MODULE_AUTHOR("James Bottomley");
245MODULE_DESCRIPTION("RAID device class");
246MODULE_LICENSE("GPL");
247
248module_init(raid_init);
249module_exit(raid_exit);
250
diff --git a/drivers/scsi/sata_mv.c b/drivers/scsi/sata_mv.c
new file mode 100644
index 00000000000..f97e3afa97d
--- /dev/null
+++ b/drivers/scsi/sata_mv.c
@@ -0,0 +1,843 @@
1/*
2 * sata_mv.c - Marvell SATA support
3 *
4 * Copyright 2005: EMC Corporation, all rights reserved.
5 *
6 * Please ALWAYS copy linux-ide@vger.kernel.org on emails.
7 *
8 * This program is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License as published by
10 * the Free Software Foundation; version 2 of the License.
11 *
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
16 *
17 * You should have received a copy of the GNU General Public License
18 * along with this program; if not, write to the Free Software
19 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
20 *
21 */
22
23#include <linux/kernel.h>
24#include <linux/module.h>
25#include <linux/pci.h>
26#include <linux/init.h>
27#include <linux/blkdev.h>
28#include <linux/delay.h>
29#include <linux/interrupt.h>
30#include <linux/sched.h>
31#include <linux/dma-mapping.h>
32#include "scsi.h"
33#include <scsi/scsi_host.h>
34#include <linux/libata.h>
35#include <asm/io.h>
36
37#define DRV_NAME "sata_mv"
38#define DRV_VERSION "0.12"
39
40enum {
41 /* BAR's are enumerated in terms of pci_resource_start() terms */
42 MV_PRIMARY_BAR = 0, /* offset 0x10: memory space */
43 MV_IO_BAR = 2, /* offset 0x18: IO space */
44 MV_MISC_BAR = 3, /* offset 0x1c: FLASH, NVRAM, SRAM */
45
46 MV_MAJOR_REG_AREA_SZ = 0x10000, /* 64KB */
47 MV_MINOR_REG_AREA_SZ = 0x2000, /* 8KB */
48
49 MV_PCI_REG_BASE = 0,
50 MV_IRQ_COAL_REG_BASE = 0x18000, /* 6xxx part only */
51 MV_SATAHC0_REG_BASE = 0x20000,
52
53 MV_PCI_REG_SZ = MV_MAJOR_REG_AREA_SZ,
54 MV_SATAHC_REG_SZ = MV_MAJOR_REG_AREA_SZ,
55 MV_SATAHC_ARBTR_REG_SZ = MV_MINOR_REG_AREA_SZ, /* arbiter */
56 MV_PORT_REG_SZ = MV_MINOR_REG_AREA_SZ,
57
58 MV_Q_CT = 32,
59 MV_CRQB_SZ = 32,
60 MV_CRPB_SZ = 8,
61
62 MV_DMA_BOUNDARY = 0xffffffffU,
63 SATAHC_MASK = (~(MV_SATAHC_REG_SZ - 1)),
64
65 MV_PORTS_PER_HC = 4,
66 /* == (port / MV_PORTS_PER_HC) to determine HC from 0-7 port */
67 MV_PORT_HC_SHIFT = 2,
68 /* == (port % MV_PORTS_PER_HC) to determine port from 0-7 port */
69 MV_PORT_MASK = 3,
70
71 /* Host Flags */
72 MV_FLAG_DUAL_HC = (1 << 30), /* two SATA Host Controllers */
73 MV_FLAG_IRQ_COALESCE = (1 << 29), /* IRQ coalescing capability */
74 MV_FLAG_BDMA = (1 << 28), /* Basic DMA */
75
76 chip_504x = 0,
77 chip_508x = 1,
78 chip_604x = 2,
79 chip_608x = 3,
80
81 /* PCI interface registers */
82
83 PCI_MAIN_CMD_STS_OFS = 0xd30,
84 STOP_PCI_MASTER = (1 << 2),
85 PCI_MASTER_EMPTY = (1 << 3),
86 GLOB_SFT_RST = (1 << 4),
87
88 PCI_IRQ_CAUSE_OFS = 0x1d58,
89 PCI_IRQ_MASK_OFS = 0x1d5c,
90 PCI_UNMASK_ALL_IRQS = 0x7fffff, /* bits 22-0 */
91
92 HC_MAIN_IRQ_CAUSE_OFS = 0x1d60,
93 HC_MAIN_IRQ_MASK_OFS = 0x1d64,
94 PORT0_ERR = (1 << 0), /* shift by port # */
95 PORT0_DONE = (1 << 1), /* shift by port # */
96 HC0_IRQ_PEND = 0x1ff, /* bits 0-8 = HC0's ports */
97 HC_SHIFT = 9, /* bits 9-17 = HC1's ports */
98 PCI_ERR = (1 << 18),
99 TRAN_LO_DONE = (1 << 19), /* 6xxx: IRQ coalescing */
100 TRAN_HI_DONE = (1 << 20), /* 6xxx: IRQ coalescing */
101 PORTS_0_7_COAL_DONE = (1 << 21), /* 6xxx: IRQ coalescing */
102 GPIO_INT = (1 << 22),
103 SELF_INT = (1 << 23),
104 TWSI_INT = (1 << 24),
105 HC_MAIN_RSVD = (0x7f << 25), /* bits 31-25 */
106 HC_MAIN_MASKED_IRQS = (TRAN_LO_DONE | TRAN_HI_DONE |
107 PORTS_0_7_COAL_DONE | GPIO_INT | TWSI_INT |
108 HC_MAIN_RSVD),
109
110 /* SATAHC registers */
111 HC_CFG_OFS = 0,
112
113 HC_IRQ_CAUSE_OFS = 0x14,
114 CRBP_DMA_DONE = (1 << 0), /* shift by port # */
115 HC_IRQ_COAL = (1 << 4), /* IRQ coalescing */
116 DEV_IRQ = (1 << 8), /* shift by port # */
117
118 /* Shadow block registers */
119 SHD_PIO_DATA_OFS = 0x100,
120 SHD_FEA_ERR_OFS = 0x104,
121 SHD_SECT_CNT_OFS = 0x108,
122 SHD_LBA_L_OFS = 0x10C,
123 SHD_LBA_M_OFS = 0x110,
124 SHD_LBA_H_OFS = 0x114,
125 SHD_DEV_HD_OFS = 0x118,
126 SHD_CMD_STA_OFS = 0x11C,
127 SHD_CTL_AST_OFS = 0x120,
128
129 /* SATA registers */
130 SATA_STATUS_OFS = 0x300, /* ctrl, err regs follow status */
131 SATA_ACTIVE_OFS = 0x350,
132
133 /* Port registers */
134 EDMA_CFG_OFS = 0,
135
136 EDMA_ERR_IRQ_CAUSE_OFS = 0x8,
137 EDMA_ERR_IRQ_MASK_OFS = 0xc,
138 EDMA_ERR_D_PAR = (1 << 0),
139 EDMA_ERR_PRD_PAR = (1 << 1),
140 EDMA_ERR_DEV = (1 << 2),
141 EDMA_ERR_DEV_DCON = (1 << 3),
142 EDMA_ERR_DEV_CON = (1 << 4),
143 EDMA_ERR_SERR = (1 << 5),
144 EDMA_ERR_SELF_DIS = (1 << 7),
145 EDMA_ERR_BIST_ASYNC = (1 << 8),
146 EDMA_ERR_CRBQ_PAR = (1 << 9),
147 EDMA_ERR_CRPB_PAR = (1 << 10),
148 EDMA_ERR_INTRL_PAR = (1 << 11),
149 EDMA_ERR_IORDY = (1 << 12),
150 EDMA_ERR_LNK_CTRL_RX = (0xf << 13),
151 EDMA_ERR_LNK_CTRL_RX_2 = (1 << 15),
152 EDMA_ERR_LNK_DATA_RX = (0xf << 17),
153 EDMA_ERR_LNK_CTRL_TX = (0x1f << 21),
154 EDMA_ERR_LNK_DATA_TX = (0x1f << 26),
155 EDMA_ERR_TRANS_PROTO = (1 << 31),
156 EDMA_ERR_FATAL = (EDMA_ERR_D_PAR | EDMA_ERR_PRD_PAR |
157 EDMA_ERR_DEV_DCON | EDMA_ERR_CRBQ_PAR |
158 EDMA_ERR_CRPB_PAR | EDMA_ERR_INTRL_PAR |
159 EDMA_ERR_IORDY | EDMA_ERR_LNK_CTRL_RX_2 |
160 EDMA_ERR_LNK_DATA_RX |
161 EDMA_ERR_LNK_DATA_TX |
162 EDMA_ERR_TRANS_PROTO),
163
164 EDMA_CMD_OFS = 0x28,
165 EDMA_EN = (1 << 0),
166 EDMA_DS = (1 << 1),
167 ATA_RST = (1 << 2),
168
169 /* BDMA is 6xxx part only */
170 BDMA_CMD_OFS = 0x224,
171 BDMA_START = (1 << 0),
172
173 MV_UNDEF = 0,
174};
175
176struct mv_port_priv {
177
178};
179
180struct mv_host_priv {
181
182};
183
184static void mv_irq_clear(struct ata_port *ap);
185static u32 mv_scr_read(struct ata_port *ap, unsigned int sc_reg_in);
186static void mv_scr_write(struct ata_port *ap, unsigned int sc_reg_in, u32 val);
187static void mv_phy_reset(struct ata_port *ap);
188static int mv_master_reset(void __iomem *mmio_base);
189static irqreturn_t mv_interrupt(int irq, void *dev_instance,
190 struct pt_regs *regs);
191static int mv_init_one(struct pci_dev *pdev, const struct pci_device_id *ent);
192
193static Scsi_Host_Template mv_sht = {
194 .module = THIS_MODULE,
195 .name = DRV_NAME,
196 .ioctl = ata_scsi_ioctl,
197 .queuecommand = ata_scsi_queuecmd,
198 .eh_strategy_handler = ata_scsi_error,
199 .can_queue = ATA_DEF_QUEUE,
200 .this_id = ATA_SHT_THIS_ID,
201 .sg_tablesize = MV_UNDEF,
202 .max_sectors = ATA_MAX_SECTORS,
203 .cmd_per_lun = ATA_SHT_CMD_PER_LUN,
204 .emulated = ATA_SHT_EMULATED,
205 .use_clustering = MV_UNDEF,
206 .proc_name = DRV_NAME,
207 .dma_boundary = MV_DMA_BOUNDARY,
208 .slave_configure = ata_scsi_slave_config,
209 .bios_param = ata_std_bios_param,
210 .ordered_flush = 1,
211};
212
213static struct ata_port_operations mv_ops = {
214 .port_disable = ata_port_disable,
215
216 .tf_load = ata_tf_load,
217 .tf_read = ata_tf_read,
218 .check_status = ata_check_status,
219 .exec_command = ata_exec_command,
220 .dev_select = ata_std_dev_select,
221
222 .phy_reset = mv_phy_reset,
223
224 .qc_prep = ata_qc_prep,
225 .qc_issue = ata_qc_issue_prot,
226
227 .eng_timeout = ata_eng_timeout,
228
229 .irq_handler = mv_interrupt,
230 .irq_clear = mv_irq_clear,
231
232 .scr_read = mv_scr_read,
233 .scr_write = mv_scr_write,
234
235 .port_start = ata_port_start,
236 .port_stop = ata_port_stop,
237 .host_stop = ata_host_stop,
238};
239
240static struct ata_port_info mv_port_info[] = {
241 { /* chip_504x */
242 .sht = &mv_sht,
243 .host_flags = (ATA_FLAG_SATA | ATA_FLAG_NO_LEGACY |
244 ATA_FLAG_SATA_RESET | ATA_FLAG_MMIO),
245 .pio_mask = 0x1f, /* pio4-0 */
246 .udma_mask = 0, /* 0x7f (udma6-0 disabled for now) */
247 .port_ops = &mv_ops,
248 },
249 { /* chip_508x */
250 .sht = &mv_sht,
251 .host_flags = (ATA_FLAG_SATA | ATA_FLAG_NO_LEGACY |
252 ATA_FLAG_SATA_RESET | ATA_FLAG_MMIO |
253 MV_FLAG_DUAL_HC),
254 .pio_mask = 0x1f, /* pio4-0 */
255 .udma_mask = 0, /* 0x7f (udma6-0 disabled for now) */
256 .port_ops = &mv_ops,
257 },
258 { /* chip_604x */
259 .sht = &mv_sht,
260 .host_flags = (ATA_FLAG_SATA | ATA_FLAG_NO_LEGACY |
261 ATA_FLAG_SATA_RESET | ATA_FLAG_MMIO |
262 MV_FLAG_IRQ_COALESCE | MV_FLAG_BDMA),
263 .pio_mask = 0x1f, /* pio4-0 */
264 .udma_mask = 0, /* 0x7f (udma6-0 disabled for now) */
265 .port_ops = &mv_ops,
266 },
267 { /* chip_608x */
268 .sht = &mv_sht,
269 .host_flags = (ATA_FLAG_SATA | ATA_FLAG_NO_LEGACY |
270 ATA_FLAG_SATA_RESET | ATA_FLAG_MMIO |
271 MV_FLAG_IRQ_COALESCE | MV_FLAG_DUAL_HC |
272 MV_FLAG_BDMA),
273 .pio_mask = 0x1f, /* pio4-0 */
274 .udma_mask = 0, /* 0x7f (udma6-0 disabled for now) */
275 .port_ops = &mv_ops,
276 },
277};
278
279static struct pci_device_id mv_pci_tbl[] = {
280 {PCI_DEVICE(PCI_VENDOR_ID_MARVELL, 0x5040), 0, 0, chip_504x},
281 {PCI_DEVICE(PCI_VENDOR_ID_MARVELL, 0x5041), 0, 0, chip_504x},
282 {PCI_DEVICE(PCI_VENDOR_ID_MARVELL, 0x5080), 0, 0, chip_508x},
283 {PCI_DEVICE(PCI_VENDOR_ID_MARVELL, 0x5081), 0, 0, chip_508x},
284
285 {PCI_DEVICE(PCI_VENDOR_ID_MARVELL, 0x6040), 0, 0, chip_604x},
286 {PCI_DEVICE(PCI_VENDOR_ID_MARVELL, 0x6041), 0, 0, chip_604x},
287 {PCI_DEVICE(PCI_VENDOR_ID_MARVELL, 0x6080), 0, 0, chip_608x},
288 {PCI_DEVICE(PCI_VENDOR_ID_MARVELL, 0x6081), 0, 0, chip_608x},
289 {} /* terminate list */
290};
291
292static struct pci_driver mv_pci_driver = {
293 .name = DRV_NAME,
294 .id_table = mv_pci_tbl,
295 .probe = mv_init_one,
296 .remove = ata_pci_remove_one,
297};
298
299/*
300 * Functions
301 */
302
303static inline void writelfl(unsigned long data, void __iomem *addr)
304{
305 writel(data, addr);
306 (void) readl(addr); /* flush to avoid PCI posted write */
307}
308
309static inline void __iomem *mv_port_addr_to_hc_base(void __iomem *port_mmio)
310{
311 return ((void __iomem *)((unsigned long)port_mmio &
312 (unsigned long)SATAHC_MASK));
313}
314
315static inline void __iomem *mv_hc_base(void __iomem *base, unsigned int hc)
316{
317 return (base + MV_SATAHC0_REG_BASE + (hc * MV_SATAHC_REG_SZ));
318}
319
320static inline void __iomem *mv_port_base(void __iomem *base, unsigned int port)
321{
322 return (mv_hc_base(base, port >> MV_PORT_HC_SHIFT) +
323 MV_SATAHC_ARBTR_REG_SZ +
324 ((port & MV_PORT_MASK) * MV_PORT_REG_SZ));
325}
326
327static inline void __iomem *mv_ap_base(struct ata_port *ap)
328{
329 return mv_port_base(ap->host_set->mmio_base, ap->port_no);
330}
331
332static inline int mv_get_hc_count(unsigned long flags)
333{
334 return ((flags & MV_FLAG_DUAL_HC) ? 2 : 1);
335}
336
337static inline int mv_is_edma_active(struct ata_port *ap)
338{
339 void __iomem *port_mmio = mv_ap_base(ap);
340 return (EDMA_EN & readl(port_mmio + EDMA_CMD_OFS));
341}
342
343static inline int mv_port_bdma_capable(struct ata_port *ap)
344{
345 return (ap->flags & MV_FLAG_BDMA);
346}
347
348static void mv_irq_clear(struct ata_port *ap)
349{
350}
351
352static unsigned int mv_scr_offset(unsigned int sc_reg_in)
353{
354 unsigned int ofs;
355
356 switch (sc_reg_in) {
357 case SCR_STATUS:
358 case SCR_CONTROL:
359 case SCR_ERROR:
360 ofs = SATA_STATUS_OFS + (sc_reg_in * sizeof(u32));
361 break;
362 case SCR_ACTIVE:
363 ofs = SATA_ACTIVE_OFS; /* active is not with the others */
364 break;
365 default:
366 ofs = 0xffffffffU;
367 break;
368 }
369 return ofs;
370}
371
372static u32 mv_scr_read(struct ata_port *ap, unsigned int sc_reg_in)
373{
374 unsigned int ofs = mv_scr_offset(sc_reg_in);
375
376 if (0xffffffffU != ofs) {
377 return readl(mv_ap_base(ap) + ofs);
378 } else {
379 return (u32) ofs;
380 }
381}
382
383static void mv_scr_write(struct ata_port *ap, unsigned int sc_reg_in, u32 val)
384{
385 unsigned int ofs = mv_scr_offset(sc_reg_in);
386
387 if (0xffffffffU != ofs) {
388 writelfl(val, mv_ap_base(ap) + ofs);
389 }
390}
391
392static int mv_master_reset(void __iomem *mmio_base)
393{
394 void __iomem *reg = mmio_base + PCI_MAIN_CMD_STS_OFS;
395 int i, rc = 0;
396 u32 t;
397
398 VPRINTK("ENTER\n");
399
400 /* Following procedure defined in PCI "main command and status
401 * register" table.
402 */
403 t = readl(reg);
404 writel(t | STOP_PCI_MASTER, reg);
405
406 for (i = 0; i < 100; i++) {
407 msleep(10);
408 t = readl(reg);
409 if (PCI_MASTER_EMPTY & t) {
410 break;
411 }
412 }
413 if (!(PCI_MASTER_EMPTY & t)) {
414 printk(KERN_ERR DRV_NAME "PCI master won't flush\n");
415 rc = 1; /* broken HW? */
416 goto done;
417 }
418
419 /* set reset */
420 i = 5;
421 do {
422 writel(t | GLOB_SFT_RST, reg);
423 t = readl(reg);
424 udelay(1);
425 } while (!(GLOB_SFT_RST & t) && (i-- > 0));
426
427 if (!(GLOB_SFT_RST & t)) {
428 printk(KERN_ERR DRV_NAME "can't set global reset\n");
429 rc = 1; /* broken HW? */
430 goto done;
431 }
432
433 /* clear reset */
434 i = 5;
435 do {
436 writel(t & ~GLOB_SFT_RST, reg);
437 t = readl(reg);
438 udelay(1);
439 } while ((GLOB_SFT_RST & t) && (i-- > 0));
440
441 if (GLOB_SFT_RST & t) {
442 printk(KERN_ERR DRV_NAME "can't clear global reset\n");
443 rc = 1; /* broken HW? */
444 }
445
446 done:
447 VPRINTK("EXIT, rc = %i\n", rc);
448 return rc;
449}
450
451static void mv_err_intr(struct ata_port *ap)
452{
453 void __iomem *port_mmio;
454 u32 edma_err_cause, serr = 0;
455
456 /* bug here b/c we got an err int on a port we don't know about,
457 * so there's no way to clear it
458 */
459 BUG_ON(NULL == ap);
460 port_mmio = mv_ap_base(ap);
461
462 edma_err_cause = readl(port_mmio + EDMA_ERR_IRQ_CAUSE_OFS);
463
464 if (EDMA_ERR_SERR & edma_err_cause) {
465 serr = scr_read(ap, SCR_ERROR);
466 scr_write_flush(ap, SCR_ERROR, serr);
467 }
468 DPRINTK("port %u error; EDMA err cause: 0x%08x SERR: 0x%08x\n",
469 ap->port_no, edma_err_cause, serr);
470
471 /* Clear EDMA now that SERR cleanup done */
472 writelfl(0, port_mmio + EDMA_ERR_IRQ_CAUSE_OFS);
473
474 /* check for fatal here and recover if needed */
475 if (EDMA_ERR_FATAL & edma_err_cause) {
476 mv_phy_reset(ap);
477 }
478}
479
480/* Handle any outstanding interrupts in a single SATAHC
481 */
482static void mv_host_intr(struct ata_host_set *host_set, u32 relevant,
483 unsigned int hc)
484{
485 void __iomem *mmio = host_set->mmio_base;
486 void __iomem *hc_mmio = mv_hc_base(mmio, hc);
487 struct ata_port *ap;
488 struct ata_queued_cmd *qc;
489 u32 hc_irq_cause;
490 int shift, port, port0, hard_port;
491 u8 ata_status;
492
493 if (hc == 0) {
494 port0 = 0;
495 } else {
496 port0 = MV_PORTS_PER_HC;
497 }
498
499 /* we'll need the HC success int register in most cases */
500 hc_irq_cause = readl(hc_mmio + HC_IRQ_CAUSE_OFS);
501 if (hc_irq_cause) {
502 writelfl(0, hc_mmio + HC_IRQ_CAUSE_OFS);
503 }
504
505 VPRINTK("ENTER, hc%u relevant=0x%08x HC IRQ cause=0x%08x\n",
506 hc,relevant,hc_irq_cause);
507
508 for (port = port0; port < port0 + MV_PORTS_PER_HC; port++) {
509 ap = host_set->ports[port];
510 hard_port = port & MV_PORT_MASK; /* range 0-3 */
511 ata_status = 0xffU;
512
513 if (((CRBP_DMA_DONE | DEV_IRQ) << hard_port) & hc_irq_cause) {
514 BUG_ON(NULL == ap);
515 /* rcv'd new resp, basic DMA complete, or ATA IRQ */
516 /* This is needed to clear the ATA INTRQ.
517 * FIXME: don't read the status reg in EDMA mode!
518 */
519 ata_status = readb((void __iomem *)
520 ap->ioaddr.status_addr);
521 }
522
523 shift = port * 2;
524 if (port >= MV_PORTS_PER_HC) {
525 shift++; /* skip bit 8 in the HC Main IRQ reg */
526 }
527 if ((PORT0_ERR << shift) & relevant) {
528 mv_err_intr(ap);
529 /* FIXME: smart to OR in ATA_ERR? */
530 ata_status = readb((void __iomem *)
531 ap->ioaddr.status_addr) | ATA_ERR;
532 }
533
534 if (ap) {
535 qc = ata_qc_from_tag(ap, ap->active_tag);
536 if (NULL != qc) {
537 VPRINTK("port %u IRQ found for qc, "
538 "ata_status 0x%x\n", port,ata_status);
539 BUG_ON(0xffU == ata_status);
540 /* mark qc status appropriately */
541 ata_qc_complete(qc, ata_status);
542 }
543 }
544 }
545 VPRINTK("EXIT\n");
546}
547
548static irqreturn_t mv_interrupt(int irq, void *dev_instance,
549 struct pt_regs *regs)
550{
551 struct ata_host_set *host_set = dev_instance;
552 unsigned int hc, handled = 0, n_hcs;
553 void __iomem *mmio;
554 u32 irq_stat;
555
556 mmio = host_set->mmio_base;
557 irq_stat = readl(mmio + HC_MAIN_IRQ_CAUSE_OFS);
558 n_hcs = mv_get_hc_count(host_set->ports[0]->flags);
559
560 /* check the cases where we either have nothing pending or have read
561 * a bogus register value which can indicate HW removal or PCI fault
562 */
563 if (!irq_stat || (0xffffffffU == irq_stat)) {
564 return IRQ_NONE;
565 }
566
567 spin_lock(&host_set->lock);
568
569 for (hc = 0; hc < n_hcs; hc++) {
570 u32 relevant = irq_stat & (HC0_IRQ_PEND << (hc * HC_SHIFT));
571 if (relevant) {
572 mv_host_intr(host_set, relevant, hc);
573 handled = 1;
574 }
575 }
576 if (PCI_ERR & irq_stat) {
577 /* FIXME: these are all masked by default, but still need
578 * to recover from them properly.
579 */
580 }
581
582 spin_unlock(&host_set->lock);
583
584 return IRQ_RETVAL(handled);
585}
586
587static void mv_phy_reset(struct ata_port *ap)
588{
589 void __iomem *port_mmio = mv_ap_base(ap);
590 struct ata_taskfile tf;
591 struct ata_device *dev = &ap->device[0];
592 u32 edma = 0, bdma;
593
594 VPRINTK("ENTER, port %u, mmio 0x%p\n", ap->port_no, port_mmio);
595
596 edma = readl(port_mmio + EDMA_CMD_OFS);
597 if (EDMA_EN & edma) {
598 /* disable EDMA if active */
599 edma &= ~EDMA_EN;
600 writelfl(edma | EDMA_DS, port_mmio + EDMA_CMD_OFS);
601 udelay(1);
602 } else if (mv_port_bdma_capable(ap) &&
603 (bdma = readl(port_mmio + BDMA_CMD_OFS)) & BDMA_START) {
604 /* disable BDMA if active */
605 writelfl(bdma & ~BDMA_START, port_mmio + BDMA_CMD_OFS);
606 }
607
608 writelfl(edma | ATA_RST, port_mmio + EDMA_CMD_OFS);
609 udelay(25); /* allow reset propagation */
610
611 /* Spec never mentions clearing the bit. Marvell's driver does
612 * clear the bit, however.
613 */
614 writelfl(edma & ~ATA_RST, port_mmio + EDMA_CMD_OFS);
615
616 VPRINTK("Done. Now calling __sata_phy_reset()\n");
617
618 /* proceed to init communications via the scr_control reg */
619 __sata_phy_reset(ap);
620
621 if (ap->flags & ATA_FLAG_PORT_DISABLED) {
622 VPRINTK("Port disabled pre-sig. Exiting.\n");
623 return;
624 }
625
626 tf.lbah = readb((void __iomem *) ap->ioaddr.lbah_addr);
627 tf.lbam = readb((void __iomem *) ap->ioaddr.lbam_addr);
628 tf.lbal = readb((void __iomem *) ap->ioaddr.lbal_addr);
629 tf.nsect = readb((void __iomem *) ap->ioaddr.nsect_addr);
630
631 dev->class = ata_dev_classify(&tf);
632 if (!ata_dev_present(dev)) {
633 VPRINTK("Port disabled post-sig: No device present.\n");
634 ata_port_disable(ap);
635 }
636 VPRINTK("EXIT\n");
637}
638
639static void mv_port_init(struct ata_ioports *port, unsigned long base)
640{
641 /* PIO related setup */
642 port->data_addr = base + SHD_PIO_DATA_OFS;
643 port->error_addr = port->feature_addr = base + SHD_FEA_ERR_OFS;
644 port->nsect_addr = base + SHD_SECT_CNT_OFS;
645 port->lbal_addr = base + SHD_LBA_L_OFS;
646 port->lbam_addr = base + SHD_LBA_M_OFS;
647 port->lbah_addr = base + SHD_LBA_H_OFS;
648 port->device_addr = base + SHD_DEV_HD_OFS;
649 port->status_addr = port->command_addr = base + SHD_CMD_STA_OFS;
650 port->altstatus_addr = port->ctl_addr = base + SHD_CTL_AST_OFS;
651 /* unused */
652 port->cmd_addr = port->bmdma_addr = port->scr_addr = 0;
653
654 /* unmask all EDMA error interrupts */
655 writel(~0, (void __iomem *)base + EDMA_ERR_IRQ_MASK_OFS);
656
657 VPRINTK("EDMA cfg=0x%08x EDMA IRQ err cause/mask=0x%08x/0x%08x\n",
658 readl((void __iomem *)base + EDMA_CFG_OFS),
659 readl((void __iomem *)base + EDMA_ERR_IRQ_CAUSE_OFS),
660 readl((void __iomem *)base + EDMA_ERR_IRQ_MASK_OFS));
661}
662
663static int mv_host_init(struct ata_probe_ent *probe_ent)
664{
665 int rc = 0, n_hc, port, hc;
666 void __iomem *mmio = probe_ent->mmio_base;
667 void __iomem *port_mmio;
668
669 if (mv_master_reset(probe_ent->mmio_base)) {
670 rc = 1;
671 goto done;
672 }
673
674 n_hc = mv_get_hc_count(probe_ent->host_flags);
675 probe_ent->n_ports = MV_PORTS_PER_HC * n_hc;
676
677 for (port = 0; port < probe_ent->n_ports; port++) {
678 port_mmio = mv_port_base(mmio, port);
679 mv_port_init(&probe_ent->port[port], (unsigned long)port_mmio);
680 }
681
682 for (hc = 0; hc < n_hc; hc++) {
683 VPRINTK("HC%i: HC config=0x%08x HC IRQ cause=0x%08x\n", hc,
684 readl(mv_hc_base(mmio, hc) + HC_CFG_OFS),
685 readl(mv_hc_base(mmio, hc) + HC_IRQ_CAUSE_OFS));
686 }
687
688 writel(~HC_MAIN_MASKED_IRQS, mmio + HC_MAIN_IRQ_MASK_OFS);
689 writel(PCI_UNMASK_ALL_IRQS, mmio + PCI_IRQ_MASK_OFS);
690
691 VPRINTK("HC MAIN IRQ cause/mask=0x%08x/0x%08x "
692 "PCI int cause/mask=0x%08x/0x%08x\n",
693 readl(mmio + HC_MAIN_IRQ_CAUSE_OFS),
694 readl(mmio + HC_MAIN_IRQ_MASK_OFS),
695 readl(mmio + PCI_IRQ_CAUSE_OFS),
696 readl(mmio + PCI_IRQ_MASK_OFS));
697
698 done:
699 return rc;
700}
701
702/* move to PCI layer, integrate w/ MSI stuff */
703static void pci_intx(struct pci_dev *pdev, int enable)
704{
705 u16 pci_command, new;
706
707 pci_read_config_word(pdev, PCI_COMMAND, &pci_command);
708
709 if (enable)
710 new = pci_command & ~PCI_COMMAND_INTX_DISABLE;
711 else
712 new = pci_command | PCI_COMMAND_INTX_DISABLE;
713
714 if (new != pci_command)
715 pci_write_config_word(pdev, PCI_COMMAND, pci_command);
716}
717
718static int mv_init_one(struct pci_dev *pdev, const struct pci_device_id *ent)
719{
720 static int printed_version = 0;
721 struct ata_probe_ent *probe_ent = NULL;
722 struct mv_host_priv *hpriv;
723 unsigned int board_idx = (unsigned int)ent->driver_data;
724 void __iomem *mmio_base;
725 int pci_dev_busy = 0;
726 int rc;
727
728 if (!printed_version++) {
729 printk(KERN_DEBUG DRV_NAME " version " DRV_VERSION "\n");
730 }
731
732 VPRINTK("ENTER for PCI Bus:Slot.Func=%u:%u.%u\n", pdev->bus->number,
733 PCI_SLOT(pdev->devfn), PCI_FUNC(pdev->devfn));
734
735 rc = pci_enable_device(pdev);
736 if (rc) {
737 return rc;
738 }
739
740 rc = pci_request_regions(pdev, DRV_NAME);
741 if (rc) {
742 pci_dev_busy = 1;
743 goto err_out;
744 }
745
746 pci_intx(pdev, 1);
747
748 probe_ent = kmalloc(sizeof(*probe_ent), GFP_KERNEL);
749 if (probe_ent == NULL) {
750 rc = -ENOMEM;
751 goto err_out_regions;
752 }
753
754 memset(probe_ent, 0, sizeof(*probe_ent));
755 probe_ent->dev = pci_dev_to_dev(pdev);
756 INIT_LIST_HEAD(&probe_ent->node);
757
758 mmio_base = ioremap_nocache(pci_resource_start(pdev, MV_PRIMARY_BAR),
759 pci_resource_len(pdev, MV_PRIMARY_BAR));
760 if (mmio_base == NULL) {
761 rc = -ENOMEM;
762 goto err_out_free_ent;
763 }
764
765 hpriv = kmalloc(sizeof(*hpriv), GFP_KERNEL);
766 if (!hpriv) {
767 rc = -ENOMEM;
768 goto err_out_iounmap;
769 }
770 memset(hpriv, 0, sizeof(*hpriv));
771
772 probe_ent->sht = mv_port_info[board_idx].sht;
773 probe_ent->host_flags = mv_port_info[board_idx].host_flags;
774 probe_ent->pio_mask = mv_port_info[board_idx].pio_mask;
775 probe_ent->udma_mask = mv_port_info[board_idx].udma_mask;
776 probe_ent->port_ops = mv_port_info[board_idx].port_ops;
777
778 probe_ent->irq = pdev->irq;
779 probe_ent->irq_flags = SA_SHIRQ;
780 probe_ent->mmio_base = mmio_base;
781 probe_ent->private_data = hpriv;
782
783 /* initialize adapter */
784 rc = mv_host_init(probe_ent);
785 if (rc) {
786 goto err_out_hpriv;
787 }
788/* mv_print_info(probe_ent); */
789
790 {
791 int b, w;
792 u32 dw[4]; /* hold a line of 16b */
793 VPRINTK("PCI config space:\n");
794 for (b = 0; b < 0x40; ) {
795 for (w = 0; w < 4; w++) {
796 (void) pci_read_config_dword(pdev,b,&dw[w]);
797 b += sizeof(*dw);
798 }
799 VPRINTK("%08x %08x %08x %08x\n",
800 dw[0],dw[1],dw[2],dw[3]);
801 }
802 }
803
804 /* FIXME: check ata_device_add return value */
805 ata_device_add(probe_ent);
806 kfree(probe_ent);
807
808 return 0;
809
810 err_out_hpriv:
811 kfree(hpriv);
812 err_out_iounmap:
813 iounmap(mmio_base);
814 err_out_free_ent:
815 kfree(probe_ent);
816 err_out_regions:
817 pci_release_regions(pdev);
818 err_out:
819 if (!pci_dev_busy) {
820 pci_disable_device(pdev);
821 }
822
823 return rc;
824}
825
826static int __init mv_init(void)
827{
828 return pci_module_init(&mv_pci_driver);
829}
830
831static void __exit mv_exit(void)
832{
833 pci_unregister_driver(&mv_pci_driver);
834}
835
836MODULE_AUTHOR("Brett Russ");
837MODULE_DESCRIPTION("SCSI low-level driver for Marvell SATA controllers");
838MODULE_LICENSE("GPL");
839MODULE_DEVICE_TABLE(pci, mv_pci_tbl);
840MODULE_VERSION(DRV_VERSION);
841
842module_init(mv_init);
843module_exit(mv_exit);
diff --git a/drivers/scsi/sata_nv.c b/drivers/scsi/sata_nv.c
index 03d9bc6e69d..a1d62dee3be 100644
--- a/drivers/scsi/sata_nv.c
+++ b/drivers/scsi/sata_nv.c
@@ -351,6 +351,7 @@ static void nv_scr_write (struct ata_port *ap, unsigned int sc_reg, u32 val)
351static void nv_host_stop (struct ata_host_set *host_set) 351static void nv_host_stop (struct ata_host_set *host_set)
352{ 352{
353 struct nv_host *host = host_set->private_data; 353 struct nv_host *host = host_set->private_data;
354 struct pci_dev *pdev = to_pci_dev(host_set->dev);
354 355
355 // Disable hotplug event interrupts. 356 // Disable hotplug event interrupts.
356 if (host->host_desc->disable_hotplug) 357 if (host->host_desc->disable_hotplug)
@@ -358,7 +359,8 @@ static void nv_host_stop (struct ata_host_set *host_set)
358 359
359 kfree(host); 360 kfree(host);
360 361
361 ata_host_stop(host_set); 362 if (host_set->mmio_base)
363 pci_iounmap(pdev, host_set->mmio_base);
362} 364}
363 365
364static int nv_init_one (struct pci_dev *pdev, const struct pci_device_id *ent) 366static int nv_init_one (struct pci_dev *pdev, const struct pci_device_id *ent)
@@ -420,8 +422,7 @@ static int nv_init_one (struct pci_dev *pdev, const struct pci_device_id *ent)
420 if (host->host_flags & NV_HOST_FLAGS_SCR_MMIO) { 422 if (host->host_flags & NV_HOST_FLAGS_SCR_MMIO) {
421 unsigned long base; 423 unsigned long base;
422 424
423 probe_ent->mmio_base = ioremap(pci_resource_start(pdev, 5), 425 probe_ent->mmio_base = pci_iomap(pdev, 5, 0);
424 pci_resource_len(pdev, 5));
425 if (probe_ent->mmio_base == NULL) { 426 if (probe_ent->mmio_base == NULL) {
426 rc = -EIO; 427 rc = -EIO;
427 goto err_out_free_host; 428 goto err_out_free_host;
@@ -457,7 +458,7 @@ static int nv_init_one (struct pci_dev *pdev, const struct pci_device_id *ent)
457 458
458err_out_iounmap: 459err_out_iounmap:
459 if (host->host_flags & NV_HOST_FLAGS_SCR_MMIO) 460 if (host->host_flags & NV_HOST_FLAGS_SCR_MMIO)
460 iounmap(probe_ent->mmio_base); 461 pci_iounmap(pdev, probe_ent->mmio_base);
461err_out_free_host: 462err_out_free_host:
462 kfree(host); 463 kfree(host);
463err_out_free_ent: 464err_out_free_ent:
diff --git a/drivers/scsi/sata_promise.c b/drivers/scsi/sata_promise.c
index 7c4f6ecc1cc..538ad727bd2 100644
--- a/drivers/scsi/sata_promise.c
+++ b/drivers/scsi/sata_promise.c
@@ -92,6 +92,7 @@ static void pdc_exec_command_mmio(struct ata_port *ap, struct ata_taskfile *tf);
92static void pdc_irq_clear(struct ata_port *ap); 92static void pdc_irq_clear(struct ata_port *ap);
93static int pdc_qc_issue_prot(struct ata_queued_cmd *qc); 93static int pdc_qc_issue_prot(struct ata_queued_cmd *qc);
94 94
95
95static Scsi_Host_Template pdc_ata_sht = { 96static Scsi_Host_Template pdc_ata_sht = {
96 .module = THIS_MODULE, 97 .module = THIS_MODULE,
97 .name = DRV_NAME, 98 .name = DRV_NAME,
@@ -132,7 +133,7 @@ static struct ata_port_operations pdc_sata_ops = {
132 .scr_write = pdc_sata_scr_write, 133 .scr_write = pdc_sata_scr_write,
133 .port_start = pdc_port_start, 134 .port_start = pdc_port_start,
134 .port_stop = pdc_port_stop, 135 .port_stop = pdc_port_stop,
135 .host_stop = ata_host_stop, 136 .host_stop = ata_pci_host_stop,
136}; 137};
137 138
138static struct ata_port_operations pdc_pata_ops = { 139static struct ata_port_operations pdc_pata_ops = {
@@ -153,7 +154,7 @@ static struct ata_port_operations pdc_pata_ops = {
153 154
154 .port_start = pdc_port_start, 155 .port_start = pdc_port_start,
155 .port_stop = pdc_port_stop, 156 .port_stop = pdc_port_stop,
156 .host_stop = ata_host_stop, 157 .host_stop = ata_pci_host_stop,
157}; 158};
158 159
159static struct ata_port_info pdc_port_info[] = { 160static struct ata_port_info pdc_port_info[] = {
@@ -282,7 +283,7 @@ static void pdc_port_stop(struct ata_port *ap)
282 283
283static void pdc_reset_port(struct ata_port *ap) 284static void pdc_reset_port(struct ata_port *ap)
284{ 285{
285 void *mmio = (void *) ap->ioaddr.cmd_addr + PDC_CTLSTAT; 286 void __iomem *mmio = (void __iomem *) ap->ioaddr.cmd_addr + PDC_CTLSTAT;
286 unsigned int i; 287 unsigned int i;
287 u32 tmp; 288 u32 tmp;
288 289
@@ -418,7 +419,7 @@ static inline unsigned int pdc_host_intr( struct ata_port *ap,
418 u8 status; 419 u8 status;
419 unsigned int handled = 0, have_err = 0; 420 unsigned int handled = 0, have_err = 0;
420 u32 tmp; 421 u32 tmp;
421 void *mmio = (void *) ap->ioaddr.cmd_addr + PDC_GLOBAL_CTL; 422 void __iomem *mmio = (void __iomem *) ap->ioaddr.cmd_addr + PDC_GLOBAL_CTL;
422 423
423 tmp = readl(mmio); 424 tmp = readl(mmio);
424 if (tmp & PDC_ERR_MASK) { 425 if (tmp & PDC_ERR_MASK) {
@@ -447,7 +448,7 @@ static inline unsigned int pdc_host_intr( struct ata_port *ap,
447static void pdc_irq_clear(struct ata_port *ap) 448static void pdc_irq_clear(struct ata_port *ap)
448{ 449{
449 struct ata_host_set *host_set = ap->host_set; 450 struct ata_host_set *host_set = ap->host_set;
450 void *mmio = host_set->mmio_base; 451 void __iomem *mmio = host_set->mmio_base;
451 452
452 readl(mmio + PDC_INT_SEQMASK); 453 readl(mmio + PDC_INT_SEQMASK);
453} 454}
@@ -459,7 +460,7 @@ static irqreturn_t pdc_interrupt (int irq, void *dev_instance, struct pt_regs *r
459 u32 mask = 0; 460 u32 mask = 0;
460 unsigned int i, tmp; 461 unsigned int i, tmp;
461 unsigned int handled = 0; 462 unsigned int handled = 0;
462 void *mmio_base; 463 void __iomem *mmio_base;
463 464
464 VPRINTK("ENTER\n"); 465 VPRINTK("ENTER\n");
465 466
@@ -581,7 +582,7 @@ static void pdc_ata_setup_port(struct ata_ioports *port, unsigned long base)
581 582
582static void pdc_host_init(unsigned int chip_id, struct ata_probe_ent *pe) 583static void pdc_host_init(unsigned int chip_id, struct ata_probe_ent *pe)
583{ 584{
584 void *mmio = pe->mmio_base; 585 void __iomem *mmio = pe->mmio_base;
585 u32 tmp; 586 u32 tmp;
586 587
587 /* 588 /*
@@ -624,7 +625,7 @@ static int pdc_ata_init_one (struct pci_dev *pdev, const struct pci_device_id *e
624 static int printed_version; 625 static int printed_version;
625 struct ata_probe_ent *probe_ent = NULL; 626 struct ata_probe_ent *probe_ent = NULL;
626 unsigned long base; 627 unsigned long base;
627 void *mmio_base; 628 void __iomem *mmio_base;
628 unsigned int board_idx = (unsigned int) ent->driver_data; 629 unsigned int board_idx = (unsigned int) ent->driver_data;
629 int pci_dev_busy = 0; 630 int pci_dev_busy = 0;
630 int rc; 631 int rc;
@@ -663,8 +664,7 @@ static int pdc_ata_init_one (struct pci_dev *pdev, const struct pci_device_id *e
663 probe_ent->dev = pci_dev_to_dev(pdev); 664 probe_ent->dev = pci_dev_to_dev(pdev);
664 INIT_LIST_HEAD(&probe_ent->node); 665 INIT_LIST_HEAD(&probe_ent->node);
665 666
666 mmio_base = ioremap(pci_resource_start(pdev, 3), 667 mmio_base = pci_iomap(pdev, 3, 0);
667 pci_resource_len(pdev, 3));
668 if (mmio_base == NULL) { 668 if (mmio_base == NULL) {
669 rc = -ENOMEM; 669 rc = -ENOMEM;
670 goto err_out_free_ent; 670 goto err_out_free_ent;
diff --git a/drivers/scsi/sata_qstor.c b/drivers/scsi/sata_qstor.c
index 9c99ab433bd..ffcdeb68641 100644
--- a/drivers/scsi/sata_qstor.c
+++ b/drivers/scsi/sata_qstor.c
@@ -494,7 +494,7 @@ static int qs_port_start(struct ata_port *ap)
494 if (rc) 494 if (rc)
495 return rc; 495 return rc;
496 qs_enter_reg_mode(ap); 496 qs_enter_reg_mode(ap);
497 pp = kcalloc(1, sizeof(*pp), GFP_KERNEL); 497 pp = kzalloc(sizeof(*pp), GFP_KERNEL);
498 if (!pp) { 498 if (!pp) {
499 rc = -ENOMEM; 499 rc = -ENOMEM;
500 goto err_out; 500 goto err_out;
@@ -538,11 +538,12 @@ static void qs_port_stop(struct ata_port *ap)
538static void qs_host_stop(struct ata_host_set *host_set) 538static void qs_host_stop(struct ata_host_set *host_set)
539{ 539{
540 void __iomem *mmio_base = host_set->mmio_base; 540 void __iomem *mmio_base = host_set->mmio_base;
541 struct pci_dev *pdev = to_pci_dev(host_set->dev);
541 542
542 writeb(0, mmio_base + QS_HCT_CTRL); /* disable host interrupts */ 543 writeb(0, mmio_base + QS_HCT_CTRL); /* disable host interrupts */
543 writeb(QS_CNFG3_GSRST, mmio_base + QS_HCF_CNFG3); /* global reset */ 544 writeb(QS_CNFG3_GSRST, mmio_base + QS_HCF_CNFG3); /* global reset */
544 545
545 ata_host_stop(host_set); 546 pci_iounmap(pdev, mmio_base);
546} 547}
547 548
548static void qs_host_init(unsigned int chip_id, struct ata_probe_ent *pe) 549static void qs_host_init(unsigned int chip_id, struct ata_probe_ent *pe)
@@ -646,8 +647,7 @@ static int qs_ata_init_one(struct pci_dev *pdev,
646 goto err_out_regions; 647 goto err_out_regions;
647 } 648 }
648 649
649 mmio_base = ioremap(pci_resource_start(pdev, 4), 650 mmio_base = pci_iomap(pdev, 4, 0);
650 pci_resource_len(pdev, 4));
651 if (mmio_base == NULL) { 651 if (mmio_base == NULL) {
652 rc = -ENOMEM; 652 rc = -ENOMEM;
653 goto err_out_regions; 653 goto err_out_regions;
@@ -697,7 +697,7 @@ static int qs_ata_init_one(struct pci_dev *pdev,
697 return 0; 697 return 0;
698 698
699err_out_iounmap: 699err_out_iounmap:
700 iounmap(mmio_base); 700 pci_iounmap(pdev, mmio_base);
701err_out_regions: 701err_out_regions:
702 pci_release_regions(pdev); 702 pci_release_regions(pdev);
703err_out: 703err_out:
diff --git a/drivers/scsi/sata_sil.c b/drivers/scsi/sata_sil.c
index 71d49548f0a..ba98a175ee3 100644
--- a/drivers/scsi/sata_sil.c
+++ b/drivers/scsi/sata_sil.c
@@ -86,6 +86,7 @@ static u32 sil_scr_read (struct ata_port *ap, unsigned int sc_reg);
86static void sil_scr_write (struct ata_port *ap, unsigned int sc_reg, u32 val); 86static void sil_scr_write (struct ata_port *ap, unsigned int sc_reg, u32 val);
87static void sil_post_set_mode (struct ata_port *ap); 87static void sil_post_set_mode (struct ata_port *ap);
88 88
89
89static struct pci_device_id sil_pci_tbl[] = { 90static struct pci_device_id sil_pci_tbl[] = {
90 { 0x1095, 0x3112, PCI_ANY_ID, PCI_ANY_ID, 0, 0, sil_3112_m15w }, 91 { 0x1095, 0x3112, PCI_ANY_ID, PCI_ANY_ID, 0, 0, sil_3112_m15w },
91 { 0x1095, 0x0240, PCI_ANY_ID, PCI_ANY_ID, 0, 0, sil_3112_m15w }, 92 { 0x1095, 0x0240, PCI_ANY_ID, PCI_ANY_ID, 0, 0, sil_3112_m15w },
@@ -172,7 +173,7 @@ static struct ata_port_operations sil_ops = {
172 .scr_write = sil_scr_write, 173 .scr_write = sil_scr_write,
173 .port_start = ata_port_start, 174 .port_start = ata_port_start,
174 .port_stop = ata_port_stop, 175 .port_stop = ata_port_stop,
175 .host_stop = ata_host_stop, 176 .host_stop = ata_pci_host_stop,
176}; 177};
177 178
178static struct ata_port_info sil_port_info[] = { 179static struct ata_port_info sil_port_info[] = {
@@ -231,6 +232,7 @@ MODULE_LICENSE("GPL");
231MODULE_DEVICE_TABLE(pci, sil_pci_tbl); 232MODULE_DEVICE_TABLE(pci, sil_pci_tbl);
232MODULE_VERSION(DRV_VERSION); 233MODULE_VERSION(DRV_VERSION);
233 234
235
234static unsigned char sil_get_device_cache_line(struct pci_dev *pdev) 236static unsigned char sil_get_device_cache_line(struct pci_dev *pdev)
235{ 237{
236 u8 cache_line = 0; 238 u8 cache_line = 0;
@@ -242,7 +244,8 @@ static void sil_post_set_mode (struct ata_port *ap)
242{ 244{
243 struct ata_host_set *host_set = ap->host_set; 245 struct ata_host_set *host_set = ap->host_set;
244 struct ata_device *dev; 246 struct ata_device *dev;
245 void *addr = host_set->mmio_base + sil_port[ap->port_no].xfer_mode; 247 void __iomem *addr =
248 host_set->mmio_base + sil_port[ap->port_no].xfer_mode;
246 u32 tmp, dev_mode[2]; 249 u32 tmp, dev_mode[2];
247 unsigned int i; 250 unsigned int i;
248 251
@@ -375,7 +378,7 @@ static int sil_init_one (struct pci_dev *pdev, const struct pci_device_id *ent)
375 static int printed_version; 378 static int printed_version;
376 struct ata_probe_ent *probe_ent = NULL; 379 struct ata_probe_ent *probe_ent = NULL;
377 unsigned long base; 380 unsigned long base;
378 void *mmio_base; 381 void __iomem *mmio_base;
379 int rc; 382 int rc;
380 unsigned int i; 383 unsigned int i;
381 int pci_dev_busy = 0; 384 int pci_dev_busy = 0;
@@ -425,8 +428,7 @@ static int sil_init_one (struct pci_dev *pdev, const struct pci_device_id *ent)
425 probe_ent->irq_flags = SA_SHIRQ; 428 probe_ent->irq_flags = SA_SHIRQ;
426 probe_ent->host_flags = sil_port_info[ent->driver_data].host_flags; 429 probe_ent->host_flags = sil_port_info[ent->driver_data].host_flags;
427 430
428 mmio_base = ioremap(pci_resource_start(pdev, 5), 431 mmio_base = pci_iomap(pdev, 5, 0);
429 pci_resource_len(pdev, 5));
430 if (mmio_base == NULL) { 432 if (mmio_base == NULL) {
431 rc = -ENOMEM; 433 rc = -ENOMEM;
432 goto err_out_free_ent; 434 goto err_out_free_ent;
diff --git a/drivers/scsi/sata_svw.c b/drivers/scsi/sata_svw.c
index 19d3bb3b0fb..d89d968beda 100644
--- a/drivers/scsi/sata_svw.c
+++ b/drivers/scsi/sata_svw.c
@@ -318,7 +318,7 @@ static struct ata_port_operations k2_sata_ops = {
318 .scr_write = k2_sata_scr_write, 318 .scr_write = k2_sata_scr_write,
319 .port_start = ata_port_start, 319 .port_start = ata_port_start,
320 .port_stop = ata_port_stop, 320 .port_stop = ata_port_stop,
321 .host_stop = ata_host_stop, 321 .host_stop = ata_pci_host_stop,
322}; 322};
323 323
324static void k2_sata_setup_port(struct ata_ioports *port, unsigned long base) 324static void k2_sata_setup_port(struct ata_ioports *port, unsigned long base)
@@ -346,7 +346,7 @@ static int k2_sata_init_one (struct pci_dev *pdev, const struct pci_device_id *e
346 static int printed_version; 346 static int printed_version;
347 struct ata_probe_ent *probe_ent = NULL; 347 struct ata_probe_ent *probe_ent = NULL;
348 unsigned long base; 348 unsigned long base;
349 void *mmio_base; 349 void __iomem *mmio_base;
350 int pci_dev_busy = 0; 350 int pci_dev_busy = 0;
351 int rc; 351 int rc;
352 int i; 352 int i;
@@ -392,8 +392,7 @@ static int k2_sata_init_one (struct pci_dev *pdev, const struct pci_device_id *e
392 probe_ent->dev = pci_dev_to_dev(pdev); 392 probe_ent->dev = pci_dev_to_dev(pdev);
393 INIT_LIST_HEAD(&probe_ent->node); 393 INIT_LIST_HEAD(&probe_ent->node);
394 394
395 mmio_base = ioremap(pci_resource_start(pdev, 5), 395 mmio_base = pci_iomap(pdev, 5, 0);
396 pci_resource_len(pdev, 5));
397 if (mmio_base == NULL) { 396 if (mmio_base == NULL) {
398 rc = -ENOMEM; 397 rc = -ENOMEM;
399 goto err_out_free_ent; 398 goto err_out_free_ent;
diff --git a/drivers/scsi/sata_sx4.c b/drivers/scsi/sata_sx4.c
index c72fcc46f0f..540a8519117 100644
--- a/drivers/scsi/sata_sx4.c
+++ b/drivers/scsi/sata_sx4.c
@@ -245,13 +245,14 @@ static struct pci_driver pdc_sata_pci_driver = {
245 245
246static void pdc20621_host_stop(struct ata_host_set *host_set) 246static void pdc20621_host_stop(struct ata_host_set *host_set)
247{ 247{
248 struct pci_dev *pdev = to_pci_dev(host_set->dev);
248 struct pdc_host_priv *hpriv = host_set->private_data; 249 struct pdc_host_priv *hpriv = host_set->private_data;
249 void *dimm_mmio = hpriv->dimm_mmio; 250 void *dimm_mmio = hpriv->dimm_mmio;
250 251
251 iounmap(dimm_mmio); 252 pci_iounmap(pdev, dimm_mmio);
252 kfree(hpriv); 253 kfree(hpriv);
253 254
254 ata_host_stop(host_set); 255 pci_iounmap(pdev, host_set->mmio_base);
255} 256}
256 257
257static int pdc_port_start(struct ata_port *ap) 258static int pdc_port_start(struct ata_port *ap)
@@ -451,9 +452,9 @@ static void pdc20621_dma_prep(struct ata_queued_cmd *qc)
451 struct scatterlist *sg = qc->sg; 452 struct scatterlist *sg = qc->sg;
452 struct ata_port *ap = qc->ap; 453 struct ata_port *ap = qc->ap;
453 struct pdc_port_priv *pp = ap->private_data; 454 struct pdc_port_priv *pp = ap->private_data;
454 void *mmio = ap->host_set->mmio_base; 455 void __iomem *mmio = ap->host_set->mmio_base;
455 struct pdc_host_priv *hpriv = ap->host_set->private_data; 456 struct pdc_host_priv *hpriv = ap->host_set->private_data;
456 void *dimm_mmio = hpriv->dimm_mmio; 457 void __iomem *dimm_mmio = hpriv->dimm_mmio;
457 unsigned int portno = ap->port_no; 458 unsigned int portno = ap->port_no;
458 unsigned int i, last, idx, total_len = 0, sgt_len; 459 unsigned int i, last, idx, total_len = 0, sgt_len;
459 u32 *buf = (u32 *) &pp->dimm_buf[PDC_DIMM_HEADER_SZ]; 460 u32 *buf = (u32 *) &pp->dimm_buf[PDC_DIMM_HEADER_SZ];
@@ -513,9 +514,9 @@ static void pdc20621_nodata_prep(struct ata_queued_cmd *qc)
513{ 514{
514 struct ata_port *ap = qc->ap; 515 struct ata_port *ap = qc->ap;
515 struct pdc_port_priv *pp = ap->private_data; 516 struct pdc_port_priv *pp = ap->private_data;
516 void *mmio = ap->host_set->mmio_base; 517 void __iomem *mmio = ap->host_set->mmio_base;
517 struct pdc_host_priv *hpriv = ap->host_set->private_data; 518 struct pdc_host_priv *hpriv = ap->host_set->private_data;
518 void *dimm_mmio = hpriv->dimm_mmio; 519 void __iomem *dimm_mmio = hpriv->dimm_mmio;
519 unsigned int portno = ap->port_no; 520 unsigned int portno = ap->port_no;
520 unsigned int i; 521 unsigned int i;
521 522
@@ -565,7 +566,7 @@ static void __pdc20621_push_hdma(struct ata_queued_cmd *qc,
565{ 566{
566 struct ata_port *ap = qc->ap; 567 struct ata_port *ap = qc->ap;
567 struct ata_host_set *host_set = ap->host_set; 568 struct ata_host_set *host_set = ap->host_set;
568 void *mmio = host_set->mmio_base; 569 void __iomem *mmio = host_set->mmio_base;
569 570
570 /* hard-code chip #0 */ 571 /* hard-code chip #0 */
571 mmio += PDC_CHIP0_OFS; 572 mmio += PDC_CHIP0_OFS;
@@ -639,7 +640,7 @@ static void pdc20621_packet_start(struct ata_queued_cmd *qc)
639 struct ata_port *ap = qc->ap; 640 struct ata_port *ap = qc->ap;
640 struct ata_host_set *host_set = ap->host_set; 641 struct ata_host_set *host_set = ap->host_set;
641 unsigned int port_no = ap->port_no; 642 unsigned int port_no = ap->port_no;
642 void *mmio = host_set->mmio_base; 643 void __iomem *mmio = host_set->mmio_base;
643 unsigned int rw = (qc->tf.flags & ATA_TFLAG_WRITE); 644 unsigned int rw = (qc->tf.flags & ATA_TFLAG_WRITE);
644 u8 seq = (u8) (port_no + 1); 645 u8 seq = (u8) (port_no + 1);
645 unsigned int port_ofs; 646 unsigned int port_ofs;
@@ -699,7 +700,7 @@ static int pdc20621_qc_issue_prot(struct ata_queued_cmd *qc)
699static inline unsigned int pdc20621_host_intr( struct ata_port *ap, 700static inline unsigned int pdc20621_host_intr( struct ata_port *ap,
700 struct ata_queued_cmd *qc, 701 struct ata_queued_cmd *qc,
701 unsigned int doing_hdma, 702 unsigned int doing_hdma,
702 void *mmio) 703 void __iomem *mmio)
703{ 704{
704 unsigned int port_no = ap->port_no; 705 unsigned int port_no = ap->port_no;
705 unsigned int port_ofs = 706 unsigned int port_ofs =
@@ -778,7 +779,7 @@ static inline unsigned int pdc20621_host_intr( struct ata_port *ap,
778static void pdc20621_irq_clear(struct ata_port *ap) 779static void pdc20621_irq_clear(struct ata_port *ap)
779{ 780{
780 struct ata_host_set *host_set = ap->host_set; 781 struct ata_host_set *host_set = ap->host_set;
781 void *mmio = host_set->mmio_base; 782 void __iomem *mmio = host_set->mmio_base;
782 783
783 mmio += PDC_CHIP0_OFS; 784 mmio += PDC_CHIP0_OFS;
784 785
@@ -792,7 +793,7 @@ static irqreturn_t pdc20621_interrupt (int irq, void *dev_instance, struct pt_re
792 u32 mask = 0; 793 u32 mask = 0;
793 unsigned int i, tmp, port_no; 794 unsigned int i, tmp, port_no;
794 unsigned int handled = 0; 795 unsigned int handled = 0;
795 void *mmio_base; 796 void __iomem *mmio_base;
796 797
797 VPRINTK("ENTER\n"); 798 VPRINTK("ENTER\n");
798 799
@@ -940,9 +941,9 @@ static void pdc20621_get_from_dimm(struct ata_probe_ent *pe, void *psource,
940 u16 idx; 941 u16 idx;
941 u8 page_mask; 942 u8 page_mask;
942 long dist; 943 long dist;
943 void *mmio = pe->mmio_base; 944 void __iomem *mmio = pe->mmio_base;
944 struct pdc_host_priv *hpriv = pe->private_data; 945 struct pdc_host_priv *hpriv = pe->private_data;
945 void *dimm_mmio = hpriv->dimm_mmio; 946 void __iomem *dimm_mmio = hpriv->dimm_mmio;
946 947
947 /* hard-code chip #0 */ 948 /* hard-code chip #0 */
948 mmio += PDC_CHIP0_OFS; 949 mmio += PDC_CHIP0_OFS;
@@ -996,9 +997,9 @@ static void pdc20621_put_to_dimm(struct ata_probe_ent *pe, void *psource,
996 u16 idx; 997 u16 idx;
997 u8 page_mask; 998 u8 page_mask;
998 long dist; 999 long dist;
999 void *mmio = pe->mmio_base; 1000 void __iomem *mmio = pe->mmio_base;
1000 struct pdc_host_priv *hpriv = pe->private_data; 1001 struct pdc_host_priv *hpriv = pe->private_data;
1001 void *dimm_mmio = hpriv->dimm_mmio; 1002 void __iomem *dimm_mmio = hpriv->dimm_mmio;
1002 1003
1003 /* hard-code chip #0 */ 1004 /* hard-code chip #0 */
1004 mmio += PDC_CHIP0_OFS; 1005 mmio += PDC_CHIP0_OFS;
@@ -1044,7 +1045,7 @@ static void pdc20621_put_to_dimm(struct ata_probe_ent *pe, void *psource,
1044static unsigned int pdc20621_i2c_read(struct ata_probe_ent *pe, u32 device, 1045static unsigned int pdc20621_i2c_read(struct ata_probe_ent *pe, u32 device,
1045 u32 subaddr, u32 *pdata) 1046 u32 subaddr, u32 *pdata)
1046{ 1047{
1047 void *mmio = pe->mmio_base; 1048 void __iomem *mmio = pe->mmio_base;
1048 u32 i2creg = 0; 1049 u32 i2creg = 0;
1049 u32 status; 1050 u32 status;
1050 u32 count =0; 1051 u32 count =0;
@@ -1103,7 +1104,7 @@ static int pdc20621_prog_dimm0(struct ata_probe_ent *pe)
1103 u32 data = 0; 1104 u32 data = 0;
1104 int size, i; 1105 int size, i;
1105 u8 bdimmsize; 1106 u8 bdimmsize;
1106 void *mmio = pe->mmio_base; 1107 void __iomem *mmio = pe->mmio_base;
1107 static const struct { 1108 static const struct {
1108 unsigned int reg; 1109 unsigned int reg;
1109 unsigned int ofs; 1110 unsigned int ofs;
@@ -1166,7 +1167,7 @@ static unsigned int pdc20621_prog_dimm_global(struct ata_probe_ent *pe)
1166{ 1167{
1167 u32 data, spd0; 1168 u32 data, spd0;
1168 int error, i; 1169 int error, i;
1169 void *mmio = pe->mmio_base; 1170 void __iomem *mmio = pe->mmio_base;
1170 1171
1171 /* hard-code chip #0 */ 1172 /* hard-code chip #0 */
1172 mmio += PDC_CHIP0_OFS; 1173 mmio += PDC_CHIP0_OFS;
@@ -1220,7 +1221,7 @@ static unsigned int pdc20621_dimm_init(struct ata_probe_ent *pe)
1220 u32 ticks=0; 1221 u32 ticks=0;
1221 u32 clock=0; 1222 u32 clock=0;
1222 u32 fparam=0; 1223 u32 fparam=0;
1223 void *mmio = pe->mmio_base; 1224 void __iomem *mmio = pe->mmio_base;
1224 1225
1225 /* hard-code chip #0 */ 1226 /* hard-code chip #0 */
1226 mmio += PDC_CHIP0_OFS; 1227 mmio += PDC_CHIP0_OFS;
@@ -1344,7 +1345,7 @@ static unsigned int pdc20621_dimm_init(struct ata_probe_ent *pe)
1344static void pdc_20621_init(struct ata_probe_ent *pe) 1345static void pdc_20621_init(struct ata_probe_ent *pe)
1345{ 1346{
1346 u32 tmp; 1347 u32 tmp;
1347 void *mmio = pe->mmio_base; 1348 void __iomem *mmio = pe->mmio_base;
1348 1349
1349 /* hard-code chip #0 */ 1350 /* hard-code chip #0 */
1350 mmio += PDC_CHIP0_OFS; 1351 mmio += PDC_CHIP0_OFS;
@@ -1377,7 +1378,8 @@ static int pdc_sata_init_one (struct pci_dev *pdev, const struct pci_device_id *
1377 static int printed_version; 1378 static int printed_version;
1378 struct ata_probe_ent *probe_ent = NULL; 1379 struct ata_probe_ent *probe_ent = NULL;
1379 unsigned long base; 1380 unsigned long base;
1380 void *mmio_base, *dimm_mmio = NULL; 1381 void __iomem *mmio_base;
1382 void __iomem *dimm_mmio = NULL;
1381 struct pdc_host_priv *hpriv = NULL; 1383 struct pdc_host_priv *hpriv = NULL;
1382 unsigned int board_idx = (unsigned int) ent->driver_data; 1384 unsigned int board_idx = (unsigned int) ent->driver_data;
1383 int pci_dev_busy = 0; 1385 int pci_dev_busy = 0;
@@ -1417,8 +1419,7 @@ static int pdc_sata_init_one (struct pci_dev *pdev, const struct pci_device_id *
1417 probe_ent->dev = pci_dev_to_dev(pdev); 1419 probe_ent->dev = pci_dev_to_dev(pdev);
1418 INIT_LIST_HEAD(&probe_ent->node); 1420 INIT_LIST_HEAD(&probe_ent->node);
1419 1421
1420 mmio_base = ioremap(pci_resource_start(pdev, 3), 1422 mmio_base = pci_iomap(pdev, 3, 0);
1421 pci_resource_len(pdev, 3));
1422 if (mmio_base == NULL) { 1423 if (mmio_base == NULL) {
1423 rc = -ENOMEM; 1424 rc = -ENOMEM;
1424 goto err_out_free_ent; 1425 goto err_out_free_ent;
@@ -1432,8 +1433,7 @@ static int pdc_sata_init_one (struct pci_dev *pdev, const struct pci_device_id *
1432 } 1433 }
1433 memset(hpriv, 0, sizeof(*hpriv)); 1434 memset(hpriv, 0, sizeof(*hpriv));
1434 1435
1435 dimm_mmio = ioremap(pci_resource_start(pdev, 4), 1436 dimm_mmio = pci_iomap(pdev, 4, 0);
1436 pci_resource_len(pdev, 4));
1437 if (!dimm_mmio) { 1437 if (!dimm_mmio) {
1438 kfree(hpriv); 1438 kfree(hpriv);
1439 rc = -ENOMEM; 1439 rc = -ENOMEM;
@@ -1480,9 +1480,9 @@ static int pdc_sata_init_one (struct pci_dev *pdev, const struct pci_device_id *
1480 1480
1481err_out_iounmap_dimm: /* only get to this label if 20621 */ 1481err_out_iounmap_dimm: /* only get to this label if 20621 */
1482 kfree(hpriv); 1482 kfree(hpriv);
1483 iounmap(dimm_mmio); 1483 pci_iounmap(pdev, dimm_mmio);
1484err_out_iounmap: 1484err_out_iounmap:
1485 iounmap(mmio_base); 1485 pci_iounmap(pdev, mmio_base);
1486err_out_free_ent: 1486err_out_free_ent:
1487 kfree(probe_ent); 1487 kfree(probe_ent);
1488err_out_regions: 1488err_out_regions:
diff --git a/drivers/scsi/sata_uli.c b/drivers/scsi/sata_uli.c
index 1566886815f..42e13ed8eb5 100644
--- a/drivers/scsi/sata_uli.c
+++ b/drivers/scsi/sata_uli.c
@@ -125,8 +125,8 @@ static struct ata_port_info uli_port_info = {
125 .sht = &uli_sht, 125 .sht = &uli_sht,
126 .host_flags = ATA_FLAG_SATA | ATA_FLAG_SATA_RESET | 126 .host_flags = ATA_FLAG_SATA | ATA_FLAG_SATA_RESET |
127 ATA_FLAG_NO_LEGACY, 127 ATA_FLAG_NO_LEGACY,
128 .pio_mask = 0x03, //support pio mode 4 (FIXME) 128 .pio_mask = 0x1f, /* pio0-4 */
129 .udma_mask = 0x7f, //support udma mode 6 129 .udma_mask = 0x7f, /* udma0-6 */
130 .port_ops = &uli_ops, 130 .port_ops = &uli_ops,
131}; 131};
132 132
diff --git a/drivers/scsi/sata_vsc.c b/drivers/scsi/sata_vsc.c
index 3985f344da4..cf94e0158a8 100644
--- a/drivers/scsi/sata_vsc.c
+++ b/drivers/scsi/sata_vsc.c
@@ -252,7 +252,7 @@ static struct ata_port_operations vsc_sata_ops = {
252 .scr_write = vsc_sata_scr_write, 252 .scr_write = vsc_sata_scr_write,
253 .port_start = ata_port_start, 253 .port_start = ata_port_start,
254 .port_stop = ata_port_stop, 254 .port_stop = ata_port_stop,
255 .host_stop = ata_host_stop, 255 .host_stop = ata_pci_host_stop,
256}; 256};
257 257
258static void __devinit vsc_sata_setup_port(struct ata_ioports *port, unsigned long base) 258static void __devinit vsc_sata_setup_port(struct ata_ioports *port, unsigned long base)
@@ -326,8 +326,7 @@ static int __devinit vsc_sata_init_one (struct pci_dev *pdev, const struct pci_d
326 probe_ent->dev = pci_dev_to_dev(pdev); 326 probe_ent->dev = pci_dev_to_dev(pdev);
327 INIT_LIST_HEAD(&probe_ent->node); 327 INIT_LIST_HEAD(&probe_ent->node);
328 328
329 mmio_base = ioremap(pci_resource_start(pdev, 0), 329 mmio_base = pci_iomap(pdev, 0, 0);
330 pci_resource_len(pdev, 0));
331 if (mmio_base == NULL) { 330 if (mmio_base == NULL) {
332 rc = -ENOMEM; 331 rc = -ENOMEM;
333 goto err_out_free_ent; 332 goto err_out_free_ent;
diff --git a/drivers/scsi/scsi.c b/drivers/scsi/scsi.c
index d14523d7e44..a780546eda9 100644
--- a/drivers/scsi/scsi.c
+++ b/drivers/scsi/scsi.c
@@ -268,6 +268,7 @@ struct scsi_cmnd *scsi_get_command(struct scsi_device *dev, int gfp_mask)
268 } else 268 } else
269 put_device(&dev->sdev_gendev); 269 put_device(&dev->sdev_gendev);
270 270
271 cmd->jiffies_at_alloc = jiffies;
271 return cmd; 272 return cmd;
272} 273}
273EXPORT_SYMBOL(scsi_get_command); 274EXPORT_SYMBOL(scsi_get_command);
@@ -627,7 +628,7 @@ int scsi_dispatch_cmd(struct scsi_cmnd *cmd)
627 spin_lock_irqsave(host->host_lock, flags); 628 spin_lock_irqsave(host->host_lock, flags);
628 scsi_cmd_get_serial(host, cmd); 629 scsi_cmd_get_serial(host, cmd);
629 630
630 if (unlikely(test_bit(SHOST_CANCEL, &host->shost_state))) { 631 if (unlikely(host->shost_state == SHOST_DEL)) {
631 cmd->result = (DID_NO_CONNECT << 16); 632 cmd->result = (DID_NO_CONNECT << 16);
632 scsi_done(cmd); 633 scsi_done(cmd);
633 } else { 634 } else {
@@ -798,9 +799,23 @@ static void scsi_softirq(struct softirq_action *h)
798 while (!list_empty(&local_q)) { 799 while (!list_empty(&local_q)) {
799 struct scsi_cmnd *cmd = list_entry(local_q.next, 800 struct scsi_cmnd *cmd = list_entry(local_q.next,
800 struct scsi_cmnd, eh_entry); 801 struct scsi_cmnd, eh_entry);
802 /* The longest time any command should be outstanding is the
803 * per command timeout multiplied by the number of retries.
804 *
805 * For a typical command, this is 2.5 minutes */
806 unsigned long wait_for
807 = cmd->allowed * cmd->timeout_per_command;
801 list_del_init(&cmd->eh_entry); 808 list_del_init(&cmd->eh_entry);
802 809
803 disposition = scsi_decide_disposition(cmd); 810 disposition = scsi_decide_disposition(cmd);
811 if (disposition != SUCCESS &&
812 time_before(cmd->jiffies_at_alloc + wait_for, jiffies)) {
813 dev_printk(KERN_ERR, &cmd->device->sdev_gendev,
814 "timing out command, waited %lus\n",
815 wait_for/HZ);
816 disposition = SUCCESS;
817 }
818
804 scsi_log_completion(cmd, disposition); 819 scsi_log_completion(cmd, disposition);
805 switch (disposition) { 820 switch (disposition) {
806 case SUCCESS: 821 case SUCCESS:
diff --git a/drivers/scsi/scsi_devinfo.c b/drivers/scsi/scsi_devinfo.c
index 6121dc1bfad..07b554affcf 100644
--- a/drivers/scsi/scsi_devinfo.c
+++ b/drivers/scsi/scsi_devinfo.c
@@ -114,6 +114,7 @@ static struct {
114 {"YAMAHA", "CDR102", "1.00", BLIST_NOLUN}, /* locks up */ 114 {"YAMAHA", "CDR102", "1.00", BLIST_NOLUN}, /* locks up */
115 {"YAMAHA", "CRW8424S", "1.0", BLIST_NOLUN}, /* locks up */ 115 {"YAMAHA", "CRW8424S", "1.0", BLIST_NOLUN}, /* locks up */
116 {"YAMAHA", "CRW6416S", "1.0c", BLIST_NOLUN}, /* locks up */ 116 {"YAMAHA", "CRW6416S", "1.0c", BLIST_NOLUN}, /* locks up */
117 {"", "Scanner", "1.80", BLIST_NOLUN}, /* responds to all lun */
117 118
118 /* 119 /*
119 * Other types of devices that have special flags. 120 * Other types of devices that have special flags.
@@ -135,7 +136,7 @@ static struct {
135 {"COMPAQ", "MSA1000 VOLUME", NULL, BLIST_SPARSELUN | BLIST_NOSTARTONADD}, 136 {"COMPAQ", "MSA1000 VOLUME", NULL, BLIST_SPARSELUN | BLIST_NOSTARTONADD},
136 {"COMPAQ", "HSV110", NULL, BLIST_REPORTLUN2 | BLIST_NOSTARTONADD}, 137 {"COMPAQ", "HSV110", NULL, BLIST_REPORTLUN2 | BLIST_NOSTARTONADD},
137 {"DDN", "SAN DataDirector", "*", BLIST_SPARSELUN}, 138 {"DDN", "SAN DataDirector", "*", BLIST_SPARSELUN},
138 {"DEC", "HSG80", NULL, BLIST_SPARSELUN | BLIST_NOSTARTONADD}, 139 {"DEC", "HSG80", NULL, BLIST_REPORTLUN2 | BLIST_NOSTARTONADD},
139 {"DELL", "PV660F", NULL, BLIST_SPARSELUN}, 140 {"DELL", "PV660F", NULL, BLIST_SPARSELUN},
140 {"DELL", "PV660F PSEUDO", NULL, BLIST_SPARSELUN}, 141 {"DELL", "PV660F PSEUDO", NULL, BLIST_SPARSELUN},
141 {"DELL", "PSEUDO DEVICE .", NULL, BLIST_SPARSELUN}, /* Dell PV 530F */ 142 {"DELL", "PSEUDO DEVICE .", NULL, BLIST_SPARSELUN}, /* Dell PV 530F */
@@ -191,6 +192,7 @@ static struct {
191 {"SGI", "RAID5", "*", BLIST_SPARSELUN}, 192 {"SGI", "RAID5", "*", BLIST_SPARSELUN},
192 {"SGI", "TP9100", "*", BLIST_REPORTLUN2}, 193 {"SGI", "TP9100", "*", BLIST_REPORTLUN2},
193 {"SGI", "Universal Xport", "*", BLIST_NO_ULD_ATTACH}, 194 {"SGI", "Universal Xport", "*", BLIST_NO_ULD_ATTACH},
195 {"IBM", "Universal Xport", "*", BLIST_NO_ULD_ATTACH},
194 {"SMSC", "USB 2 HS-CF", NULL, BLIST_SPARSELUN | BLIST_INQUIRY_36}, 196 {"SMSC", "USB 2 HS-CF", NULL, BLIST_SPARSELUN | BLIST_INQUIRY_36},
195 {"SONY", "CD-ROM CDU-8001", NULL, BLIST_BORKEN}, 197 {"SONY", "CD-ROM CDU-8001", NULL, BLIST_BORKEN},
196 {"SONY", "TSL", NULL, BLIST_FORCELUN}, /* DDS3 & DDS4 autoloaders */ 198 {"SONY", "TSL", NULL, BLIST_FORCELUN}, /* DDS3 & DDS4 autoloaders */
diff --git a/drivers/scsi/scsi_error.c b/drivers/scsi/scsi_error.c
index 0fc8b48f052..895c9452be4 100644
--- a/drivers/scsi/scsi_error.c
+++ b/drivers/scsi/scsi_error.c
@@ -20,6 +20,7 @@
20#include <linux/string.h> 20#include <linux/string.h>
21#include <linux/slab.h> 21#include <linux/slab.h>
22#include <linux/kernel.h> 22#include <linux/kernel.h>
23#include <linux/kthread.h>
23#include <linux/interrupt.h> 24#include <linux/interrupt.h>
24#include <linux/blkdev.h> 25#include <linux/blkdev.h>
25#include <linux/delay.h> 26#include <linux/delay.h>
@@ -75,7 +76,7 @@ int scsi_eh_scmd_add(struct scsi_cmnd *scmd, int eh_flag)
75 76
76 scmd->eh_eflags |= eh_flag; 77 scmd->eh_eflags |= eh_flag;
77 list_add_tail(&scmd->eh_entry, &shost->eh_cmd_q); 78 list_add_tail(&scmd->eh_entry, &shost->eh_cmd_q);
78 set_bit(SHOST_RECOVERY, &shost->shost_state); 79 scsi_host_set_state(shost, SHOST_RECOVERY);
79 shost->host_failed++; 80 shost->host_failed++;
80 scsi_eh_wakeup(shost); 81 scsi_eh_wakeup(shost);
81 spin_unlock_irqrestore(shost->host_lock, flags); 82 spin_unlock_irqrestore(shost->host_lock, flags);
@@ -115,7 +116,6 @@ void scsi_add_timer(struct scsi_cmnd *scmd, int timeout,
115 116
116 add_timer(&scmd->eh_timeout); 117 add_timer(&scmd->eh_timeout);
117} 118}
118EXPORT_SYMBOL(scsi_add_timer);
119 119
120/** 120/**
121 * scsi_delete_timer - Delete/cancel timer for a given function. 121 * scsi_delete_timer - Delete/cancel timer for a given function.
@@ -143,7 +143,6 @@ int scsi_delete_timer(struct scsi_cmnd *scmd)
143 143
144 return rtn; 144 return rtn;
145} 145}
146EXPORT_SYMBOL(scsi_delete_timer);
147 146
148/** 147/**
149 * scsi_times_out - Timeout function for normal scsi commands. 148 * scsi_times_out - Timeout function for normal scsi commands.
@@ -197,7 +196,8 @@ int scsi_block_when_processing_errors(struct scsi_device *sdev)
197{ 196{
198 int online; 197 int online;
199 198
200 wait_event(sdev->host->host_wait, (!test_bit(SHOST_RECOVERY, &sdev->host->shost_state))); 199 wait_event(sdev->host->host_wait, (sdev->host->shost_state !=
200 SHOST_RECOVERY));
201 201
202 online = scsi_device_online(sdev); 202 online = scsi_device_online(sdev);
203 203
@@ -775,9 +775,11 @@ retry_tur:
775 __FUNCTION__, scmd, rtn)); 775 __FUNCTION__, scmd, rtn));
776 if (rtn == SUCCESS) 776 if (rtn == SUCCESS)
777 return 0; 777 return 0;
778 else if (rtn == NEEDS_RETRY) 778 else if (rtn == NEEDS_RETRY) {
779 if (retry_cnt--) 779 if (retry_cnt--)
780 goto retry_tur; 780 goto retry_tur;
781 return 0;
782 }
781 return 1; 783 return 1;
782} 784}
783 785
@@ -1458,7 +1460,7 @@ static void scsi_restart_operations(struct Scsi_Host *shost)
1458 SCSI_LOG_ERROR_RECOVERY(3, printk("%s: waking up host to restart\n", 1460 SCSI_LOG_ERROR_RECOVERY(3, printk("%s: waking up host to restart\n",
1459 __FUNCTION__)); 1461 __FUNCTION__));
1460 1462
1461 clear_bit(SHOST_RECOVERY, &shost->shost_state); 1463 scsi_host_set_state(shost, SHOST_RUNNING);
1462 1464
1463 wake_up(&shost->host_wait); 1465 wake_up(&shost->host_wait);
1464 1466
@@ -1582,16 +1584,8 @@ int scsi_error_handler(void *data)
1582 int rtn; 1584 int rtn;
1583 DECLARE_MUTEX_LOCKED(sem); 1585 DECLARE_MUTEX_LOCKED(sem);
1584 1586
1585 /*
1586 * Flush resources
1587 */
1588
1589 daemonize("scsi_eh_%d", shost->host_no);
1590
1591 current->flags |= PF_NOFREEZE; 1587 current->flags |= PF_NOFREEZE;
1592
1593 shost->eh_wait = &sem; 1588 shost->eh_wait = &sem;
1594 shost->ehandler = current;
1595 1589
1596 /* 1590 /*
1597 * Wake up the thread that created us. 1591 * Wake up the thread that created us.
@@ -1599,8 +1593,6 @@ int scsi_error_handler(void *data)
1599 SCSI_LOG_ERROR_RECOVERY(3, printk("Wake up parent of" 1593 SCSI_LOG_ERROR_RECOVERY(3, printk("Wake up parent of"
1600 " scsi_eh_%d\n",shost->host_no)); 1594 " scsi_eh_%d\n",shost->host_no));
1601 1595
1602 complete(shost->eh_notify);
1603
1604 while (1) { 1596 while (1) {
1605 /* 1597 /*
1606 * If we get a signal, it means we are supposed to go 1598 * If we get a signal, it means we are supposed to go
@@ -1621,7 +1613,7 @@ int scsi_error_handler(void *data)
1621 * semaphores isn't unreasonable. 1613 * semaphores isn't unreasonable.
1622 */ 1614 */
1623 down_interruptible(&sem); 1615 down_interruptible(&sem);
1624 if (shost->eh_kill) 1616 if (kthread_should_stop())
1625 break; 1617 break;
1626 1618
1627 SCSI_LOG_ERROR_RECOVERY(1, printk("Error handler" 1619 SCSI_LOG_ERROR_RECOVERY(1, printk("Error handler"
@@ -1660,22 +1652,6 @@ int scsi_error_handler(void *data)
1660 * Make sure that nobody tries to wake us up again. 1652 * Make sure that nobody tries to wake us up again.
1661 */ 1653 */
1662 shost->eh_wait = NULL; 1654 shost->eh_wait = NULL;
1663
1664 /*
1665 * Knock this down too. From this point on, the host is flying
1666 * without a pilot. If this is because the module is being unloaded,
1667 * that's fine. If the user sent a signal to this thing, we are
1668 * potentially in real danger.
1669 */
1670 shost->eh_active = 0;
1671 shost->ehandler = NULL;
1672
1673 /*
1674 * If anyone is waiting for us to exit (i.e. someone trying to unload
1675 * a driver), then wake up that process to let them know we are on
1676 * the way out the door.
1677 */
1678 complete_and_exit(shost->eh_notify, 0);
1679 return 0; 1655 return 0;
1680} 1656}
1681 1657
@@ -1846,12 +1822,16 @@ EXPORT_SYMBOL(scsi_reset_provider);
1846int scsi_normalize_sense(const u8 *sense_buffer, int sb_len, 1822int scsi_normalize_sense(const u8 *sense_buffer, int sb_len,
1847 struct scsi_sense_hdr *sshdr) 1823 struct scsi_sense_hdr *sshdr)
1848{ 1824{
1849 if (!sense_buffer || !sb_len || (sense_buffer[0] & 0x70) != 0x70) 1825 if (!sense_buffer || !sb_len)
1850 return 0; 1826 return 0;
1851 1827
1852 memset(sshdr, 0, sizeof(struct scsi_sense_hdr)); 1828 memset(sshdr, 0, sizeof(struct scsi_sense_hdr));
1853 1829
1854 sshdr->response_code = (sense_buffer[0] & 0x7f); 1830 sshdr->response_code = (sense_buffer[0] & 0x7f);
1831
1832 if (!scsi_sense_valid(sshdr))
1833 return 0;
1834
1855 if (sshdr->response_code >= 0x72) { 1835 if (sshdr->response_code >= 0x72) {
1856 /* 1836 /*
1857 * descriptor format 1837 * descriptor format
diff --git a/drivers/scsi/scsi_ioctl.c b/drivers/scsi/scsi_ioctl.c
index 7a6b530115a..b7fddac8134 100644
--- a/drivers/scsi/scsi_ioctl.c
+++ b/drivers/scsi/scsi_ioctl.c
@@ -30,20 +30,20 @@
30 30
31#define MAX_BUF PAGE_SIZE 31#define MAX_BUF PAGE_SIZE
32 32
33/* 33/**
34 * If we are told to probe a host, we will return 0 if the host is not 34 * ioctl_probe -- return host identification
35 * present, 1 if the host is present, and will return an identifying 35 * @host: host to identify
36 * string at *arg, if arg is non null, filling to the length stored at 36 * @buffer: userspace buffer for identification
37 * (int *) arg 37 *
38 * Return an identifying string at @buffer, if @buffer is non-NULL, filling
39 * to the length stored at * (int *) @buffer.
38 */ 40 */
39
40static int ioctl_probe(struct Scsi_Host *host, void __user *buffer) 41static int ioctl_probe(struct Scsi_Host *host, void __user *buffer)
41{ 42{
42 unsigned int len, slen; 43 unsigned int len, slen;
43 const char *string; 44 const char *string;
44 int temp = host->hostt->present;
45 45
46 if (temp && buffer) { 46 if (buffer) {
47 if (get_user(len, (unsigned int __user *) buffer)) 47 if (get_user(len, (unsigned int __user *) buffer))
48 return -EFAULT; 48 return -EFAULT;
49 49
@@ -59,7 +59,7 @@ static int ioctl_probe(struct Scsi_Host *host, void __user *buffer)
59 return -EFAULT; 59 return -EFAULT;
60 } 60 }
61 } 61 }
62 return temp; 62 return 1;
63} 63}
64 64
65/* 65/*
@@ -88,25 +88,18 @@ static int ioctl_probe(struct Scsi_Host *host, void __user *buffer)
88static int ioctl_internal_command(struct scsi_device *sdev, char *cmd, 88static int ioctl_internal_command(struct scsi_device *sdev, char *cmd,
89 int timeout, int retries) 89 int timeout, int retries)
90{ 90{
91 struct scsi_request *sreq;
92 int result; 91 int result;
93 struct scsi_sense_hdr sshdr; 92 struct scsi_sense_hdr sshdr;
94 93
95 SCSI_LOG_IOCTL(1, printk("Trying ioctl with scsi command %d\n", *cmd)); 94 SCSI_LOG_IOCTL(1, printk("Trying ioctl with scsi command %d\n", *cmd));
96 95
97 sreq = scsi_allocate_request(sdev, GFP_KERNEL); 96 result = scsi_execute_req(sdev, cmd, DMA_NONE, NULL, 0,
98 if (!sreq) { 97 &sshdr, timeout, retries);
99 printk(KERN_WARNING "SCSI internal ioctl failed, no memory\n");
100 return -ENOMEM;
101 }
102
103 sreq->sr_data_direction = DMA_NONE;
104 scsi_wait_req(sreq, cmd, NULL, 0, timeout, retries);
105 98
106 SCSI_LOG_IOCTL(2, printk("Ioctl returned 0x%x\n", sreq->sr_result)); 99 SCSI_LOG_IOCTL(2, printk("Ioctl returned 0x%x\n", result));
107 100
108 if ((driver_byte(sreq->sr_result) & DRIVER_SENSE) && 101 if ((driver_byte(result) & DRIVER_SENSE) &&
109 (scsi_request_normalize_sense(sreq, &sshdr))) { 102 (scsi_sense_valid(&sshdr))) {
110 switch (sshdr.sense_key) { 103 switch (sshdr.sense_key) {
111 case ILLEGAL_REQUEST: 104 case ILLEGAL_REQUEST:
112 if (cmd[0] == ALLOW_MEDIUM_REMOVAL) 105 if (cmd[0] == ALLOW_MEDIUM_REMOVAL)
@@ -125,7 +118,7 @@ static int ioctl_internal_command(struct scsi_device *sdev, char *cmd,
125 case UNIT_ATTENTION: 118 case UNIT_ATTENTION:
126 if (sdev->removable) { 119 if (sdev->removable) {
127 sdev->changed = 1; 120 sdev->changed = 1;
128 sreq->sr_result = 0; /* This is no longer considered an error */ 121 result = 0; /* This is no longer considered an error */
129 break; 122 break;
130 } 123 }
131 default: /* Fall through for non-removable media */ 124 default: /* Fall through for non-removable media */
@@ -135,15 +128,13 @@ static int ioctl_internal_command(struct scsi_device *sdev, char *cmd,
135 sdev->channel, 128 sdev->channel,
136 sdev->id, 129 sdev->id,
137 sdev->lun, 130 sdev->lun,
138 sreq->sr_result); 131 result);
139 scsi_print_req_sense(" ", sreq); 132 scsi_print_sense_hdr(" ", &sshdr);
140 break; 133 break;
141 } 134 }
142 } 135 }
143 136
144 result = sreq->sr_result;
145 SCSI_LOG_IOCTL(2, printk("IOCTL Releasing command\n")); 137 SCSI_LOG_IOCTL(2, printk("IOCTL Releasing command\n"));
146 scsi_release_request(sreq);
147 return result; 138 return result;
148} 139}
149 140
@@ -208,8 +199,8 @@ int scsi_ioctl_send_command(struct scsi_device *sdev,
208{ 199{
209 char *buf; 200 char *buf;
210 unsigned char cmd[MAX_COMMAND_SIZE]; 201 unsigned char cmd[MAX_COMMAND_SIZE];
202 unsigned char sense[SCSI_SENSE_BUFFERSIZE];
211 char __user *cmd_in; 203 char __user *cmd_in;
212 struct scsi_request *sreq;
213 unsigned char opcode; 204 unsigned char opcode;
214 unsigned int inlen, outlen, cmdlen; 205 unsigned int inlen, outlen, cmdlen;
215 unsigned int needed, buf_needed; 206 unsigned int needed, buf_needed;
@@ -321,31 +312,23 @@ int scsi_ioctl_send_command(struct scsi_device *sdev,
321 break; 312 break;
322 } 313 }
323 314
324 sreq = scsi_allocate_request(sdev, GFP_KERNEL); 315 result = scsi_execute(sdev, cmd, data_direction, buf, needed,
325 if (!sreq) { 316 sense, timeout, retries, 0);
326 result = -EINTR;
327 goto error;
328 }
329
330 sreq->sr_data_direction = data_direction;
331 scsi_wait_req(sreq, cmd, buf, needed, timeout, retries);
332 317
333 /* 318 /*
334 * If there was an error condition, pass the info back to the user. 319 * If there was an error condition, pass the info back to the user.
335 */ 320 */
336 result = sreq->sr_result;
337 if (result) { 321 if (result) {
338 int sb_len = sizeof(sreq->sr_sense_buffer); 322 int sb_len = sizeof(*sense);
339 323
340 sb_len = (sb_len > OMAX_SB_LEN) ? OMAX_SB_LEN : sb_len; 324 sb_len = (sb_len > OMAX_SB_LEN) ? OMAX_SB_LEN : sb_len;
341 if (copy_to_user(cmd_in, sreq->sr_sense_buffer, sb_len)) 325 if (copy_to_user(cmd_in, sense, sb_len))
342 result = -EFAULT; 326 result = -EFAULT;
343 } else { 327 } else {
344 if (copy_to_user(cmd_in, buf, outlen)) 328 if (copy_to_user(cmd_in, buf, outlen))
345 result = -EFAULT; 329 result = -EFAULT;
346 } 330 }
347 331
348 scsi_release_request(sreq);
349error: 332error:
350 kfree(buf); 333 kfree(buf);
351 return result; 334 return result;
@@ -475,8 +458,7 @@ int scsi_nonblockable_ioctl(struct scsi_device *sdev, int cmd,
475 * error processing, as long as the device was opened 458 * error processing, as long as the device was opened
476 * non-blocking */ 459 * non-blocking */
477 if (filp && filp->f_flags & O_NONBLOCK) { 460 if (filp && filp->f_flags & O_NONBLOCK) {
478 if (test_bit(SHOST_RECOVERY, 461 if (sdev->host->shost_state == SHOST_RECOVERY)
479 &sdev->host->shost_state))
480 return -ENODEV; 462 return -ENODEV;
481 } else if (!scsi_block_when_processing_errors(sdev)) 463 } else if (!scsi_block_when_processing_errors(sdev))
482 return -ENODEV; 464 return -ENODEV;
diff --git a/drivers/scsi/scsi_lib.c b/drivers/scsi/scsi_lib.c
index 7a91ca3d32a..77f2d444f7e 100644
--- a/drivers/scsi/scsi_lib.c
+++ b/drivers/scsi/scsi_lib.c
@@ -232,23 +232,6 @@ void scsi_do_req(struct scsi_request *sreq, const void *cmnd,
232} 232}
233EXPORT_SYMBOL(scsi_do_req); 233EXPORT_SYMBOL(scsi_do_req);
234 234
235static void scsi_wait_done(struct scsi_cmnd *cmd)
236{
237 struct request *req = cmd->request;
238 struct request_queue *q = cmd->device->request_queue;
239 unsigned long flags;
240
241 req->rq_status = RQ_SCSI_DONE; /* Busy, but indicate request done */
242
243 spin_lock_irqsave(q->queue_lock, flags);
244 if (blk_rq_tagged(req))
245 blk_queue_end_tag(q, req);
246 spin_unlock_irqrestore(q->queue_lock, flags);
247
248 if (req->waiting)
249 complete(req->waiting);
250}
251
252/* This is the end routine we get to if a command was never attached 235/* This is the end routine we get to if a command was never attached
253 * to the request. Simply complete the request without changing 236 * to the request. Simply complete the request without changing
254 * rq_status; this will cause a DRIVER_ERROR. */ 237 * rq_status; this will cause a DRIVER_ERROR. */
@@ -263,21 +246,114 @@ void scsi_wait_req(struct scsi_request *sreq, const void *cmnd, void *buffer,
263 unsigned bufflen, int timeout, int retries) 246 unsigned bufflen, int timeout, int retries)
264{ 247{
265 DECLARE_COMPLETION(wait); 248 DECLARE_COMPLETION(wait);
266 249 int write = (sreq->sr_data_direction == DMA_TO_DEVICE);
267 sreq->sr_request->waiting = &wait; 250 struct request *req;
268 sreq->sr_request->rq_status = RQ_SCSI_BUSY; 251
269 sreq->sr_request->end_io = scsi_wait_req_end_io; 252 req = blk_get_request(sreq->sr_device->request_queue, write,
270 scsi_do_req(sreq, cmnd, buffer, bufflen, scsi_wait_done, 253 __GFP_WAIT);
271 timeout, retries); 254 if (bufflen && blk_rq_map_kern(sreq->sr_device->request_queue, req,
255 buffer, bufflen, __GFP_WAIT)) {
256 sreq->sr_result = DRIVER_ERROR << 24;
257 blk_put_request(req);
258 return;
259 }
260
261 req->flags |= REQ_NOMERGE;
262 req->waiting = &wait;
263 req->end_io = scsi_wait_req_end_io;
264 req->cmd_len = COMMAND_SIZE(((u8 *)cmnd)[0]);
265 req->sense = sreq->sr_sense_buffer;
266 req->sense_len = 0;
267 memcpy(req->cmd, cmnd, req->cmd_len);
268 req->timeout = timeout;
269 req->flags |= REQ_BLOCK_PC;
270 req->rq_disk = NULL;
271 blk_insert_request(sreq->sr_device->request_queue, req,
272 sreq->sr_data_direction == DMA_TO_DEVICE, NULL);
272 wait_for_completion(&wait); 273 wait_for_completion(&wait);
273 sreq->sr_request->waiting = NULL; 274 sreq->sr_request->waiting = NULL;
274 if (sreq->sr_request->rq_status != RQ_SCSI_DONE) 275 sreq->sr_result = req->errors;
276 if (req->errors)
275 sreq->sr_result |= (DRIVER_ERROR << 24); 277 sreq->sr_result |= (DRIVER_ERROR << 24);
276 278
277 __scsi_release_request(sreq); 279 blk_put_request(req);
278} 280}
281
279EXPORT_SYMBOL(scsi_wait_req); 282EXPORT_SYMBOL(scsi_wait_req);
280 283
284/**
285 * scsi_execute - insert request and wait for the result
286 * @sdev: scsi device
287 * @cmd: scsi command
288 * @data_direction: data direction
289 * @buffer: data buffer
290 * @bufflen: len of buffer
291 * @sense: optional sense buffer
292 * @timeout: request timeout in seconds
293 * @retries: number of times to retry request
294 * @flags: or into request flags;
295 *
296 * returns the req->errors value which is the the scsi_cmnd result
297 * field.
298 **/
299int scsi_execute(struct scsi_device *sdev, const unsigned char *cmd,
300 int data_direction, void *buffer, unsigned bufflen,
301 unsigned char *sense, int timeout, int retries, int flags)
302{
303 struct request *req;
304 int write = (data_direction == DMA_TO_DEVICE);
305 int ret = DRIVER_ERROR << 24;
306
307 req = blk_get_request(sdev->request_queue, write, __GFP_WAIT);
308
309 if (bufflen && blk_rq_map_kern(sdev->request_queue, req,
310 buffer, bufflen, __GFP_WAIT))
311 goto out;
312
313 req->cmd_len = COMMAND_SIZE(cmd[0]);
314 memcpy(req->cmd, cmd, req->cmd_len);
315 req->sense = sense;
316 req->sense_len = 0;
317 req->timeout = timeout;
318 req->flags |= flags | REQ_BLOCK_PC | REQ_SPECIAL | REQ_QUIET;
319
320 /*
321 * head injection *required* here otherwise quiesce won't work
322 */
323 blk_execute_rq(req->q, NULL, req, 1);
324
325 ret = req->errors;
326 out:
327 blk_put_request(req);
328
329 return ret;
330}
331EXPORT_SYMBOL(scsi_execute);
332
333
334int scsi_execute_req(struct scsi_device *sdev, const unsigned char *cmd,
335 int data_direction, void *buffer, unsigned bufflen,
336 struct scsi_sense_hdr *sshdr, int timeout, int retries)
337{
338 char *sense = NULL;
339 int result;
340
341 if (sshdr) {
342 sense = kmalloc(SCSI_SENSE_BUFFERSIZE, GFP_KERNEL);
343 if (!sense)
344 return DRIVER_ERROR << 24;
345 memset(sense, 0, SCSI_SENSE_BUFFERSIZE);
346 }
347 result = scsi_execute(sdev, cmd, data_direction, buffer, bufflen,
348 sense, timeout, retries, 0);
349 if (sshdr)
350 scsi_normalize_sense(sense, SCSI_SENSE_BUFFERSIZE, sshdr);
351
352 kfree(sense);
353 return result;
354}
355EXPORT_SYMBOL(scsi_execute_req);
356
281/* 357/*
282 * Function: scsi_init_cmd_errh() 358 * Function: scsi_init_cmd_errh()
283 * 359 *
@@ -348,7 +424,7 @@ void scsi_device_unbusy(struct scsi_device *sdev)
348 424
349 spin_lock_irqsave(shost->host_lock, flags); 425 spin_lock_irqsave(shost->host_lock, flags);
350 shost->host_busy--; 426 shost->host_busy--;
351 if (unlikely(test_bit(SHOST_RECOVERY, &shost->shost_state) && 427 if (unlikely((shost->shost_state == SHOST_RECOVERY) &&
352 shost->host_failed)) 428 shost->host_failed))
353 scsi_eh_wakeup(shost); 429 scsi_eh_wakeup(shost);
354 spin_unlock(shost->host_lock); 430 spin_unlock(shost->host_lock);
@@ -851,17 +927,20 @@ void scsi_io_completion(struct scsi_cmnd *cmd, unsigned int good_bytes,
851 scsi_requeue_command(q, cmd); 927 scsi_requeue_command(q, cmd);
852 return; 928 return;
853 } 929 }
854 printk(KERN_INFO "Device %s not ready.\n", 930 if (!(req->flags & REQ_QUIET))
855 req->rq_disk ? req->rq_disk->disk_name : ""); 931 dev_printk(KERN_INFO,
932 &cmd->device->sdev_gendev,
933 "Device not ready.\n");
856 cmd = scsi_end_request(cmd, 0, this_count, 1); 934 cmd = scsi_end_request(cmd, 0, this_count, 1);
857 return; 935 return;
858 case VOLUME_OVERFLOW: 936 case VOLUME_OVERFLOW:
859 printk(KERN_INFO "Volume overflow <%d %d %d %d> CDB: ", 937 if (!(req->flags & REQ_QUIET)) {
860 cmd->device->host->host_no, 938 dev_printk(KERN_INFO,
861 (int)cmd->device->channel, 939 &cmd->device->sdev_gendev,
862 (int)cmd->device->id, (int)cmd->device->lun); 940 "Volume overflow, CDB: ");
863 __scsi_print_command(cmd->data_cmnd); 941 __scsi_print_command(cmd->data_cmnd);
864 scsi_print_sense("", cmd); 942 scsi_print_sense("", cmd);
943 }
865 cmd = scsi_end_request(cmd, 0, block_bytes, 1); 944 cmd = scsi_end_request(cmd, 0, block_bytes, 1);
866 return; 945 return;
867 default: 946 default:
@@ -878,14 +957,13 @@ void scsi_io_completion(struct scsi_cmnd *cmd, unsigned int good_bytes,
878 return; 957 return;
879 } 958 }
880 if (result) { 959 if (result) {
881 printk(KERN_INFO "SCSI error : <%d %d %d %d> return code " 960 if (!(req->flags & REQ_QUIET)) {
882 "= 0x%x\n", cmd->device->host->host_no, 961 dev_printk(KERN_INFO, &cmd->device->sdev_gendev,
883 cmd->device->channel, 962 "SCSI error: return code = 0x%x\n", result);
884 cmd->device->id, 963
885 cmd->device->lun, result); 964 if (driver_byte(result) & DRIVER_SENSE)
886 965 scsi_print_sense("", cmd);
887 if (driver_byte(result) & DRIVER_SENSE) 966 }
888 scsi_print_sense("", cmd);
889 /* 967 /*
890 * Mark a single buffer as not uptodate. Queue the remainder. 968 * Mark a single buffer as not uptodate. Queue the remainder.
891 * We sometimes get this cruft in the event that a medium error 969 * We sometimes get this cruft in the event that a medium error
@@ -1020,6 +1098,12 @@ static int scsi_issue_flush_fn(request_queue_t *q, struct gendisk *disk,
1020 return -EOPNOTSUPP; 1098 return -EOPNOTSUPP;
1021} 1099}
1022 1100
1101static void scsi_generic_done(struct scsi_cmnd *cmd)
1102{
1103 BUG_ON(!blk_pc_request(cmd->request));
1104 scsi_io_completion(cmd, cmd->result == 0 ? cmd->bufflen : 0, 0);
1105}
1106
1023static int scsi_prep_fn(struct request_queue *q, struct request *req) 1107static int scsi_prep_fn(struct request_queue *q, struct request *req)
1024{ 1108{
1025 struct scsi_device *sdev = q->queuedata; 1109 struct scsi_device *sdev = q->queuedata;
@@ -1061,7 +1145,7 @@ static int scsi_prep_fn(struct request_queue *q, struct request *req)
1061 * these two cases differently. We differentiate by looking 1145 * these two cases differently. We differentiate by looking
1062 * at request->cmd, as this tells us the real story. 1146 * at request->cmd, as this tells us the real story.
1063 */ 1147 */
1064 if (req->flags & REQ_SPECIAL) { 1148 if (req->flags & REQ_SPECIAL && req->special) {
1065 struct scsi_request *sreq = req->special; 1149 struct scsi_request *sreq = req->special;
1066 1150
1067 if (sreq->sr_magic == SCSI_REQ_MAGIC) { 1151 if (sreq->sr_magic == SCSI_REQ_MAGIC) {
@@ -1073,7 +1157,7 @@ static int scsi_prep_fn(struct request_queue *q, struct request *req)
1073 cmd = req->special; 1157 cmd = req->special;
1074 } else if (req->flags & (REQ_CMD | REQ_BLOCK_PC)) { 1158 } else if (req->flags & (REQ_CMD | REQ_BLOCK_PC)) {
1075 1159
1076 if(unlikely(specials_only)) { 1160 if(unlikely(specials_only) && !(req->flags & REQ_SPECIAL)) {
1077 if(specials_only == SDEV_QUIESCE || 1161 if(specials_only == SDEV_QUIESCE ||
1078 specials_only == SDEV_BLOCK) 1162 specials_only == SDEV_BLOCK)
1079 return BLKPREP_DEFER; 1163 return BLKPREP_DEFER;
@@ -1142,11 +1226,26 @@ static int scsi_prep_fn(struct request_queue *q, struct request *req)
1142 /* 1226 /*
1143 * Initialize the actual SCSI command for this request. 1227 * Initialize the actual SCSI command for this request.
1144 */ 1228 */
1145 drv = *(struct scsi_driver **)req->rq_disk->private_data; 1229 if (req->rq_disk) {
1146 if (unlikely(!drv->init_command(cmd))) { 1230 drv = *(struct scsi_driver **)req->rq_disk->private_data;
1147 scsi_release_buffers(cmd); 1231 if (unlikely(!drv->init_command(cmd))) {
1148 scsi_put_command(cmd); 1232 scsi_release_buffers(cmd);
1149 return BLKPREP_KILL; 1233 scsi_put_command(cmd);
1234 return BLKPREP_KILL;
1235 }
1236 } else {
1237 memcpy(cmd->cmnd, req->cmd, sizeof(cmd->cmnd));
1238 if (rq_data_dir(req) == WRITE)
1239 cmd->sc_data_direction = DMA_TO_DEVICE;
1240 else if (req->data_len)
1241 cmd->sc_data_direction = DMA_FROM_DEVICE;
1242 else
1243 cmd->sc_data_direction = DMA_NONE;
1244
1245 cmd->transfersize = req->data_len;
1246 cmd->allowed = 3;
1247 cmd->timeout_per_command = req->timeout;
1248 cmd->done = scsi_generic_done;
1150 } 1249 }
1151 } 1250 }
1152 1251
@@ -1207,7 +1306,7 @@ static inline int scsi_host_queue_ready(struct request_queue *q,
1207 struct Scsi_Host *shost, 1306 struct Scsi_Host *shost,
1208 struct scsi_device *sdev) 1307 struct scsi_device *sdev)
1209{ 1308{
1210 if (test_bit(SHOST_RECOVERY, &shost->shost_state)) 1309 if (shost->shost_state == SHOST_RECOVERY)
1211 return 0; 1310 return 0;
1212 if (shost->host_busy == 0 && shost->host_blocked) { 1311 if (shost->host_busy == 0 && shost->host_blocked) {
1213 /* 1312 /*
@@ -1539,9 +1638,9 @@ void scsi_exit_queue(void)
1539 } 1638 }
1540} 1639}
1541/** 1640/**
1542 * __scsi_mode_sense - issue a mode sense, falling back from 10 to 1641 * scsi_mode_sense - issue a mode sense, falling back from 10 to
1543 * six bytes if necessary. 1642 * six bytes if necessary.
1544 * @sreq: SCSI request to fill in with the MODE_SENSE 1643 * @sdev: SCSI device to be queried
1545 * @dbd: set if mode sense will allow block descriptors to be returned 1644 * @dbd: set if mode sense will allow block descriptors to be returned
1546 * @modepage: mode page being requested 1645 * @modepage: mode page being requested
1547 * @buffer: request buffer (may not be smaller than eight bytes) 1646 * @buffer: request buffer (may not be smaller than eight bytes)
@@ -1549,26 +1648,34 @@ void scsi_exit_queue(void)
1549 * @timeout: command timeout 1648 * @timeout: command timeout
1550 * @retries: number of retries before failing 1649 * @retries: number of retries before failing
1551 * @data: returns a structure abstracting the mode header data 1650 * @data: returns a structure abstracting the mode header data
1651 * @sense: place to put sense data (or NULL if no sense to be collected).
1652 * must be SCSI_SENSE_BUFFERSIZE big.
1552 * 1653 *
1553 * Returns zero if unsuccessful, or the header offset (either 4 1654 * Returns zero if unsuccessful, or the header offset (either 4
1554 * or 8 depending on whether a six or ten byte command was 1655 * or 8 depending on whether a six or ten byte command was
1555 * issued) if successful. 1656 * issued) if successful.
1556 **/ 1657 **/
1557int 1658int
1558__scsi_mode_sense(struct scsi_request *sreq, int dbd, int modepage, 1659scsi_mode_sense(struct scsi_device *sdev, int dbd, int modepage,
1559 unsigned char *buffer, int len, int timeout, int retries, 1660 unsigned char *buffer, int len, int timeout, int retries,
1560 struct scsi_mode_data *data) { 1661 struct scsi_mode_data *data, struct scsi_sense_hdr *sshdr) {
1561 unsigned char cmd[12]; 1662 unsigned char cmd[12];
1562 int use_10_for_ms; 1663 int use_10_for_ms;
1563 int header_length; 1664 int header_length;
1665 int result;
1666 struct scsi_sense_hdr my_sshdr;
1564 1667
1565 memset(data, 0, sizeof(*data)); 1668 memset(data, 0, sizeof(*data));
1566 memset(&cmd[0], 0, 12); 1669 memset(&cmd[0], 0, 12);
1567 cmd[1] = dbd & 0x18; /* allows DBD and LLBA bits */ 1670 cmd[1] = dbd & 0x18; /* allows DBD and LLBA bits */
1568 cmd[2] = modepage; 1671 cmd[2] = modepage;
1569 1672
1673 /* caller might not be interested in sense, but we need it */
1674 if (!sshdr)
1675 sshdr = &my_sshdr;
1676
1570 retry: 1677 retry:
1571 use_10_for_ms = sreq->sr_device->use_10_for_ms; 1678 use_10_for_ms = sdev->use_10_for_ms;
1572 1679
1573 if (use_10_for_ms) { 1680 if (use_10_for_ms) {
1574 if (len < 8) 1681 if (len < 8)
@@ -1586,36 +1693,31 @@ __scsi_mode_sense(struct scsi_request *sreq, int dbd, int modepage,
1586 header_length = 4; 1693 header_length = 4;
1587 } 1694 }
1588 1695
1589 sreq->sr_cmd_len = 0;
1590 memset(sreq->sr_sense_buffer, 0, sizeof(sreq->sr_sense_buffer));
1591 sreq->sr_data_direction = DMA_FROM_DEVICE;
1592
1593 memset(buffer, 0, len); 1696 memset(buffer, 0, len);
1594 1697
1595 scsi_wait_req(sreq, cmd, buffer, len, timeout, retries); 1698 result = scsi_execute_req(sdev, cmd, DMA_FROM_DEVICE, buffer, len,
1699 sshdr, timeout, retries);
1596 1700
1597 /* This code looks awful: what it's doing is making sure an 1701 /* This code looks awful: what it's doing is making sure an
1598 * ILLEGAL REQUEST sense return identifies the actual command 1702 * ILLEGAL REQUEST sense return identifies the actual command
1599 * byte as the problem. MODE_SENSE commands can return 1703 * byte as the problem. MODE_SENSE commands can return
1600 * ILLEGAL REQUEST if the code page isn't supported */ 1704 * ILLEGAL REQUEST if the code page isn't supported */
1601 1705
1602 if (use_10_for_ms && !scsi_status_is_good(sreq->sr_result) && 1706 if (use_10_for_ms && !scsi_status_is_good(result) &&
1603 (driver_byte(sreq->sr_result) & DRIVER_SENSE)) { 1707 (driver_byte(result) & DRIVER_SENSE)) {
1604 struct scsi_sense_hdr sshdr; 1708 if (scsi_sense_valid(sshdr)) {
1605 1709 if ((sshdr->sense_key == ILLEGAL_REQUEST) &&
1606 if (scsi_request_normalize_sense(sreq, &sshdr)) { 1710 (sshdr->asc == 0x20) && (sshdr->ascq == 0)) {
1607 if ((sshdr.sense_key == ILLEGAL_REQUEST) &&
1608 (sshdr.asc == 0x20) && (sshdr.ascq == 0)) {
1609 /* 1711 /*
1610 * Invalid command operation code 1712 * Invalid command operation code
1611 */ 1713 */
1612 sreq->sr_device->use_10_for_ms = 0; 1714 sdev->use_10_for_ms = 0;
1613 goto retry; 1715 goto retry;
1614 } 1716 }
1615 } 1717 }
1616 } 1718 }
1617 1719
1618 if(scsi_status_is_good(sreq->sr_result)) { 1720 if(scsi_status_is_good(result)) {
1619 data->header_length = header_length; 1721 data->header_length = header_length;
1620 if(use_10_for_ms) { 1722 if(use_10_for_ms) {
1621 data->length = buffer[0]*256 + buffer[1] + 2; 1723 data->length = buffer[0]*256 + buffer[1] + 2;
@@ -1632,73 +1734,31 @@ __scsi_mode_sense(struct scsi_request *sreq, int dbd, int modepage,
1632 } 1734 }
1633 } 1735 }
1634 1736
1635 return sreq->sr_result; 1737 return result;
1636}
1637EXPORT_SYMBOL(__scsi_mode_sense);
1638
1639/**
1640 * scsi_mode_sense - issue a mode sense, falling back from 10 to
1641 * six bytes if necessary.
1642 * @sdev: scsi device to send command to.
1643 * @dbd: set if mode sense will disable block descriptors in the return
1644 * @modepage: mode page being requested
1645 * @buffer: request buffer (may not be smaller than eight bytes)
1646 * @len: length of request buffer.
1647 * @timeout: command timeout
1648 * @retries: number of retries before failing
1649 *
1650 * Returns zero if unsuccessful, or the header offset (either 4
1651 * or 8 depending on whether a six or ten byte command was
1652 * issued) if successful.
1653 **/
1654int
1655scsi_mode_sense(struct scsi_device *sdev, int dbd, int modepage,
1656 unsigned char *buffer, int len, int timeout, int retries,
1657 struct scsi_mode_data *data)
1658{
1659 struct scsi_request *sreq = scsi_allocate_request(sdev, GFP_KERNEL);
1660 int ret;
1661
1662 if (!sreq)
1663 return -1;
1664
1665 ret = __scsi_mode_sense(sreq, dbd, modepage, buffer, len,
1666 timeout, retries, data);
1667
1668 scsi_release_request(sreq);
1669
1670 return ret;
1671} 1738}
1672EXPORT_SYMBOL(scsi_mode_sense); 1739EXPORT_SYMBOL(scsi_mode_sense);
1673 1740
1674int 1741int
1675scsi_test_unit_ready(struct scsi_device *sdev, int timeout, int retries) 1742scsi_test_unit_ready(struct scsi_device *sdev, int timeout, int retries)
1676{ 1743{
1677 struct scsi_request *sreq;
1678 char cmd[] = { 1744 char cmd[] = {
1679 TEST_UNIT_READY, 0, 0, 0, 0, 0, 1745 TEST_UNIT_READY, 0, 0, 0, 0, 0,
1680 }; 1746 };
1747 struct scsi_sense_hdr sshdr;
1681 int result; 1748 int result;
1682 1749
1683 sreq = scsi_allocate_request(sdev, GFP_KERNEL); 1750 result = scsi_execute_req(sdev, cmd, DMA_NONE, NULL, 0, &sshdr,
1684 if (!sreq) 1751 timeout, retries);
1685 return -ENOMEM;
1686
1687 sreq->sr_data_direction = DMA_NONE;
1688 scsi_wait_req(sreq, cmd, NULL, 0, timeout, retries);
1689 1752
1690 if ((driver_byte(sreq->sr_result) & DRIVER_SENSE) && sdev->removable) { 1753 if ((driver_byte(result) & DRIVER_SENSE) && sdev->removable) {
1691 struct scsi_sense_hdr sshdr;
1692 1754
1693 if ((scsi_request_normalize_sense(sreq, &sshdr)) && 1755 if ((scsi_sense_valid(&sshdr)) &&
1694 ((sshdr.sense_key == UNIT_ATTENTION) || 1756 ((sshdr.sense_key == UNIT_ATTENTION) ||
1695 (sshdr.sense_key == NOT_READY))) { 1757 (sshdr.sense_key == NOT_READY))) {
1696 sdev->changed = 1; 1758 sdev->changed = 1;
1697 sreq->sr_result = 0; 1759 result = 0;
1698 } 1760 }
1699 } 1761 }
1700 result = sreq->sr_result;
1701 scsi_release_request(sreq);
1702 return result; 1762 return result;
1703} 1763}
1704EXPORT_SYMBOL(scsi_test_unit_ready); 1764EXPORT_SYMBOL(scsi_test_unit_ready);
diff --git a/drivers/scsi/scsi_priv.h b/drivers/scsi/scsi_priv.h
index d30d7f4e63e..ee6de1768e5 100644
--- a/drivers/scsi/scsi_priv.h
+++ b/drivers/scsi/scsi_priv.h
@@ -63,6 +63,9 @@ extern int __init scsi_init_devinfo(void);
63extern void scsi_exit_devinfo(void); 63extern void scsi_exit_devinfo(void);
64 64
65/* scsi_error.c */ 65/* scsi_error.c */
66extern void scsi_add_timer(struct scsi_cmnd *, int,
67 void (*)(struct scsi_cmnd *));
68extern int scsi_delete_timer(struct scsi_cmnd *);
66extern void scsi_times_out(struct scsi_cmnd *cmd); 69extern void scsi_times_out(struct scsi_cmnd *cmd);
67extern int scsi_error_handler(void *host); 70extern int scsi_error_handler(void *host);
68extern int scsi_decide_disposition(struct scsi_cmnd *cmd); 71extern int scsi_decide_disposition(struct scsi_cmnd *cmd);
diff --git a/drivers/scsi/scsi_scan.c b/drivers/scsi/scsi_scan.c
index 48edd67982a..19c9a232a75 100644
--- a/drivers/scsi/scsi_scan.c
+++ b/drivers/scsi/scsi_scan.c
@@ -111,15 +111,14 @@ MODULE_PARM_DESC(inq_timeout,
111 111
112/** 112/**
113 * scsi_unlock_floptical - unlock device via a special MODE SENSE command 113 * scsi_unlock_floptical - unlock device via a special MODE SENSE command
114 * @sreq: used to send the command 114 * @sdev: scsi device to send command to
115 * @result: area to store the result of the MODE SENSE 115 * @result: area to store the result of the MODE SENSE
116 * 116 *
117 * Description: 117 * Description:
118 * Send a vendor specific MODE SENSE (not a MODE SELECT) command using 118 * Send a vendor specific MODE SENSE (not a MODE SELECT) command.
119 * @sreq to unlock a device, storing the (unused) results into result.
120 * Called for BLIST_KEY devices. 119 * Called for BLIST_KEY devices.
121 **/ 120 **/
122static void scsi_unlock_floptical(struct scsi_request *sreq, 121static void scsi_unlock_floptical(struct scsi_device *sdev,
123 unsigned char *result) 122 unsigned char *result)
124{ 123{
125 unsigned char scsi_cmd[MAX_COMMAND_SIZE]; 124 unsigned char scsi_cmd[MAX_COMMAND_SIZE];
@@ -129,11 +128,10 @@ static void scsi_unlock_floptical(struct scsi_request *sreq,
129 scsi_cmd[1] = 0; 128 scsi_cmd[1] = 0;
130 scsi_cmd[2] = 0x2e; 129 scsi_cmd[2] = 0x2e;
131 scsi_cmd[3] = 0; 130 scsi_cmd[3] = 0;
132 scsi_cmd[4] = 0x2a; /* size */ 131 scsi_cmd[4] = 0x2a; /* size */
133 scsi_cmd[5] = 0; 132 scsi_cmd[5] = 0;
134 sreq->sr_cmd_len = 0; 133 scsi_execute_req(sdev, scsi_cmd, DMA_FROM_DEVICE, result, 0x2a, NULL,
135 sreq->sr_data_direction = DMA_FROM_DEVICE; 134 SCSI_TIMEOUT, 3);
136 scsi_wait_req(sreq, scsi_cmd, result, 0x2a /* size */, SCSI_TIMEOUT, 3);
137} 135}
138 136
139/** 137/**
@@ -433,26 +431,25 @@ void scsi_target_reap(struct scsi_target *starget)
433 431
434/** 432/**
435 * scsi_probe_lun - probe a single LUN using a SCSI INQUIRY 433 * scsi_probe_lun - probe a single LUN using a SCSI INQUIRY
436 * @sreq: used to send the INQUIRY 434 * @sdev: scsi_device to probe
437 * @inq_result: area to store the INQUIRY result 435 * @inq_result: area to store the INQUIRY result
436 * @result_len: len of inq_result
438 * @bflags: store any bflags found here 437 * @bflags: store any bflags found here
439 * 438 *
440 * Description: 439 * Description:
441 * Probe the lun associated with @sreq using a standard SCSI INQUIRY; 440 * Probe the lun associated with @req using a standard SCSI INQUIRY;
442 * 441 *
443 * If the INQUIRY is successful, sreq->sr_result is zero and: the 442 * If the INQUIRY is successful, zero is returned and the
444 * INQUIRY data is in @inq_result; the scsi_level and INQUIRY length 443 * INQUIRY data is in @inq_result; the scsi_level and INQUIRY length
445 * are copied to the Scsi_Device at @sreq->sr_device (sdev); 444 * are copied to the Scsi_Device any flags value is stored in *@bflags.
446 * any flags value is stored in *@bflags.
447 **/ 445 **/
448static void scsi_probe_lun(struct scsi_request *sreq, char *inq_result, 446static int scsi_probe_lun(struct scsi_device *sdev, char *inq_result,
449 int *bflags) 447 int result_len, int *bflags)
450{ 448{
451 struct scsi_device *sdev = sreq->sr_device; /* a bit ugly */
452 unsigned char scsi_cmd[MAX_COMMAND_SIZE]; 449 unsigned char scsi_cmd[MAX_COMMAND_SIZE];
453 int first_inquiry_len, try_inquiry_len, next_inquiry_len; 450 int first_inquiry_len, try_inquiry_len, next_inquiry_len;
454 int response_len = 0; 451 int response_len = 0;
455 int pass, count; 452 int pass, count, result;
456 struct scsi_sense_hdr sshdr; 453 struct scsi_sense_hdr sshdr;
457 454
458 *bflags = 0; 455 *bflags = 0;
@@ -475,28 +472,26 @@ static void scsi_probe_lun(struct scsi_request *sreq, char *inq_result,
475 memset(scsi_cmd, 0, 6); 472 memset(scsi_cmd, 0, 6);
476 scsi_cmd[0] = INQUIRY; 473 scsi_cmd[0] = INQUIRY;
477 scsi_cmd[4] = (unsigned char) try_inquiry_len; 474 scsi_cmd[4] = (unsigned char) try_inquiry_len;
478 sreq->sr_cmd_len = 0;
479 sreq->sr_data_direction = DMA_FROM_DEVICE;
480 475
481 memset(inq_result, 0, try_inquiry_len); 476 memset(inq_result, 0, try_inquiry_len);
482 scsi_wait_req(sreq, (void *) scsi_cmd, (void *) inq_result, 477
483 try_inquiry_len, 478 result = scsi_execute_req(sdev, scsi_cmd, DMA_FROM_DEVICE,
484 HZ/2 + HZ*scsi_inq_timeout, 3); 479 inq_result, try_inquiry_len, &sshdr,
480 HZ / 2 + HZ * scsi_inq_timeout, 3);
485 481
486 SCSI_LOG_SCAN_BUS(3, printk(KERN_INFO "scsi scan: INQUIRY %s " 482 SCSI_LOG_SCAN_BUS(3, printk(KERN_INFO "scsi scan: INQUIRY %s "
487 "with code 0x%x\n", 483 "with code 0x%x\n",
488 sreq->sr_result ? "failed" : "successful", 484 result ? "failed" : "successful", result));
489 sreq->sr_result));
490 485
491 if (sreq->sr_result) { 486 if (result) {
492 /* 487 /*
493 * not-ready to ready transition [asc/ascq=0x28/0x0] 488 * not-ready to ready transition [asc/ascq=0x28/0x0]
494 * or power-on, reset [asc/ascq=0x29/0x0], continue. 489 * or power-on, reset [asc/ascq=0x29/0x0], continue.
495 * INQUIRY should not yield UNIT_ATTENTION 490 * INQUIRY should not yield UNIT_ATTENTION
496 * but many buggy devices do so anyway. 491 * but many buggy devices do so anyway.
497 */ 492 */
498 if ((driver_byte(sreq->sr_result) & DRIVER_SENSE) && 493 if ((driver_byte(result) & DRIVER_SENSE) &&
499 scsi_request_normalize_sense(sreq, &sshdr)) { 494 scsi_sense_valid(&sshdr)) {
500 if ((sshdr.sense_key == UNIT_ATTENTION) && 495 if ((sshdr.sense_key == UNIT_ATTENTION) &&
501 ((sshdr.asc == 0x28) || 496 ((sshdr.asc == 0x28) ||
502 (sshdr.asc == 0x29)) && 497 (sshdr.asc == 0x29)) &&
@@ -507,7 +502,7 @@ static void scsi_probe_lun(struct scsi_request *sreq, char *inq_result,
507 break; 502 break;
508 } 503 }
509 504
510 if (sreq->sr_result == 0) { 505 if (result == 0) {
511 response_len = (unsigned char) inq_result[4] + 5; 506 response_len = (unsigned char) inq_result[4] + 5;
512 if (response_len > 255) 507 if (response_len > 255)
513 response_len = first_inquiry_len; /* sanity */ 508 response_len = first_inquiry_len; /* sanity */
@@ -556,8 +551,8 @@ static void scsi_probe_lun(struct scsi_request *sreq, char *inq_result,
556 551
557 /* If the last transfer attempt got an error, assume the 552 /* If the last transfer attempt got an error, assume the
558 * peripheral doesn't exist or is dead. */ 553 * peripheral doesn't exist or is dead. */
559 if (sreq->sr_result) 554 if (result)
560 return; 555 return -EIO;
561 556
562 /* Don't report any more data than the device says is valid */ 557 /* Don't report any more data than the device says is valid */
563 sdev->inquiry_len = min(try_inquiry_len, response_len); 558 sdev->inquiry_len = min(try_inquiry_len, response_len);
@@ -593,7 +588,7 @@ static void scsi_probe_lun(struct scsi_request *sreq, char *inq_result,
593 (sdev->scsi_level == 1 && (inq_result[3] & 0x0f) == 1)) 588 (sdev->scsi_level == 1 && (inq_result[3] & 0x0f) == 1))
594 sdev->scsi_level++; 589 sdev->scsi_level++;
595 590
596 return; 591 return 0;
597} 592}
598 593
599/** 594/**
@@ -800,9 +795,8 @@ static int scsi_probe_and_add_lun(struct scsi_target *starget,
800 void *hostdata) 795 void *hostdata)
801{ 796{
802 struct scsi_device *sdev; 797 struct scsi_device *sdev;
803 struct scsi_request *sreq;
804 unsigned char *result; 798 unsigned char *result;
805 int bflags, res = SCSI_SCAN_NO_RESPONSE; 799 int bflags, res = SCSI_SCAN_NO_RESPONSE, result_len = 256;
806 struct Scsi_Host *shost = dev_to_shost(starget->dev.parent); 800 struct Scsi_Host *shost = dev_to_shost(starget->dev.parent);
807 801
808 /* 802 /*
@@ -831,16 +825,13 @@ static int scsi_probe_and_add_lun(struct scsi_target *starget,
831 sdev = scsi_alloc_sdev(starget, lun, hostdata); 825 sdev = scsi_alloc_sdev(starget, lun, hostdata);
832 if (!sdev) 826 if (!sdev)
833 goto out; 827 goto out;
834 sreq = scsi_allocate_request(sdev, GFP_ATOMIC); 828
835 if (!sreq) 829 result = kmalloc(result_len, GFP_ATOMIC |
836 goto out_free_sdev;
837 result = kmalloc(256, GFP_ATOMIC |
838 ((shost->unchecked_isa_dma) ? __GFP_DMA : 0)); 830 ((shost->unchecked_isa_dma) ? __GFP_DMA : 0));
839 if (!result) 831 if (!result)
840 goto out_free_sreq; 832 goto out_free_sdev;
841 833
842 scsi_probe_lun(sreq, result, &bflags); 834 if (scsi_probe_lun(sdev, result, result_len, &bflags))
843 if (sreq->sr_result)
844 goto out_free_result; 835 goto out_free_result;
845 836
846 /* 837 /*
@@ -868,7 +859,7 @@ static int scsi_probe_and_add_lun(struct scsi_target *starget,
868 if (res == SCSI_SCAN_LUN_PRESENT) { 859 if (res == SCSI_SCAN_LUN_PRESENT) {
869 if (bflags & BLIST_KEY) { 860 if (bflags & BLIST_KEY) {
870 sdev->lockable = 0; 861 sdev->lockable = 0;
871 scsi_unlock_floptical(sreq, result); 862 scsi_unlock_floptical(sdev, result);
872 } 863 }
873 if (bflagsp) 864 if (bflagsp)
874 *bflagsp = bflags; 865 *bflagsp = bflags;
@@ -876,8 +867,6 @@ static int scsi_probe_and_add_lun(struct scsi_target *starget,
876 867
877 out_free_result: 868 out_free_result:
878 kfree(result); 869 kfree(result);
879 out_free_sreq:
880 scsi_release_request(sreq);
881 out_free_sdev: 870 out_free_sdev:
882 if (res == SCSI_SCAN_LUN_PRESENT) { 871 if (res == SCSI_SCAN_LUN_PRESENT) {
883 if (sdevp) { 872 if (sdevp) {
@@ -1070,8 +1059,8 @@ static int scsi_report_lun_scan(struct scsi_device *sdev, int bflags,
1070 unsigned int lun; 1059 unsigned int lun;
1071 unsigned int num_luns; 1060 unsigned int num_luns;
1072 unsigned int retries; 1061 unsigned int retries;
1062 int result;
1073 struct scsi_lun *lunp, *lun_data; 1063 struct scsi_lun *lunp, *lun_data;
1074 struct scsi_request *sreq;
1075 u8 *data; 1064 u8 *data;
1076 struct scsi_sense_hdr sshdr; 1065 struct scsi_sense_hdr sshdr;
1077 struct scsi_target *starget = scsi_target(sdev); 1066 struct scsi_target *starget = scsi_target(sdev);
@@ -1089,10 +1078,6 @@ static int scsi_report_lun_scan(struct scsi_device *sdev, int bflags,
1089 if (bflags & BLIST_NOLUN) 1078 if (bflags & BLIST_NOLUN)
1090 return 0; 1079 return 0;
1091 1080
1092 sreq = scsi_allocate_request(sdev, GFP_ATOMIC);
1093 if (!sreq)
1094 goto out;
1095
1096 sprintf(devname, "host %d channel %d id %d", 1081 sprintf(devname, "host %d channel %d id %d",
1097 sdev->host->host_no, sdev->channel, sdev->id); 1082 sdev->host->host_no, sdev->channel, sdev->id);
1098 1083
@@ -1110,7 +1095,7 @@ static int scsi_report_lun_scan(struct scsi_device *sdev, int bflags,
1110 lun_data = kmalloc(length, GFP_ATOMIC | 1095 lun_data = kmalloc(length, GFP_ATOMIC |
1111 (sdev->host->unchecked_isa_dma ? __GFP_DMA : 0)); 1096 (sdev->host->unchecked_isa_dma ? __GFP_DMA : 0));
1112 if (!lun_data) 1097 if (!lun_data)
1113 goto out_release_request; 1098 goto out;
1114 1099
1115 scsi_cmd[0] = REPORT_LUNS; 1100 scsi_cmd[0] = REPORT_LUNS;
1116 1101
@@ -1129,8 +1114,6 @@ static int scsi_report_lun_scan(struct scsi_device *sdev, int bflags,
1129 1114
1130 scsi_cmd[10] = 0; /* reserved */ 1115 scsi_cmd[10] = 0; /* reserved */
1131 scsi_cmd[11] = 0; /* control */ 1116 scsi_cmd[11] = 0; /* control */
1132 sreq->sr_cmd_len = 0;
1133 sreq->sr_data_direction = DMA_FROM_DEVICE;
1134 1117
1135 /* 1118 /*
1136 * We can get a UNIT ATTENTION, for example a power on/reset, so 1119 * We can get a UNIT ATTENTION, for example a power on/reset, so
@@ -1146,29 +1129,29 @@ static int scsi_report_lun_scan(struct scsi_device *sdev, int bflags,
1146 SCSI_LOG_SCAN_BUS(3, printk (KERN_INFO "scsi scan: Sending" 1129 SCSI_LOG_SCAN_BUS(3, printk (KERN_INFO "scsi scan: Sending"
1147 " REPORT LUNS to %s (try %d)\n", devname, 1130 " REPORT LUNS to %s (try %d)\n", devname,
1148 retries)); 1131 retries));
1149 scsi_wait_req(sreq, scsi_cmd, lun_data, length, 1132
1150 SCSI_TIMEOUT + 4*HZ, 3); 1133 result = scsi_execute_req(sdev, scsi_cmd, DMA_FROM_DEVICE,
1134 lun_data, length, &sshdr,
1135 SCSI_TIMEOUT + 4 * HZ, 3);
1136
1151 SCSI_LOG_SCAN_BUS(3, printk (KERN_INFO "scsi scan: REPORT LUNS" 1137 SCSI_LOG_SCAN_BUS(3, printk (KERN_INFO "scsi scan: REPORT LUNS"
1152 " %s (try %d) result 0x%x\n", sreq->sr_result 1138 " %s (try %d) result 0x%x\n", result
1153 ? "failed" : "successful", retries, 1139 ? "failed" : "successful", retries, result));
1154 sreq->sr_result)); 1140 if (result == 0)
1155 if (sreq->sr_result == 0)
1156 break; 1141 break;
1157 else if (scsi_request_normalize_sense(sreq, &sshdr)) { 1142 else if (scsi_sense_valid(&sshdr)) {
1158 if (sshdr.sense_key != UNIT_ATTENTION) 1143 if (sshdr.sense_key != UNIT_ATTENTION)
1159 break; 1144 break;
1160 } 1145 }
1161 } 1146 }
1162 1147
1163 if (sreq->sr_result) { 1148 if (result) {
1164 /* 1149 /*
1165 * The device probably does not support a REPORT LUN command 1150 * The device probably does not support a REPORT LUN command
1166 */ 1151 */
1167 kfree(lun_data); 1152 kfree(lun_data);
1168 scsi_release_request(sreq);
1169 return 1; 1153 return 1;
1170 } 1154 }
1171 scsi_release_request(sreq);
1172 1155
1173 /* 1156 /*
1174 * Get the length from the first four bytes of lun_data. 1157 * Get the length from the first four bytes of lun_data.
@@ -1242,8 +1225,6 @@ static int scsi_report_lun_scan(struct scsi_device *sdev, int bflags,
1242 kfree(lun_data); 1225 kfree(lun_data);
1243 return 0; 1226 return 0;
1244 1227
1245 out_release_request:
1246 scsi_release_request(sreq);
1247 out: 1228 out:
1248 /* 1229 /*
1249 * We are out of memory, don't try scanning any further. 1230 * We are out of memory, don't try scanning any further.
@@ -1265,9 +1246,12 @@ struct scsi_device *__scsi_add_device(struct Scsi_Host *shost, uint channel,
1265 1246
1266 get_device(&starget->dev); 1247 get_device(&starget->dev);
1267 down(&shost->scan_mutex); 1248 down(&shost->scan_mutex);
1268 res = scsi_probe_and_add_lun(starget, lun, NULL, &sdev, 1, hostdata); 1249 if (scsi_host_scan_allowed(shost)) {
1269 if (res != SCSI_SCAN_LUN_PRESENT) 1250 res = scsi_probe_and_add_lun(starget, lun, NULL, &sdev, 1,
1270 sdev = ERR_PTR(-ENODEV); 1251 hostdata);
1252 if (res != SCSI_SCAN_LUN_PRESENT)
1253 sdev = ERR_PTR(-ENODEV);
1254 }
1271 up(&shost->scan_mutex); 1255 up(&shost->scan_mutex);
1272 scsi_target_reap(starget); 1256 scsi_target_reap(starget);
1273 put_device(&starget->dev); 1257 put_device(&starget->dev);
@@ -1417,11 +1401,15 @@ int scsi_scan_host_selected(struct Scsi_Host *shost, unsigned int channel,
1417 return -EINVAL; 1401 return -EINVAL;
1418 1402
1419 down(&shost->scan_mutex); 1403 down(&shost->scan_mutex);
1420 if (channel == SCAN_WILD_CARD) 1404 if (scsi_host_scan_allowed(shost)) {
1421 for (channel = 0; channel <= shost->max_channel; channel++) 1405 if (channel == SCAN_WILD_CARD)
1406 for (channel = 0; channel <= shost->max_channel;
1407 channel++)
1408 scsi_scan_channel(shost, channel, id, lun,
1409 rescan);
1410 else
1422 scsi_scan_channel(shost, channel, id, lun, rescan); 1411 scsi_scan_channel(shost, channel, id, lun, rescan);
1423 else 1412 }
1424 scsi_scan_channel(shost, channel, id, lun, rescan);
1425 up(&shost->scan_mutex); 1413 up(&shost->scan_mutex);
1426 1414
1427 return 0; 1415 return 0;
diff --git a/drivers/scsi/scsi_sysfs.c b/drivers/scsi/scsi_sysfs.c
index beed7fbe1cb..dae59d1da07 100644
--- a/drivers/scsi/scsi_sysfs.c
+++ b/drivers/scsi/scsi_sysfs.c
@@ -48,6 +48,30 @@ const char *scsi_device_state_name(enum scsi_device_state state)
48 return name; 48 return name;
49} 49}
50 50
51static struct {
52 enum scsi_host_state value;
53 char *name;
54} shost_states[] = {
55 { SHOST_CREATED, "created" },
56 { SHOST_RUNNING, "running" },
57 { SHOST_CANCEL, "cancel" },
58 { SHOST_DEL, "deleted" },
59 { SHOST_RECOVERY, "recovery" },
60};
61const char *scsi_host_state_name(enum scsi_host_state state)
62{
63 int i;
64 char *name = NULL;
65
66 for (i = 0; i < sizeof(shost_states)/sizeof(shost_states[0]); i++) {
67 if (shost_states[i].value == state) {
68 name = shost_states[i].name;
69 break;
70 }
71 }
72 return name;
73}
74
51static int check_set(unsigned int *val, char *src) 75static int check_set(unsigned int *val, char *src)
52{ 76{
53 char *last; 77 char *last;
@@ -124,6 +148,43 @@ static ssize_t store_scan(struct class_device *class_dev, const char *buf,
124}; 148};
125static CLASS_DEVICE_ATTR(scan, S_IWUSR, NULL, store_scan); 149static CLASS_DEVICE_ATTR(scan, S_IWUSR, NULL, store_scan);
126 150
151static ssize_t
152store_shost_state(struct class_device *class_dev, const char *buf, size_t count)
153{
154 int i;
155 struct Scsi_Host *shost = class_to_shost(class_dev);
156 enum scsi_host_state state = 0;
157
158 for (i = 0; i < sizeof(shost_states)/sizeof(shost_states[0]); i++) {
159 const int len = strlen(shost_states[i].name);
160 if (strncmp(shost_states[i].name, buf, len) == 0 &&
161 buf[len] == '\n') {
162 state = shost_states[i].value;
163 break;
164 }
165 }
166 if (!state)
167 return -EINVAL;
168
169 if (scsi_host_set_state(shost, state))
170 return -EINVAL;
171 return count;
172}
173
174static ssize_t
175show_shost_state(struct class_device *class_dev, char *buf)
176{
177 struct Scsi_Host *shost = class_to_shost(class_dev);
178 const char *name = scsi_host_state_name(shost->shost_state);
179
180 if (!name)
181 return -EINVAL;
182
183 return snprintf(buf, 20, "%s\n", name);
184}
185
186static CLASS_DEVICE_ATTR(state, S_IRUGO | S_IWUSR, show_shost_state, store_shost_state);
187
127shost_rd_attr(unique_id, "%u\n"); 188shost_rd_attr(unique_id, "%u\n");
128shost_rd_attr(host_busy, "%hu\n"); 189shost_rd_attr(host_busy, "%hu\n");
129shost_rd_attr(cmd_per_lun, "%hd\n"); 190shost_rd_attr(cmd_per_lun, "%hd\n");
@@ -139,6 +200,7 @@ static struct class_device_attribute *scsi_sysfs_shost_attrs[] = {
139 &class_device_attr_unchecked_isa_dma, 200 &class_device_attr_unchecked_isa_dma,
140 &class_device_attr_proc_name, 201 &class_device_attr_proc_name,
141 &class_device_attr_scan, 202 &class_device_attr_scan,
203 &class_device_attr_state,
142 NULL 204 NULL
143}; 205};
144 206
diff --git a/drivers/scsi/scsi_transport_fc.c b/drivers/scsi/scsi_transport_fc.c
index e6412fce423..2cab556b6e8 100644
--- a/drivers/scsi/scsi_transport_fc.c
+++ b/drivers/scsi/scsi_transport_fc.c
@@ -252,7 +252,8 @@ struct fc_internal {
252 252
253#define to_fc_internal(tmpl) container_of(tmpl, struct fc_internal, t) 253#define to_fc_internal(tmpl) container_of(tmpl, struct fc_internal, t)
254 254
255static int fc_target_setup(struct device *dev) 255static int fc_target_setup(struct transport_container *tc, struct device *dev,
256 struct class_device *cdev)
256{ 257{
257 struct scsi_target *starget = to_scsi_target(dev); 258 struct scsi_target *starget = to_scsi_target(dev);
258 struct fc_rport *rport = starget_to_rport(starget); 259 struct fc_rport *rport = starget_to_rport(starget);
@@ -281,7 +282,8 @@ static DECLARE_TRANSPORT_CLASS(fc_transport_class,
281 NULL, 282 NULL,
282 NULL); 283 NULL);
283 284
284static int fc_host_setup(struct device *dev) 285static int fc_host_setup(struct transport_container *tc, struct device *dev,
286 struct class_device *cdev)
285{ 287{
286 struct Scsi_Host *shost = dev_to_shost(dev); 288 struct Scsi_Host *shost = dev_to_shost(dev);
287 289
diff --git a/drivers/scsi/scsi_transport_spi.c b/drivers/scsi/scsi_transport_spi.c
index 7670919a087..ef577c8c218 100644
--- a/drivers/scsi/scsi_transport_spi.c
+++ b/drivers/scsi/scsi_transport_spi.c
@@ -28,14 +28,14 @@
28#include "scsi_priv.h" 28#include "scsi_priv.h"
29#include <scsi/scsi_device.h> 29#include <scsi/scsi_device.h>
30#include <scsi/scsi_host.h> 30#include <scsi/scsi_host.h>
31#include <scsi/scsi_request.h> 31#include <scsi/scsi_cmnd.h>
32#include <scsi/scsi_eh.h> 32#include <scsi/scsi_eh.h>
33#include <scsi/scsi_transport.h> 33#include <scsi/scsi_transport.h>
34#include <scsi/scsi_transport_spi.h> 34#include <scsi/scsi_transport_spi.h>
35 35
36#define SPI_PRINTK(x, l, f, a...) dev_printk(l, &(x)->dev, f , ##a) 36#define SPI_PRINTK(x, l, f, a...) dev_printk(l, &(x)->dev, f , ##a)
37 37
38#define SPI_NUM_ATTRS 13 /* increase this if you add attributes */ 38#define SPI_NUM_ATTRS 14 /* increase this if you add attributes */
39#define SPI_OTHER_ATTRS 1 /* Increase this if you add "always 39#define SPI_OTHER_ATTRS 1 /* Increase this if you add "always
40 * on" attributes */ 40 * on" attributes */
41#define SPI_HOST_ATTRS 1 41#define SPI_HOST_ATTRS 1
@@ -106,27 +106,31 @@ static int sprint_frac(char *dest, int value, int denom)
106 return result; 106 return result;
107} 107}
108 108
109/* Modification of scsi_wait_req that will clear UNIT ATTENTION conditions 109static int spi_execute(struct scsi_device *sdev, const void *cmd,
110 * resulting from (likely) bus and device resets */ 110 enum dma_data_direction dir,
111static void spi_wait_req(struct scsi_request *sreq, const void *cmd, 111 void *buffer, unsigned bufflen,
112 void *buffer, unsigned bufflen) 112 struct scsi_sense_hdr *sshdr)
113{ 113{
114 int i; 114 int i, result;
115 unsigned char sense[SCSI_SENSE_BUFFERSIZE];
115 116
116 for(i = 0; i < DV_RETRIES; i++) { 117 for(i = 0; i < DV_RETRIES; i++) {
117 sreq->sr_request->flags |= REQ_FAILFAST; 118 result = scsi_execute(sdev, cmd, dir, buffer, bufflen,
118 119 sense, DV_TIMEOUT, /* retries */ 1,
119 scsi_wait_req(sreq, cmd, buffer, bufflen, 120 REQ_FAILFAST);
120 DV_TIMEOUT, /* retries */ 1); 121 if (result & DRIVER_SENSE) {
121 if (sreq->sr_result & DRIVER_SENSE) { 122 struct scsi_sense_hdr sshdr_tmp;
122 struct scsi_sense_hdr sshdr; 123 if (!sshdr)
123 124 sshdr = &sshdr_tmp;
124 if (scsi_request_normalize_sense(sreq, &sshdr) 125
125 && sshdr.sense_key == UNIT_ATTENTION) 126 if (scsi_normalize_sense(sense, sizeof(*sense),
127 sshdr)
128 && sshdr->sense_key == UNIT_ATTENTION)
126 continue; 129 continue;
127 } 130 }
128 break; 131 break;
129 } 132 }
133 return result;
130} 134}
131 135
132static struct { 136static struct {
@@ -162,7 +166,8 @@ static inline enum spi_signal_type spi_signal_to_value(const char *name)
162 return SPI_SIGNAL_UNKNOWN; 166 return SPI_SIGNAL_UNKNOWN;
163} 167}
164 168
165static int spi_host_setup(struct device *dev) 169static int spi_host_setup(struct transport_container *tc, struct device *dev,
170 struct class_device *cdev)
166{ 171{
167 struct Scsi_Host *shost = dev_to_shost(dev); 172 struct Scsi_Host *shost = dev_to_shost(dev);
168 173
@@ -196,7 +201,9 @@ static int spi_host_match(struct attribute_container *cont,
196 return &i->t.host_attrs.ac == cont; 201 return &i->t.host_attrs.ac == cont;
197} 202}
198 203
199static int spi_device_configure(struct device *dev) 204static int spi_device_configure(struct transport_container *tc,
205 struct device *dev,
206 struct class_device *cdev)
200{ 207{
201 struct scsi_device *sdev = to_scsi_device(dev); 208 struct scsi_device *sdev = to_scsi_device(dev);
202 struct scsi_target *starget = sdev->sdev_target; 209 struct scsi_target *starget = sdev->sdev_target;
@@ -214,7 +221,9 @@ static int spi_device_configure(struct device *dev)
214 return 0; 221 return 0;
215} 222}
216 223
217static int spi_setup_transport_attrs(struct device *dev) 224static int spi_setup_transport_attrs(struct transport_container *tc,
225 struct device *dev,
226 struct class_device *cdev)
218{ 227{
219 struct scsi_target *starget = to_scsi_target(dev); 228 struct scsi_target *starget = to_scsi_target(dev);
220 229
@@ -231,6 +240,7 @@ static int spi_setup_transport_attrs(struct device *dev)
231 spi_rd_strm(starget) = 0; 240 spi_rd_strm(starget) = 0;
232 spi_rti(starget) = 0; 241 spi_rti(starget) = 0;
233 spi_pcomp_en(starget) = 0; 242 spi_pcomp_en(starget) = 0;
243 spi_hold_mcs(starget) = 0;
234 spi_dv_pending(starget) = 0; 244 spi_dv_pending(starget) = 0;
235 spi_initial_dv(starget) = 0; 245 spi_initial_dv(starget) = 0;
236 init_MUTEX(&spi_dv_sem(starget)); 246 init_MUTEX(&spi_dv_sem(starget));
@@ -347,6 +357,7 @@ spi_transport_rd_attr(wr_flow, "%d\n");
347spi_transport_rd_attr(rd_strm, "%d\n"); 357spi_transport_rd_attr(rd_strm, "%d\n");
348spi_transport_rd_attr(rti, "%d\n"); 358spi_transport_rd_attr(rti, "%d\n");
349spi_transport_rd_attr(pcomp_en, "%d\n"); 359spi_transport_rd_attr(pcomp_en, "%d\n");
360spi_transport_rd_attr(hold_mcs, "%d\n");
350 361
351/* we only care about the first child device so we return 1 */ 362/* we only care about the first child device so we return 1 */
352static int child_iter(struct device *dev, void *data) 363static int child_iter(struct device *dev, void *data)
@@ -539,13 +550,13 @@ enum spi_compare_returns {
539/* This is for read/write Domain Validation: If the device supports 550/* This is for read/write Domain Validation: If the device supports
540 * an echo buffer, we do read/write tests to it */ 551 * an echo buffer, we do read/write tests to it */
541static enum spi_compare_returns 552static enum spi_compare_returns
542spi_dv_device_echo_buffer(struct scsi_request *sreq, u8 *buffer, 553spi_dv_device_echo_buffer(struct scsi_device *sdev, u8 *buffer,
543 u8 *ptr, const int retries) 554 u8 *ptr, const int retries)
544{ 555{
545 struct scsi_device *sdev = sreq->sr_device;
546 int len = ptr - buffer; 556 int len = ptr - buffer;
547 int j, k, r; 557 int j, k, r, result;
548 unsigned int pattern = 0x0000ffff; 558 unsigned int pattern = 0x0000ffff;
559 struct scsi_sense_hdr sshdr;
549 560
550 const char spi_write_buffer[] = { 561 const char spi_write_buffer[] = {
551 WRITE_BUFFER, 0x0a, 0, 0, 0, 0, 0, len >> 8, len & 0xff, 0 562 WRITE_BUFFER, 0x0a, 0, 0, 0, 0, 0, len >> 8, len & 0xff, 0
@@ -590,14 +601,12 @@ spi_dv_device_echo_buffer(struct scsi_request *sreq, u8 *buffer,
590 } 601 }
591 602
592 for (r = 0; r < retries; r++) { 603 for (r = 0; r < retries; r++) {
593 sreq->sr_cmd_len = 0; /* wait_req to fill in */ 604 result = spi_execute(sdev, spi_write_buffer, DMA_TO_DEVICE,
594 sreq->sr_data_direction = DMA_TO_DEVICE; 605 buffer, len, &sshdr);
595 spi_wait_req(sreq, spi_write_buffer, buffer, len); 606 if(result || !scsi_device_online(sdev)) {
596 if(sreq->sr_result || !scsi_device_online(sdev)) {
597 struct scsi_sense_hdr sshdr;
598 607
599 scsi_device_set_state(sdev, SDEV_QUIESCE); 608 scsi_device_set_state(sdev, SDEV_QUIESCE);
600 if (scsi_request_normalize_sense(sreq, &sshdr) 609 if (scsi_sense_valid(&sshdr)
601 && sshdr.sense_key == ILLEGAL_REQUEST 610 && sshdr.sense_key == ILLEGAL_REQUEST
602 /* INVALID FIELD IN CDB */ 611 /* INVALID FIELD IN CDB */
603 && sshdr.asc == 0x24 && sshdr.ascq == 0x00) 612 && sshdr.asc == 0x24 && sshdr.ascq == 0x00)
@@ -609,14 +618,13 @@ spi_dv_device_echo_buffer(struct scsi_request *sreq, u8 *buffer,
609 return SPI_COMPARE_SKIP_TEST; 618 return SPI_COMPARE_SKIP_TEST;
610 619
611 620
612 SPI_PRINTK(sdev->sdev_target, KERN_ERR, "Write Buffer failure %x\n", sreq->sr_result); 621 SPI_PRINTK(sdev->sdev_target, KERN_ERR, "Write Buffer failure %x\n", result);
613 return SPI_COMPARE_FAILURE; 622 return SPI_COMPARE_FAILURE;
614 } 623 }
615 624
616 memset(ptr, 0, len); 625 memset(ptr, 0, len);
617 sreq->sr_cmd_len = 0; /* wait_req to fill in */ 626 spi_execute(sdev, spi_read_buffer, DMA_FROM_DEVICE,
618 sreq->sr_data_direction = DMA_FROM_DEVICE; 627 ptr, len, NULL);
619 spi_wait_req(sreq, spi_read_buffer, ptr, len);
620 scsi_device_set_state(sdev, SDEV_QUIESCE); 628 scsi_device_set_state(sdev, SDEV_QUIESCE);
621 629
622 if (memcmp(buffer, ptr, len) != 0) 630 if (memcmp(buffer, ptr, len) != 0)
@@ -628,25 +636,22 @@ spi_dv_device_echo_buffer(struct scsi_request *sreq, u8 *buffer,
628/* This is for the simplest form of Domain Validation: a read test 636/* This is for the simplest form of Domain Validation: a read test
629 * on the inquiry data from the device */ 637 * on the inquiry data from the device */
630static enum spi_compare_returns 638static enum spi_compare_returns
631spi_dv_device_compare_inquiry(struct scsi_request *sreq, u8 *buffer, 639spi_dv_device_compare_inquiry(struct scsi_device *sdev, u8 *buffer,
632 u8 *ptr, const int retries) 640 u8 *ptr, const int retries)
633{ 641{
634 int r; 642 int r, result;
635 const int len = sreq->sr_device->inquiry_len; 643 const int len = sdev->inquiry_len;
636 struct scsi_device *sdev = sreq->sr_device;
637 const char spi_inquiry[] = { 644 const char spi_inquiry[] = {
638 INQUIRY, 0, 0, 0, len, 0 645 INQUIRY, 0, 0, 0, len, 0
639 }; 646 };
640 647
641 for (r = 0; r < retries; r++) { 648 for (r = 0; r < retries; r++) {
642 sreq->sr_cmd_len = 0; /* wait_req to fill in */
643 sreq->sr_data_direction = DMA_FROM_DEVICE;
644
645 memset(ptr, 0, len); 649 memset(ptr, 0, len);
646 650
647 spi_wait_req(sreq, spi_inquiry, ptr, len); 651 result = spi_execute(sdev, spi_inquiry, DMA_FROM_DEVICE,
652 ptr, len, NULL);
648 653
649 if(sreq->sr_result || !scsi_device_online(sdev)) { 654 if(result || !scsi_device_online(sdev)) {
650 scsi_device_set_state(sdev, SDEV_QUIESCE); 655 scsi_device_set_state(sdev, SDEV_QUIESCE);
651 return SPI_COMPARE_FAILURE; 656 return SPI_COMPARE_FAILURE;
652 } 657 }
@@ -667,12 +672,11 @@ spi_dv_device_compare_inquiry(struct scsi_request *sreq, u8 *buffer,
667} 672}
668 673
669static enum spi_compare_returns 674static enum spi_compare_returns
670spi_dv_retrain(struct scsi_request *sreq, u8 *buffer, u8 *ptr, 675spi_dv_retrain(struct scsi_device *sdev, u8 *buffer, u8 *ptr,
671 enum spi_compare_returns 676 enum spi_compare_returns
672 (*compare_fn)(struct scsi_request *, u8 *, u8 *, int)) 677 (*compare_fn)(struct scsi_device *, u8 *, u8 *, int))
673{ 678{
674 struct spi_internal *i = to_spi_internal(sreq->sr_host->transportt); 679 struct spi_internal *i = to_spi_internal(sdev->host->transportt);
675 struct scsi_device *sdev = sreq->sr_device;
676 struct scsi_target *starget = sdev->sdev_target; 680 struct scsi_target *starget = sdev->sdev_target;
677 int period = 0, prevperiod = 0; 681 int period = 0, prevperiod = 0;
678 enum spi_compare_returns retval; 682 enum spi_compare_returns retval;
@@ -680,7 +684,7 @@ spi_dv_retrain(struct scsi_request *sreq, u8 *buffer, u8 *ptr,
680 684
681 for (;;) { 685 for (;;) {
682 int newperiod; 686 int newperiod;
683 retval = compare_fn(sreq, buffer, ptr, DV_LOOPS); 687 retval = compare_fn(sdev, buffer, ptr, DV_LOOPS);
684 688
685 if (retval == SPI_COMPARE_SUCCESS 689 if (retval == SPI_COMPARE_SUCCESS
686 || retval == SPI_COMPARE_SKIP_TEST) 690 || retval == SPI_COMPARE_SKIP_TEST)
@@ -726,9 +730,9 @@ spi_dv_retrain(struct scsi_request *sreq, u8 *buffer, u8 *ptr,
726} 730}
727 731
728static int 732static int
729spi_dv_device_get_echo_buffer(struct scsi_request *sreq, u8 *buffer) 733spi_dv_device_get_echo_buffer(struct scsi_device *sdev, u8 *buffer)
730{ 734{
731 int l; 735 int l, result;
732 736
733 /* first off do a test unit ready. This can error out 737 /* first off do a test unit ready. This can error out
734 * because of reservations or some other reason. If it 738 * because of reservations or some other reason. If it
@@ -744,18 +748,16 @@ spi_dv_device_get_echo_buffer(struct scsi_request *sreq, u8 *buffer)
744 }; 748 };
745 749
746 750
747 sreq->sr_cmd_len = 0;
748 sreq->sr_data_direction = DMA_NONE;
749
750 /* We send a set of three TURs to clear any outstanding 751 /* We send a set of three TURs to clear any outstanding
751 * unit attention conditions if they exist (Otherwise the 752 * unit attention conditions if they exist (Otherwise the
752 * buffer tests won't be happy). If the TUR still fails 753 * buffer tests won't be happy). If the TUR still fails
753 * (reservation conflict, device not ready, etc) just 754 * (reservation conflict, device not ready, etc) just
754 * skip the write tests */ 755 * skip the write tests */
755 for (l = 0; ; l++) { 756 for (l = 0; ; l++) {
756 spi_wait_req(sreq, spi_test_unit_ready, NULL, 0); 757 result = spi_execute(sdev, spi_test_unit_ready, DMA_NONE,
758 NULL, 0, NULL);
757 759
758 if(sreq->sr_result) { 760 if(result) {
759 if(l >= 3) 761 if(l >= 3)
760 return 0; 762 return 0;
761 } else { 763 } else {
@@ -764,12 +766,10 @@ spi_dv_device_get_echo_buffer(struct scsi_request *sreq, u8 *buffer)
764 } 766 }
765 } 767 }
766 768
767 sreq->sr_cmd_len = 0; 769 result = spi_execute(sdev, spi_read_buffer_descriptor,
768 sreq->sr_data_direction = DMA_FROM_DEVICE; 770 DMA_FROM_DEVICE, buffer, 4, NULL);
769
770 spi_wait_req(sreq, spi_read_buffer_descriptor, buffer, 4);
771 771
772 if (sreq->sr_result) 772 if (result)
773 /* Device has no echo buffer */ 773 /* Device has no echo buffer */
774 return 0; 774 return 0;
775 775
@@ -777,17 +777,16 @@ spi_dv_device_get_echo_buffer(struct scsi_request *sreq, u8 *buffer)
777} 777}
778 778
779static void 779static void
780spi_dv_device_internal(struct scsi_request *sreq, u8 *buffer) 780spi_dv_device_internal(struct scsi_device *sdev, u8 *buffer)
781{ 781{
782 struct spi_internal *i = to_spi_internal(sreq->sr_host->transportt); 782 struct spi_internal *i = to_spi_internal(sdev->host->transportt);
783 struct scsi_device *sdev = sreq->sr_device;
784 struct scsi_target *starget = sdev->sdev_target; 783 struct scsi_target *starget = sdev->sdev_target;
785 int len = sdev->inquiry_len; 784 int len = sdev->inquiry_len;
786 /* first set us up for narrow async */ 785 /* first set us up for narrow async */
787 DV_SET(offset, 0); 786 DV_SET(offset, 0);
788 DV_SET(width, 0); 787 DV_SET(width, 0);
789 788
790 if (spi_dv_device_compare_inquiry(sreq, buffer, buffer, DV_LOOPS) 789 if (spi_dv_device_compare_inquiry(sdev, buffer, buffer, DV_LOOPS)
791 != SPI_COMPARE_SUCCESS) { 790 != SPI_COMPARE_SUCCESS) {
792 SPI_PRINTK(starget, KERN_ERR, "Domain Validation Initial Inquiry Failed\n"); 791 SPI_PRINTK(starget, KERN_ERR, "Domain Validation Initial Inquiry Failed\n");
793 /* FIXME: should probably offline the device here? */ 792 /* FIXME: should probably offline the device here? */
@@ -799,7 +798,7 @@ spi_dv_device_internal(struct scsi_request *sreq, u8 *buffer)
799 scsi_device_wide(sdev)) { 798 scsi_device_wide(sdev)) {
800 i->f->set_width(starget, 1); 799 i->f->set_width(starget, 1);
801 800
802 if (spi_dv_device_compare_inquiry(sreq, buffer, 801 if (spi_dv_device_compare_inquiry(sdev, buffer,
803 buffer + len, 802 buffer + len,
804 DV_LOOPS) 803 DV_LOOPS)
805 != SPI_COMPARE_SUCCESS) { 804 != SPI_COMPARE_SUCCESS) {
@@ -820,7 +819,7 @@ spi_dv_device_internal(struct scsi_request *sreq, u8 *buffer)
820 819
821 len = 0; 820 len = 0;
822 if (scsi_device_dt(sdev)) 821 if (scsi_device_dt(sdev))
823 len = spi_dv_device_get_echo_buffer(sreq, buffer); 822 len = spi_dv_device_get_echo_buffer(sdev, buffer);
824 823
825 retry: 824 retry:
826 825
@@ -846,7 +845,7 @@ spi_dv_device_internal(struct scsi_request *sreq, u8 *buffer)
846 845
847 if (len == 0) { 846 if (len == 0) {
848 SPI_PRINTK(starget, KERN_INFO, "Domain Validation skipping write tests\n"); 847 SPI_PRINTK(starget, KERN_INFO, "Domain Validation skipping write tests\n");
849 spi_dv_retrain(sreq, buffer, buffer + len, 848 spi_dv_retrain(sdev, buffer, buffer + len,
850 spi_dv_device_compare_inquiry); 849 spi_dv_device_compare_inquiry);
851 return; 850 return;
852 } 851 }
@@ -856,7 +855,7 @@ spi_dv_device_internal(struct scsi_request *sreq, u8 *buffer)
856 len = SPI_MAX_ECHO_BUFFER_SIZE; 855 len = SPI_MAX_ECHO_BUFFER_SIZE;
857 } 856 }
858 857
859 if (spi_dv_retrain(sreq, buffer, buffer + len, 858 if (spi_dv_retrain(sdev, buffer, buffer + len,
860 spi_dv_device_echo_buffer) 859 spi_dv_device_echo_buffer)
861 == SPI_COMPARE_SKIP_TEST) { 860 == SPI_COMPARE_SKIP_TEST) {
862 /* OK, the stupid drive can't do a write echo buffer 861 /* OK, the stupid drive can't do a write echo buffer
@@ -879,16 +878,12 @@ spi_dv_device_internal(struct scsi_request *sreq, u8 *buffer)
879void 878void
880spi_dv_device(struct scsi_device *sdev) 879spi_dv_device(struct scsi_device *sdev)
881{ 880{
882 struct scsi_request *sreq = scsi_allocate_request(sdev, GFP_KERNEL);
883 struct scsi_target *starget = sdev->sdev_target; 881 struct scsi_target *starget = sdev->sdev_target;
884 u8 *buffer; 882 u8 *buffer;
885 const int len = SPI_MAX_ECHO_BUFFER_SIZE*2; 883 const int len = SPI_MAX_ECHO_BUFFER_SIZE*2;
886 884
887 if (unlikely(!sreq))
888 return;
889
890 if (unlikely(scsi_device_get(sdev))) 885 if (unlikely(scsi_device_get(sdev)))
891 goto out_free_req; 886 return;
892 887
893 buffer = kmalloc(len, GFP_KERNEL); 888 buffer = kmalloc(len, GFP_KERNEL);
894 889
@@ -909,7 +904,7 @@ spi_dv_device(struct scsi_device *sdev)
909 904
910 SPI_PRINTK(starget, KERN_INFO, "Beginning Domain Validation\n"); 905 SPI_PRINTK(starget, KERN_INFO, "Beginning Domain Validation\n");
911 906
912 spi_dv_device_internal(sreq, buffer); 907 spi_dv_device_internal(sdev, buffer);
913 908
914 SPI_PRINTK(starget, KERN_INFO, "Ending Domain Validation\n"); 909 SPI_PRINTK(starget, KERN_INFO, "Ending Domain Validation\n");
915 910
@@ -924,8 +919,6 @@ spi_dv_device(struct scsi_device *sdev)
924 kfree(buffer); 919 kfree(buffer);
925 out_put: 920 out_put:
926 scsi_device_put(sdev); 921 scsi_device_put(sdev);
927 out_free_req:
928 scsi_release_request(sreq);
929} 922}
930EXPORT_SYMBOL(spi_dv_device); 923EXPORT_SYMBOL(spi_dv_device);
931 924
@@ -1028,10 +1021,17 @@ void spi_display_xfer_agreement(struct scsi_target *starget)
1028 sprint_frac(tmp, picosec, 1000); 1021 sprint_frac(tmp, picosec, 1000);
1029 1022
1030 dev_info(&starget->dev, 1023 dev_info(&starget->dev,
1031 "%s %sSCSI %d.%d MB/s %s%s%s (%s ns, offset %d)\n", 1024 "%s %sSCSI %d.%d MB/s %s%s%s%s%s%s%s%s (%s ns, offset %d)\n",
1032 scsi, tp->width ? "WIDE " : "", kb100/10, kb100 % 10, 1025 scsi, tp->width ? "WIDE " : "", kb100/10, kb100 % 10,
1033 tp->dt ? "DT" : "ST", tp->iu ? " IU" : "", 1026 tp->dt ? "DT" : "ST",
1034 tp->qas ? " QAS" : "", tmp, tp->offset); 1027 tp->iu ? " IU" : "",
1028 tp->qas ? " QAS" : "",
1029 tp->rd_strm ? " RDSTRM" : "",
1030 tp->rti ? " RTI" : "",
1031 tp->wr_flow ? " WRFLOW" : "",
1032 tp->pcomp_en ? " PCOMP" : "",
1033 tp->hold_mcs ? " HMCS" : "",
1034 tmp, tp->offset);
1035 } else { 1035 } else {
1036 dev_info(&starget->dev, "%sasynchronous.\n", 1036 dev_info(&starget->dev, "%sasynchronous.\n",
1037 tp->width ? "wide " : ""); 1037 tp->width ? "wide " : "");
@@ -1073,6 +1073,7 @@ static int spi_device_match(struct attribute_container *cont,
1073{ 1073{
1074 struct scsi_device *sdev; 1074 struct scsi_device *sdev;
1075 struct Scsi_Host *shost; 1075 struct Scsi_Host *shost;
1076 struct spi_internal *i;
1076 1077
1077 if (!scsi_is_sdev_device(dev)) 1078 if (!scsi_is_sdev_device(dev))
1078 return 0; 1079 return 0;
@@ -1085,6 +1086,9 @@ static int spi_device_match(struct attribute_container *cont,
1085 /* Note: this class has no device attributes, so it has 1086 /* Note: this class has no device attributes, so it has
1086 * no per-HBA allocation and thus we don't need to distinguish 1087 * no per-HBA allocation and thus we don't need to distinguish
1087 * the attribute containers for the device */ 1088 * the attribute containers for the device */
1089 i = to_spi_internal(shost->transportt);
1090 if (i->f->deny_binding && i->f->deny_binding(sdev->sdev_target))
1091 return 0;
1088 return 1; 1092 return 1;
1089} 1093}
1090 1094
@@ -1092,6 +1096,7 @@ static int spi_target_match(struct attribute_container *cont,
1092 struct device *dev) 1096 struct device *dev)
1093{ 1097{
1094 struct Scsi_Host *shost; 1098 struct Scsi_Host *shost;
1099 struct scsi_target *starget;
1095 struct spi_internal *i; 1100 struct spi_internal *i;
1096 1101
1097 if (!scsi_is_target_device(dev)) 1102 if (!scsi_is_target_device(dev))
@@ -1103,7 +1108,11 @@ static int spi_target_match(struct attribute_container *cont,
1103 return 0; 1108 return 0;
1104 1109
1105 i = to_spi_internal(shost->transportt); 1110 i = to_spi_internal(shost->transportt);
1106 1111 starget = to_scsi_target(dev);
1112
1113 if (i->f->deny_binding && i->f->deny_binding(starget))
1114 return 0;
1115
1107 return &i->t.target_attrs.ac == cont; 1116 return &i->t.target_attrs.ac == cont;
1108} 1117}
1109 1118
@@ -1154,6 +1163,7 @@ spi_attach_transport(struct spi_function_template *ft)
1154 SETUP_ATTRIBUTE(rd_strm); 1163 SETUP_ATTRIBUTE(rd_strm);
1155 SETUP_ATTRIBUTE(rti); 1164 SETUP_ATTRIBUTE(rti);
1156 SETUP_ATTRIBUTE(pcomp_en); 1165 SETUP_ATTRIBUTE(pcomp_en);
1166 SETUP_ATTRIBUTE(hold_mcs);
1157 1167
1158 /* if you add an attribute but forget to increase SPI_NUM_ATTRS 1168 /* if you add an attribute but forget to increase SPI_NUM_ATTRS
1159 * this bug will trigger */ 1169 * this bug will trigger */
diff --git a/drivers/scsi/sd.c b/drivers/scsi/sd.c
index 0410e1bf109..de564b38605 100644
--- a/drivers/scsi/sd.c
+++ b/drivers/scsi/sd.c
@@ -59,7 +59,6 @@
59#include <scsi/scsi_eh.h> 59#include <scsi/scsi_eh.h>
60#include <scsi/scsi_host.h> 60#include <scsi/scsi_host.h>
61#include <scsi/scsi_ioctl.h> 61#include <scsi/scsi_ioctl.h>
62#include <scsi/scsi_request.h>
63#include <scsi/scsicam.h> 62#include <scsi/scsicam.h>
64 63
65#include "scsi_logging.h" 64#include "scsi_logging.h"
@@ -125,7 +124,7 @@ static int sd_issue_flush(struct device *, sector_t *);
125static void sd_end_flush(request_queue_t *, struct request *); 124static void sd_end_flush(request_queue_t *, struct request *);
126static int sd_prepare_flush(request_queue_t *, struct request *); 125static int sd_prepare_flush(request_queue_t *, struct request *);
127static void sd_read_capacity(struct scsi_disk *sdkp, char *diskname, 126static void sd_read_capacity(struct scsi_disk *sdkp, char *diskname,
128 struct scsi_request *SRpnt, unsigned char *buffer); 127 unsigned char *buffer);
129 128
130static struct scsi_driver sd_template = { 129static struct scsi_driver sd_template = {
131 .owner = THIS_MODULE, 130 .owner = THIS_MODULE,
@@ -682,19 +681,13 @@ not_present:
682 681
683static int sd_sync_cache(struct scsi_device *sdp) 682static int sd_sync_cache(struct scsi_device *sdp)
684{ 683{
685 struct scsi_request *sreq;
686 int retries, res; 684 int retries, res;
685 struct scsi_sense_hdr sshdr;
687 686
688 if (!scsi_device_online(sdp)) 687 if (!scsi_device_online(sdp))
689 return -ENODEV; 688 return -ENODEV;
690 689
691 sreq = scsi_allocate_request(sdp, GFP_KERNEL);
692 if (!sreq) {
693 printk("FAILED\n No memory for request\n");
694 return -ENOMEM;
695 }
696 690
697 sreq->sr_data_direction = DMA_NONE;
698 for (retries = 3; retries > 0; --retries) { 691 for (retries = 3; retries > 0; --retries) {
699 unsigned char cmd[10] = { 0 }; 692 unsigned char cmd[10] = { 0 };
700 693
@@ -703,22 +696,20 @@ static int sd_sync_cache(struct scsi_device *sdp)
703 * Leave the rest of the command zero to indicate 696 * Leave the rest of the command zero to indicate
704 * flush everything. 697 * flush everything.
705 */ 698 */
706 scsi_wait_req(sreq, cmd, NULL, 0, SD_TIMEOUT, SD_MAX_RETRIES); 699 res = scsi_execute_req(sdp, cmd, DMA_NONE, NULL, 0, &sshdr,
707 if (sreq->sr_result == 0) 700 SD_TIMEOUT, SD_MAX_RETRIES);
701 if (res == 0)
708 break; 702 break;
709 } 703 }
710 704
711 res = sreq->sr_result; 705 if (res) { printk(KERN_WARNING "FAILED\n status = %x, message = %02x, "
712 if (res) {
713 printk(KERN_WARNING "FAILED\n status = %x, message = %02x, "
714 "host = %d, driver = %02x\n ", 706 "host = %d, driver = %02x\n ",
715 status_byte(res), msg_byte(res), 707 status_byte(res), msg_byte(res),
716 host_byte(res), driver_byte(res)); 708 host_byte(res), driver_byte(res));
717 if (driver_byte(res) & DRIVER_SENSE) 709 if (driver_byte(res) & DRIVER_SENSE)
718 scsi_print_req_sense("sd", sreq); 710 scsi_print_sense_hdr("sd", &sshdr);
719 } 711 }
720 712
721 scsi_release_request(sreq);
722 return res; 713 return res;
723} 714}
724 715
@@ -957,22 +948,19 @@ static void sd_rw_intr(struct scsi_cmnd * SCpnt)
957 scsi_io_completion(SCpnt, good_bytes, block_sectors << 9); 948 scsi_io_completion(SCpnt, good_bytes, block_sectors << 9);
958} 949}
959 950
960static int media_not_present(struct scsi_disk *sdkp, struct scsi_request *srp) 951static int media_not_present(struct scsi_disk *sdkp,
952 struct scsi_sense_hdr *sshdr)
961{ 953{
962 struct scsi_sense_hdr sshdr;
963 954
964 if (!srp->sr_result) 955 if (!scsi_sense_valid(sshdr))
965 return 0;
966 if (!(driver_byte(srp->sr_result) & DRIVER_SENSE))
967 return 0; 956 return 0;
968 /* not invoked for commands that could return deferred errors */ 957 /* not invoked for commands that could return deferred errors */
969 if (scsi_request_normalize_sense(srp, &sshdr)) { 958 if (sshdr->sense_key != NOT_READY &&
970 if (sshdr.sense_key != NOT_READY && 959 sshdr->sense_key != UNIT_ATTENTION)
971 sshdr.sense_key != UNIT_ATTENTION) 960 return 0;
972 return 0; 961 if (sshdr->asc != 0x3A) /* medium not present */
973 if (sshdr.asc != 0x3A) /* medium not present */ 962 return 0;
974 return 0; 963
975 }
976 set_media_not_present(sdkp); 964 set_media_not_present(sdkp);
977 return 1; 965 return 1;
978} 966}
@@ -981,10 +969,10 @@ static int media_not_present(struct scsi_disk *sdkp, struct scsi_request *srp)
981 * spinup disk - called only in sd_revalidate_disk() 969 * spinup disk - called only in sd_revalidate_disk()
982 */ 970 */
983static void 971static void
984sd_spinup_disk(struct scsi_disk *sdkp, char *diskname, 972sd_spinup_disk(struct scsi_disk *sdkp, char *diskname)
985 struct scsi_request *SRpnt, unsigned char *buffer) { 973{
986 unsigned char cmd[10]; 974 unsigned char cmd[10];
987 unsigned long spintime_value = 0; 975 unsigned long spintime_expire = 0;
988 int retries, spintime; 976 int retries, spintime;
989 unsigned int the_result; 977 unsigned int the_result;
990 struct scsi_sense_hdr sshdr; 978 struct scsi_sense_hdr sshdr;
@@ -1001,18 +989,13 @@ sd_spinup_disk(struct scsi_disk *sdkp, char *diskname,
1001 cmd[0] = TEST_UNIT_READY; 989 cmd[0] = TEST_UNIT_READY;
1002 memset((void *) &cmd[1], 0, 9); 990 memset((void *) &cmd[1], 0, 9);
1003 991
1004 SRpnt->sr_cmd_len = 0; 992 the_result = scsi_execute_req(sdkp->device, cmd,
1005 memset(SRpnt->sr_sense_buffer, 0, 993 DMA_NONE, NULL, 0,
1006 SCSI_SENSE_BUFFERSIZE); 994 &sshdr, SD_TIMEOUT,
1007 SRpnt->sr_data_direction = DMA_NONE; 995 SD_MAX_RETRIES);
1008 996
1009 scsi_wait_req (SRpnt, (void *) cmd, (void *) buffer,
1010 0/*512*/, SD_TIMEOUT, SD_MAX_RETRIES);
1011
1012 the_result = SRpnt->sr_result;
1013 if (the_result) 997 if (the_result)
1014 sense_valid = scsi_request_normalize_sense( 998 sense_valid = scsi_sense_valid(&sshdr);
1015 SRpnt, &sshdr);
1016 retries++; 999 retries++;
1017 } while (retries < 3 && 1000 } while (retries < 3 &&
1018 (!scsi_status_is_good(the_result) || 1001 (!scsi_status_is_good(the_result) ||
@@ -1024,7 +1007,7 @@ sd_spinup_disk(struct scsi_disk *sdkp, char *diskname,
1024 * any media in it, don't bother with any of the rest of 1007 * any media in it, don't bother with any of the rest of
1025 * this crap. 1008 * this crap.
1026 */ 1009 */
1027 if (media_not_present(sdkp, SRpnt)) 1010 if (media_not_present(sdkp, &sshdr))
1028 return; 1011 return;
1029 1012
1030 if ((driver_byte(the_result) & DRIVER_SENSE) == 0) { 1013 if ((driver_byte(the_result) & DRIVER_SENSE) == 0) {
@@ -1063,33 +1046,42 @@ sd_spinup_disk(struct scsi_disk *sdkp, char *diskname,
1063 cmd[1] = 1; /* Return immediately */ 1046 cmd[1] = 1; /* Return immediately */
1064 memset((void *) &cmd[2], 0, 8); 1047 memset((void *) &cmd[2], 0, 8);
1065 cmd[4] = 1; /* Start spin cycle */ 1048 cmd[4] = 1; /* Start spin cycle */
1066 SRpnt->sr_cmd_len = 0; 1049 scsi_execute_req(sdkp->device, cmd, DMA_NONE,
1067 memset(SRpnt->sr_sense_buffer, 0, 1050 NULL, 0, &sshdr,
1068 SCSI_SENSE_BUFFERSIZE); 1051 SD_TIMEOUT, SD_MAX_RETRIES);
1069 1052 spintime_expire = jiffies + 100 * HZ;
1070 SRpnt->sr_data_direction = DMA_NONE; 1053 spintime = 1;
1071 scsi_wait_req(SRpnt, (void *)cmd,
1072 (void *) buffer, 0/*512*/,
1073 SD_TIMEOUT, SD_MAX_RETRIES);
1074 spintime_value = jiffies;
1075 } 1054 }
1076 spintime = 1;
1077 /* Wait 1 second for next try */ 1055 /* Wait 1 second for next try */
1078 msleep(1000); 1056 msleep(1000);
1079 printk("."); 1057 printk(".");
1058
1059 /*
1060 * Wait for USB flash devices with slow firmware.
1061 * Yes, this sense key/ASC combination shouldn't
1062 * occur here. It's characteristic of these devices.
1063 */
1064 } else if (sense_valid &&
1065 sshdr.sense_key == UNIT_ATTENTION &&
1066 sshdr.asc == 0x28) {
1067 if (!spintime) {
1068 spintime_expire = jiffies + 5 * HZ;
1069 spintime = 1;
1070 }
1071 /* Wait 1 second for next try */
1072 msleep(1000);
1080 } else { 1073 } else {
1081 /* we don't understand the sense code, so it's 1074 /* we don't understand the sense code, so it's
1082 * probably pointless to loop */ 1075 * probably pointless to loop */
1083 if(!spintime) { 1076 if(!spintime) {
1084 printk(KERN_NOTICE "%s: Unit Not Ready, " 1077 printk(KERN_NOTICE "%s: Unit Not Ready, "
1085 "sense:\n", diskname); 1078 "sense:\n", diskname);
1086 scsi_print_req_sense("", SRpnt); 1079 scsi_print_sense_hdr("", &sshdr);
1087 } 1080 }
1088 break; 1081 break;
1089 } 1082 }
1090 1083
1091 } while (spintime && 1084 } while (spintime && time_before_eq(jiffies, spintime_expire));
1092 time_after(spintime_value + 100 * HZ, jiffies));
1093 1085
1094 if (spintime) { 1086 if (spintime) {
1095 if (scsi_status_is_good(the_result)) 1087 if (scsi_status_is_good(the_result))
@@ -1104,14 +1096,15 @@ sd_spinup_disk(struct scsi_disk *sdkp, char *diskname,
1104 */ 1096 */
1105static void 1097static void
1106sd_read_capacity(struct scsi_disk *sdkp, char *diskname, 1098sd_read_capacity(struct scsi_disk *sdkp, char *diskname,
1107 struct scsi_request *SRpnt, unsigned char *buffer) { 1099 unsigned char *buffer)
1100{
1108 unsigned char cmd[16]; 1101 unsigned char cmd[16];
1109 struct scsi_device *sdp = sdkp->device;
1110 int the_result, retries; 1102 int the_result, retries;
1111 int sector_size = 0; 1103 int sector_size = 0;
1112 int longrc = 0; 1104 int longrc = 0;
1113 struct scsi_sense_hdr sshdr; 1105 struct scsi_sense_hdr sshdr;
1114 int sense_valid = 0; 1106 int sense_valid = 0;
1107 struct scsi_device *sdp = sdkp->device;
1115 1108
1116repeat: 1109repeat:
1117 retries = 3; 1110 retries = 3;
@@ -1128,20 +1121,15 @@ repeat:
1128 memset((void *) buffer, 0, 8); 1121 memset((void *) buffer, 0, 8);
1129 } 1122 }
1130 1123
1131 SRpnt->sr_cmd_len = 0; 1124 the_result = scsi_execute_req(sdp, cmd, DMA_FROM_DEVICE,
1132 memset(SRpnt->sr_sense_buffer, 0, SCSI_SENSE_BUFFERSIZE); 1125 buffer, longrc ? 12 : 8, &sshdr,
1133 SRpnt->sr_data_direction = DMA_FROM_DEVICE; 1126 SD_TIMEOUT, SD_MAX_RETRIES);
1134
1135 scsi_wait_req(SRpnt, (void *) cmd, (void *) buffer,
1136 longrc ? 12 : 8, SD_TIMEOUT, SD_MAX_RETRIES);
1137 1127
1138 if (media_not_present(sdkp, SRpnt)) 1128 if (media_not_present(sdkp, &sshdr))
1139 return; 1129 return;
1140 1130
1141 the_result = SRpnt->sr_result;
1142 if (the_result) 1131 if (the_result)
1143 sense_valid = scsi_request_normalize_sense(SRpnt, 1132 sense_valid = scsi_sense_valid(&sshdr);
1144 &sshdr);
1145 retries--; 1133 retries--;
1146 1134
1147 } while (the_result && retries); 1135 } while (the_result && retries);
@@ -1156,7 +1144,7 @@ repeat:
1156 driver_byte(the_result)); 1144 driver_byte(the_result));
1157 1145
1158 if (driver_byte(the_result) & DRIVER_SENSE) 1146 if (driver_byte(the_result) & DRIVER_SENSE)
1159 scsi_print_req_sense("sd", SRpnt); 1147 scsi_print_sense_hdr("sd", &sshdr);
1160 else 1148 else
1161 printk("%s : sense not available. \n", diskname); 1149 printk("%s : sense not available. \n", diskname);
1162 1150
@@ -1296,11 +1284,13 @@ got_data:
1296 1284
1297/* called with buffer of length 512 */ 1285/* called with buffer of length 512 */
1298static inline int 1286static inline int
1299sd_do_mode_sense(struct scsi_request *SRpnt, int dbd, int modepage, 1287sd_do_mode_sense(struct scsi_device *sdp, int dbd, int modepage,
1300 unsigned char *buffer, int len, struct scsi_mode_data *data) 1288 unsigned char *buffer, int len, struct scsi_mode_data *data,
1289 struct scsi_sense_hdr *sshdr)
1301{ 1290{
1302 return __scsi_mode_sense(SRpnt, dbd, modepage, buffer, len, 1291 return scsi_mode_sense(sdp, dbd, modepage, buffer, len,
1303 SD_TIMEOUT, SD_MAX_RETRIES, data); 1292 SD_TIMEOUT, SD_MAX_RETRIES, data,
1293 sshdr);
1304} 1294}
1305 1295
1306/* 1296/*
@@ -1309,25 +1299,27 @@ sd_do_mode_sense(struct scsi_request *SRpnt, int dbd, int modepage,
1309 */ 1299 */
1310static void 1300static void
1311sd_read_write_protect_flag(struct scsi_disk *sdkp, char *diskname, 1301sd_read_write_protect_flag(struct scsi_disk *sdkp, char *diskname,
1312 struct scsi_request *SRpnt, unsigned char *buffer) { 1302 unsigned char *buffer)
1303{
1313 int res; 1304 int res;
1305 struct scsi_device *sdp = sdkp->device;
1314 struct scsi_mode_data data; 1306 struct scsi_mode_data data;
1315 1307
1316 set_disk_ro(sdkp->disk, 0); 1308 set_disk_ro(sdkp->disk, 0);
1317 if (sdkp->device->skip_ms_page_3f) { 1309 if (sdp->skip_ms_page_3f) {
1318 printk(KERN_NOTICE "%s: assuming Write Enabled\n", diskname); 1310 printk(KERN_NOTICE "%s: assuming Write Enabled\n", diskname);
1319 return; 1311 return;
1320 } 1312 }
1321 1313
1322 if (sdkp->device->use_192_bytes_for_3f) { 1314 if (sdp->use_192_bytes_for_3f) {
1323 res = sd_do_mode_sense(SRpnt, 0, 0x3F, buffer, 192, &data); 1315 res = sd_do_mode_sense(sdp, 0, 0x3F, buffer, 192, &data, NULL);
1324 } else { 1316 } else {
1325 /* 1317 /*
1326 * First attempt: ask for all pages (0x3F), but only 4 bytes. 1318 * First attempt: ask for all pages (0x3F), but only 4 bytes.
1327 * We have to start carefully: some devices hang if we ask 1319 * We have to start carefully: some devices hang if we ask
1328 * for more than is available. 1320 * for more than is available.
1329 */ 1321 */
1330 res = sd_do_mode_sense(SRpnt, 0, 0x3F, buffer, 4, &data); 1322 res = sd_do_mode_sense(sdp, 0, 0x3F, buffer, 4, &data, NULL);
1331 1323
1332 /* 1324 /*
1333 * Second attempt: ask for page 0 When only page 0 is 1325 * Second attempt: ask for page 0 When only page 0 is
@@ -1336,14 +1328,14 @@ sd_read_write_protect_flag(struct scsi_disk *sdkp, char *diskname,
1336 * CDB. 1328 * CDB.
1337 */ 1329 */
1338 if (!scsi_status_is_good(res)) 1330 if (!scsi_status_is_good(res))
1339 res = sd_do_mode_sense(SRpnt, 0, 0, buffer, 4, &data); 1331 res = sd_do_mode_sense(sdp, 0, 0, buffer, 4, &data, NULL);
1340 1332
1341 /* 1333 /*
1342 * Third attempt: ask 255 bytes, as we did earlier. 1334 * Third attempt: ask 255 bytes, as we did earlier.
1343 */ 1335 */
1344 if (!scsi_status_is_good(res)) 1336 if (!scsi_status_is_good(res))
1345 res = sd_do_mode_sense(SRpnt, 0, 0x3F, buffer, 255, 1337 res = sd_do_mode_sense(sdp, 0, 0x3F, buffer, 255,
1346 &data); 1338 &data, NULL);
1347 } 1339 }
1348 1340
1349 if (!scsi_status_is_good(res)) { 1341 if (!scsi_status_is_good(res)) {
@@ -1365,19 +1357,20 @@ sd_read_write_protect_flag(struct scsi_disk *sdkp, char *diskname,
1365 */ 1357 */
1366static void 1358static void
1367sd_read_cache_type(struct scsi_disk *sdkp, char *diskname, 1359sd_read_cache_type(struct scsi_disk *sdkp, char *diskname,
1368 struct scsi_request *SRpnt, unsigned char *buffer) 1360 unsigned char *buffer)
1369{ 1361{
1370 int len = 0, res; 1362 int len = 0, res;
1363 struct scsi_device *sdp = sdkp->device;
1371 1364
1372 int dbd; 1365 int dbd;
1373 int modepage; 1366 int modepage;
1374 struct scsi_mode_data data; 1367 struct scsi_mode_data data;
1375 struct scsi_sense_hdr sshdr; 1368 struct scsi_sense_hdr sshdr;
1376 1369
1377 if (sdkp->device->skip_ms_page_8) 1370 if (sdp->skip_ms_page_8)
1378 goto defaults; 1371 goto defaults;
1379 1372
1380 if (sdkp->device->type == TYPE_RBC) { 1373 if (sdp->type == TYPE_RBC) {
1381 modepage = 6; 1374 modepage = 6;
1382 dbd = 8; 1375 dbd = 8;
1383 } else { 1376 } else {
@@ -1386,7 +1379,7 @@ sd_read_cache_type(struct scsi_disk *sdkp, char *diskname,
1386 } 1379 }
1387 1380
1388 /* cautiously ask */ 1381 /* cautiously ask */
1389 res = sd_do_mode_sense(SRpnt, dbd, modepage, buffer, 4, &data); 1382 res = sd_do_mode_sense(sdp, dbd, modepage, buffer, 4, &data, &sshdr);
1390 1383
1391 if (!scsi_status_is_good(res)) 1384 if (!scsi_status_is_good(res))
1392 goto bad_sense; 1385 goto bad_sense;
@@ -1407,7 +1400,7 @@ sd_read_cache_type(struct scsi_disk *sdkp, char *diskname,
1407 len += data.header_length + data.block_descriptor_length; 1400 len += data.header_length + data.block_descriptor_length;
1408 1401
1409 /* Get the data */ 1402 /* Get the data */
1410 res = sd_do_mode_sense(SRpnt, dbd, modepage, buffer, len, &data); 1403 res = sd_do_mode_sense(sdp, dbd, modepage, buffer, len, &data, &sshdr);
1411 1404
1412 if (scsi_status_is_good(res)) { 1405 if (scsi_status_is_good(res)) {
1413 const char *types[] = { 1406 const char *types[] = {
@@ -1439,7 +1432,7 @@ sd_read_cache_type(struct scsi_disk *sdkp, char *diskname,
1439 } 1432 }
1440 1433
1441bad_sense: 1434bad_sense:
1442 if (scsi_request_normalize_sense(SRpnt, &sshdr) && 1435 if (scsi_sense_valid(&sshdr) &&
1443 sshdr.sense_key == ILLEGAL_REQUEST && 1436 sshdr.sense_key == ILLEGAL_REQUEST &&
1444 sshdr.asc == 0x24 && sshdr.ascq == 0x0) 1437 sshdr.asc == 0x24 && sshdr.ascq == 0x0)
1445 printk(KERN_NOTICE "%s: cache data unavailable\n", 1438 printk(KERN_NOTICE "%s: cache data unavailable\n",
@@ -1464,7 +1457,6 @@ static int sd_revalidate_disk(struct gendisk *disk)
1464{ 1457{
1465 struct scsi_disk *sdkp = scsi_disk(disk); 1458 struct scsi_disk *sdkp = scsi_disk(disk);
1466 struct scsi_device *sdp = sdkp->device; 1459 struct scsi_device *sdp = sdkp->device;
1467 struct scsi_request *sreq;
1468 unsigned char *buffer; 1460 unsigned char *buffer;
1469 1461
1470 SCSI_LOG_HLQUEUE(3, printk("sd_revalidate_disk: disk=%s\n", disk->disk_name)); 1462 SCSI_LOG_HLQUEUE(3, printk("sd_revalidate_disk: disk=%s\n", disk->disk_name));
@@ -1476,18 +1468,11 @@ static int sd_revalidate_disk(struct gendisk *disk)
1476 if (!scsi_device_online(sdp)) 1468 if (!scsi_device_online(sdp))
1477 goto out; 1469 goto out;
1478 1470
1479 sreq = scsi_allocate_request(sdp, GFP_KERNEL);
1480 if (!sreq) {
1481 printk(KERN_WARNING "(sd_revalidate_disk:) Request allocation "
1482 "failure.\n");
1483 goto out;
1484 }
1485
1486 buffer = kmalloc(512, GFP_KERNEL | __GFP_DMA); 1471 buffer = kmalloc(512, GFP_KERNEL | __GFP_DMA);
1487 if (!buffer) { 1472 if (!buffer) {
1488 printk(KERN_WARNING "(sd_revalidate_disk:) Memory allocation " 1473 printk(KERN_WARNING "(sd_revalidate_disk:) Memory allocation "
1489 "failure.\n"); 1474 "failure.\n");
1490 goto out_release_request; 1475 goto out;
1491 } 1476 }
1492 1477
1493 /* defaults, until the device tells us otherwise */ 1478 /* defaults, until the device tells us otherwise */
@@ -1498,25 +1483,23 @@ static int sd_revalidate_disk(struct gendisk *disk)
1498 sdkp->WCE = 0; 1483 sdkp->WCE = 0;
1499 sdkp->RCD = 0; 1484 sdkp->RCD = 0;
1500 1485
1501 sd_spinup_disk(sdkp, disk->disk_name, sreq, buffer); 1486 sd_spinup_disk(sdkp, disk->disk_name);
1502 1487
1503 /* 1488 /*
1504 * Without media there is no reason to ask; moreover, some devices 1489 * Without media there is no reason to ask; moreover, some devices
1505 * react badly if we do. 1490 * react badly if we do.
1506 */ 1491 */
1507 if (sdkp->media_present) { 1492 if (sdkp->media_present) {
1508 sd_read_capacity(sdkp, disk->disk_name, sreq, buffer); 1493 sd_read_capacity(sdkp, disk->disk_name, buffer);
1509 if (sdp->removable) 1494 if (sdp->removable)
1510 sd_read_write_protect_flag(sdkp, disk->disk_name, 1495 sd_read_write_protect_flag(sdkp, disk->disk_name,
1511 sreq, buffer); 1496 buffer);
1512 sd_read_cache_type(sdkp, disk->disk_name, sreq, buffer); 1497 sd_read_cache_type(sdkp, disk->disk_name, buffer);
1513 } 1498 }
1514 1499
1515 set_capacity(disk, sdkp->capacity); 1500 set_capacity(disk, sdkp->capacity);
1516 kfree(buffer); 1501 kfree(buffer);
1517 1502
1518 out_release_request:
1519 scsi_release_request(sreq);
1520 out: 1503 out:
1521 return 0; 1504 return 0;
1522} 1505}
diff --git a/drivers/scsi/sg.c b/drivers/scsi/sg.c
index e822ca0e97c..b1b69d738d0 100644
--- a/drivers/scsi/sg.c
+++ b/drivers/scsi/sg.c
@@ -61,7 +61,7 @@ static int sg_version_num = 30533; /* 2 digits for each component */
61 61
62#ifdef CONFIG_SCSI_PROC_FS 62#ifdef CONFIG_SCSI_PROC_FS
63#include <linux/proc_fs.h> 63#include <linux/proc_fs.h>
64static char *sg_version_date = "20050328"; 64static char *sg_version_date = "20050901";
65 65
66static int sg_proc_init(void); 66static int sg_proc_init(void);
67static void sg_proc_cleanup(void); 67static void sg_proc_cleanup(void);
@@ -1027,8 +1027,7 @@ sg_ioctl(struct inode *inode, struct file *filp,
1027 if (sdp->detached) 1027 if (sdp->detached)
1028 return -ENODEV; 1028 return -ENODEV;
1029 if (filp->f_flags & O_NONBLOCK) { 1029 if (filp->f_flags & O_NONBLOCK) {
1030 if (test_bit(SHOST_RECOVERY, 1030 if (sdp->device->host->shost_state == SHOST_RECOVERY)
1031 &sdp->device->host->shost_state))
1032 return -EBUSY; 1031 return -EBUSY;
1033 } else if (!scsi_block_when_processing_errors(sdp->device)) 1032 } else if (!scsi_block_when_processing_errors(sdp->device))
1034 return -EBUSY; 1033 return -EBUSY;
@@ -1795,12 +1794,12 @@ st_map_user_pages(struct scatterlist *sgl, const unsigned int max_pages,
1795 unsigned long uaddr, size_t count, int rw, 1794 unsigned long uaddr, size_t count, int rw,
1796 unsigned long max_pfn) 1795 unsigned long max_pfn)
1797{ 1796{
1797 unsigned long end = (uaddr + count + PAGE_SIZE - 1) >> PAGE_SHIFT;
1798 unsigned long start = uaddr >> PAGE_SHIFT;
1799 const int nr_pages = end - start;
1798 int res, i, j; 1800 int res, i, j;
1799 unsigned int nr_pages;
1800 struct page **pages; 1801 struct page **pages;
1801 1802
1802 nr_pages = ((uaddr & ~PAGE_MASK) + count + ~PAGE_MASK) >> PAGE_SHIFT;
1803
1804 /* User attempted Overflow! */ 1803 /* User attempted Overflow! */
1805 if ((uaddr + count) < uaddr) 1804 if ((uaddr + count) < uaddr)
1806 return -EINVAL; 1805 return -EINVAL;
diff --git a/drivers/scsi/sr.c b/drivers/scsi/sr.c
index 2f259f24952..ce63fc8312d 100644
--- a/drivers/scsi/sr.c
+++ b/drivers/scsi/sr.c
@@ -50,10 +50,10 @@
50#include <scsi/scsi_dbg.h> 50#include <scsi/scsi_dbg.h>
51#include <scsi/scsi_device.h> 51#include <scsi/scsi_device.h>
52#include <scsi/scsi_driver.h> 52#include <scsi/scsi_driver.h>
53#include <scsi/scsi_cmnd.h>
53#include <scsi/scsi_eh.h> 54#include <scsi/scsi_eh.h>
54#include <scsi/scsi_host.h> 55#include <scsi/scsi_host.h>
55#include <scsi/scsi_ioctl.h> /* For the door lock/unlock commands */ 56#include <scsi/scsi_ioctl.h> /* For the door lock/unlock commands */
56#include <scsi/scsi_request.h>
57 57
58#include "scsi_logging.h" 58#include "scsi_logging.h"
59#include "sr.h" 59#include "sr.h"
@@ -199,15 +199,7 @@ int sr_media_change(struct cdrom_device_info *cdi, int slot)
199 /* check multisession offset etc */ 199 /* check multisession offset etc */
200 sr_cd_check(cdi); 200 sr_cd_check(cdi);
201 201
202 /* 202 get_sectorsize(cd);
203 * If the disk changed, the capacity will now be different,
204 * so we force a re-read of this information
205 * Force 2048 for the sector size so that filesystems won't
206 * be trying to use something that is too small if the disc
207 * has changed.
208 */
209 cd->needs_sector_size = 1;
210 cd->device->sector_size = 2048;
211 } 203 }
212 return retval; 204 return retval;
213} 205}
@@ -538,13 +530,6 @@ static int sr_open(struct cdrom_device_info *cdi, int purpose)
538 if (!scsi_block_when_processing_errors(sdev)) 530 if (!scsi_block_when_processing_errors(sdev))
539 goto error_out; 531 goto error_out;
540 532
541 /*
542 * If this device did not have media in the drive at boot time, then
543 * we would have been unable to get the sector size. Check to see if
544 * this is the case, and try again.
545 */
546 if (cd->needs_sector_size)
547 get_sectorsize(cd);
548 return 0; 533 return 0;
549 534
550error_out: 535error_out:
@@ -604,7 +589,6 @@ static int sr_probe(struct device *dev)
604 cd->driver = &sr_template; 589 cd->driver = &sr_template;
605 cd->disk = disk; 590 cd->disk = disk;
606 cd->capacity = 0x1fffff; 591 cd->capacity = 0x1fffff;
607 cd->needs_sector_size = 1;
608 cd->device->changed = 1; /* force recheck CD type */ 592 cd->device->changed = 1; /* force recheck CD type */
609 cd->use = 1; 593 cd->use = 1;
610 cd->readcd_known = 0; 594 cd->readcd_known = 0;
@@ -658,43 +642,30 @@ static void get_sectorsize(struct scsi_cd *cd)
658 unsigned char *buffer; 642 unsigned char *buffer;
659 int the_result, retries = 3; 643 int the_result, retries = 3;
660 int sector_size; 644 int sector_size;
661 struct scsi_request *SRpnt = NULL;
662 request_queue_t *queue; 645 request_queue_t *queue;
663 646
664 buffer = kmalloc(512, GFP_KERNEL | GFP_DMA); 647 buffer = kmalloc(512, GFP_KERNEL | GFP_DMA);
665 if (!buffer) 648 if (!buffer)
666 goto Enomem; 649 goto Enomem;
667 SRpnt = scsi_allocate_request(cd->device, GFP_KERNEL);
668 if (!SRpnt)
669 goto Enomem;
670 650
671 do { 651 do {
672 cmd[0] = READ_CAPACITY; 652 cmd[0] = READ_CAPACITY;
673 memset((void *) &cmd[1], 0, 9); 653 memset((void *) &cmd[1], 0, 9);
674 /* Mark as really busy */
675 SRpnt->sr_request->rq_status = RQ_SCSI_BUSY;
676 SRpnt->sr_cmd_len = 0;
677
678 memset(buffer, 0, 8); 654 memset(buffer, 0, 8);
679 655
680 /* Do the command and wait.. */ 656 /* Do the command and wait.. */
681 SRpnt->sr_data_direction = DMA_FROM_DEVICE; 657 the_result = scsi_execute_req(cd->device, cmd, DMA_FROM_DEVICE,
682 scsi_wait_req(SRpnt, (void *) cmd, (void *) buffer, 658 buffer, 8, NULL, SR_TIMEOUT,
683 8, SR_TIMEOUT, MAX_RETRIES); 659 MAX_RETRIES);
684 660
685 the_result = SRpnt->sr_result;
686 retries--; 661 retries--;
687 662
688 } while (the_result && retries); 663 } while (the_result && retries);
689 664
690 665
691 scsi_release_request(SRpnt);
692 SRpnt = NULL;
693
694 if (the_result) { 666 if (the_result) {
695 cd->capacity = 0x1fffff; 667 cd->capacity = 0x1fffff;
696 sector_size = 2048; /* A guess, just in case */ 668 sector_size = 2048; /* A guess, just in case */
697 cd->needs_sector_size = 1;
698 } else { 669 } else {
699#if 0 670#if 0
700 if (cdrom_get_last_written(&cd->cdi, 671 if (cdrom_get_last_written(&cd->cdi,
@@ -727,7 +698,6 @@ static void get_sectorsize(struct scsi_cd *cd)
727 printk("%s: unsupported sector size %d.\n", 698 printk("%s: unsupported sector size %d.\n",
728 cd->cdi.name, sector_size); 699 cd->cdi.name, sector_size);
729 cd->capacity = 0; 700 cd->capacity = 0;
730 cd->needs_sector_size = 1;
731 } 701 }
732 702
733 cd->device->sector_size = sector_size; 703 cd->device->sector_size = sector_size;
@@ -736,7 +706,6 @@ static void get_sectorsize(struct scsi_cd *cd)
736 * Add this so that we have the ability to correctly gauge 706 * Add this so that we have the ability to correctly gauge
737 * what the device is capable of. 707 * what the device is capable of.
738 */ 708 */
739 cd->needs_sector_size = 0;
740 set_capacity(cd->disk, cd->capacity); 709 set_capacity(cd->disk, cd->capacity);
741 } 710 }
742 711
@@ -748,10 +717,7 @@ out:
748 717
749Enomem: 718Enomem:
750 cd->capacity = 0x1fffff; 719 cd->capacity = 0x1fffff;
751 sector_size = 2048; /* A guess, just in case */ 720 cd->device->sector_size = 2048; /* A guess, just in case */
752 cd->needs_sector_size = 1;
753 if (SRpnt)
754 scsi_release_request(SRpnt);
755 goto out; 721 goto out;
756} 722}
757 723
@@ -759,8 +725,8 @@ static void get_capabilities(struct scsi_cd *cd)
759{ 725{
760 unsigned char *buffer; 726 unsigned char *buffer;
761 struct scsi_mode_data data; 727 struct scsi_mode_data data;
762 struct scsi_request *SRpnt;
763 unsigned char cmd[MAX_COMMAND_SIZE]; 728 unsigned char cmd[MAX_COMMAND_SIZE];
729 struct scsi_sense_hdr sshdr;
764 unsigned int the_result; 730 unsigned int the_result;
765 int retries, rc, n; 731 int retries, rc, n;
766 732
@@ -776,19 +742,11 @@ static void get_capabilities(struct scsi_cd *cd)
776 "" 742 ""
777 }; 743 };
778 744
779 /* allocate a request for the TEST_UNIT_READY */
780 SRpnt = scsi_allocate_request(cd->device, GFP_KERNEL);
781 if (!SRpnt) {
782 printk(KERN_WARNING "(get_capabilities:) Request allocation "
783 "failure.\n");
784 return;
785 }
786 745
787 /* allocate transfer buffer */ 746 /* allocate transfer buffer */
788 buffer = kmalloc(512, GFP_KERNEL | GFP_DMA); 747 buffer = kmalloc(512, GFP_KERNEL | GFP_DMA);
789 if (!buffer) { 748 if (!buffer) {
790 printk(KERN_ERR "sr: out of memory.\n"); 749 printk(KERN_ERR "sr: out of memory.\n");
791 scsi_release_request(SRpnt);
792 return; 750 return;
793 } 751 }
794 752
@@ -800,24 +758,19 @@ static void get_capabilities(struct scsi_cd *cd)
800 memset((void *)cmd, 0, MAX_COMMAND_SIZE); 758 memset((void *)cmd, 0, MAX_COMMAND_SIZE);
801 cmd[0] = TEST_UNIT_READY; 759 cmd[0] = TEST_UNIT_READY;
802 760
803 SRpnt->sr_cmd_len = 0; 761 the_result = scsi_execute_req (cd->device, cmd, DMA_NONE, NULL,
804 SRpnt->sr_sense_buffer[0] = 0; 762 0, &sshdr, SR_TIMEOUT,
805 SRpnt->sr_sense_buffer[2] = 0; 763 MAX_RETRIES);
806 SRpnt->sr_data_direction = DMA_NONE;
807
808 scsi_wait_req (SRpnt, (void *) cmd, buffer,
809 0, SR_TIMEOUT, MAX_RETRIES);
810 764
811 the_result = SRpnt->sr_result;
812 retries++; 765 retries++;
813 } while (retries < 5 && 766 } while (retries < 5 &&
814 (!scsi_status_is_good(the_result) || 767 (!scsi_status_is_good(the_result) ||
815 ((driver_byte(the_result) & DRIVER_SENSE) && 768 (scsi_sense_valid(&sshdr) &&
816 SRpnt->sr_sense_buffer[2] == UNIT_ATTENTION))); 769 sshdr.sense_key == UNIT_ATTENTION)));
817 770
818 /* ask for mode page 0x2a */ 771 /* ask for mode page 0x2a */
819 rc = scsi_mode_sense(cd->device, 0, 0x2a, buffer, 128, 772 rc = scsi_mode_sense(cd->device, 0, 0x2a, buffer, 128,
820 SR_TIMEOUT, 3, &data); 773 SR_TIMEOUT, 3, &data, NULL);
821 774
822 if (!scsi_status_is_good(rc)) { 775 if (!scsi_status_is_good(rc)) {
823 /* failed, drive doesn't have capabilities mode page */ 776 /* failed, drive doesn't have capabilities mode page */
@@ -825,7 +778,6 @@ static void get_capabilities(struct scsi_cd *cd)
825 cd->cdi.mask |= (CDC_CD_R | CDC_CD_RW | CDC_DVD_R | 778 cd->cdi.mask |= (CDC_CD_R | CDC_CD_RW | CDC_DVD_R |
826 CDC_DVD | CDC_DVD_RAM | 779 CDC_DVD | CDC_DVD_RAM |
827 CDC_SELECT_DISC | CDC_SELECT_SPEED); 780 CDC_SELECT_DISC | CDC_SELECT_SPEED);
828 scsi_release_request(SRpnt);
829 kfree(buffer); 781 kfree(buffer);
830 printk("%s: scsi-1 drive\n", cd->cdi.name); 782 printk("%s: scsi-1 drive\n", cd->cdi.name);
831 return; 783 return;
@@ -885,7 +837,6 @@ static void get_capabilities(struct scsi_cd *cd)
885 cd->device->writeable = 1; 837 cd->device->writeable = 1;
886 } 838 }
887 839
888 scsi_release_request(SRpnt);
889 kfree(buffer); 840 kfree(buffer);
890} 841}
891 842
diff --git a/drivers/scsi/sr.h b/drivers/scsi/sr.h
index 0b317800720..d2bcd99c272 100644
--- a/drivers/scsi/sr.h
+++ b/drivers/scsi/sr.h
@@ -33,7 +33,6 @@ typedef struct scsi_cd {
33 struct scsi_device *device; 33 struct scsi_device *device;
34 unsigned int vendor; /* vendor code, see sr_vendor.c */ 34 unsigned int vendor; /* vendor code, see sr_vendor.c */
35 unsigned long ms_offset; /* for reading multisession-CD's */ 35 unsigned long ms_offset; /* for reading multisession-CD's */
36 unsigned needs_sector_size:1; /* needs to get sector size */
37 unsigned use:1; /* is this device still supportable */ 36 unsigned use:1; /* is this device still supportable */
38 unsigned xa_flag:1; /* CD has XA sectors ? */ 37 unsigned xa_flag:1; /* CD has XA sectors ? */
39 unsigned readcd_known:1; /* drive supports READ_CD (0xbe) */ 38 unsigned readcd_known:1; /* drive supports READ_CD (0xbe) */
diff --git a/drivers/scsi/sr_ioctl.c b/drivers/scsi/sr_ioctl.c
index 82d68fdb154..6e45ac3c43c 100644
--- a/drivers/scsi/sr_ioctl.c
+++ b/drivers/scsi/sr_ioctl.c
@@ -17,7 +17,7 @@
17#include <scsi/scsi_eh.h> 17#include <scsi/scsi_eh.h>
18#include <scsi/scsi_host.h> 18#include <scsi/scsi_host.h>
19#include <scsi/scsi_ioctl.h> 19#include <scsi/scsi_ioctl.h>
20#include <scsi/scsi_request.h> 20#include <scsi/scsi_cmnd.h>
21 21
22#include "sr.h" 22#include "sr.h"
23 23
@@ -84,41 +84,37 @@ static int sr_fake_playtrkind(struct cdrom_device_info *cdi, struct cdrom_ti *ti
84 84
85int sr_do_ioctl(Scsi_CD *cd, struct packet_command *cgc) 85int sr_do_ioctl(Scsi_CD *cd, struct packet_command *cgc)
86{ 86{
87 struct scsi_request *SRpnt;
88 struct scsi_device *SDev; 87 struct scsi_device *SDev;
89 struct request *req; 88 struct scsi_sense_hdr sshdr;
90 int result, err = 0, retries = 0; 89 int result, err = 0, retries = 0;
90 struct request_sense *sense = cgc->sense;
91 91
92 SDev = cd->device; 92 SDev = cd->device;
93 SRpnt = scsi_allocate_request(SDev, GFP_KERNEL); 93
94 if (!SRpnt) { 94 if (!sense) {
95 printk(KERN_ERR "Unable to allocate SCSI request in sr_do_ioctl"); 95 sense = kmalloc(sizeof(*sense), GFP_KERNEL);
96 err = -ENOMEM; 96 if (!sense) {
97 goto out; 97 err = -ENOMEM;
98 } 98 goto out;
99 SRpnt->sr_data_direction = cgc->data_direction; 99 }
100 }
100 101
101 retry: 102 retry:
102 if (!scsi_block_when_processing_errors(SDev)) { 103 if (!scsi_block_when_processing_errors(SDev)) {
103 err = -ENODEV; 104 err = -ENODEV;
104 goto out_free; 105 goto out;
105 } 106 }
106 107
107 scsi_wait_req(SRpnt, cgc->cmd, cgc->buffer, cgc->buflen, 108 memset(sense, 0, sizeof(*sense));
108 cgc->timeout, IOCTL_RETRIES); 109 result = scsi_execute(SDev, cgc->cmd, cgc->data_direction,
109 110 cgc->buffer, cgc->buflen, (char *)sense,
110 req = SRpnt->sr_request; 111 cgc->timeout, IOCTL_RETRIES, 0);
111 if (SRpnt->sr_buffer && req->buffer && SRpnt->sr_buffer != req->buffer) {
112 memcpy(req->buffer, SRpnt->sr_buffer, SRpnt->sr_bufflen);
113 kfree(SRpnt->sr_buffer);
114 SRpnt->sr_buffer = req->buffer;
115 }
116 112
117 result = SRpnt->sr_result; 113 scsi_normalize_sense((char *)sense, sizeof(*sense), &sshdr);
118 114
119 /* Minimal error checking. Ignore cases we know about, and report the rest. */ 115 /* Minimal error checking. Ignore cases we know about, and report the rest. */
120 if (driver_byte(result) != 0) { 116 if (driver_byte(result) != 0) {
121 switch (SRpnt->sr_sense_buffer[2] & 0xf) { 117 switch (sshdr.sense_key) {
122 case UNIT_ATTENTION: 118 case UNIT_ATTENTION:
123 SDev->changed = 1; 119 SDev->changed = 1;
124 if (!cgc->quiet) 120 if (!cgc->quiet)
@@ -128,8 +124,8 @@ int sr_do_ioctl(Scsi_CD *cd, struct packet_command *cgc)
128 err = -ENOMEDIUM; 124 err = -ENOMEDIUM;
129 break; 125 break;
130 case NOT_READY: /* This happens if there is no disc in drive */ 126 case NOT_READY: /* This happens if there is no disc in drive */
131 if (SRpnt->sr_sense_buffer[12] == 0x04 && 127 if (sshdr.asc == 0x04 &&
132 SRpnt->sr_sense_buffer[13] == 0x01) { 128 sshdr.ascq == 0x01) {
133 /* sense: Logical unit is in process of becoming ready */ 129 /* sense: Logical unit is in process of becoming ready */
134 if (!cgc->quiet) 130 if (!cgc->quiet)
135 printk(KERN_INFO "%s: CDROM not ready yet.\n", cd->cdi.name); 131 printk(KERN_INFO "%s: CDROM not ready yet.\n", cd->cdi.name);
@@ -146,37 +142,33 @@ int sr_do_ioctl(Scsi_CD *cd, struct packet_command *cgc)
146 if (!cgc->quiet) 142 if (!cgc->quiet)
147 printk(KERN_INFO "%s: CDROM not ready. Make sure there is a disc in the drive.\n", cd->cdi.name); 143 printk(KERN_INFO "%s: CDROM not ready. Make sure there is a disc in the drive.\n", cd->cdi.name);
148#ifdef DEBUG 144#ifdef DEBUG
149 scsi_print_req_sense("sr", SRpnt); 145 scsi_print_sense_hdr("sr", &sshdr);
150#endif 146#endif
151 err = -ENOMEDIUM; 147 err = -ENOMEDIUM;
152 break; 148 break;
153 case ILLEGAL_REQUEST: 149 case ILLEGAL_REQUEST:
154 err = -EIO; 150 err = -EIO;
155 if (SRpnt->sr_sense_buffer[12] == 0x20 && 151 if (sshdr.asc == 0x20 &&
156 SRpnt->sr_sense_buffer[13] == 0x00) 152 sshdr.ascq == 0x00)
157 /* sense: Invalid command operation code */ 153 /* sense: Invalid command operation code */
158 err = -EDRIVE_CANT_DO_THIS; 154 err = -EDRIVE_CANT_DO_THIS;
159#ifdef DEBUG 155#ifdef DEBUG
160 __scsi_print_command(cgc->cmd); 156 __scsi_print_command(cgc->cmd);
161 scsi_print_req_sense("sr", SRpnt); 157 scsi_print_sense_hdr("sr", &sshdr);
162#endif 158#endif
163 break; 159 break;
164 default: 160 default:
165 printk(KERN_ERR "%s: CDROM (ioctl) error, command: ", cd->cdi.name); 161 printk(KERN_ERR "%s: CDROM (ioctl) error, command: ", cd->cdi.name);
166 __scsi_print_command(cgc->cmd); 162 __scsi_print_command(cgc->cmd);
167 scsi_print_req_sense("sr", SRpnt); 163 scsi_print_sense_hdr("sr", &sshdr);
168 err = -EIO; 164 err = -EIO;
169 } 165 }
170 } 166 }
171 167
172 if (cgc->sense)
173 memcpy(cgc->sense, SRpnt->sr_sense_buffer, sizeof(*cgc->sense));
174
175 /* Wake up a process waiting for device */ 168 /* Wake up a process waiting for device */
176 out_free:
177 scsi_release_request(SRpnt);
178 SRpnt = NULL;
179 out: 169 out:
170 if (!cgc->sense)
171 kfree(sense);
180 cgc->stat = err; 172 cgc->stat = err;
181 return err; 173 return err;
182} 174}
diff --git a/drivers/scsi/st.c b/drivers/scsi/st.c
index 0a7839db575..a93308ae973 100644
--- a/drivers/scsi/st.c
+++ b/drivers/scsi/st.c
@@ -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 char *verstr = "20050501"; 20static char *verstr = "20050830";
21 21
22#include <linux/module.h> 22#include <linux/module.h>
23 23
@@ -219,6 +219,12 @@ static int switch_partition(struct scsi_tape *);
219 219
220static int st_int_ioctl(struct scsi_tape *, unsigned int, unsigned long); 220static int st_int_ioctl(struct scsi_tape *, unsigned int, unsigned long);
221 221
222static void scsi_tape_release(struct kref *);
223
224#define to_scsi_tape(obj) container_of(obj, struct scsi_tape, kref)
225
226static DECLARE_MUTEX(st_ref_sem);
227
222 228
223#include "osst_detect.h" 229#include "osst_detect.h"
224#ifndef SIGS_FROM_OSST 230#ifndef SIGS_FROM_OSST
@@ -230,6 +236,46 @@ static int st_int_ioctl(struct scsi_tape *, unsigned int, unsigned long);
230 {"OnStream", "FW-", "", "osst"} 236 {"OnStream", "FW-", "", "osst"}
231#endif 237#endif
232 238
239static struct scsi_tape *scsi_tape_get(int dev)
240{
241 struct scsi_tape *STp = NULL;
242
243 down(&st_ref_sem);
244 write_lock(&st_dev_arr_lock);
245
246 if (dev < st_dev_max && scsi_tapes != NULL)
247 STp = scsi_tapes[dev];
248 if (!STp) goto out;
249
250 kref_get(&STp->kref);
251
252 if (!STp->device)
253 goto out_put;
254
255 if (scsi_device_get(STp->device))
256 goto out_put;
257
258 goto out;
259
260out_put:
261 kref_put(&STp->kref, scsi_tape_release);
262 STp = NULL;
263out:
264 write_unlock(&st_dev_arr_lock);
265 up(&st_ref_sem);
266 return STp;
267}
268
269static void scsi_tape_put(struct scsi_tape *STp)
270{
271 struct scsi_device *sdev = STp->device;
272
273 down(&st_ref_sem);
274 kref_put(&STp->kref, scsi_tape_release);
275 scsi_device_put(sdev);
276 up(&st_ref_sem);
277}
278
233struct st_reject_data { 279struct st_reject_data {
234 char *vendor; 280 char *vendor;
235 char *model; 281 char *model;
@@ -311,7 +357,7 @@ static int st_chk_result(struct scsi_tape *STp, struct scsi_request * SRpnt)
311 return 0; 357 return 0;
312 358
313 cmdstatp = &STp->buffer->cmdstat; 359 cmdstatp = &STp->buffer->cmdstat;
314 st_analyze_sense(STp->buffer->last_SRpnt, cmdstatp); 360 st_analyze_sense(SRpnt, cmdstatp);
315 361
316 if (cmdstatp->have_sense) 362 if (cmdstatp->have_sense)
317 scode = STp->buffer->cmdstat.sense_hdr.sense_key; 363 scode = STp->buffer->cmdstat.sense_hdr.sense_key;
@@ -399,10 +445,10 @@ static void st_sleep_done(struct scsi_cmnd * SCpnt)
399 445
400 (STp->buffer)->cmdstat.midlevel_result = SCpnt->result; 446 (STp->buffer)->cmdstat.midlevel_result = SCpnt->result;
401 SCpnt->request->rq_status = RQ_SCSI_DONE; 447 SCpnt->request->rq_status = RQ_SCSI_DONE;
402 (STp->buffer)->last_SRpnt = SCpnt->sc_request;
403 DEB( STp->write_pending = 0; ) 448 DEB( STp->write_pending = 0; )
404 449
405 complete(SCpnt->request->waiting); 450 if (SCpnt->request->waiting)
451 complete(SCpnt->request->waiting);
406} 452}
407 453
408/* Do the scsi command. Waits until command performed if do_wait is true. 454/* Do the scsi command. Waits until command performed if do_wait is true.
@@ -412,8 +458,20 @@ static struct scsi_request *
412st_do_scsi(struct scsi_request * SRpnt, struct scsi_tape * STp, unsigned char *cmd, 458st_do_scsi(struct scsi_request * SRpnt, struct scsi_tape * STp, unsigned char *cmd,
413 int bytes, int direction, int timeout, int retries, int do_wait) 459 int bytes, int direction, int timeout, int retries, int do_wait)
414{ 460{
461 struct completion *waiting;
415 unsigned char *bp; 462 unsigned char *bp;
416 463
464 /* if async, make sure there's no command outstanding */
465 if (!do_wait && ((STp->buffer)->last_SRpnt)) {
466 printk(KERN_ERR "%s: Async command already active.\n",
467 tape_name(STp));
468 if (signal_pending(current))
469 (STp->buffer)->syscall_result = (-EINTR);
470 else
471 (STp->buffer)->syscall_result = (-EBUSY);
472 return NULL;
473 }
474
417 if (SRpnt == NULL) { 475 if (SRpnt == NULL) {
418 SRpnt = scsi_allocate_request(STp->device, GFP_ATOMIC); 476 SRpnt = scsi_allocate_request(STp->device, GFP_ATOMIC);
419 if (SRpnt == NULL) { 477 if (SRpnt == NULL) {
@@ -427,7 +485,13 @@ st_do_scsi(struct scsi_request * SRpnt, struct scsi_tape * STp, unsigned char *c
427 } 485 }
428 } 486 }
429 487
430 init_completion(&STp->wait); 488 /* If async IO, set last_SRpnt. This ptr tells write_behind_check
489 which IO is outstanding. It's nulled out when the IO completes. */
490 if (!do_wait)
491 (STp->buffer)->last_SRpnt = SRpnt;
492
493 waiting = &STp->wait;
494 init_completion(waiting);
431 SRpnt->sr_use_sg = STp->buffer->do_dio || (bytes > (STp->buffer)->frp[0].length); 495 SRpnt->sr_use_sg = STp->buffer->do_dio || (bytes > (STp->buffer)->frp[0].length);
432 if (SRpnt->sr_use_sg) { 496 if (SRpnt->sr_use_sg) {
433 if (!STp->buffer->do_dio) 497 if (!STp->buffer->do_dio)
@@ -438,17 +502,20 @@ st_do_scsi(struct scsi_request * SRpnt, struct scsi_tape * STp, unsigned char *c
438 bp = (STp->buffer)->b_data; 502 bp = (STp->buffer)->b_data;
439 SRpnt->sr_data_direction = direction; 503 SRpnt->sr_data_direction = direction;
440 SRpnt->sr_cmd_len = 0; 504 SRpnt->sr_cmd_len = 0;
441 SRpnt->sr_request->waiting = &(STp->wait); 505 SRpnt->sr_request->waiting = waiting;
442 SRpnt->sr_request->rq_status = RQ_SCSI_BUSY; 506 SRpnt->sr_request->rq_status = RQ_SCSI_BUSY;
443 SRpnt->sr_request->rq_disk = STp->disk; 507 SRpnt->sr_request->rq_disk = STp->disk;
508 SRpnt->sr_request->end_io = blk_end_sync_rq;
444 STp->buffer->cmdstat.have_sense = 0; 509 STp->buffer->cmdstat.have_sense = 0;
445 510
446 scsi_do_req(SRpnt, (void *) cmd, bp, bytes, 511 scsi_do_req(SRpnt, (void *) cmd, bp, bytes,
447 st_sleep_done, timeout, retries); 512 st_sleep_done, timeout, retries);
448 513
449 if (do_wait) { 514 if (do_wait) {
450 wait_for_completion(SRpnt->sr_request->waiting); 515 wait_for_completion(waiting);
451 SRpnt->sr_request->waiting = NULL; 516 SRpnt->sr_request->waiting = NULL;
517 if (SRpnt->sr_request->rq_status != RQ_SCSI_DONE)
518 SRpnt->sr_result |= (DRIVER_ERROR << 24);
452 (STp->buffer)->syscall_result = st_chk_result(STp, SRpnt); 519 (STp->buffer)->syscall_result = st_chk_result(STp, SRpnt);
453 } 520 }
454 return SRpnt; 521 return SRpnt;
@@ -465,6 +532,7 @@ static int write_behind_check(struct scsi_tape * STp)
465 struct st_buffer *STbuffer; 532 struct st_buffer *STbuffer;
466 struct st_partstat *STps; 533 struct st_partstat *STps;
467 struct st_cmdstatus *cmdstatp; 534 struct st_cmdstatus *cmdstatp;
535 struct scsi_request *SRpnt;
468 536
469 STbuffer = STp->buffer; 537 STbuffer = STp->buffer;
470 if (!STbuffer->writing) 538 if (!STbuffer->writing)
@@ -478,10 +546,14 @@ static int write_behind_check(struct scsi_tape * STp)
478 ) /* end DEB */ 546 ) /* end DEB */
479 547
480 wait_for_completion(&(STp->wait)); 548 wait_for_completion(&(STp->wait));
481 (STp->buffer)->last_SRpnt->sr_request->waiting = NULL; 549 SRpnt = STbuffer->last_SRpnt;
550 STbuffer->last_SRpnt = NULL;
551 SRpnt->sr_request->waiting = NULL;
552 if (SRpnt->sr_request->rq_status != RQ_SCSI_DONE)
553 SRpnt->sr_result |= (DRIVER_ERROR << 24);
482 554
483 (STp->buffer)->syscall_result = st_chk_result(STp, (STp->buffer)->last_SRpnt); 555 (STp->buffer)->syscall_result = st_chk_result(STp, SRpnt);
484 scsi_release_request((STp->buffer)->last_SRpnt); 556 scsi_release_request(SRpnt);
485 557
486 STbuffer->buffer_bytes -= STbuffer->writing; 558 STbuffer->buffer_bytes -= STbuffer->writing;
487 STps = &(STp->ps[STp->partition]); 559 STps = &(STp->ps[STp->partition]);
@@ -1055,25 +1127,20 @@ static int st_open(struct inode *inode, struct file *filp)
1055 */ 1127 */
1056 filp->f_mode &= ~(FMODE_PREAD | FMODE_PWRITE); 1128 filp->f_mode &= ~(FMODE_PREAD | FMODE_PWRITE);
1057 1129
1130 if (!(STp = scsi_tape_get(dev)))
1131 return -ENXIO;
1132
1058 write_lock(&st_dev_arr_lock); 1133 write_lock(&st_dev_arr_lock);
1059 if (dev >= st_dev_max || scsi_tapes == NULL ||
1060 ((STp = scsi_tapes[dev]) == NULL)) {
1061 write_unlock(&st_dev_arr_lock);
1062 return (-ENXIO);
1063 }
1064 filp->private_data = STp; 1134 filp->private_data = STp;
1065 name = tape_name(STp); 1135 name = tape_name(STp);
1066 1136
1067 if (STp->in_use) { 1137 if (STp->in_use) {
1068 write_unlock(&st_dev_arr_lock); 1138 write_unlock(&st_dev_arr_lock);
1139 scsi_tape_put(STp);
1069 DEB( printk(ST_DEB_MSG "%s: Device already in use.\n", name); ) 1140 DEB( printk(ST_DEB_MSG "%s: Device already in use.\n", name); )
1070 return (-EBUSY); 1141 return (-EBUSY);
1071 } 1142 }
1072 1143
1073 if(scsi_device_get(STp->device)) {
1074 write_unlock(&st_dev_arr_lock);
1075 return (-ENXIO);
1076 }
1077 STp->in_use = 1; 1144 STp->in_use = 1;
1078 write_unlock(&st_dev_arr_lock); 1145 write_unlock(&st_dev_arr_lock);
1079 STp->rew_at_close = STp->autorew_dev = (iminor(inode) & 0x80) == 0; 1146 STp->rew_at_close = STp->autorew_dev = (iminor(inode) & 0x80) == 0;
@@ -1118,7 +1185,7 @@ static int st_open(struct inode *inode, struct file *filp)
1118 err_out: 1185 err_out:
1119 normalize_buffer(STp->buffer); 1186 normalize_buffer(STp->buffer);
1120 STp->in_use = 0; 1187 STp->in_use = 0;
1121 scsi_device_put(STp->device); 1188 scsi_tape_put(STp);
1122 return retval; 1189 return retval;
1123 1190
1124} 1191}
@@ -1250,7 +1317,7 @@ static int st_release(struct inode *inode, struct file *filp)
1250 write_lock(&st_dev_arr_lock); 1317 write_lock(&st_dev_arr_lock);
1251 STp->in_use = 0; 1318 STp->in_use = 0;
1252 write_unlock(&st_dev_arr_lock); 1319 write_unlock(&st_dev_arr_lock);
1253 scsi_device_put(STp->device); 1320 scsi_tape_put(STp);
1254 1321
1255 return result; 1322 return result;
1256} 1323}
@@ -3887,6 +3954,7 @@ static int st_probe(struct device *dev)
3887 goto out_put_disk; 3954 goto out_put_disk;
3888 } 3955 }
3889 memset(tpnt, 0, sizeof(struct scsi_tape)); 3956 memset(tpnt, 0, sizeof(struct scsi_tape));
3957 kref_init(&tpnt->kref);
3890 tpnt->disk = disk; 3958 tpnt->disk = disk;
3891 sprintf(disk->disk_name, "st%d", i); 3959 sprintf(disk->disk_name, "st%d", i);
3892 disk->private_data = &tpnt->driver; 3960 disk->private_data = &tpnt->driver;
@@ -3902,6 +3970,7 @@ static int st_probe(struct device *dev)
3902 tpnt->tape_type = MT_ISSCSI2; 3970 tpnt->tape_type = MT_ISSCSI2;
3903 3971
3904 tpnt->buffer = buffer; 3972 tpnt->buffer = buffer;
3973 tpnt->buffer->last_SRpnt = NULL;
3905 3974
3906 tpnt->inited = 0; 3975 tpnt->inited = 0;
3907 tpnt->dirty = 0; 3976 tpnt->dirty = 0;
@@ -4076,15 +4145,10 @@ static int st_remove(struct device *dev)
4076 tpnt->modes[mode].cdevs[j] = NULL; 4145 tpnt->modes[mode].cdevs[j] = NULL;
4077 } 4146 }
4078 } 4147 }
4079 tpnt->device = NULL;
4080 4148
4081 if (tpnt->buffer) { 4149 down(&st_ref_sem);
4082 tpnt->buffer->orig_frp_segs = 0; 4150 kref_put(&tpnt->kref, scsi_tape_release);
4083 normalize_buffer(tpnt->buffer); 4151 up(&st_ref_sem);
4084 kfree(tpnt->buffer);
4085 }
4086 put_disk(tpnt->disk);
4087 kfree(tpnt);
4088 return 0; 4152 return 0;
4089 } 4153 }
4090 } 4154 }
@@ -4093,6 +4157,34 @@ static int st_remove(struct device *dev)
4093 return 0; 4157 return 0;
4094} 4158}
4095 4159
4160/**
4161 * scsi_tape_release - Called to free the Scsi_Tape structure
4162 * @kref: pointer to embedded kref
4163 *
4164 * st_ref_sem must be held entering this routine. Because it is
4165 * called on last put, you should always use the scsi_tape_get()
4166 * scsi_tape_put() helpers which manipulate the semaphore directly
4167 * and never do a direct kref_put().
4168 **/
4169static void scsi_tape_release(struct kref *kref)
4170{
4171 struct scsi_tape *tpnt = to_scsi_tape(kref);
4172 struct gendisk *disk = tpnt->disk;
4173
4174 tpnt->device = NULL;
4175
4176 if (tpnt->buffer) {
4177 tpnt->buffer->orig_frp_segs = 0;
4178 normalize_buffer(tpnt->buffer);
4179 kfree(tpnt->buffer);
4180 }
4181
4182 disk->private_data = NULL;
4183 put_disk(disk);
4184 kfree(tpnt);
4185 return;
4186}
4187
4096static void st_intr(struct scsi_cmnd *SCpnt) 4188static void st_intr(struct scsi_cmnd *SCpnt)
4097{ 4189{
4098 scsi_io_completion(SCpnt, (SCpnt->result ? 0: SCpnt->bufflen), 1); 4190 scsi_io_completion(SCpnt, (SCpnt->result ? 0: SCpnt->bufflen), 1);
@@ -4348,12 +4440,12 @@ static int st_map_user_pages(struct scatterlist *sgl, const unsigned int max_pag
4348static int sgl_map_user_pages(struct scatterlist *sgl, const unsigned int max_pages, 4440static int sgl_map_user_pages(struct scatterlist *sgl, const unsigned int max_pages,
4349 unsigned long uaddr, size_t count, int rw) 4441 unsigned long uaddr, size_t count, int rw)
4350{ 4442{
4443 unsigned long end = (uaddr + count + PAGE_SIZE - 1) >> PAGE_SHIFT;
4444 unsigned long start = uaddr >> PAGE_SHIFT;
4445 const int nr_pages = end - start;
4351 int res, i, j; 4446 int res, i, j;
4352 unsigned int nr_pages;
4353 struct page **pages; 4447 struct page **pages;
4354 4448
4355 nr_pages = ((uaddr & ~PAGE_MASK) + count + ~PAGE_MASK) >> PAGE_SHIFT;
4356
4357 /* User attempted Overflow! */ 4449 /* User attempted Overflow! */
4358 if ((uaddr + count) < uaddr) 4450 if ((uaddr + count) < uaddr)
4359 return -EINVAL; 4451 return -EINVAL;
diff --git a/drivers/scsi/st.h b/drivers/scsi/st.h
index 061da111398..790acac160b 100644
--- a/drivers/scsi/st.h
+++ b/drivers/scsi/st.h
@@ -3,7 +3,7 @@
3#define _ST_H 3#define _ST_H
4 4
5#include <linux/completion.h> 5#include <linux/completion.h>
6 6#include <linux/kref.h>
7 7
8/* Descriptor for analyzed sense data */ 8/* Descriptor for analyzed sense data */
9struct st_cmdstatus { 9struct st_cmdstatus {
@@ -156,6 +156,7 @@ struct scsi_tape {
156 unsigned char last_sense[16]; 156 unsigned char last_sense[16];
157#endif 157#endif
158 struct gendisk *disk; 158 struct gendisk *disk;
159 struct kref kref;
159}; 160};
160 161
161/* Bit masks for use_pf */ 162/* Bit masks for use_pf */
diff --git a/drivers/serial/68328serial.c b/drivers/serial/68328serial.c
index 9097f2f7b12..2efb317153c 100644
--- a/drivers/serial/68328serial.c
+++ b/drivers/serial/68328serial.c
@@ -40,7 +40,6 @@
40#include <asm/io.h> 40#include <asm/io.h>
41#include <asm/irq.h> 41#include <asm/irq.h>
42#include <asm/system.h> 42#include <asm/system.h>
43#include <asm/segment.h>
44#include <asm/delay.h> 43#include <asm/delay.h>
45#include <asm/uaccess.h> 44#include <asm/uaccess.h>
46 45
diff --git a/drivers/serial/68360serial.c b/drivers/serial/68360serial.c
index b116122e569..170c9d2a749 100644
--- a/drivers/serial/68360serial.c
+++ b/drivers/serial/68360serial.c
@@ -2474,8 +2474,7 @@ static struct tty_operations rs_360_ops = {
2474 .tiocmset = rs_360_tiocmset, 2474 .tiocmset = rs_360_tiocmset,
2475}; 2475};
2476 2476
2477/* int __init rs_360_init(void) */ 2477static int __init rs_360_init(void)
2478int rs_360_init(void)
2479{ 2478{
2480 struct serial_state * state; 2479 struct serial_state * state;
2481 ser_info_t *info; 2480 ser_info_t *info;
@@ -2827,10 +2826,7 @@ int rs_360_init(void)
2827 2826
2828 return 0; 2827 return 0;
2829} 2828}
2830 2829module_init(rs_360_init);
2831
2832
2833
2834 2830
2835/* This must always be called before the rs_360_init() function, otherwise 2831/* This must always be called before the rs_360_init() function, otherwise
2836 * it blows away the port control information. 2832 * it blows away the port control information.
diff --git a/drivers/serial/Kconfig b/drivers/serial/Kconfig
index db8f39c3009..b745a1b9e83 100644
--- a/drivers/serial/Kconfig
+++ b/drivers/serial/Kconfig
@@ -308,7 +308,7 @@ config SERIAL_S3C2410_CONSOLE
308 308
309config SERIAL_DZ 309config SERIAL_DZ
310 bool "DECstation DZ serial driver" 310 bool "DECstation DZ serial driver"
311 depends on MACH_DECSTATION && MIPS32 311 depends on MACH_DECSTATION && 32BIT
312 select SERIAL_CORE 312 select SERIAL_CORE
313 help 313 help
314 DZ11-family serial controllers for VAXstations, including the 314 DZ11-family serial controllers for VAXstations, including the
diff --git a/drivers/serial/cpm_uart/cpm_uart_core.c b/drivers/serial/cpm_uart/cpm_uart_core.c
index 282b32351d8..25825f2aba2 100644
--- a/drivers/serial/cpm_uart/cpm_uart_core.c
+++ b/drivers/serial/cpm_uart/cpm_uart_core.c
@@ -403,10 +403,8 @@ static int cpm_uart_startup(struct uart_port *port)
403 403
404inline void cpm_uart_wait_until_send(struct uart_cpm_port *pinfo) 404inline void cpm_uart_wait_until_send(struct uart_cpm_port *pinfo)
405{ 405{
406 unsigned long target_jiffies = jiffies + pinfo->wait_closing; 406 set_current_state(TASK_UNINTERRUPTIBLE);
407 407 schedule_timeout(pinfo->wait_closing);
408 while (!time_after(jiffies, target_jiffies))
409 schedule();
410} 408}
411 409
412/* 410/*
@@ -425,9 +423,12 @@ static void cpm_uart_shutdown(struct uart_port *port)
425 /* If the port is not the console, disable Rx and Tx. */ 423 /* If the port is not the console, disable Rx and Tx. */
426 if (!(pinfo->flags & FLAG_CONSOLE)) { 424 if (!(pinfo->flags & FLAG_CONSOLE)) {
427 /* Wait for all the BDs marked sent */ 425 /* Wait for all the BDs marked sent */
428 while(!cpm_uart_tx_empty(port)) 426 while(!cpm_uart_tx_empty(port)) {
427 set_current_state(TASK_UNINTERRUPTIBLE);
429 schedule_timeout(2); 428 schedule_timeout(2);
430 if(pinfo->wait_closing) 429 }
430
431 if (pinfo->wait_closing)
431 cpm_uart_wait_until_send(pinfo); 432 cpm_uart_wait_until_send(pinfo);
432 433
433 /* Stop uarts */ 434 /* Stop uarts */
diff --git a/drivers/serial/cpm_uart/cpm_uart_cpm2.c b/drivers/serial/cpm_uart/cpm_uart_cpm2.c
index c4c8f4b44f5..15ad58d9488 100644
--- a/drivers/serial/cpm_uart/cpm_uart_cpm2.c
+++ b/drivers/serial/cpm_uart/cpm_uart_cpm2.c
@@ -142,6 +142,14 @@ void scc2_lineif(struct uart_cpm_port *pinfo)
142 * be supported in a sane fashion. 142 * be supported in a sane fashion.
143 */ 143 */
144#ifndef CONFIG_STX_GP3 144#ifndef CONFIG_STX_GP3
145#ifdef CONFIG_MPC8560_ADS
146 volatile iop_cpm2_t *io = &cpm2_immr->im_ioport;
147 io->iop_ppard |= 0x00000018;
148 io->iop_psord &= ~0x00000008; /* Rx */
149 io->iop_psord &= ~0x00000010; /* Tx */
150 io->iop_pdird &= ~0x00000008; /* Rx */
151 io->iop_pdird |= 0x00000010; /* Tx */
152#else
145 volatile iop_cpm2_t *io = &cpm2_immr->im_ioport; 153 volatile iop_cpm2_t *io = &cpm2_immr->im_ioport;
146 io->iop_pparb |= 0x008b0000; 154 io->iop_pparb |= 0x008b0000;
147 io->iop_pdirb |= 0x00880000; 155 io->iop_pdirb |= 0x00880000;
@@ -149,6 +157,7 @@ void scc2_lineif(struct uart_cpm_port *pinfo)
149 io->iop_pdirb &= ~0x00030000; 157 io->iop_pdirb &= ~0x00030000;
150 io->iop_psorb &= ~0x00030000; 158 io->iop_psorb &= ~0x00030000;
151#endif 159#endif
160#endif
152 cpm2_immr->im_cpmux.cmx_scr &= 0xff00ffff; 161 cpm2_immr->im_cpmux.cmx_scr &= 0xff00ffff;
153 cpm2_immr->im_cpmux.cmx_scr |= 0x00090000; 162 cpm2_immr->im_cpmux.cmx_scr |= 0x00090000;
154 pinfo->brg = 2; 163 pinfo->brg = 2;
@@ -257,6 +266,7 @@ int cpm_uart_init_portdesc(void)
257 cpm_uart_ports[UART_SMC1].smcp = (smc_t *) & cpm2_immr->im_smc[0]; 266 cpm_uart_ports[UART_SMC1].smcp = (smc_t *) & cpm2_immr->im_smc[0];
258 cpm_uart_ports[UART_SMC1].smcup = 267 cpm_uart_ports[UART_SMC1].smcup =
259 (smc_uart_t *) & cpm2_immr->im_dprambase[PROFF_SMC1]; 268 (smc_uart_t *) & cpm2_immr->im_dprambase[PROFF_SMC1];
269 *(u16 *)(&cpm2_immr->im_dprambase[PROFF_SMC1_BASE]) = PROFF_SMC1;
260 cpm_uart_ports[UART_SMC1].port.mapbase = 270 cpm_uart_ports[UART_SMC1].port.mapbase =
261 (unsigned long)&cpm2_immr->im_smc[0]; 271 (unsigned long)&cpm2_immr->im_smc[0];
262 cpm_uart_ports[UART_SMC1].smcp->smc_smcm |= (SMCM_RX | SMCM_TX); 272 cpm_uart_ports[UART_SMC1].smcp->smc_smcm |= (SMCM_RX | SMCM_TX);
@@ -269,6 +279,7 @@ int cpm_uart_init_portdesc(void)
269 cpm_uart_ports[UART_SMC2].smcp = (smc_t *) & cpm2_immr->im_smc[1]; 279 cpm_uart_ports[UART_SMC2].smcp = (smc_t *) & cpm2_immr->im_smc[1];
270 cpm_uart_ports[UART_SMC2].smcup = 280 cpm_uart_ports[UART_SMC2].smcup =
271 (smc_uart_t *) & cpm2_immr->im_dprambase[PROFF_SMC2]; 281 (smc_uart_t *) & cpm2_immr->im_dprambase[PROFF_SMC2];
282 *(u16 *)(&cpm2_immr->im_dprambase[PROFF_SMC2_BASE]) = PROFF_SMC2;
272 cpm_uart_ports[UART_SMC2].port.mapbase = 283 cpm_uart_ports[UART_SMC2].port.mapbase =
273 (unsigned long)&cpm2_immr->im_smc[1]; 284 (unsigned long)&cpm2_immr->im_smc[1];
274 cpm_uart_ports[UART_SMC2].smcp->smc_smcm |= (SMCM_RX | SMCM_TX); 285 cpm_uart_ports[UART_SMC2].smcp->smc_smcm |= (SMCM_RX | SMCM_TX);
diff --git a/drivers/serial/crisv10.c b/drivers/serial/crisv10.c
index 23b8871e74c..40d3e7139cf 100644
--- a/drivers/serial/crisv10.c
+++ b/drivers/serial/crisv10.c
@@ -446,7 +446,6 @@ static char *serial_version = "$Revision: 1.25 $";
446#include <asm/io.h> 446#include <asm/io.h>
447#include <asm/irq.h> 447#include <asm/irq.h>
448#include <asm/system.h> 448#include <asm/system.h>
449#include <asm/segment.h>
450#include <asm/bitops.h> 449#include <asm/bitops.h>
451#include <linux/delay.h> 450#include <linux/delay.h>
452 451
@@ -5041,17 +5040,3 @@ rs_init(void)
5041/* this makes sure that rs_init is called during kernel boot */ 5040/* this makes sure that rs_init is called during kernel boot */
5042 5041
5043module_init(rs_init); 5042module_init(rs_init);
5044
5045/*
5046 * register_serial and unregister_serial allows for serial ports to be
5047 * configured at run-time, to support PCMCIA modems.
5048 */
5049int
5050register_serial(struct serial_struct *req)
5051{
5052 return -1;
5053}
5054
5055void unregister_serial(int line)
5056{
5057}
diff --git a/drivers/serial/icom.c b/drivers/serial/icom.c
index 79f8df4d66b..eb31125c6a3 100644
--- a/drivers/serial/icom.c
+++ b/drivers/serial/icom.c
@@ -56,7 +56,6 @@
56#include <linux/bitops.h> 56#include <linux/bitops.h>
57 57
58#include <asm/system.h> 58#include <asm/system.h>
59#include <asm/segment.h>
60#include <asm/io.h> 59#include <asm/io.h>
61#include <asm/irq.h> 60#include <asm/irq.h>
62#include <asm/uaccess.h> 61#include <asm/uaccess.h>
diff --git a/drivers/serial/mcfserial.c b/drivers/serial/mcfserial.c
index 8c40167778d..43b03c55f45 100644
--- a/drivers/serial/mcfserial.c
+++ b/drivers/serial/mcfserial.c
@@ -40,7 +40,6 @@
40#include <asm/io.h> 40#include <asm/io.h>
41#include <asm/irq.h> 41#include <asm/irq.h>
42#include <asm/system.h> 42#include <asm/system.h>
43#include <asm/segment.h>
44#include <asm/semaphore.h> 43#include <asm/semaphore.h>
45#include <asm/delay.h> 44#include <asm/delay.h>
46#include <asm/coldfire.h> 45#include <asm/coldfire.h>
diff --git a/drivers/serial/pmac_zilog.c b/drivers/serial/pmac_zilog.c
index 5bfde99e245..5ddd8ab1f10 100644
--- a/drivers/serial/pmac_zilog.c
+++ b/drivers/serial/pmac_zilog.c
@@ -1600,7 +1600,7 @@ static int pmz_suspend(struct macio_dev *mdev, pm_message_t pm_state)
1600 return 0; 1600 return 0;
1601 } 1601 }
1602 1602
1603 if (pm_state == mdev->ofdev.dev.power.power_state || pm_state < 2) 1603 if (pm_state.event == mdev->ofdev.dev.power.power_state.event)
1604 return 0; 1604 return 0;
1605 1605
1606 pmz_debug("suspend, switching to state %d\n", pm_state); 1606 pmz_debug("suspend, switching to state %d\n", pm_state);
@@ -1660,7 +1660,7 @@ static int pmz_resume(struct macio_dev *mdev)
1660 if (uap == NULL) 1660 if (uap == NULL)
1661 return 0; 1661 return 0;
1662 1662
1663 if (mdev->ofdev.dev.power.power_state == 0) 1663 if (mdev->ofdev.dev.power.power_state.event == PM_EVENT_ON)
1664 return 0; 1664 return 0;
1665 1665
1666 pmz_debug("resume, switching to state 0\n"); 1666 pmz_debug("resume, switching to state 0\n");
@@ -1713,7 +1713,7 @@ static int pmz_resume(struct macio_dev *mdev)
1713 1713
1714 pmz_debug("resume, switching complete\n"); 1714 pmz_debug("resume, switching complete\n");
1715 1715
1716 mdev->ofdev.dev.power.power_state = 0; 1716 mdev->ofdev.dev.power.power_state.event = PM_EVENT_ON;
1717 1717
1718 return 0; 1718 return 0;
1719} 1719}
diff --git a/drivers/serial/serial_core.c b/drivers/serial/serial_core.c
index dea156a62d0..2d8622eef70 100644
--- a/drivers/serial/serial_core.c
+++ b/drivers/serial/serial_core.c
@@ -1947,21 +1947,29 @@ int uart_resume_port(struct uart_driver *drv, struct uart_port *port)
1947static inline void 1947static inline void
1948uart_report_port(struct uart_driver *drv, struct uart_port *port) 1948uart_report_port(struct uart_driver *drv, struct uart_port *port)
1949{ 1949{
1950 printk("%s%d", drv->dev_name, port->line); 1950 char address[64];
1951 printk(" at "); 1951
1952 switch (port->iotype) { 1952 switch (port->iotype) {
1953 case UPIO_PORT: 1953 case UPIO_PORT:
1954 printk("I/O 0x%x", port->iobase); 1954 snprintf(address, sizeof(address),
1955 "I/O 0x%x", port->iobase);
1955 break; 1956 break;
1956 case UPIO_HUB6: 1957 case UPIO_HUB6:
1957 printk("I/O 0x%x offset 0x%x", port->iobase, port->hub6); 1958 snprintf(address, sizeof(address),
1959 "I/O 0x%x offset 0x%x", port->iobase, port->hub6);
1958 break; 1960 break;
1959 case UPIO_MEM: 1961 case UPIO_MEM:
1960 case UPIO_MEM32: 1962 case UPIO_MEM32:
1961 printk("MMIO 0x%lx", port->mapbase); 1963 snprintf(address, sizeof(address),
1964 "MMIO 0x%lx", port->mapbase);
1965 break;
1966 default:
1967 strlcpy(address, "*unknown*", sizeof(address));
1962 break; 1968 break;
1963 } 1969 }
1964 printk(" (irq = %d) is a %s\n", port->irq, uart_type(port)); 1970
1971 printk(KERN_INFO "%s%d at %s (irq = %d) is a %s\n",
1972 drv->dev_name, port->line, address, port->irq, uart_type(port));
1965} 1973}
1966 1974
1967static void 1975static void
diff --git a/drivers/serial/serial_lh7a40x.c b/drivers/serial/serial_lh7a40x.c
index 32f808d157a..8302376800c 100644
--- a/drivers/serial/serial_lh7a40x.c
+++ b/drivers/serial/serial_lh7a40x.c
@@ -207,7 +207,7 @@ static void lh7a40xuart_tx_chars (struct uart_port* port)
207 return; 207 return;
208 } 208 }
209 if (uart_circ_empty (xmit) || uart_tx_stopped (port)) { 209 if (uart_circ_empty (xmit) || uart_tx_stopped (port)) {
210 lh7a40xuart_stop_tx (port, 0); 210 lh7a40xuart_stop_tx (port);
211 return; 211 return;
212 } 212 }
213 213
@@ -229,7 +229,7 @@ static void lh7a40xuart_tx_chars (struct uart_port* port)
229 uart_write_wakeup (port); 229 uart_write_wakeup (port);
230 230
231 if (uart_circ_empty (xmit)) 231 if (uart_circ_empty (xmit))
232 lh7a40xuart_stop_tx (port, 0); 232 lh7a40xuart_stop_tx (port);
233} 233}
234 234
235static void lh7a40xuart_modem_status (struct uart_port* port) 235static void lh7a40xuart_modem_status (struct uart_port* port)
diff --git a/drivers/serial/sunsu.c b/drivers/serial/sunsu.c
index 0cc879eb1c0..5959e6755a8 100644
--- a/drivers/serial/sunsu.c
+++ b/drivers/serial/sunsu.c
@@ -269,7 +269,10 @@ static void sunsu_stop_tx(struct uart_port *port)
269 269
270 __stop_tx(up); 270 __stop_tx(up);
271 271
272 if (up->port.type == PORT_16C950 && tty_stop /*FIXME*/) { 272 /*
273 * We really want to stop the transmitter from sending.
274 */
275 if (up->port.type == PORT_16C950) {
273 up->acr |= UART_ACR_TXDIS; 276 up->acr |= UART_ACR_TXDIS;
274 serial_icr_write(up, UART_ACR, up->acr); 277 serial_icr_write(up, UART_ACR, up->acr);
275 } 278 }
@@ -283,10 +286,11 @@ static void sunsu_start_tx(struct uart_port *port)
283 up->ier |= UART_IER_THRI; 286 up->ier |= UART_IER_THRI;
284 serial_out(up, UART_IER, up->ier); 287 serial_out(up, UART_IER, up->ier);
285 } 288 }
289
286 /* 290 /*
287 * We only do this from uart_start 291 * Re-enable the transmitter if we disabled it.
288 */ 292 */
289 if (tty_start && up->port.type == PORT_16C950 /*FIXME*/) { 293 if (up->port.type == PORT_16C950 && up->acr & UART_ACR_TXDIS) {
290 up->acr &= ~UART_ACR_TXDIS; 294 up->acr &= ~UART_ACR_TXDIS;
291 serial_icr_write(up, UART_ACR, up->acr); 295 serial_icr_write(up, UART_ACR, up->acr);
292 } 296 }
diff --git a/drivers/usb/atm/usbatm.c b/drivers/usb/atm/usbatm.c
index bb1db195985..c466739428b 100644
--- a/drivers/usb/atm/usbatm.c
+++ b/drivers/usb/atm/usbatm.c
@@ -960,7 +960,7 @@ int usbatm_usb_probe(struct usb_interface *intf, const struct usb_device_id *id,
960 intf->altsetting->desc.bInterfaceNumber); 960 intf->altsetting->desc.bInterfaceNumber);
961 961
962 /* instance init */ 962 /* instance init */
963 instance = kcalloc(1, sizeof(*instance) + sizeof(struct urb *) * (num_rcv_urbs + num_snd_urbs), GFP_KERNEL); 963 instance = kzalloc(sizeof(*instance) + sizeof(struct urb *) * (num_rcv_urbs + num_snd_urbs), GFP_KERNEL);
964 if (!instance) { 964 if (!instance) {
965 dev_dbg(dev, "%s: no memory for instance data!\n", __func__); 965 dev_dbg(dev, "%s: no memory for instance data!\n", __func__);
966 return -ENOMEM; 966 return -ENOMEM;
diff --git a/drivers/usb/core/hcd.c b/drivers/usb/core/hcd.c
index 79422a3b07b..12ecdb03ee5 100644
--- a/drivers/usb/core/hcd.c
+++ b/drivers/usb/core/hcd.c
@@ -782,7 +782,7 @@ static int usb_register_bus(struct usb_bus *bus)
782 return -E2BIG; 782 return -E2BIG;
783 } 783 }
784 784
785 bus->class_dev = class_device_create(usb_host_class, MKDEV(0,0), bus->controller, "usb%d", busnum); 785 bus->class_dev = class_device_create(usb_host_class, MKDEV(0,0), bus->controller, "usb_host%d", busnum);
786 if (IS_ERR(bus->class_dev)) { 786 if (IS_ERR(bus->class_dev)) {
787 clear_bit(busnum, busmap.busmap); 787 clear_bit(busnum, busmap.busmap);
788 up(&usb_bus_list_lock); 788 up(&usb_bus_list_lock);
@@ -1669,7 +1669,7 @@ struct usb_hcd *usb_create_hcd (const struct hc_driver *driver,
1669{ 1669{
1670 struct usb_hcd *hcd; 1670 struct usb_hcd *hcd;
1671 1671
1672 hcd = kcalloc(1, sizeof(*hcd) + driver->hcd_priv_size, GFP_KERNEL); 1672 hcd = kzalloc(sizeof(*hcd) + driver->hcd_priv_size, GFP_KERNEL);
1673 if (!hcd) { 1673 if (!hcd) {
1674 dev_dbg (dev, "hcd alloc failed\n"); 1674 dev_dbg (dev, "hcd alloc failed\n");
1675 return NULL; 1675 return NULL;
diff --git a/drivers/usb/core/hub.c b/drivers/usb/core/hub.c
index c3e46d24a37..c9412daff68 100644
--- a/drivers/usb/core/hub.c
+++ b/drivers/usb/core/hub.c
@@ -1570,7 +1570,7 @@ static int __usb_suspend_device (struct usb_device *udev, int port1,
1570 struct usb_driver *driver; 1570 struct usb_driver *driver;
1571 1571
1572 intf = udev->actconfig->interface[i]; 1572 intf = udev->actconfig->interface[i];
1573 if (state <= intf->dev.power.power_state) 1573 if (state.event <= intf->dev.power.power_state.event)
1574 continue; 1574 continue;
1575 if (!intf->dev.driver) 1575 if (!intf->dev.driver)
1576 continue; 1576 continue;
@@ -1578,11 +1578,11 @@ static int __usb_suspend_device (struct usb_device *udev, int port1,
1578 1578
1579 if (driver->suspend) { 1579 if (driver->suspend) {
1580 status = driver->suspend(intf, state); 1580 status = driver->suspend(intf, state);
1581 if (intf->dev.power.power_state != state 1581 if (intf->dev.power.power_state.event != state.event
1582 || status) 1582 || status)
1583 dev_err(&intf->dev, 1583 dev_err(&intf->dev,
1584 "suspend %d fail, code %d\n", 1584 "suspend %d fail, code %d\n",
1585 state, status); 1585 state.event, status);
1586 } 1586 }
1587 1587
1588 /* only drivers with suspend() can ever resume(); 1588 /* only drivers with suspend() can ever resume();
@@ -1595,7 +1595,7 @@ static int __usb_suspend_device (struct usb_device *udev, int port1,
1595 * since we know every driver's probe/disconnect works 1595 * since we know every driver's probe/disconnect works
1596 * even for drivers that can't suspend. 1596 * even for drivers that can't suspend.
1597 */ 1597 */
1598 if (!driver->suspend || state > PM_SUSPEND_MEM) { 1598 if (!driver->suspend || state.event > PM_EVENT_FREEZE) {
1599#if 1 1599#if 1
1600 dev_warn(&intf->dev, "resume is unsafe!\n"); 1600 dev_warn(&intf->dev, "resume is unsafe!\n");
1601#else 1601#else
@@ -1616,7 +1616,7 @@ static int __usb_suspend_device (struct usb_device *udev, int port1,
1616 * policies (when HNP doesn't apply) once we have mechanisms to 1616 * policies (when HNP doesn't apply) once we have mechanisms to
1617 * turn power back on! (Likely not before 2.7...) 1617 * turn power back on! (Likely not before 2.7...)
1618 */ 1618 */
1619 if (state > PM_SUSPEND_MEM) { 1619 if (state.event > PM_EVENT_FREEZE) {
1620 dev_warn(&udev->dev, "no poweroff yet, suspending instead\n"); 1620 dev_warn(&udev->dev, "no poweroff yet, suspending instead\n");
1621 } 1621 }
1622 1622
@@ -1733,7 +1733,7 @@ static int finish_port_resume(struct usb_device *udev)
1733 struct usb_driver *driver; 1733 struct usb_driver *driver;
1734 1734
1735 intf = udev->actconfig->interface[i]; 1735 intf = udev->actconfig->interface[i];
1736 if (intf->dev.power.power_state == PMSG_ON) 1736 if (intf->dev.power.power_state.event == PM_EVENT_ON)
1737 continue; 1737 continue;
1738 if (!intf->dev.driver) { 1738 if (!intf->dev.driver) {
1739 /* FIXME maybe force to alt 0 */ 1739 /* FIXME maybe force to alt 0 */
@@ -1747,11 +1747,11 @@ static int finish_port_resume(struct usb_device *udev)
1747 1747
1748 /* can we do better than just logging errors? */ 1748 /* can we do better than just logging errors? */
1749 status = driver->resume(intf); 1749 status = driver->resume(intf);
1750 if (intf->dev.power.power_state != PMSG_ON 1750 if (intf->dev.power.power_state.event != PM_EVENT_ON
1751 || status) 1751 || status)
1752 dev_dbg(&intf->dev, 1752 dev_dbg(&intf->dev,
1753 "resume fail, state %d code %d\n", 1753 "resume fail, state %d code %d\n",
1754 intf->dev.power.power_state, status); 1754 intf->dev.power.power_state.event, status);
1755 } 1755 }
1756 status = 0; 1756 status = 0;
1757 1757
@@ -1934,7 +1934,7 @@ static int hub_resume(struct usb_interface *intf)
1934 unsigned port1; 1934 unsigned port1;
1935 int status; 1935 int status;
1936 1936
1937 if (intf->dev.power.power_state == PM_SUSPEND_ON) 1937 if (intf->dev.power.power_state.event == PM_EVENT_ON)
1938 return 0; 1938 return 0;
1939 1939
1940 for (port1 = 1; port1 <= hdev->maxchild; port1++) { 1940 for (port1 = 1; port1 <= hdev->maxchild; port1++) {
diff --git a/drivers/usb/core/usb.c b/drivers/usb/core/usb.c
index 99c85d2f92d..2cddd8a0043 100644
--- a/drivers/usb/core/usb.c
+++ b/drivers/usb/core/usb.c
@@ -1400,7 +1400,7 @@ static int usb_generic_suspend(struct device *dev, pm_message_t message)
1400 driver = to_usb_driver(dev->driver); 1400 driver = to_usb_driver(dev->driver);
1401 1401
1402 /* there's only one USB suspend state */ 1402 /* there's only one USB suspend state */
1403 if (intf->dev.power.power_state) 1403 if (intf->dev.power.power_state.event)
1404 return 0; 1404 return 0;
1405 1405
1406 if (driver->suspend) 1406 if (driver->suspend)
diff --git a/drivers/usb/host/ehci-dbg.c b/drivers/usb/host/ehci-dbg.c
index b01efb6b36f..65ac9fef3a7 100644
--- a/drivers/usb/host/ehci-dbg.c
+++ b/drivers/usb/host/ehci-dbg.c
@@ -641,7 +641,7 @@ show_registers (struct class_device *class_dev, char *buf)
641 641
642 spin_lock_irqsave (&ehci->lock, flags); 642 spin_lock_irqsave (&ehci->lock, flags);
643 643
644 if (bus->controller->power.power_state) { 644 if (bus->controller->power.power_state.event) {
645 size = scnprintf (next, size, 645 size = scnprintf (next, size,
646 "bus %s, device %s (driver " DRIVER_VERSION ")\n" 646 "bus %s, device %s (driver " DRIVER_VERSION ")\n"
647 "%s\n" 647 "%s\n"
diff --git a/drivers/usb/host/ehci-sched.c b/drivers/usb/host/ehci-sched.c
index b56f25864ed..4c972b57c7c 100644
--- a/drivers/usb/host/ehci-sched.c
+++ b/drivers/usb/host/ehci-sched.c
@@ -638,7 +638,7 @@ iso_stream_alloc (unsigned mem_flags)
638{ 638{
639 struct ehci_iso_stream *stream; 639 struct ehci_iso_stream *stream;
640 640
641 stream = kcalloc(1, sizeof *stream, mem_flags); 641 stream = kzalloc(sizeof *stream, mem_flags);
642 if (likely (stream != NULL)) { 642 if (likely (stream != NULL)) {
643 INIT_LIST_HEAD(&stream->td_list); 643 INIT_LIST_HEAD(&stream->td_list);
644 INIT_LIST_HEAD(&stream->free_list); 644 INIT_LIST_HEAD(&stream->free_list);
diff --git a/drivers/usb/host/isp116x-hcd.c b/drivers/usb/host/isp116x-hcd.c
index 76cb496c583..75128c37180 100644
--- a/drivers/usb/host/isp116x-hcd.c
+++ b/drivers/usb/host/isp116x-hcd.c
@@ -717,7 +717,7 @@ static int isp116x_urb_enqueue(struct usb_hcd *hcd,
717 } 717 }
718 /* avoid all allocations within spinlocks: request or endpoint */ 718 /* avoid all allocations within spinlocks: request or endpoint */
719 if (!hep->hcpriv) { 719 if (!hep->hcpriv) {
720 ep = kcalloc(1, sizeof *ep, mem_flags); 720 ep = kzalloc(sizeof *ep, mem_flags);
721 if (!ep) 721 if (!ep)
722 return -ENOMEM; 722 return -ENOMEM;
723 } 723 }
diff --git a/drivers/usb/host/ohci-dbg.c b/drivers/usb/host/ohci-dbg.c
index c58408c95c3..447f488f5d9 100644
--- a/drivers/usb/host/ohci-dbg.c
+++ b/drivers/usb/host/ohci-dbg.c
@@ -631,7 +631,7 @@ show_registers (struct class_device *class_dev, char *buf)
631 hcd->product_desc, 631 hcd->product_desc,
632 hcd_name); 632 hcd_name);
633 633
634 if (bus->controller->power.power_state) { 634 if (bus->controller->power.power_state.event) {
635 size -= scnprintf (next, size, 635 size -= scnprintf (next, size,
636 "SUSPENDED (no register access)\n"); 636 "SUSPENDED (no register access)\n");
637 goto done; 637 goto done;
diff --git a/drivers/usb/host/sl811-hcd.c b/drivers/usb/host/sl811-hcd.c
index 7a890a65f55..d2a1fd40dfc 100644
--- a/drivers/usb/host/sl811-hcd.c
+++ b/drivers/usb/host/sl811-hcd.c
@@ -835,7 +835,7 @@ static int sl811h_urb_enqueue(
835 835
836 /* avoid all allocations within spinlocks */ 836 /* avoid all allocations within spinlocks */
837 if (!hep->hcpriv) 837 if (!hep->hcpriv)
838 ep = kcalloc(1, sizeof *ep, mem_flags); 838 ep = kzalloc(sizeof *ep, mem_flags);
839 839
840 spin_lock_irqsave(&sl811->lock, flags); 840 spin_lock_irqsave(&sl811->lock, flags);
841 841
@@ -1781,9 +1781,9 @@ sl811h_suspend(struct device *dev, pm_message_t state, u32 phase)
1781 if (phase != SUSPEND_POWER_DOWN) 1781 if (phase != SUSPEND_POWER_DOWN)
1782 return retval; 1782 return retval;
1783 1783
1784 if (state <= PM_SUSPEND_MEM) 1784 if (state.event == PM_EVENT_FREEZE)
1785 retval = sl811h_hub_suspend(hcd); 1785 retval = sl811h_hub_suspend(hcd);
1786 else 1786 else if (state.event == PM_EVENT_SUSPEND)
1787 port_power(sl811, 0); 1787 port_power(sl811, 0);
1788 if (retval == 0) 1788 if (retval == 0)
1789 dev->power.power_state = state; 1789 dev->power.power_state = state;
@@ -1802,7 +1802,7 @@ sl811h_resume(struct device *dev, u32 phase)
1802 /* with no "check to see if VBUS is still powered" board hook, 1802 /* with no "check to see if VBUS is still powered" board hook,
1803 * let's assume it'd only be powered to enable remote wakeup. 1803 * let's assume it'd only be powered to enable remote wakeup.
1804 */ 1804 */
1805 if (dev->power.power_state > PM_SUSPEND_MEM 1805 if (dev->power.power_state.event == PM_EVENT_SUSPEND
1806 || !hcd->can_wakeup) { 1806 || !hcd->can_wakeup) {
1807 sl811->port1 = 0; 1807 sl811->port1 = 0;
1808 port_power(sl811, 1); 1808 port_power(sl811, 1);
diff --git a/drivers/usb/input/acecad.c b/drivers/usb/input/acecad.c
index 13532f3e3ef..74f8760d7c0 100644
--- a/drivers/usb/input/acecad.c
+++ b/drivers/usb/input/acecad.c
@@ -152,7 +152,7 @@ static int usb_acecad_probe(struct usb_interface *intf, const struct usb_device_
152 pipe = usb_rcvintpipe(dev, endpoint->bEndpointAddress); 152 pipe = usb_rcvintpipe(dev, endpoint->bEndpointAddress);
153 maxp = usb_maxpacket(dev, pipe, usb_pipeout(pipe)); 153 maxp = usb_maxpacket(dev, pipe, usb_pipeout(pipe));
154 154
155 acecad = kcalloc(1, sizeof(struct usb_acecad), GFP_KERNEL); 155 acecad = kzalloc(sizeof(struct usb_acecad), GFP_KERNEL);
156 if (!acecad) 156 if (!acecad)
157 return -ENOMEM; 157 return -ENOMEM;
158 158
diff --git a/drivers/usb/input/itmtouch.c b/drivers/usb/input/itmtouch.c
index 0dc439f1082..becb87efb86 100644
--- a/drivers/usb/input/itmtouch.c
+++ b/drivers/usb/input/itmtouch.c
@@ -166,7 +166,7 @@ static int itmtouch_probe(struct usb_interface *intf, const struct usb_device_id
166 interface = intf->cur_altsetting; 166 interface = intf->cur_altsetting;
167 endpoint = &interface->endpoint[0].desc; 167 endpoint = &interface->endpoint[0].desc;
168 168
169 if (!(itmtouch = kcalloc(1, sizeof(struct itmtouch_dev), GFP_KERNEL))) { 169 if (!(itmtouch = kzalloc(sizeof(struct itmtouch_dev), GFP_KERNEL))) {
170 err("%s - Out of memory.", __FUNCTION__); 170 err("%s - Out of memory.", __FUNCTION__);
171 return -ENOMEM; 171 return -ENOMEM;
172 } 172 }
diff --git a/drivers/usb/input/pid.c b/drivers/usb/input/pid.c
index 25696386347..acc71ec560e 100644
--- a/drivers/usb/input/pid.c
+++ b/drivers/usb/input/pid.c
@@ -263,7 +263,7 @@ int hid_pid_init(struct hid_device *hid)
263 struct hid_ff_pid *private; 263 struct hid_ff_pid *private;
264 struct hid_input *hidinput = list_entry(&hid->inputs, struct hid_input, list); 264 struct hid_input *hidinput = list_entry(&hid->inputs, struct hid_input, list);
265 265
266 private = hid->ff_private = kcalloc(1, sizeof(struct hid_ff_pid), GFP_KERNEL); 266 private = hid->ff_private = kzalloc(sizeof(struct hid_ff_pid), GFP_KERNEL);
267 if (!private) 267 if (!private)
268 return -ENOMEM; 268 return -ENOMEM;
269 269
diff --git a/drivers/usb/media/w9968cf.c b/drivers/usb/media/w9968cf.c
index ca9f3a30634..f36c0b6c6e3 100644
--- a/drivers/usb/media/w9968cf.c
+++ b/drivers/usb/media/w9968cf.c
@@ -1523,7 +1523,6 @@ static u32 w9968cf_i2c_func(struct i2c_adapter* adap)
1523static int w9968cf_i2c_attach_inform(struct i2c_client* client) 1523static int w9968cf_i2c_attach_inform(struct i2c_client* client)
1524{ 1524{
1525 struct w9968cf_device* cam = i2c_get_adapdata(client->adapter); 1525 struct w9968cf_device* cam = i2c_get_adapdata(client->adapter);
1526 const char* clientname = i2c_clientname(client);
1527 int id = client->driver->id, err = 0; 1526 int id = client->driver->id, err = 0;
1528 1527
1529 if (id == I2C_DRIVERID_OVCAMCHIP) { 1528 if (id == I2C_DRIVERID_OVCAMCHIP) {
@@ -1535,12 +1534,12 @@ static int w9968cf_i2c_attach_inform(struct i2c_client* client)
1535 } 1534 }
1536 } else { 1535 } else {
1537 DBG(4, "Rejected client [%s] with driver [%s]", 1536 DBG(4, "Rejected client [%s] with driver [%s]",
1538 clientname, client->driver->name) 1537 client->name, client->driver->name)
1539 return -EINVAL; 1538 return -EINVAL;
1540 } 1539 }
1541 1540
1542 DBG(5, "I2C attach client [%s] with driver [%s]", 1541 DBG(5, "I2C attach client [%s] with driver [%s]",
1543 clientname, client->driver->name) 1542 client->name, client->driver->name)
1544 1543
1545 return 0; 1544 return 0;
1546} 1545}
@@ -1549,12 +1548,11 @@ static int w9968cf_i2c_attach_inform(struct i2c_client* client)
1549static int w9968cf_i2c_detach_inform(struct i2c_client* client) 1548static int w9968cf_i2c_detach_inform(struct i2c_client* client)
1550{ 1549{
1551 struct w9968cf_device* cam = i2c_get_adapdata(client->adapter); 1550 struct w9968cf_device* cam = i2c_get_adapdata(client->adapter);
1552 const char* clientname = i2c_clientname(client);
1553 1551
1554 if (cam->sensor_client == client) 1552 if (cam->sensor_client == client)
1555 cam->sensor_client = NULL; 1553 cam->sensor_client = NULL;
1556 1554
1557 DBG(5, "I2C detach client [%s]", clientname) 1555 DBG(5, "I2C detach client [%s]", client->name)
1558 1556
1559 return 0; 1557 return 0;
1560} 1558}
@@ -1573,15 +1571,13 @@ static int w9968cf_i2c_init(struct w9968cf_device* cam)
1573 int err = 0; 1571 int err = 0;
1574 1572
1575 static struct i2c_algorithm algo = { 1573 static struct i2c_algorithm algo = {
1576 .name = "W996[87]CF algorithm",
1577 .id = I2C_ALGO_SMBUS,
1578 .smbus_xfer = w9968cf_i2c_smbus_xfer, 1574 .smbus_xfer = w9968cf_i2c_smbus_xfer,
1579 .algo_control = w9968cf_i2c_control, 1575 .algo_control = w9968cf_i2c_control,
1580 .functionality = w9968cf_i2c_func, 1576 .functionality = w9968cf_i2c_func,
1581 }; 1577 };
1582 1578
1583 static struct i2c_adapter adap = { 1579 static struct i2c_adapter adap = {
1584 .id = I2C_ALGO_SMBUS | I2C_HW_SMBUS_W9968CF, 1580 .id = I2C_HW_SMBUS_W9968CF,
1585 .class = I2C_CLASS_CAM_DIGITAL, 1581 .class = I2C_CLASS_CAM_DIGITAL,
1586 .owner = THIS_MODULE, 1582 .owner = THIS_MODULE,
1587 .client_register = w9968cf_i2c_attach_inform, 1583 .client_register = w9968cf_i2c_attach_inform,
diff --git a/drivers/usb/misc/usbtest.c b/drivers/usb/misc/usbtest.c
index cda7249a90b..fd7fb98e4b2 100644
--- a/drivers/usb/misc/usbtest.c
+++ b/drivers/usb/misc/usbtest.c
@@ -1533,7 +1533,7 @@ usbtest_ioctl (struct usb_interface *intf, unsigned int code, void *buf)
1533 if (down_interruptible (&dev->sem)) 1533 if (down_interruptible (&dev->sem))
1534 return -ERESTARTSYS; 1534 return -ERESTARTSYS;
1535 1535
1536 if (intf->dev.power.power_state != PMSG_ON) { 1536 if (intf->dev.power.power_state.event != PM_EVENT_ON) {
1537 up (&dev->sem); 1537 up (&dev->sem);
1538 return -EHOSTUNREACH; 1538 return -EHOSTUNREACH;
1539 } 1539 }
diff --git a/drivers/video/aty/aty128fb.c b/drivers/video/aty/aty128fb.c
index 7bc1d44d881..b0eba3ac642 100644
--- a/drivers/video/aty/aty128fb.c
+++ b/drivers/video/aty/aty128fb.c
@@ -2323,17 +2323,16 @@ static int aty128_pci_suspend(struct pci_dev *pdev, pm_message_t state)
2323 * can properly take care of D3 ? Also, with swsusp, we 2323 * can properly take care of D3 ? Also, with swsusp, we
2324 * know we'll be rebooted, ... 2324 * know we'll be rebooted, ...
2325 */ 2325 */
2326#ifdef CONFIG_PPC_PMAC 2326#ifndef CONFIG_PPC_PMAC
2327 /* HACK ALERT ! Once I find a proper way to say to each driver 2327 /* HACK ALERT ! Once I find a proper way to say to each driver
2328 * individually what will happen with it's PCI slot, I'll change 2328 * individually what will happen with it's PCI slot, I'll change
2329 * that. On laptops, the AGP slot is just unclocked, so D2 is 2329 * that. On laptops, the AGP slot is just unclocked, so D2 is
2330 * expected, while on desktops, the card is powered off 2330 * expected, while on desktops, the card is powered off
2331 */ 2331 */
2332 if (state >= 3) 2332 return 0;
2333 state = 2;
2334#endif /* CONFIG_PPC_PMAC */ 2333#endif /* CONFIG_PPC_PMAC */
2335 2334
2336 if (state != 2 || state == pdev->dev.power.power_state) 2335 if (state.event == pdev->dev.power.power_state.event)
2337 return 0; 2336 return 0;
2338 2337
2339 printk(KERN_DEBUG "aty128fb: suspending...\n"); 2338 printk(KERN_DEBUG "aty128fb: suspending...\n");
@@ -2367,7 +2366,7 @@ static int aty128_pci_suspend(struct pci_dev *pdev, pm_message_t state)
2367 * used dummy fb ops, 2.5 need proper support for this at the 2366 * used dummy fb ops, 2.5 need proper support for this at the
2368 * fbdev level 2367 * fbdev level
2369 */ 2368 */
2370 if (state == 2) 2369 if (state.event != PM_EVENT_ON)
2371 aty128_set_suspend(par, 1); 2370 aty128_set_suspend(par, 1);
2372 2371
2373 release_console_sem(); 2372 release_console_sem();
@@ -2382,12 +2381,11 @@ static int aty128_do_resume(struct pci_dev *pdev)
2382 struct fb_info *info = pci_get_drvdata(pdev); 2381 struct fb_info *info = pci_get_drvdata(pdev);
2383 struct aty128fb_par *par = info->par; 2382 struct aty128fb_par *par = info->par;
2384 2383
2385 if (pdev->dev.power.power_state == 0) 2384 if (pdev->dev.power.power_state.event == PM_EVENT_ON)
2386 return 0; 2385 return 0;
2387 2386
2388 /* Wakeup chip */ 2387 /* Wakeup chip */
2389 if (pdev->dev.power.power_state == 2) 2388 aty128_set_suspend(par, 0);
2390 aty128_set_suspend(par, 0);
2391 par->asleep = 0; 2389 par->asleep = 0;
2392 2390
2393 /* Restore display & engine */ 2391 /* Restore display & engine */
diff --git a/drivers/video/aty/atyfb_base.c b/drivers/video/aty/atyfb_base.c
index 8c42538dc8c..3e10bd837d9 100644
--- a/drivers/video/aty/atyfb_base.c
+++ b/drivers/video/aty/atyfb_base.c
@@ -2022,17 +2022,16 @@ static int atyfb_pci_suspend(struct pci_dev *pdev, pm_message_t state)
2022 struct fb_info *info = pci_get_drvdata(pdev); 2022 struct fb_info *info = pci_get_drvdata(pdev);
2023 struct atyfb_par *par = (struct atyfb_par *) info->par; 2023 struct atyfb_par *par = (struct atyfb_par *) info->par;
2024 2024
2025#ifdef CONFIG_PPC_PMAC 2025#ifndef CONFIG_PPC_PMAC
2026 /* HACK ALERT ! Once I find a proper way to say to each driver 2026 /* HACK ALERT ! Once I find a proper way to say to each driver
2027 * individually what will happen with it's PCI slot, I'll change 2027 * individually what will happen with it's PCI slot, I'll change
2028 * that. On laptops, the AGP slot is just unclocked, so D2 is 2028 * that. On laptops, the AGP slot is just unclocked, so D2 is
2029 * expected, while on desktops, the card is powered off 2029 * expected, while on desktops, the card is powered off
2030 */ 2030 */
2031 if (state >= 3) 2031 return 0;
2032 state = 2;
2033#endif /* CONFIG_PPC_PMAC */ 2032#endif /* CONFIG_PPC_PMAC */
2034 2033
2035 if (state != 2 || state == pdev->dev.power.power_state) 2034 if (state.event == pdev->dev.power.power_state.event)
2036 return 0; 2035 return 0;
2037 2036
2038 acquire_console_sem(); 2037 acquire_console_sem();
@@ -2071,12 +2070,12 @@ static int atyfb_pci_resume(struct pci_dev *pdev)
2071 struct fb_info *info = pci_get_drvdata(pdev); 2070 struct fb_info *info = pci_get_drvdata(pdev);
2072 struct atyfb_par *par = (struct atyfb_par *) info->par; 2071 struct atyfb_par *par = (struct atyfb_par *) info->par;
2073 2072
2074 if (pdev->dev.power.power_state == 0) 2073 if (pdev->dev.power.power_state.event == PM_EVENT_ON)
2075 return 0; 2074 return 0;
2076 2075
2077 acquire_console_sem(); 2076 acquire_console_sem();
2078 2077
2079 if (pdev->dev.power.power_state == 2) 2078 if (pdev->dev.power.power_state.event == 2)
2080 aty_power_mgmt(0, par); 2079 aty_power_mgmt(0, par);
2081 par->asleep = 0; 2080 par->asleep = 0;
2082 2081
diff --git a/drivers/video/aty/radeon_i2c.c b/drivers/video/aty/radeon_i2c.c
index 762244164c8..a9d0414e465 100644
--- a/drivers/video/aty/radeon_i2c.c
+++ b/drivers/video/aty/radeon_i2c.c
@@ -75,7 +75,7 @@ static int radeon_setup_i2c_bus(struct radeon_i2c_chan *chan, const char *name)
75 75
76 strcpy(chan->adapter.name, name); 76 strcpy(chan->adapter.name, name);
77 chan->adapter.owner = THIS_MODULE; 77 chan->adapter.owner = THIS_MODULE;
78 chan->adapter.id = I2C_ALGO_ATI; 78 chan->adapter.id = I2C_HW_B_RADEON;
79 chan->adapter.algo_data = &chan->algo; 79 chan->adapter.algo_data = &chan->algo;
80 chan->adapter.dev.parent = &chan->rinfo->pdev->dev; 80 chan->adapter.dev.parent = &chan->rinfo->pdev->dev;
81 chan->algo.setsda = radeon_gpio_setsda; 81 chan->algo.setsda = radeon_gpio_setsda;
diff --git a/drivers/video/aty/radeon_pm.c b/drivers/video/aty/radeon_pm.c
index 98352af3932..59a1b6f8506 100644
--- a/drivers/video/aty/radeon_pm.c
+++ b/drivers/video/aty/radeon_pm.c
@@ -2526,18 +2526,18 @@ int radeonfb_pci_suspend(struct pci_dev *pdev, pm_message_t state)
2526 struct radeonfb_info *rinfo = info->par; 2526 struct radeonfb_info *rinfo = info->par;
2527 int i; 2527 int i;
2528 2528
2529 if (state == pdev->dev.power.power_state) 2529 if (state.event == pdev->dev.power.power_state.event)
2530 return 0; 2530 return 0;
2531 2531
2532 printk(KERN_DEBUG "radeonfb (%s): suspending to state: %d...\n", 2532 printk(KERN_DEBUG "radeonfb (%s): suspending to state: %d...\n",
2533 pci_name(pdev), state); 2533 pci_name(pdev), state.event);
2534 2534
2535 /* For suspend-to-disk, we cheat here. We don't suspend anything and 2535 /* For suspend-to-disk, we cheat here. We don't suspend anything and
2536 * let fbcon continue drawing until we are all set. That shouldn't 2536 * let fbcon continue drawing until we are all set. That shouldn't
2537 * really cause any problem at this point, provided that the wakeup 2537 * really cause any problem at this point, provided that the wakeup
2538 * code knows that any state in memory may not match the HW 2538 * code knows that any state in memory may not match the HW
2539 */ 2539 */
2540 if (state != PM_SUSPEND_MEM) 2540 if (state.event == PM_EVENT_FREEZE)
2541 goto done; 2541 goto done;
2542 2542
2543 acquire_console_sem(); 2543 acquire_console_sem();
@@ -2616,7 +2616,7 @@ int radeonfb_pci_resume(struct pci_dev *pdev)
2616 struct radeonfb_info *rinfo = info->par; 2616 struct radeonfb_info *rinfo = info->par;
2617 int rc = 0; 2617 int rc = 0;
2618 2618
2619 if (pdev->dev.power.power_state == 0) 2619 if (pdev->dev.power.power_state.event == PM_EVENT_ON)
2620 return 0; 2620 return 0;
2621 2621
2622 if (rinfo->no_schedule) { 2622 if (rinfo->no_schedule) {
@@ -2626,7 +2626,7 @@ int radeonfb_pci_resume(struct pci_dev *pdev)
2626 acquire_console_sem(); 2626 acquire_console_sem();
2627 2627
2628 printk(KERN_DEBUG "radeonfb (%s): resuming from state: %d...\n", 2628 printk(KERN_DEBUG "radeonfb (%s): resuming from state: %d...\n",
2629 pci_name(pdev), pdev->dev.power.power_state); 2629 pci_name(pdev), pdev->dev.power.power_state.event);
2630 2630
2631 2631
2632 if (pci_enable_device(pdev)) { 2632 if (pci_enable_device(pdev)) {
@@ -2637,7 +2637,7 @@ int radeonfb_pci_resume(struct pci_dev *pdev)
2637 } 2637 }
2638 pci_set_master(pdev); 2638 pci_set_master(pdev);
2639 2639
2640 if (pdev->dev.power.power_state == PM_SUSPEND_MEM) { 2640 if (pdev->dev.power.power_state.event == PM_EVENT_SUSPEND) {
2641 /* Wakeup chip. Check from config space if we were powered off 2641 /* Wakeup chip. Check from config space if we were powered off
2642 * (todo: additionally, check CLK_PIN_CNTL too) 2642 * (todo: additionally, check CLK_PIN_CNTL too)
2643 */ 2643 */
diff --git a/drivers/video/backlight/Makefile b/drivers/video/backlight/Makefile
index 9aae884475b..4af321fae39 100644
--- a/drivers/video/backlight/Makefile
+++ b/drivers/video/backlight/Makefile
@@ -3,3 +3,4 @@
3obj-$(CONFIG_LCD_CLASS_DEVICE) += lcd.o 3obj-$(CONFIG_LCD_CLASS_DEVICE) += lcd.o
4obj-$(CONFIG_BACKLIGHT_CLASS_DEVICE) += backlight.o 4obj-$(CONFIG_BACKLIGHT_CLASS_DEVICE) += backlight.o
5obj-$(CONFIG_BACKLIGHT_CORGI) += corgi_bl.o 5obj-$(CONFIG_BACKLIGHT_CORGI) += corgi_bl.o
6obj-$(CONFIG_SHARP_LOCOMO) += locomolcd.o
diff --git a/drivers/video/backlight/locomolcd.c b/drivers/video/backlight/locomolcd.c
new file mode 100644
index 00000000000..ada6e75eb04
--- /dev/null
+++ b/drivers/video/backlight/locomolcd.c
@@ -0,0 +1,157 @@
1/*
2 * Backlight control code for Sharp Zaurus SL-5500
3 *
4 * Copyright 2005 John Lenz <lenz@cs.wisc.edu>
5 * Maintainer: Pavel Machek <pavel@suse.cz> (unless John wants to :-)
6 * GPL v2
7 *
8 * This driver assumes single CPU. That's okay, because collie is
9 * slightly old hardware, and noone is going to retrofit second CPU to
10 * old PDA.
11 */
12
13/* LCD power functions */
14#include <linux/config.h>
15#include <linux/module.h>
16#include <linux/init.h>
17#include <linux/delay.h>
18#include <linux/device.h>
19#include <linux/interrupt.h>
20
21#include <asm/hardware/locomo.h>
22#include <asm/irq.h>
23
24#ifdef CONFIG_SA1100_COLLIE
25#include <asm/arch/collie.h>
26#else
27#include <asm/arch/poodle.h>
28#endif
29
30extern void (*sa1100fb_lcd_power)(int on);
31
32static struct locomo_dev *locomolcd_dev;
33
34static void locomolcd_on(int comadj)
35{
36 locomo_gpio_set_dir(locomolcd_dev, LOCOMO_GPIO_LCD_VSHA_ON, 0);
37 locomo_gpio_write(locomolcd_dev, LOCOMO_GPIO_LCD_VSHA_ON, 1);
38 mdelay(2);
39
40 locomo_gpio_set_dir(locomolcd_dev, LOCOMO_GPIO_LCD_VSHD_ON, 0);
41 locomo_gpio_write(locomolcd_dev, LOCOMO_GPIO_LCD_VSHD_ON, 1);
42 mdelay(2);
43
44 locomo_m62332_senddata(locomolcd_dev, comadj, 0);
45 mdelay(5);
46
47 locomo_gpio_set_dir(locomolcd_dev, LOCOMO_GPIO_LCD_VEE_ON, 0);
48 locomo_gpio_write(locomolcd_dev, LOCOMO_GPIO_LCD_VEE_ON, 1);
49 mdelay(10);
50
51 /* TFTCRST | CPSOUT=0 | CPSEN */
52 locomo_writel(0x01, locomolcd_dev->mapbase + LOCOMO_TC);
53
54 /* Set CPSD */
55 locomo_writel(6, locomolcd_dev->mapbase + LOCOMO_CPSD);
56
57 /* TFTCRST | CPSOUT=0 | CPSEN */
58 locomo_writel((0x04 | 0x01), locomolcd_dev->mapbase + LOCOMO_TC);
59 mdelay(10);
60
61 locomo_gpio_set_dir(locomolcd_dev, LOCOMO_GPIO_LCD_MOD, 0);
62 locomo_gpio_write(locomolcd_dev, LOCOMO_GPIO_LCD_MOD, 1);
63}
64
65static void locomolcd_off(int comadj)
66{
67 /* TFTCRST=1 | CPSOUT=1 | CPSEN = 0 */
68 locomo_writel(0x06, locomolcd_dev->mapbase + LOCOMO_TC);
69 mdelay(1);
70
71 locomo_gpio_write(locomolcd_dev, LOCOMO_GPIO_LCD_VSHA_ON, 0);
72 mdelay(110);
73
74 locomo_gpio_write(locomolcd_dev, LOCOMO_GPIO_LCD_VEE_ON, 0);
75 mdelay(700);
76
77 /* TFTCRST=0 | CPSOUT=0 | CPSEN = 0 */
78 locomo_writel(0, locomolcd_dev->mapbase + LOCOMO_TC);
79 locomo_gpio_write(locomolcd_dev, LOCOMO_GPIO_LCD_MOD, 0);
80 locomo_gpio_write(locomolcd_dev, LOCOMO_GPIO_LCD_VSHD_ON, 0);
81}
82
83void locomolcd_power(int on)
84{
85 int comadj = 118;
86 unsigned long flags;
87
88 local_irq_save(flags);
89
90 if (!locomolcd_dev) {
91 local_irq_restore(flags);
92 return;
93 }
94
95 /* read comadj */
96#ifdef CONFIG_MACH_POODLE
97 comadj = 118;
98#else
99 comadj = 128;
100#endif
101
102 if (on)
103 locomolcd_on(comadj);
104 else
105 locomolcd_off(comadj);
106
107 local_irq_restore(flags);
108}
109EXPORT_SYMBOL(locomolcd_power);
110
111static int poodle_lcd_probe(struct locomo_dev *dev)
112{
113 unsigned long flags;
114
115 local_irq_save(flags);
116 locomolcd_dev = dev;
117
118 /* the poodle_lcd_power function is called for the first time
119 * from fs_initcall, which is before locomo is activated.
120 * We need to recall poodle_lcd_power here*/
121#ifdef CONFIG_MACH_POODLE
122 locomolcd_power(1);
123#endif
124 local_irq_restore(flags);
125 return 0;
126}
127
128static int poodle_lcd_remove(struct locomo_dev *dev)
129{
130 unsigned long flags;
131 local_irq_save(flags);
132 locomolcd_dev = NULL;
133 local_irq_restore(flags);
134 return 0;
135}
136
137static struct locomo_driver poodle_lcd_driver = {
138 .drv = {
139 .name = "locomo-backlight",
140 },
141 .devid = LOCOMO_DEVID_BACKLIGHT,
142 .probe = poodle_lcd_probe,
143 .remove = poodle_lcd_remove,
144};
145
146static int __init poodle_lcd_init(void)
147{
148 int ret = locomo_driver_register(&poodle_lcd_driver);
149 if (ret) return ret;
150
151#ifdef CONFIG_SA1100_COLLIE
152 sa1100fb_lcd_power = locomolcd_power;
153#endif
154 return 0;
155}
156device_initcall(poodle_lcd_init);
157
diff --git a/drivers/video/chipsfb.c b/drivers/video/chipsfb.c
index e75a965ec76..4131243cfdf 100644
--- a/drivers/video/chipsfb.c
+++ b/drivers/video/chipsfb.c
@@ -462,9 +462,9 @@ static int chipsfb_pci_suspend(struct pci_dev *pdev, pm_message_t state)
462{ 462{
463 struct fb_info *p = pci_get_drvdata(pdev); 463 struct fb_info *p = pci_get_drvdata(pdev);
464 464
465 if (state == pdev->dev.power.power_state) 465 if (state.event == pdev->dev.power.power_state.event)
466 return 0; 466 return 0;
467 if (state != PM_SUSPEND_MEM) 467 if (state.event != PM_SUSPEND_MEM)
468 goto done; 468 goto done;
469 469
470 acquire_console_sem(); 470 acquire_console_sem();
diff --git a/drivers/video/i810/i810_main.c b/drivers/video/i810/i810_main.c
index 7513fb9b19c..6db183462b9 100644
--- a/drivers/video/i810/i810_main.c
+++ b/drivers/video/i810/i810_main.c
@@ -1506,12 +1506,12 @@ static int i810fb_suspend(struct pci_dev *dev, pm_message_t state)
1506 struct i810fb_par *par = (struct i810fb_par *) info->par; 1506 struct i810fb_par *par = (struct i810fb_par *) info->par;
1507 int blank = 0, prev_state = par->cur_state; 1507 int blank = 0, prev_state = par->cur_state;
1508 1508
1509 if (state == prev_state) 1509 if (state.event == prev_state)
1510 return 0; 1510 return 0;
1511 1511
1512 par->cur_state = state; 1512 par->cur_state = state.event;
1513 1513
1514 switch (state) { 1514 switch (state.event) {
1515 case 1: 1515 case 1:
1516 blank = VESA_VSYNC_SUSPEND; 1516 blank = VESA_VSYNC_SUSPEND;
1517 break; 1517 break;
diff --git a/drivers/video/matrox/matroxfb_maven.c b/drivers/video/matrox/matroxfb_maven.c
index 67f85344f0c..ad60bbb16cd 100644
--- a/drivers/video/matrox/matroxfb_maven.c
+++ b/drivers/video/matrox/matroxfb_maven.c
@@ -1271,7 +1271,7 @@ ERROR0:;
1271} 1271}
1272 1272
1273static int maven_attach_adapter(struct i2c_adapter* adapter) { 1273static int maven_attach_adapter(struct i2c_adapter* adapter) {
1274 if (adapter->id == (I2C_ALGO_BIT | I2C_HW_B_G400)) 1274 if (adapter->id == I2C_HW_B_G400)
1275 return i2c_probe(adapter, &addr_data, &maven_detect_client); 1275 return i2c_probe(adapter, &addr_data, &maven_detect_client);
1276 return 0; 1276 return 0;
1277} 1277}
diff --git a/drivers/video/nvidia/nv_i2c.c b/drivers/video/nvidia/nv_i2c.c
index 3757c1407c1..1a91bffdda2 100644
--- a/drivers/video/nvidia/nv_i2c.c
+++ b/drivers/video/nvidia/nv_i2c.c
@@ -90,14 +90,13 @@ static int nvidia_gpio_getsda(void *data)
90 return val; 90 return val;
91} 91}
92 92
93#define I2C_ALGO_NVIDIA 0x0e0000
94static int nvidia_setup_i2c_bus(struct nvidia_i2c_chan *chan, const char *name) 93static int nvidia_setup_i2c_bus(struct nvidia_i2c_chan *chan, const char *name)
95{ 94{
96 int rc; 95 int rc;
97 96
98 strcpy(chan->adapter.name, name); 97 strcpy(chan->adapter.name, name);
99 chan->adapter.owner = THIS_MODULE; 98 chan->adapter.owner = THIS_MODULE;
100 chan->adapter.id = I2C_ALGO_NVIDIA; 99 chan->adapter.id = I2C_HW_B_NVIDIA;
101 chan->adapter.algo_data = &chan->algo; 100 chan->adapter.algo_data = &chan->algo;
102 chan->adapter.dev.parent = &chan->par->pci_dev->dev; 101 chan->adapter.dev.parent = &chan->par->pci_dev->dev;
103 chan->algo.setsda = nvidia_gpio_setsda; 102 chan->algo.setsda = nvidia_gpio_setsda;
diff --git a/drivers/video/pmag-aa-fb.c b/drivers/video/pmag-aa-fb.c
index 3e00ad7f2e3..28d1fe5fe34 100644
--- a/drivers/video/pmag-aa-fb.c
+++ b/drivers/video/pmag-aa-fb.c
@@ -413,7 +413,7 @@ static struct fb_ops aafb_ops = {
413 413
414static int __init init_one(int slot) 414static int __init init_one(int slot)
415{ 415{
416 unsigned long base_addr = get_tc_base_addr(slot); 416 unsigned long base_addr = CKSEG1ADDR(get_tc_base_addr(slot));
417 struct aafb_info *ip = &my_fb_info[slot]; 417 struct aafb_info *ip = &my_fb_info[slot];
418 418
419 memset(ip, 0, sizeof(struct aafb_info)); 419 memset(ip, 0, sizeof(struct aafb_info));
diff --git a/drivers/video/pmag-ba-fb.c b/drivers/video/pmag-ba-fb.c
index f8095588e99..c98f1c8d7dc 100644
--- a/drivers/video/pmag-ba-fb.c
+++ b/drivers/video/pmag-ba-fb.c
@@ -1,57 +1,55 @@
1/* 1/*
2 * linux/drivers/video/pmag-ba-fb.c 2 * linux/drivers/video/pmag-ba-fb.c
3 * 3 *
4 * PMAG-BA TurboChannel framebuffer card support ... derived from: 4 * PMAG-BA TURBOchannel Color Frame Buffer (CFB) card support,
5 * derived from:
5 * "HP300 Topcat framebuffer support (derived from macfb of all things) 6 * "HP300 Topcat framebuffer support (derived from macfb of all things)
6 * Phil Blundell <philb@gnu.org> 1998", the original code can be 7 * Phil Blundell <philb@gnu.org> 1998", the original code can be
7 * found in the file hpfb.c in the same directory. 8 * found in the file hpfb.c in the same directory.
8 * 9 *
9 * Based on digital document: 10 * Based on digital document:
10 * "PMAG-BA TURBOchannel Color Frame Buffer 11 * "PMAG-BA TURBOchannel Color Frame Buffer
11 * Functional Specification", Revision 1.2, August 27, 1990 12 * Functional Specification", Revision 1.2, August 27, 1990
12 * 13 *
13 * DECstation related code Copyright (C) 1999, 2000, 2001 by 14 * DECstation related code Copyright (C) 1999, 2000, 2001 by
14 * Michael Engel <engel@unix-ag.org>, 15 * Michael Engel <engel@unix-ag.org>,
15 * Karsten Merker <merker@linuxtag.org> and 16 * Karsten Merker <merker@linuxtag.org> and
16 * Harald Koerfgen. 17 * Harald Koerfgen.
17 * This file is subject to the terms and conditions of the GNU General 18 * Copyright (c) 2005 Maciej W. Rozycki
18 * Public License. See the file COPYING in the main directory of this
19 * archive for more details.
20 * 19 *
20 * This file is subject to the terms and conditions of the GNU General
21 * Public License. See the file COPYING in the main directory of this
22 * archive for more details.
21 */ 23 */
22#include <linux/module.h> 24
23#include <linux/kernel.h> 25#include <linux/compiler.h>
24#include <linux/sched.h>
25#include <linux/errno.h> 26#include <linux/errno.h>
26#include <linux/string.h>
27#include <linux/timer.h>
28#include <linux/mm.h>
29#include <linux/tty.h>
30#include <linux/slab.h>
31#include <linux/delay.h>
32#include <linux/init.h>
33#include <linux/fb.h> 27#include <linux/fb.h>
34#include <asm/bootinfo.h> 28#include <linux/init.h>
35#include <asm/dec/machtype.h> 29#include <linux/kernel.h>
30#include <linux/module.h>
31#include <linux/types.h>
32
33#include <asm/bug.h>
34#include <asm/io.h>
35#include <asm/system.h>
36
36#include <asm/dec/tc.h> 37#include <asm/dec/tc.h>
38
37#include <video/pmag-ba-fb.h> 39#include <video/pmag-ba-fb.h>
38 40
39struct pmag_ba_ramdac_regs { 41
40 unsigned char addr_low; 42struct pmagbafb_par {
41 unsigned char pad0[3]; 43 struct fb_info *next;
42 unsigned char addr_hi; 44 volatile void __iomem *mmio;
43 unsigned char pad1[3]; 45 volatile u32 __iomem *dac;
44 unsigned char data; 46 int slot;
45 unsigned char pad2[3];
46 unsigned char cmap;
47}; 47};
48 48
49/*
50 * Max 3 TURBOchannel slots -> max 3 PMAG-BA :)
51 */
52static struct fb_info pmagba_fb_info[3];
53 49
54static struct fb_var_screeninfo pmagbafb_defined = { 50static struct fb_info *root_pmagbafb_dev;
51
52static struct fb_var_screeninfo pmagbafb_defined __initdata = {
55 .xres = 1024, 53 .xres = 1024,
56 .yres = 864, 54 .yres = 864,
57 .xres_virtual = 1024, 55 .xres_virtual = 1024,
@@ -61,58 +59,71 @@ static struct fb_var_screeninfo pmagbafb_defined = {
61 .green.length = 8, 59 .green.length = 8,
62 .blue.length = 8, 60 .blue.length = 8,
63 .activate = FB_ACTIVATE_NOW, 61 .activate = FB_ACTIVATE_NOW,
64 .height = 274, 62 .height = -1,
65 .width = 195, 63 .width = -1,
66 .accel = FB_ACCEL_NONE, 64 .accel_flags = FB_ACCEL_NONE,
65 .pixclock = 14452,
66 .left_margin = 116,
67 .right_margin = 12,
68 .upper_margin = 34,
69 .lower_margin = 12,
70 .hsync_len = 128,
71 .vsync_len = 3,
72 .sync = FB_SYNC_ON_GREEN,
67 .vmode = FB_VMODE_NONINTERLACED, 73 .vmode = FB_VMODE_NONINTERLACED,
68}; 74};
69 75
70static struct fb_fix_screeninfo pmagbafb_fix = { 76static struct fb_fix_screeninfo pmagbafb_fix __initdata = {
71 .id = "PMAG-BA", 77 .id = "PMAG-BA",
72 .smem_len = (1024 * 864), 78 .smem_len = (1024 * 1024),
73 .type = FB_TYPE_PACKED_PIXELS, 79 .type = FB_TYPE_PACKED_PIXELS,
74 .visual = FB_VISUAL_PSEUDOCOLOR, 80 .visual = FB_VISUAL_PSEUDOCOLOR,
75 .line_length = 1024, 81 .line_length = 1024,
82 .mmio_len = PMAG_BA_SIZE - PMAG_BA_BT459,
76}; 83};
77 84
78/* 85
79 * Turn hardware cursor off 86static inline void dac_write(struct pmagbafb_par *par, unsigned int reg, u8 v)
80 */
81void pmagbafb_erase_cursor(struct pmag_ba_ramdac_regs *bt459_regs)
82{ 87{
83 bt459_regs->addr_low = 0; 88 writeb(v, par->dac + reg / 4);
84 bt459_regs->addr_hi = 3;
85 bt459_regs->data = 0;
86} 89}
87 90
91static inline u8 dac_read(struct pmagbafb_par *par, unsigned int reg)
92{
93 return readb(par->dac + reg / 4);
94}
95
96
88/* 97/*
89 * Set the palette. 98 * Set the palette.
90 */ 99 */
91static int pmagbafb_setcolreg(unsigned regno, unsigned red, unsigned green, 100static int pmagbafb_setcolreg(unsigned int regno, unsigned int red,
92 unsigned blue, unsigned transp, 101 unsigned int green, unsigned int blue,
93 struct fb_info *info) 102 unsigned int transp, struct fb_info *info)
94{ 103{
95 struct pmag_ba_ramdac_regs *bt459_regs = (struct pmag_ba_ramdac_regs *) info->par; 104 struct pmagbafb_par *par = info->par;
96 105
97 if (regno >= info->cmap.len) 106 BUG_ON(regno >= info->cmap.len);
98 return 1;
99 107
100 red >>= 8; /* The cmap fields are 16 bits */ 108 red >>= 8; /* The cmap fields are 16 bits */
101 green >>= 8; /* wide, but the harware colormap */ 109 green >>= 8; /* wide, but the hardware colormap */
102 blue >>= 8; /* registers are only 8 bits wide */ 110 blue >>= 8; /* registers are only 8 bits wide */
103 111
104 bt459_regs->addr_low = (__u8) regno; 112 mb();
105 bt459_regs->addr_hi = 0; 113 dac_write(par, BT459_ADDR_LO, regno);
106 bt459_regs->cmap = red; 114 dac_write(par, BT459_ADDR_HI, 0x00);
107 bt459_regs->cmap = green; 115 wmb();
108 bt459_regs->cmap = blue; 116 dac_write(par, BT459_CMAP, red);
117 wmb();
118 dac_write(par, BT459_CMAP, green);
119 wmb();
120 dac_write(par, BT459_CMAP, blue);
121
109 return 0; 122 return 0;
110} 123}
111 124
112static struct fb_ops pmagbafb_ops = { 125static struct fb_ops pmagbafb_ops = {
113 .owner = THIS_MODULE, 126 .owner = THIS_MODULE,
114 .fb_get_fix = gen_get_fix,
115 .fb_get_var = gen_get_var,
116 .fb_setcolreg = pmagbafb_setcolreg, 127 .fb_setcolreg = pmagbafb_setcolreg,
117 .fb_fillrect = cfb_fillrect, 128 .fb_fillrect = cfb_fillrect,
118 .fb_copyarea = cfb_copyarea, 129 .fb_copyarea = cfb_copyarea,
@@ -120,63 +131,133 @@ static struct fb_ops pmagbafb_ops = {
120 .fb_cursor = soft_cursor, 131 .fb_cursor = soft_cursor,
121}; 132};
122 133
123int __init pmagbafb_init_one(int slot) 134
135/*
136 * Turn the hardware cursor off.
137 */
138static void __init pmagbafb_erase_cursor(struct fb_info *info)
139{
140 struct pmagbafb_par *par = info->par;
141
142 mb();
143 dac_write(par, BT459_ADDR_LO, 0x00);
144 dac_write(par, BT459_ADDR_HI, 0x03);
145 wmb();
146 dac_write(par, BT459_DATA, 0x00);
147}
148
149
150static int __init pmagbafb_init_one(int slot)
124{ 151{
125 unsigned long base_addr = get_tc_base_addr(slot); 152 struct fb_info *info;
126 struct fb_info *info = &pmagba_fb_info[slot]; 153 struct pmagbafb_par *par;
127 struct display *disp = &pmagba_disp[slot]; 154 unsigned long base_addr;
128 155
129 printk("PMAG-BA framebuffer in slot %d\n", slot); 156 info = framebuffer_alloc(sizeof(struct pmagbafb_par), NULL);
130 /* 157 if (!info)
131 * Framebuffer display memory base address and friends 158 return -ENOMEM;
132 */ 159
133 pmagbafb_fix.smem_start = base_addr + PMAG_BA_ONBOARD_FBMEM_OFFSET; 160 par = info->par;
134 info->par = (base_addr + PMAG_BA_BT459_OFFSET); 161 par->slot = slot;
135 162 claim_tc_card(par->slot);
136 /* 163
137 * Configure the Bt459 RAM DAC 164 base_addr = get_tc_base_addr(par->slot);
138 */ 165
139 pmagbafb_erase_cursor((struct pmag_ba_ramdac_regs *) info->par); 166 par->next = root_pmagbafb_dev;
140 167 root_pmagbafb_dev = info;
141 /* 168
142 * Let there be consoles.. 169 if (fb_alloc_cmap(&info->cmap, 256, 0) < 0)
143 */ 170 goto err_alloc;
171
144 info->fbops = &pmagbafb_ops; 172 info->fbops = &pmagbafb_ops;
173 info->fix = pmagbafb_fix;
145 info->var = pmagbafb_defined; 174 info->var = pmagbafb_defined;
146 info->fix = pmagbafb_fix;
147 info->screen_base = pmagbafb_fix.smem_start;
148 info->flags = FBINFO_DEFAULT; 175 info->flags = FBINFO_DEFAULT;
149 176
150 fb_alloc_cmap(&fb_info.cmap, 256, 0); 177 /* MMIO mapping setup. */
178 info->fix.mmio_start = base_addr;
179 par->mmio = ioremap_nocache(info->fix.mmio_start, info->fix.mmio_len);
180 if (!par->mmio)
181 goto err_cmap;
182 par->dac = par->mmio + PMAG_BA_BT459;
183
184 /* Frame buffer mapping setup. */
185 info->fix.smem_start = base_addr + PMAG_BA_FBMEM;
186 info->screen_base = ioremap_nocache(info->fix.smem_start,
187 info->fix.smem_len);
188 if (!info->screen_base)
189 goto err_mmio_map;
190 info->screen_size = info->fix.smem_len;
191
192 pmagbafb_erase_cursor(info);
151 193
152 if (register_framebuffer(info) < 0) 194 if (register_framebuffer(info) < 0)
153 return 1; 195 goto err_smem_map;
196
197 pr_info("fb%d: %s frame buffer device in slot %d\n",
198 info->node, info->fix.id, par->slot);
199
154 return 0; 200 return 0;
201
202
203err_smem_map:
204 iounmap(info->screen_base);
205
206err_mmio_map:
207 iounmap(par->mmio);
208
209err_cmap:
210 fb_dealloc_cmap(&info->cmap);
211
212err_alloc:
213 root_pmagbafb_dev = par->next;
214 release_tc_card(par->slot);
215 framebuffer_release(info);
216 return -ENXIO;
155} 217}
156 218
157/* 219static void __exit pmagbafb_exit_one(void)
158 * Initialise the framebuffer 220{
159 */ 221 struct fb_info *info = root_pmagbafb_dev;
222 struct pmagbafb_par *par = info->par;
160 223
161int __init pmagbafb_init(void) 224 unregister_framebuffer(info);
225 iounmap(info->screen_base);
226 iounmap(par->mmio);
227 fb_dealloc_cmap(&info->cmap);
228 root_pmagbafb_dev = par->next;
229 release_tc_card(par->slot);
230 framebuffer_release(info);
231}
232
233
234/*
235 * Initialise the framebuffer.
236 */
237static int __init pmagbafb_init(void)
162{ 238{
163 int sid; 239 int count = 0;
164 int found = 0; 240 int slot;
165 241
166 if (fb_get_options("pmagbafb", NULL)) 242 if (fb_get_options("pmagbafb", NULL))
167 return -ENODEV; 243 return -ENXIO;
168 244
169 if (TURBOCHANNEL) { 245 while ((slot = search_tc_card("PMAG-BA")) >= 0) {
170 while ((sid = search_tc_card("PMAG-BA")) >= 0) { 246 if (pmagbafb_init_one(slot) < 0)
171 found = 1; 247 break;
172 claim_tc_card(sid); 248 count++;
173 pmagbafb_init_one(sid);
174 }
175 return found ? 0 : -ENODEV;
176 } else {
177 return -ENODEV;
178 } 249 }
250 return (count > 0) ? 0 : -ENXIO;
179} 251}
180 252
253static void __exit pmagbafb_exit(void)
254{
255 while (root_pmagbafb_dev)
256 pmagbafb_exit_one();
257}
258
259
181module_init(pmagbafb_init); 260module_init(pmagbafb_init);
261module_exit(pmagbafb_exit);
262
182MODULE_LICENSE("GPL"); 263MODULE_LICENSE("GPL");
diff --git a/drivers/video/pmagb-b-fb.c b/drivers/video/pmagb-b-fb.c
index d14eaee91cf..a483b13e117 100644
--- a/drivers/video/pmagb-b-fb.c
+++ b/drivers/video/pmagb-b-fb.c
@@ -1,114 +1,128 @@
1/* 1/*
2 * linux/drivers/video/pmagb-b-fb.c 2 * linux/drivers/video/pmagb-b-fb.c
3 * 3 *
4 * PMAGB-B TurboChannel framebuffer card support ... derived from: 4 * PMAGB-B TURBOchannel Smart Frame Buffer (SFB) card support,
5 * derived from:
5 * "HP300 Topcat framebuffer support (derived from macfb of all things) 6 * "HP300 Topcat framebuffer support (derived from macfb of all things)
6 * Phil Blundell <philb@gnu.org> 1998", the original code can be 7 * Phil Blundell <philb@gnu.org> 1998", the original code can be
7 * found in the file hpfb.c in the same directory. 8 * found in the file hpfb.c in the same directory.
8 * 9 *
9 * DECstation related code Copyright (C) 1999, 2000, 2001 by 10 * DECstation related code Copyright (C) 1999, 2000, 2001 by
10 * Michael Engel <engel@unix-ag.org>, 11 * Michael Engel <engel@unix-ag.org>,
11 * Karsten Merker <merker@linuxtag.org> and 12 * Karsten Merker <merker@linuxtag.org> and
12 * Harald Koerfgen. 13 * Harald Koerfgen.
13 * This file is subject to the terms and conditions of the GNU General 14 * Copyright (c) 2005 Maciej W. Rozycki
14 * Public License. See the file COPYING in the main directory of this
15 * archive for more details.
16 * 15 *
16 * This file is subject to the terms and conditions of the GNU General
17 * Public License. See the file COPYING in the main directory of this
18 * archive for more details.
17 */ 19 */
18 20
19/* 21#include <linux/compiler.h>
20 * We currently only support the PMAGB-B in high resolution mode
21 * as I know of no way to detect low resolution mode set via jumper.
22 * KM, 2001/01/07
23 */
24
25#include <linux/module.h>
26#include <linux/kernel.h>
27#include <linux/sched.h>
28#include <linux/errno.h>
29#include <linux/string.h>
30#include <linux/timer.h>
31#include <linux/mm.h>
32#include <linux/tty.h>
33#include <linux/slab.h>
34#include <linux/delay.h> 22#include <linux/delay.h>
35#include <linux/init.h> 23#include <linux/errno.h>
36#include <linux/fb.h> 24#include <linux/fb.h>
37#include <asm/bootinfo.h> 25#include <linux/init.h>
38#include <asm/dec/machtype.h> 26#include <linux/kernel.h>
27#include <linux/module.h>
28#include <linux/types.h>
29
30#include <asm/bug.h>
31#include <asm/io.h>
32#include <asm/system.h>
33
39#include <asm/dec/tc.h> 34#include <asm/dec/tc.h>
35
40#include <video/pmagb-b-fb.h> 36#include <video/pmagb-b-fb.h>
41 37
42struct pmagb_b_ramdac_regs { 38
43 unsigned char addr_low; 39struct pmagbbfb_par {
44 unsigned char pad0[3]; 40 struct fb_info *next;
45 unsigned char addr_hi; 41 volatile void __iomem *mmio;
46 unsigned char pad1[3]; 42 volatile void __iomem *smem;
47 unsigned char data; 43 volatile u32 __iomem *sfb;
48 unsigned char pad2[3]; 44 volatile u32 __iomem *dac;
49 unsigned char cmap; 45 unsigned int osc0;
46 unsigned int osc1;
47 int slot;
50}; 48};
51 49
52/*
53 * Max 3 TURBOchannel slots -> max 3 PMAGB-B :)
54 */
55static struct fb_info pmagbb_fb_info[3];
56 50
57static struct fb_var_screeninfo pmagbbfb_defined = { 51static struct fb_info *root_pmagbbfb_dev;
58 .xres = 1280, 52
59 .yres = 1024, 53static struct fb_var_screeninfo pmagbbfb_defined __initdata = {
60 .xres_virtual = 1280,
61 .yres_virtual = 1024,
62 .bits_per_pixel = 8, 54 .bits_per_pixel = 8,
63 .red.length = 8, 55 .red.length = 8,
64 .green.length = 8, 56 .green.length = 8,
65 .blue.length = 8, 57 .blue.length = 8,
66 .activate = FB_ACTIVATE_NOW, 58 .activate = FB_ACTIVATE_NOW,
67 .height = 274, 59 .height = -1,
68 .width = 195, 60 .width = -1,
69 .accel_flags = FB_ACCEL_NONE, 61 .accel_flags = FB_ACCEL_NONE,
62 .sync = FB_SYNC_ON_GREEN,
70 .vmode = FB_VMODE_NONINTERLACED, 63 .vmode = FB_VMODE_NONINTERLACED,
71}; 64};
72 65
73static struct fb_fix_screeninfo pmagbafb_fix = { 66static struct fb_fix_screeninfo pmagbbfb_fix __initdata = {
74 .id = "PMAGB-BA", 67 .id = "PMAGB-BA",
75 .smem_len = (1280 * 1024), 68 .smem_len = (2048 * 1024),
76 .type = FB_TYPE_PACKED_PIXELS, 69 .type = FB_TYPE_PACKED_PIXELS,
77 .visual = FB_VISUAL_PSEUDOCOLOR, 70 .visual = FB_VISUAL_PSEUDOCOLOR,
78 .line_length = 1280, 71 .mmio_len = PMAGB_B_FBMEM,
72};
73
74
75static inline void sfb_write(struct pmagbbfb_par *par, unsigned int reg, u32 v)
76{
77 writel(v, par->sfb + reg / 4);
79} 78}
80 79
81/* 80static inline u32 sfb_read(struct pmagbbfb_par *par, unsigned int reg)
82 * Turn hardware cursor off 81{
83 */ 82 return readl(par->sfb + reg / 4);
84void pmagbbfb_erase_cursor(struct pmagb_b_ramdac_regs *bt459_regs) 83}
84
85static inline void dac_write(struct pmagbbfb_par *par, unsigned int reg, u8 v)
85{ 86{
86 bt459_regs->addr_low = 0; 87 writeb(v, par->dac + reg / 4);
87 bt459_regs->addr_hi = 3;
88 bt459_regs->data = 0;
89} 88}
90 89
90static inline u8 dac_read(struct pmagbbfb_par *par, unsigned int reg)
91{
92 return readb(par->dac + reg / 4);
93}
94
95static inline void gp0_write(struct pmagbbfb_par *par, u32 v)
96{
97 writel(v, par->mmio + PMAGB_B_GP0);
98}
99
100
91/* 101/*
92 * Set the palette. 102 * Set the palette.
93 */ 103 */
94static int pmagbbfb_setcolreg(unsigned regno, unsigned red, unsigned green, 104static int pmagbbfb_setcolreg(unsigned int regno, unsigned int red,
95 unsigned blue, unsigned transp, 105 unsigned int green, unsigned int blue,
96 struct fb_info *info) 106 unsigned int transp, struct fb_info *info)
97{ 107{
98 struct pmagb_b_ramdac_regs *bt459_regs = (struct pmagb_b_ramdac_regs *) info->par; 108 struct pmagbbfb_par *par = info->par;
99 109
100 if (regno >= info->cmap.len) 110 BUG_ON(regno >= info->cmap.len);
101 return 1;
102 111
103 red >>= 8; /* The cmap fields are 16 bits */ 112 red >>= 8; /* The cmap fields are 16 bits */
104 green >>= 8; /* wide, but the harware colormap */ 113 green >>= 8; /* wide, but the hardware colormap */
105 blue >>= 8; /* registers are only 8 bits wide */ 114 blue >>= 8; /* registers are only 8 bits wide */
106 115
107 bt459_regs->addr_low = (__u8) regno; 116 mb();
108 bt459_regs->addr_hi = 0; 117 dac_write(par, BT459_ADDR_LO, regno);
109 bt459_regs->cmap = red; 118 dac_write(par, BT459_ADDR_HI, 0x00);
110 bt459_regs->cmap = green; 119 wmb();
111 bt459_regs->cmap = blue; 120 dac_write(par, BT459_CMAP, red);
121 wmb();
122 dac_write(par, BT459_CMAP, green);
123 wmb();
124 dac_write(par, BT459_CMAP, blue);
125
112 return 0; 126 return 0;
113} 127}
114 128
@@ -121,62 +135,247 @@ static struct fb_ops pmagbbfb_ops = {
121 .fb_cursor = soft_cursor, 135 .fb_cursor = soft_cursor,
122}; 136};
123 137
124int __init pmagbbfb_init_one(int slot) 138
139/*
140 * Turn the hardware cursor off.
141 */
142static void __init pmagbbfb_erase_cursor(struct fb_info *info)
143{
144 struct pmagbbfb_par *par = info->par;
145
146 mb();
147 dac_write(par, BT459_ADDR_LO, 0x00);
148 dac_write(par, BT459_ADDR_HI, 0x03);
149 wmb();
150 dac_write(par, BT459_DATA, 0x00);
151}
152
153/*
154 * Set up screen parameters.
155 */
156static void __init pmagbbfb_screen_setup(struct fb_info *info)
157{
158 struct pmagbbfb_par *par = info->par;
159
160 info->var.xres = ((sfb_read(par, SFB_REG_VID_HOR) >>
161 SFB_VID_HOR_PIX_SHIFT) & SFB_VID_HOR_PIX_MASK) * 4;
162 info->var.xres_virtual = info->var.xres;
163 info->var.yres = (sfb_read(par, SFB_REG_VID_VER) >>
164 SFB_VID_VER_SL_SHIFT) & SFB_VID_VER_SL_MASK;
165 info->var.yres_virtual = info->var.yres;
166 info->var.left_margin = ((sfb_read(par, SFB_REG_VID_HOR) >>
167 SFB_VID_HOR_BP_SHIFT) &
168 SFB_VID_HOR_BP_MASK) * 4;
169 info->var.right_margin = ((sfb_read(par, SFB_REG_VID_HOR) >>
170 SFB_VID_HOR_FP_SHIFT) &
171 SFB_VID_HOR_FP_MASK) * 4;
172 info->var.upper_margin = (sfb_read(par, SFB_REG_VID_VER) >>
173 SFB_VID_VER_BP_SHIFT) & SFB_VID_VER_BP_MASK;
174 info->var.lower_margin = (sfb_read(par, SFB_REG_VID_VER) >>
175 SFB_VID_VER_FP_SHIFT) & SFB_VID_VER_FP_MASK;
176 info->var.hsync_len = ((sfb_read(par, SFB_REG_VID_HOR) >>
177 SFB_VID_HOR_SYN_SHIFT) &
178 SFB_VID_HOR_SYN_MASK) * 4;
179 info->var.vsync_len = (sfb_read(par, SFB_REG_VID_VER) >>
180 SFB_VID_VER_SYN_SHIFT) & SFB_VID_VER_SYN_MASK;
181
182 info->fix.line_length = info->var.xres;
183};
184
185/*
186 * Determine oscillator configuration.
187 */
188static void __init pmagbbfb_osc_setup(struct fb_info *info)
125{ 189{
126 unsigned long base_addr = get_tc_base_addr(slot); 190 static unsigned int pmagbbfb_freqs[] __initdata = {
127 struct fb_info *info = &pmagbb_fb_info[slot]; 191 130808, 119843, 104000, 92980, 74367, 72800,
128 192 69197, 66000, 65000, 50350, 36000, 32000, 25175
129 printk("PMAGB-BA framebuffer in slot %d\n", slot); 193 };
130 /* 194 struct pmagbbfb_par *par = info->par;
131 * Framebuffer display memory base address and friends 195 u32 count0 = 8, count1 = 8, counttc = 16 * 256 + 8;
132 */ 196 u32 freq0, freq1, freqtc = get_tc_speed() / 250;
133 pmagbbfb_fix.smem_start = base_addr + PMAGB_B_ONBOARD_FBMEM_OFFSET; 197 int i, j;
134 info->par = (base_addr + PMAGB_B_BT459_OFFSET); 198
135 199 gp0_write(par, 0); /* select Osc0 */
136 /* 200 for (j = 0; j < 16; j++) {
137 * Configure the Bt459 RAM DAC 201 mb();
138 */ 202 sfb_write(par, SFB_REG_TCCLK_COUNT, 0);
139 pmagbbfb_erase_cursor((struct pmagb_b_ramdac_regs *) info->par); 203 mb();
140 204 for (i = 0; i < 100; i++) { /* nominally max. 20.5us */
141 /* 205 if (sfb_read(par, SFB_REG_TCCLK_COUNT) == 0)
142 * Let there be consoles.. 206 break;
143 */ 207 udelay(1);
208 }
209 count0 += sfb_read(par, SFB_REG_VIDCLK_COUNT);
210 }
211
212 gp0_write(par, 1); /* select Osc1 */
213 for (j = 0; j < 16; j++) {
214 mb();
215 sfb_write(par, SFB_REG_TCCLK_COUNT, 0);
216
217 for (i = 0; i < 100; i++) { /* nominally max. 20.5us */
218 if (sfb_read(par, SFB_REG_TCCLK_COUNT) == 0)
219 break;
220 udelay(1);
221 }
222 count1 += sfb_read(par, SFB_REG_VIDCLK_COUNT);
223 }
224
225 freq0 = (freqtc * count0 + counttc / 2) / counttc;
226 par->osc0 = freq0;
227 if (freq0 >= pmagbbfb_freqs[0] - (pmagbbfb_freqs[0] + 32) / 64 &&
228 freq0 <= pmagbbfb_freqs[0] + (pmagbbfb_freqs[0] + 32) / 64)
229 par->osc0 = pmagbbfb_freqs[0];
230
231 freq1 = (par->osc0 * count1 + count0 / 2) / count0;
232 par->osc1 = freq1;
233 for (i = 0; i < sizeof(pmagbbfb_freqs) / sizeof(*pmagbbfb_freqs); i++)
234 if (freq1 >= pmagbbfb_freqs[i] -
235 (pmagbbfb_freqs[i] + 128) / 256 &&
236 freq1 <= pmagbbfb_freqs[i] +
237 (pmagbbfb_freqs[i] + 128) / 256) {
238 par->osc1 = pmagbbfb_freqs[i];
239 break;
240 }
241
242 if (par->osc0 - par->osc1 <= (par->osc0 + par->osc1 + 256) / 512 ||
243 par->osc1 - par->osc0 <= (par->osc0 + par->osc1 + 256) / 512)
244 par->osc1 = 0;
245
246 gp0_write(par, par->osc1 != 0); /* reselect OscX */
247
248 info->var.pixclock = par->osc1 ?
249 (1000000000 + par->osc1 / 2) / par->osc1 :
250 (1000000000 + par->osc0 / 2) / par->osc0;
251};
252
253
254static int __init pmagbbfb_init_one(int slot)
255{
256 char freq0[12], freq1[12];
257 struct fb_info *info;
258 struct pmagbbfb_par *par;
259 unsigned long base_addr;
260 u32 vid_base;
261
262 info = framebuffer_alloc(sizeof(struct pmagbbfb_par), NULL);
263 if (!info)
264 return -ENOMEM;
265
266 par = info->par;
267 par->slot = slot;
268 claim_tc_card(par->slot);
269
270 base_addr = get_tc_base_addr(par->slot);
271
272 par->next = root_pmagbbfb_dev;
273 root_pmagbbfb_dev = info;
274
275 if (fb_alloc_cmap(&info->cmap, 256, 0) < 0)
276 goto err_alloc;
277
144 info->fbops = &pmagbbfb_ops; 278 info->fbops = &pmagbbfb_ops;
145 info->var = pmagbbfb_defined;
146 info->fix = pmagbbfb_fix; 279 info->fix = pmagbbfb_fix;
147 info->screen_base = pmagbbfb_fix.smem_start; 280 info->var = pmagbbfb_defined;
148 info->flags = FBINFO_DEFAULT; 281 info->flags = FBINFO_DEFAULT;
149 282
150 fb_alloc_cmap(&fb_info.cmap, 256, 0); 283 /* MMIO mapping setup. */
284 info->fix.mmio_start = base_addr;
285 par->mmio = ioremap_nocache(info->fix.mmio_start, info->fix.mmio_len);
286 if (!par->mmio)
287 goto err_cmap;
288 par->sfb = par->mmio + PMAGB_B_SFB;
289 par->dac = par->mmio + PMAGB_B_BT459;
290
291 /* Frame buffer mapping setup. */
292 info->fix.smem_start = base_addr + PMAGB_B_FBMEM;
293 par->smem = ioremap_nocache(info->fix.smem_start, info->fix.smem_len);
294 if (!par->smem)
295 goto err_mmio_map;
296 vid_base = sfb_read(par, SFB_REG_VID_BASE);
297 info->screen_base = (void __iomem *)par->smem + vid_base * 0x1000;
298 info->screen_size = info->fix.smem_len - 2 * vid_base * 0x1000;
299
300 pmagbbfb_erase_cursor(info);
301 pmagbbfb_screen_setup(info);
302 pmagbbfb_osc_setup(info);
151 303
152 if (register_framebuffer(info) < 0) 304 if (register_framebuffer(info) < 0)
153 return 1; 305 goto err_smem_map;
306
307 snprintf(freq0, sizeof(freq0), "%u.%03uMHz",
308 par->osc0 / 1000, par->osc0 % 1000);
309 snprintf(freq1, sizeof(freq1), "%u.%03uMHz",
310 par->osc1 / 1000, par->osc1 % 1000);
311
312 pr_info("fb%d: %s frame buffer device in slot %d\n",
313 info->node, info->fix.id, par->slot);
314 pr_info("fb%d: Osc0: %s, Osc1: %s, Osc%u selected\n",
315 info->node, freq0, par->osc1 ? freq1 : "disabled",
316 par->osc1 != 0);
317
154 return 0; 318 return 0;
319
320
321err_smem_map:
322 iounmap(par->smem);
323
324err_mmio_map:
325 iounmap(par->mmio);
326
327err_cmap:
328 fb_dealloc_cmap(&info->cmap);
329
330err_alloc:
331 root_pmagbbfb_dev = par->next;
332 release_tc_card(par->slot);
333 framebuffer_release(info);
334 return -ENXIO;
155} 335}
156 336
157/* 337static void __exit pmagbbfb_exit_one(void)
158 * Initialise the framebuffer 338{
159 */ 339 struct fb_info *info = root_pmagbbfb_dev;
340 struct pmagbbfb_par *par = info->par;
341
342 unregister_framebuffer(info);
343 iounmap(par->smem);
344 iounmap(par->mmio);
345 fb_dealloc_cmap(&info->cmap);
346 root_pmagbbfb_dev = par->next;
347 release_tc_card(par->slot);
348 framebuffer_release(info);
349}
160 350
161int __init pmagbbfb_init(void) 351
352/*
353 * Initialise the framebuffer.
354 */
355static int __init pmagbbfb_init(void)
162{ 356{
163 int sid; 357 int count = 0;
164 int found = 0; 358 int slot;
165 359
166 if (fb_get_options("pmagbbfb", NULL)) 360 if (fb_get_options("pmagbbfb", NULL))
167 return -ENODEV; 361 return -ENXIO;
168 362
169 if (TURBOCHANNEL) { 363 while ((slot = search_tc_card("PMAGB-BA")) >= 0) {
170 while ((sid = search_tc_card("PMAGB-BA")) >= 0) { 364 if (pmagbbfb_init_one(slot) < 0)
171 found = 1; 365 break;
172 claim_tc_card(sid); 366 count++;
173 pmagbbfb_init_one(sid);
174 }
175 return found ? 0 : -ENODEV;
176 } else {
177 return -ENODEV;
178 } 367 }
368 return (count > 0) ? 0 : -ENXIO;
369}
370
371static void __exit pmagbbfb_exit(void)
372{
373 while (root_pmagbbfb_dev)
374 pmagbbfb_exit_one();
179} 375}
180 376
377
181module_init(pmagbbfb_init); 378module_init(pmagbbfb_init);
379module_exit(pmagbbfb_exit);
380
182MODULE_LICENSE("GPL"); 381MODULE_LICENSE("GPL");
diff --git a/drivers/video/q40fb.c b/drivers/video/q40fb.c
index 71b69da0c40..162012bb926 100644
--- a/drivers/video/q40fb.c
+++ b/drivers/video/q40fb.c
@@ -21,7 +21,6 @@
21 21
22#include <asm/uaccess.h> 22#include <asm/uaccess.h>
23#include <asm/setup.h> 23#include <asm/setup.h>
24#include <asm/segment.h>
25#include <asm/system.h> 24#include <asm/system.h>
26#include <asm/q40_master.h> 25#include <asm/q40_master.h>
27#include <linux/fb.h> 26#include <linux/fb.h>
diff --git a/drivers/video/riva/rivafb-i2c.c b/drivers/video/riva/rivafb-i2c.c
index da1334dfd51..77151d8e076 100644
--- a/drivers/video/riva/rivafb-i2c.c
+++ b/drivers/video/riva/rivafb-i2c.c
@@ -92,14 +92,13 @@ static int riva_gpio_getsda(void* data)
92 return val; 92 return val;
93} 93}
94 94
95#define I2C_ALGO_RIVA 0x0e0000
96static int riva_setup_i2c_bus(struct riva_i2c_chan *chan, const char *name) 95static int riva_setup_i2c_bus(struct riva_i2c_chan *chan, const char *name)
97{ 96{
98 int rc; 97 int rc;
99 98
100 strcpy(chan->adapter.name, name); 99 strcpy(chan->adapter.name, name);
101 chan->adapter.owner = THIS_MODULE; 100 chan->adapter.owner = THIS_MODULE;
102 chan->adapter.id = I2C_ALGO_RIVA; 101 chan->adapter.id = I2C_HW_B_RIVA;
103 chan->adapter.algo_data = &chan->algo; 102 chan->adapter.algo_data = &chan->algo;
104 chan->adapter.dev.parent = &chan->par->pdev->dev; 103 chan->adapter.dev.parent = &chan->par->pdev->dev;
105 chan->algo.setsda = riva_gpio_setsda; 104 chan->algo.setsda = riva_gpio_setsda;
diff --git a/drivers/video/s1d13xxxfb.c b/drivers/video/s1d13xxxfb.c
index 3848be2b9d2..fa98d91c42e 100644
--- a/drivers/video/s1d13xxxfb.c
+++ b/drivers/video/s1d13xxxfb.c
@@ -655,7 +655,7 @@ bail:
655} 655}
656 656
657#ifdef CONFIG_PM 657#ifdef CONFIG_PM
658static int s1d13xxxfb_suspend(struct device *dev, u32 state, u32 level) 658static int s1d13xxxfb_suspend(struct device *dev, pm_message_t state, u32 level)
659{ 659{
660 struct fb_info *info = dev_get_drvdata(dev); 660 struct fb_info *info = dev_get_drvdata(dev);
661 struct s1d13xxxfb_par *s1dfb = info->par; 661 struct s1d13xxxfb_par *s1dfb = info->par;
diff --git a/drivers/video/savage/savagefb-i2c.c b/drivers/video/savage/savagefb-i2c.c
index 024a0cecff1..847698b5cfe 100644
--- a/drivers/video/savage/savagefb-i2c.c
+++ b/drivers/video/savage/savagefb-i2c.c
@@ -137,7 +137,6 @@ static int prosavage_gpio_getsda(void* data)
137 return (0 != (GET_CR_DATA(chan->ioaddr) & PROSAVAGE_I2C_SDA_IN)); 137 return (0 != (GET_CR_DATA(chan->ioaddr) & PROSAVAGE_I2C_SDA_IN));
138} 138}
139 139
140#define I2C_ALGO_SAVAGE 0x0f0000
141static int savage_setup_i2c_bus(struct savagefb_i2c_chan *chan, 140static int savage_setup_i2c_bus(struct savagefb_i2c_chan *chan,
142 const char *name) 141 const char *name)
143{ 142{
@@ -147,7 +146,7 @@ static int savage_setup_i2c_bus(struct savagefb_i2c_chan *chan,
147 if (add_bus && chan->par) { 146 if (add_bus && chan->par) {
148 strcpy(chan->adapter.name, name); 147 strcpy(chan->adapter.name, name);
149 chan->adapter.owner = THIS_MODULE; 148 chan->adapter.owner = THIS_MODULE;
150 chan->adapter.id = I2C_ALGO_SAVAGE; 149 chan->adapter.id = I2C_HW_B_SAVAGE;
151 chan->adapter.algo_data = &chan->algo; 150 chan->adapter.algo_data = &chan->algo;
152 chan->adapter.dev.parent = &chan->par->pcidev->dev; 151 chan->adapter.dev.parent = &chan->par->pcidev->dev;
153 chan->algo.udelay = 40; 152 chan->algo.udelay = 40;
diff --git a/drivers/video/savage/savagefb_driver.c b/drivers/video/savage/savagefb_driver.c
index f4633d1891f..117ad42f120 100644
--- a/drivers/video/savage/savagefb_driver.c
+++ b/drivers/video/savage/savagefb_driver.c
@@ -2110,7 +2110,6 @@ static int savagefb_suspend (struct pci_dev* dev, pm_message_t state)
2110 struct savagefb_par *par = (struct savagefb_par *)info->par; 2110 struct savagefb_par *par = (struct savagefb_par *)info->par;
2111 2111
2112 DBG("savagefb_suspend"); 2112 DBG("savagefb_suspend");
2113 printk(KERN_DEBUG "state: %u\n", state);
2114 2113
2115 acquire_console_sem(); 2114 acquire_console_sem();
2116 fb_set_suspend(info, pci_choose_state(dev, state)); 2115 fb_set_suspend(info, pci_choose_state(dev, state));
diff --git a/drivers/video/w100fb.c b/drivers/video/w100fb.c
index adcda697ea6..0030c071da8 100644
--- a/drivers/video/w100fb.c
+++ b/drivers/video/w100fb.c
@@ -5,9 +5,15 @@
5 * 5 *
6 * Copyright (C) 2002, ATI Corp. 6 * Copyright (C) 2002, ATI Corp.
7 * Copyright (C) 2004-2005 Richard Purdie 7 * Copyright (C) 2004-2005 Richard Purdie
8 * Copyright (c) 2005 Ian Molton
8 * 9 *
9 * Rewritten for 2.6 by Richard Purdie <rpurdie@rpsys.net> 10 * Rewritten for 2.6 by Richard Purdie <rpurdie@rpsys.net>
10 * 11 *
12 * Generic platform support by Ian Molton <spyro@f2s.com>
13 * and Richard Purdie <rpurdie@rpsys.net>
14 *
15 * w32xx support by Ian Molton
16 *
11 * This program is free software; you can redistribute it and/or modify 17 * 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 18 * it under the terms of the GNU General Public License version 2 as
13 * published by the Free Software Foundation. 19 * published by the Free Software Foundation.
@@ -21,7 +27,7 @@
21#include <linux/mm.h> 27#include <linux/mm.h>
22#include <linux/device.h> 28#include <linux/device.h>
23#include <linux/string.h> 29#include <linux/string.h>
24#include <linux/proc_fs.h> 30#include <linux/vmalloc.h>
25#include <asm/io.h> 31#include <asm/io.h>
26#include <asm/uaccess.h> 32#include <asm/uaccess.h>
27#include <video/w100fb.h> 33#include <video/w100fb.h>
@@ -30,114 +36,78 @@
30/* 36/*
31 * Prototypes 37 * Prototypes
32 */ 38 */
33static void w100fb_save_buffer(void);
34static void w100fb_clear_buffer(void);
35static void w100fb_restore_buffer(void);
36static void w100fb_clear_screen(u32 mode, long int offset);
37static void w100_resume(void);
38static void w100_suspend(u32 mode); 39static void w100_suspend(u32 mode);
39static void w100_init_qvga_rotation(u16 deg);
40static void w100_init_vga_rotation(u16 deg);
41static void w100_vsync(void); 40static void w100_vsync(void);
42static void w100_init_sharp_lcd(u32 mode); 41static void w100_hw_init(struct w100fb_par*);
43static void w100_pwm_setup(void); 42static void w100_pwm_setup(struct w100fb_par*);
44static void w100_InitExtMem(u32 mode); 43static void w100_init_clocks(struct w100fb_par*);
45static void w100_hw_init(void); 44static void w100_setup_memory(struct w100fb_par*);
46static u16 w100_set_fastsysclk(u16 Freq); 45static void w100_init_lcd(struct w100fb_par*);
47 46static void w100_set_dispregs(struct w100fb_par*);
48static void lcdtg_hw_init(u32 mode); 47static void w100_update_enable(void);
49static void lcdtg_lcd_change(u32 mode); 48static void w100_update_disable(void);
50static void lcdtg_resume(void); 49static void calc_hsync(struct w100fb_par *par);
51static void lcdtg_suspend(void); 50struct w100_pll_info *w100_get_xtal_table(unsigned int freq);
52
53
54/* Register offsets & lengths */
55#define REMAPPED_FB_LEN 0x15ffff
56
57#define BITS_PER_PIXEL 16
58 51
59/* Pseudo palette size */ 52/* Pseudo palette size */
60#define MAX_PALETTES 16 53#define MAX_PALETTES 16
61 54
62/* for resolution change */
63#define LCD_MODE_INIT (-1)
64#define LCD_MODE_480 0
65#define LCD_MODE_320 1
66#define LCD_MODE_240 2
67#define LCD_MODE_640 3
68
69#define LCD_SHARP_QVGA 0
70#define LCD_SHARP_VGA 1
71
72#define LCD_MODE_PORTRAIT 0
73#define LCD_MODE_LANDSCAPE 1
74
75#define W100_SUSPEND_EXTMEM 0 55#define W100_SUSPEND_EXTMEM 0
76#define W100_SUSPEND_ALL 1 56#define W100_SUSPEND_ALL 1
77 57
78/* General frame buffer data structures */ 58#define BITS_PER_PIXEL 16
79struct w100fb_par {
80 u32 xres;
81 u32 yres;
82 int fastsysclk_mode;
83 int lcdMode;
84 int rotation_flag;
85 int blanking_flag;
86 int comadj;
87 int phadadj;
88};
89
90static struct w100fb_par *current_par;
91 59
92/* Remapped addresses for base cfg, memmapped regs and the frame buffer itself */ 60/* Remapped addresses for base cfg, memmapped regs and the frame buffer itself */
93static void *remapped_base; 61static void *remapped_base;
94static void *remapped_regs; 62static void *remapped_regs;
95static void *remapped_fbuf; 63static void *remapped_fbuf;
96 64
97/* External Function */ 65#define REMAPPED_FB_LEN 0x15ffff
98static void(*w100fb_ssp_send)(u8 adrs, u8 data); 66
67/* This is the offset in the w100's address space we map the current
68 framebuffer memory to. We use the position of external memory as
69 we can remap internal memory to there if external isn't present. */
70#define W100_FB_BASE MEM_EXT_BASE_VALUE
71
99 72
100/* 73/*
101 * Sysfs functions 74 * Sysfs functions
102 */ 75 */
103 76static ssize_t flip_show(struct device *dev, struct device_attribute *attr, char *buf)
104static ssize_t rotation_show(struct device *dev, struct device_attribute *attr, char *buf)
105{ 77{
106 struct fb_info *info = dev_get_drvdata(dev); 78 struct fb_info *info = dev_get_drvdata(dev);
107 struct w100fb_par *par=info->par; 79 struct w100fb_par *par=info->par;
108 80
109 return sprintf(buf, "%d\n",par->rotation_flag); 81 return sprintf(buf, "%d\n",par->flip);
110} 82}
111 83
112static ssize_t rotation_store(struct device *dev, struct device_attribute *attr, const char *buf, size_t count) 84static ssize_t flip_store(struct device *dev, struct device_attribute *attr, const char *buf, size_t count)
113{ 85{
114 unsigned int rotate; 86 unsigned int flip;
115 struct fb_info *info = dev_get_drvdata(dev); 87 struct fb_info *info = dev_get_drvdata(dev);
116 struct w100fb_par *par=info->par; 88 struct w100fb_par *par=info->par;
117 89
118 rotate = simple_strtoul(buf, NULL, 10); 90 flip = simple_strtoul(buf, NULL, 10);
91
92 if (flip > 0)
93 par->flip = 1;
94 else
95 par->flip = 0;
119 96
120 if (rotate > 0) par->rotation_flag = 1; 97 w100_update_disable();
121 else par->rotation_flag = 0; 98 w100_set_dispregs(par);
99 w100_update_enable();
122 100
123 if (par->lcdMode == LCD_MODE_320) 101 calc_hsync(par);
124 w100_init_qvga_rotation(par->rotation_flag ? 270 : 90);
125 else if (par->lcdMode == LCD_MODE_240)
126 w100_init_qvga_rotation(par->rotation_flag ? 180 : 0);
127 else if (par->lcdMode == LCD_MODE_640)
128 w100_init_vga_rotation(par->rotation_flag ? 270 : 90);
129 else if (par->lcdMode == LCD_MODE_480)
130 w100_init_vga_rotation(par->rotation_flag ? 180 : 0);
131 102
132 return count; 103 return count;
133} 104}
134 105
135static DEVICE_ATTR(rotation, 0644, rotation_show, rotation_store); 106static DEVICE_ATTR(flip, 0644, flip_show, flip_store);
136 107
137static ssize_t w100fb_reg_read(struct device *dev, struct device_attribute *attr, const char *buf, size_t count) 108static ssize_t w100fb_reg_read(struct device *dev, struct device_attribute *attr, const char *buf, size_t count)
138{ 109{
139 unsigned long param; 110 unsigned long regs, param;
140 unsigned long regs;
141 regs = simple_strtoul(buf, NULL, 16); 111 regs = simple_strtoul(buf, NULL, 16);
142 param = readl(remapped_regs + regs); 112 param = readl(remapped_regs + regs);
143 printk("Read Register 0x%08lX: 0x%08lX\n", regs, param); 113 printk("Read Register 0x%08lX: 0x%08lX\n", regs, param);
@@ -148,8 +118,7 @@ static DEVICE_ATTR(reg_read, 0200, NULL, w100fb_reg_read);
148 118
149static ssize_t w100fb_reg_write(struct device *dev, struct device_attribute *attr, const char *buf, size_t count) 119static ssize_t w100fb_reg_write(struct device *dev, struct device_attribute *attr, const char *buf, size_t count)
150{ 120{
151 unsigned long regs; 121 unsigned long regs, param;
152 unsigned long param;
153 sscanf(buf, "%lx %lx", &regs, &param); 122 sscanf(buf, "%lx %lx", &regs, &param);
154 123
155 if (regs <= 0x2000) { 124 if (regs <= 0x2000) {
@@ -163,54 +132,56 @@ static ssize_t w100fb_reg_write(struct device *dev, struct device_attribute *att
163static DEVICE_ATTR(reg_write, 0200, NULL, w100fb_reg_write); 132static DEVICE_ATTR(reg_write, 0200, NULL, w100fb_reg_write);
164 133
165 134
166static ssize_t fastsysclk_show(struct device *dev, struct device_attribute *attr, char *buf) 135static ssize_t fastpllclk_show(struct device *dev, struct device_attribute *attr, char *buf)
167{ 136{
168 struct fb_info *info = dev_get_drvdata(dev); 137 struct fb_info *info = dev_get_drvdata(dev);
169 struct w100fb_par *par=info->par; 138 struct w100fb_par *par=info->par;
170 139
171 return sprintf(buf, "%d\n",par->fastsysclk_mode); 140 return sprintf(buf, "%d\n",par->fastpll_mode);
172} 141}
173 142
174static ssize_t fastsysclk_store(struct device *dev, struct device_attribute *attr, const char *buf, size_t count) 143static ssize_t fastpllclk_store(struct device *dev, struct device_attribute *attr, const char *buf, size_t count)
175{ 144{
176 int param;
177 struct fb_info *info = dev_get_drvdata(dev); 145 struct fb_info *info = dev_get_drvdata(dev);
178 struct w100fb_par *par=info->par; 146 struct w100fb_par *par=info->par;
179 147
180 param = simple_strtoul(buf, NULL, 10); 148 if (simple_strtoul(buf, NULL, 10) > 0) {
181 149 par->fastpll_mode=1;
182 if (param == 75) { 150 printk("w100fb: Using fast system clock (if possible)\n");
183 printk("Set fastsysclk %d\n", param); 151 } else {
184 par->fastsysclk_mode = param; 152 par->fastpll_mode=0;
185 w100_set_fastsysclk(par->fastsysclk_mode); 153 printk("w100fb: Using normal system clock\n");
186 } else if (param == 100) {
187 printk("Set fastsysclk %d\n", param);
188 par->fastsysclk_mode = param;
189 w100_set_fastsysclk(par->fastsysclk_mode);
190 } 154 }
155
156 w100_init_clocks(par);
157 calc_hsync(par);
158
191 return count; 159 return count;
192} 160}
193 161
194static DEVICE_ATTR(fastsysclk, 0644, fastsysclk_show, fastsysclk_store); 162static DEVICE_ATTR(fastpllclk, 0644, fastpllclk_show, fastpllclk_store);
195 163
196/* 164/*
197 * The touchscreen on this device needs certain information 165 * Some touchscreens need hsync information from the video driver to
198 * from the video driver to function correctly. We export it here. 166 * function correctly. We export it here.
199 */ 167 */
200int w100fb_get_xres(void) { 168unsigned long w100fb_get_hsynclen(struct device *dev)
201 return current_par->xres; 169{
202} 170 struct fb_info *info = dev_get_drvdata(dev);
171 struct w100fb_par *par=info->par;
203 172
204int w100fb_get_blanking(void) { 173 /* If display is blanked/suspended, hsync isn't active */
205 return current_par->blanking_flag; 174 if (par->blanked)
175 return 0;
176 else
177 return par->hsync_len;
206} 178}
179EXPORT_SYMBOL(w100fb_get_hsynclen);
207 180
208int w100fb_get_fastsysclk(void) { 181static void w100fb_clear_screen(struct w100fb_par *par)
209 return current_par->fastsysclk_mode; 182{
183 memset_io(remapped_fbuf + (W100_FB_BASE-MEM_WINDOW_BASE), 0, (par->xres * par->yres * BITS_PER_PIXEL/8));
210} 184}
211EXPORT_SYMBOL(w100fb_get_xres);
212EXPORT_SYMBOL(w100fb_get_blanking);
213EXPORT_SYMBOL(w100fb_get_fastsysclk);
214 185
215 186
216/* 187/*
@@ -234,7 +205,6 @@ static int w100fb_setcolreg(u_int regno, u_int red, u_int green, u_int blue,
234 * according to the RGB bitfield information. 205 * according to the RGB bitfield information.
235 */ 206 */
236 if (regno < MAX_PALETTES) { 207 if (regno < MAX_PALETTES) {
237
238 u32 *pal = info->pseudo_palette; 208 u32 *pal = info->pseudo_palette;
239 209
240 val = (red & 0xf800) | ((green & 0xfc00) >> 5) | ((blue & 0xf800) >> 11); 210 val = (red & 0xf800) | ((green & 0xfc00) >> 5) | ((blue & 0xf800) >> 11);
@@ -250,115 +220,90 @@ static int w100fb_setcolreg(u_int regno, u_int red, u_int green, u_int blue,
250 */ 220 */
251static int w100fb_blank(int blank_mode, struct fb_info *info) 221static int w100fb_blank(int blank_mode, struct fb_info *info)
252{ 222{
253 struct w100fb_par *par; 223 struct w100fb_par *par = info->par;
254 par=info->par; 224 struct w100_tg_info *tg = par->mach->tg;
255 225
256 switch(blank_mode) { 226 switch(blank_mode) {
257 227
258 case FB_BLANK_NORMAL: /* Normal blanking */ 228 case FB_BLANK_NORMAL: /* Normal blanking */
259 case FB_BLANK_VSYNC_SUSPEND: /* VESA blank (vsync off) */ 229 case FB_BLANK_VSYNC_SUSPEND: /* VESA blank (vsync off) */
260 case FB_BLANK_HSYNC_SUSPEND: /* VESA blank (hsync off) */ 230 case FB_BLANK_HSYNC_SUSPEND: /* VESA blank (hsync off) */
261 case FB_BLANK_POWERDOWN: /* Poweroff */ 231 case FB_BLANK_POWERDOWN: /* Poweroff */
262 if (par->blanking_flag == 0) { 232 if (par->blanked == 0) {
263 w100fb_save_buffer(); 233 if(tg && tg->suspend)
264 lcdtg_suspend(); 234 tg->suspend(par);
265 par->blanking_flag = 1; 235 par->blanked = 1;
266 } 236 }
267 break; 237 break;
268 238
269 case FB_BLANK_UNBLANK: /* Unblanking */ 239 case FB_BLANK_UNBLANK: /* Unblanking */
270 if (par->blanking_flag != 0) { 240 if (par->blanked != 0) {
271 w100fb_restore_buffer(); 241 if(tg && tg->resume)
272 lcdtg_resume(); 242 tg->resume(par);
273 par->blanking_flag = 0; 243 par->blanked = 0;
274 } 244 }
275 break; 245 break;
276 } 246 }
277 return 0; 247 return 0;
278} 248}
279 249
250
280/* 251/*
281 * Change the resolution by calling the appropriate hardware functions 252 * Change the resolution by calling the appropriate hardware functions
282 */ 253 */
283static void w100fb_changeres(int rotate_mode, u32 mode) 254static void w100fb_activate_var(struct w100fb_par *par)
284{ 255{
285 u16 rotation=0; 256 struct w100_tg_info *tg = par->mach->tg;
286
287 switch(rotate_mode) {
288 case LCD_MODE_LANDSCAPE:
289 rotation=(current_par->rotation_flag ? 270 : 90);
290 break;
291 case LCD_MODE_PORTRAIT:
292 rotation=(current_par->rotation_flag ? 180 : 0);
293 break;
294 }
295 257
296 w100_pwm_setup(); 258 w100_pwm_setup(par);
297 switch(mode) { 259 w100_setup_memory(par);
298 case LCD_SHARP_QVGA: 260 w100_init_clocks(par);
299 w100_vsync(); 261 w100fb_clear_screen(par);
300 w100_suspend(W100_SUSPEND_EXTMEM); 262 w100_vsync();
301 w100_init_sharp_lcd(LCD_SHARP_QVGA); 263
302 w100_init_qvga_rotation(rotation); 264 w100_update_disable();
303 w100_InitExtMem(LCD_SHARP_QVGA); 265 w100_init_lcd(par);
304 w100fb_clear_screen(LCD_SHARP_QVGA, 0); 266 w100_set_dispregs(par);
305 lcdtg_lcd_change(LCD_SHARP_QVGA); 267 w100_update_enable();
306 break; 268
307 case LCD_SHARP_VGA: 269 calc_hsync(par);
308 w100fb_clear_screen(LCD_SHARP_QVGA, 0); 270
309 writel(0xBFFFA000, remapped_regs + mmMC_EXT_MEM_LOCATION); 271 if (!par->blanked && tg && tg->change)
310 w100_InitExtMem(LCD_SHARP_VGA); 272 tg->change(par);
311 w100fb_clear_screen(LCD_SHARP_VGA, 0x200000);
312 w100_vsync();
313 w100_init_sharp_lcd(LCD_SHARP_VGA);
314 if (rotation != 0)
315 w100_init_vga_rotation(rotation);
316 lcdtg_lcd_change(LCD_SHARP_VGA);
317 break;
318 }
319} 273}
320 274
321/* 275
322 * Set up the display for the fb subsystem 276/* Select the smallest mode that allows the desired resolution to be
277 * displayed. If desired, the x and y parameters can be rounded up to
278 * match the selected mode.
323 */ 279 */
324static void w100fb_activate_var(struct fb_info *info) 280static struct w100_mode *w100fb_get_mode(struct w100fb_par *par, unsigned int *x, unsigned int *y, int saveval)
325{ 281{
326 u32 temp32; 282 struct w100_mode *mode = NULL;
327 struct w100fb_par *par=info->par; 283 struct w100_mode *modelist = par->mach->modelist;
328 struct fb_var_screeninfo *var = &info->var; 284 unsigned int best_x = 0xffffffff, best_y = 0xffffffff;
285 unsigned int i;
286
287 for (i = 0 ; i < par->mach->num_modes ; i++) {
288 if (modelist[i].xres >= *x && modelist[i].yres >= *y &&
289 modelist[i].xres < best_x && modelist[i].yres < best_y) {
290 best_x = modelist[i].xres;
291 best_y = modelist[i].yres;
292 mode = &modelist[i];
293 } else if(modelist[i].xres >= *y && modelist[i].yres >= *x &&
294 modelist[i].xres < best_y && modelist[i].yres < best_x) {
295 best_x = modelist[i].yres;
296 best_y = modelist[i].xres;
297 mode = &modelist[i];
298 }
299 }
329 300
330 /* Set the hardware to 565 */ 301 if (mode && saveval) {
331 temp32 = readl(remapped_regs + mmDISP_DEBUG2); 302 *x = best_x;
332 temp32 &= 0xff7fffff; 303 *y = best_y;
333 temp32 |= 0x00800000; 304 }
334 writel(temp32, remapped_regs + mmDISP_DEBUG2);
335 305
336 if (par->lcdMode == LCD_MODE_INIT) { 306 return mode;
337 w100_init_sharp_lcd(LCD_SHARP_VGA);
338 w100_init_vga_rotation(par->rotation_flag ? 270 : 90);
339 par->lcdMode = LCD_MODE_640;
340 lcdtg_hw_init(LCD_SHARP_VGA);
341 } else if (var->xres == 320 && var->yres == 240) {
342 if (par->lcdMode != LCD_MODE_320) {
343 w100fb_changeres(LCD_MODE_LANDSCAPE, LCD_SHARP_QVGA);
344 par->lcdMode = LCD_MODE_320;
345 }
346 } else if (var->xres == 240 && var->yres == 320) {
347 if (par->lcdMode != LCD_MODE_240) {
348 w100fb_changeres(LCD_MODE_PORTRAIT, LCD_SHARP_QVGA);
349 par->lcdMode = LCD_MODE_240;
350 }
351 } else if (var->xres == 640 && var->yres == 480) {
352 if (par->lcdMode != LCD_MODE_640) {
353 w100fb_changeres(LCD_MODE_LANDSCAPE, LCD_SHARP_VGA);
354 par->lcdMode = LCD_MODE_640;
355 }
356 } else if (var->xres == 480 && var->yres == 640) {
357 if (par->lcdMode != LCD_MODE_480) {
358 w100fb_changeres(LCD_MODE_PORTRAIT, LCD_SHARP_VGA);
359 par->lcdMode = LCD_MODE_480;
360 }
361 } else printk(KERN_ERR "W100FB: Resolution error!\n");
362} 307}
363 308
364 309
@@ -366,31 +311,19 @@ static void w100fb_activate_var(struct fb_info *info)
366 * w100fb_check_var(): 311 * w100fb_check_var():
367 * Get the video params out of 'var'. If a value doesn't fit, round it up, 312 * Get the video params out of 'var'. If a value doesn't fit, round it up,
368 * if it's too big, return -EINVAL. 313 * if it's too big, return -EINVAL.
369 *
370 */ 314 */
371static int w100fb_check_var(struct fb_var_screeninfo *var, struct fb_info *info) 315static int w100fb_check_var(struct fb_var_screeninfo *var, struct fb_info *info)
372{ 316{
373 if (var->xres < var->yres) { /* Portrait mode */ 317 struct w100fb_par *par=info->par;
374 if ((var->xres > 480) || (var->yres > 640)) { 318
375 return -EINVAL; 319 if(!w100fb_get_mode(par, &var->xres, &var->yres, 1))
376 } else if ((var->xres > 240) || (var->yres > 320)) { 320 return -EINVAL;
377 var->xres = 480; 321
378 var->yres = 640; 322 if (par->mach->mem && ((var->xres*var->yres*BITS_PER_PIXEL/8) > (par->mach->mem->size+1)))
379 } else { 323 return -EINVAL;
380 var->xres = 240; 324
381 var->yres = 320; 325 if (!par->mach->mem && ((var->xres*var->yres*BITS_PER_PIXEL/8) > (MEM_INT_SIZE+1)))
382 } 326 return -EINVAL;
383 } else { /* Landscape mode */
384 if ((var->xres > 640) || (var->yres > 480)) {
385 return -EINVAL;
386 } else if ((var->xres > 320) || (var->yres > 240)) {
387 var->xres = 640;
388 var->yres = 480;
389 } else {
390 var->xres = 320;
391 var->yres = 240;
392 }
393 }
394 327
395 var->xres_virtual = max(var->xres_virtual, var->xres); 328 var->xres_virtual = max(var->xres_virtual, var->xres);
396 var->yres_virtual = max(var->yres_virtual, var->yres); 329 var->yres_virtual = max(var->yres_virtual, var->yres);
@@ -409,13 +342,11 @@ static int w100fb_check_var(struct fb_var_screeninfo *var, struct fb_info *info)
409 var->transp.offset = var->transp.length = 0; 342 var->transp.offset = var->transp.length = 0;
410 343
411 var->nonstd = 0; 344 var->nonstd = 0;
412
413 var->height = -1; 345 var->height = -1;
414 var->width = -1; 346 var->width = -1;
415 var->vmode = FB_VMODE_NONINTERLACED; 347 var->vmode = FB_VMODE_NONINTERLACED;
416
417 var->sync = 0; 348 var->sync = 0;
418 var->pixclock = 0x04; /* 171521; */ 349 var->pixclock = 0x04; /* 171521; */
419 350
420 return 0; 351 return 0;
421} 352}
@@ -430,274 +361,286 @@ static int w100fb_set_par(struct fb_info *info)
430{ 361{
431 struct w100fb_par *par=info->par; 362 struct w100fb_par *par=info->par;
432 363
433 par->xres = info->var.xres; 364 if (par->xres != info->var.xres || par->yres != info->var.yres) {
434 par->yres = info->var.yres; 365 par->xres = info->var.xres;
435 366 par->yres = info->var.yres;
436 info->fix.visual = FB_VISUAL_TRUECOLOR; 367 par->mode = w100fb_get_mode(par, &par->xres, &par->yres, 0);
437
438 info->fix.ypanstep = 0;
439 info->fix.ywrapstep = 0;
440 368
441 if (par->blanking_flag) 369 info->fix.visual = FB_VISUAL_TRUECOLOR;
442 w100fb_clear_buffer(); 370 info->fix.ypanstep = 0;
371 info->fix.ywrapstep = 0;
372 info->fix.line_length = par->xres * BITS_PER_PIXEL / 8;
443 373
444 w100fb_activate_var(info); 374 if ((par->xres*par->yres*BITS_PER_PIXEL/8) > (MEM_INT_SIZE+1)) {
375 par->extmem_active = 1;
376 info->fix.smem_len = par->mach->mem->size+1;
377 } else {
378 par->extmem_active = 0;
379 info->fix.smem_len = MEM_INT_SIZE+1;
380 }
445 381
446 if (par->lcdMode == LCD_MODE_480) { 382 w100fb_activate_var(par);
447 info->fix.line_length = (480 * BITS_PER_PIXEL) / 8;
448 info->fix.smem_len = 0x200000;
449 } else if (par->lcdMode == LCD_MODE_320) {
450 info->fix.line_length = (320 * BITS_PER_PIXEL) / 8;
451 info->fix.smem_len = 0x60000;
452 } else if (par->lcdMode == LCD_MODE_240) {
453 info->fix.line_length = (240 * BITS_PER_PIXEL) / 8;
454 info->fix.smem_len = 0x60000;
455 } else if (par->lcdMode == LCD_MODE_INIT || par->lcdMode == LCD_MODE_640) {
456 info->fix.line_length = (640 * BITS_PER_PIXEL) / 8;
457 info->fix.smem_len = 0x200000;
458 } 383 }
459
460 return 0; 384 return 0;
461} 385}
462 386
463 387
464/* 388/*
465 * Frame buffer operations 389 * Frame buffer operations
466 */ 390 */
467static struct fb_ops w100fb_ops = { 391static struct fb_ops w100fb_ops = {
468 .owner = THIS_MODULE, 392 .owner = THIS_MODULE,
469 .fb_check_var = w100fb_check_var, 393 .fb_check_var = w100fb_check_var,
470 .fb_set_par = w100fb_set_par, 394 .fb_set_par = w100fb_set_par,
471 .fb_setcolreg = w100fb_setcolreg, 395 .fb_setcolreg = w100fb_setcolreg,
472 .fb_blank = w100fb_blank, 396 .fb_blank = w100fb_blank,
473 .fb_fillrect = cfb_fillrect, 397 .fb_fillrect = cfb_fillrect,
474 .fb_copyarea = cfb_copyarea, 398 .fb_copyarea = cfb_copyarea,
475 .fb_imageblit = cfb_imageblit, 399 .fb_imageblit = cfb_imageblit,
476 .fb_cursor = soft_cursor, 400 .fb_cursor = soft_cursor,
477}; 401};
478 402
479 403#ifdef CONFIG_PM
480static void w100fb_clear_screen(u32 mode, long int offset) 404static void w100fb_save_vidmem(struct w100fb_par *par)
481{ 405{
482 int i, numPix = 0; 406 int memsize;
483
484 if (mode == LCD_SHARP_VGA)
485 numPix = 640 * 480;
486 else if (mode == LCD_SHARP_QVGA)
487 numPix = 320 * 240;
488 407
489 for (i = 0; i < numPix; i++) 408 if (par->extmem_active) {
490 writew(0xffff, remapped_fbuf + offset + (2*i)); 409 memsize=par->mach->mem->size;
491} 410 par->saved_extmem = vmalloc(memsize);
492 411 if (par->saved_extmem)
493 412 memcpy_fromio(par->saved_extmem, remapped_fbuf + (W100_FB_BASE-MEM_WINDOW_BASE), memsize);
494/* Need to split up the buffers to stay within the limits of kmalloc */
495#define W100_BUF_NUM 6
496static uint32_t *gSaveImagePtr[W100_BUF_NUM] = { NULL };
497
498static void w100fb_save_buffer(void)
499{
500 int i, j, bufsize;
501
502 bufsize=(current_par->xres * current_par->yres * BITS_PER_PIXEL / 8) / W100_BUF_NUM;
503 for (i = 0; i < W100_BUF_NUM; i++) {
504 if (gSaveImagePtr[i] == NULL)
505 gSaveImagePtr[i] = kmalloc(bufsize, GFP_KERNEL);
506 if (gSaveImagePtr[i] == NULL) {
507 w100fb_clear_buffer();
508 printk(KERN_WARNING "can't alloc pre-off image buffer %d\n", i);
509 break;
510 }
511 for (j = 0; j < bufsize/4; j++)
512 *(gSaveImagePtr[i] + j) = readl(remapped_fbuf + (bufsize*i) + j*4);
513 } 413 }
414 memsize=MEM_INT_SIZE;
415 par->saved_intmem = vmalloc(memsize);
416 if (par->saved_intmem && par->extmem_active)
417 memcpy_fromio(par->saved_intmem, remapped_fbuf + (W100_FB_BASE-MEM_INT_BASE_VALUE), memsize);
418 else if (par->saved_intmem)
419 memcpy_fromio(par->saved_intmem, remapped_fbuf + (W100_FB_BASE-MEM_WINDOW_BASE), memsize);
514} 420}
515 421
516 422static void w100fb_restore_vidmem(struct w100fb_par *par)
517static void w100fb_restore_buffer(void)
518{ 423{
519 int i, j, bufsize; 424 int memsize;
520 425
521 bufsize=(current_par->xres * current_par->yres * BITS_PER_PIXEL / 8) / W100_BUF_NUM; 426 if (par->extmem_active && par->saved_extmem) {
522 for (i = 0; i < W100_BUF_NUM; i++) { 427 memsize=par->mach->mem->size;
523 if (gSaveImagePtr[i] == NULL) { 428 memcpy_toio(remapped_fbuf + (W100_FB_BASE-MEM_WINDOW_BASE), par->saved_extmem, memsize);
524 printk(KERN_WARNING "can't find pre-off image buffer %d\n", i); 429 vfree(par->saved_extmem);
525 w100fb_clear_buffer();
526 break;
527 }
528 for (j = 0; j < (bufsize/4); j++)
529 writel(*(gSaveImagePtr[i] + j),remapped_fbuf + (bufsize*i) + (j*4));
530 kfree(gSaveImagePtr[i]);
531 gSaveImagePtr[i] = NULL;
532 } 430 }
533} 431 if (par->saved_intmem) {
534 432 memsize=MEM_INT_SIZE;
535 433 if (par->extmem_active)
536static void w100fb_clear_buffer(void) 434 memcpy_toio(remapped_fbuf + (W100_FB_BASE-MEM_INT_BASE_VALUE), par->saved_intmem, memsize);
537{ 435 else
538 int i; 436 memcpy_toio(remapped_fbuf + (W100_FB_BASE-MEM_WINDOW_BASE), par->saved_intmem, memsize);
539 for (i = 0; i < W100_BUF_NUM; i++) { 437 vfree(par->saved_intmem);
540 kfree(gSaveImagePtr[i]);
541 gSaveImagePtr[i] = NULL;
542 } 438 }
543} 439}
544 440
545 441static int w100fb_suspend(struct device *dev, pm_message_t state, uint32_t level)
546#ifdef CONFIG_PM
547static int w100fb_suspend(struct device *dev, pm_message_t state, u32 level)
548{ 442{
549 if (level == SUSPEND_POWER_DOWN) { 443 if (level == SUSPEND_POWER_DOWN) {
550 struct fb_info *info = dev_get_drvdata(dev); 444 struct fb_info *info = dev_get_drvdata(dev);
551 struct w100fb_par *par=info->par; 445 struct w100fb_par *par=info->par;
446 struct w100_tg_info *tg = par->mach->tg;
552 447
553 w100fb_save_buffer(); 448 w100fb_save_vidmem(par);
554 lcdtg_suspend(); 449 if(tg && tg->suspend)
450 tg->suspend(par);
555 w100_suspend(W100_SUSPEND_ALL); 451 w100_suspend(W100_SUSPEND_ALL);
556 par->blanking_flag = 1; 452 par->blanked = 1;
557 } 453 }
558 return 0; 454 return 0;
559} 455}
560 456
561static int w100fb_resume(struct device *dev, u32 level) 457static int w100fb_resume(struct device *dev, uint32_t level)
562{ 458{
563 if (level == RESUME_POWER_ON) { 459 if (level == RESUME_POWER_ON) {
564 struct fb_info *info = dev_get_drvdata(dev); 460 struct fb_info *info = dev_get_drvdata(dev);
565 struct w100fb_par *par=info->par; 461 struct w100fb_par *par=info->par;
566 462 struct w100_tg_info *tg = par->mach->tg;
567 w100_resume(); 463
568 w100fb_restore_buffer(); 464 w100_hw_init(par);
569 lcdtg_resume(); 465 w100fb_activate_var(par);
570 par->blanking_flag = 0; 466 w100fb_restore_vidmem(par);
467 if(tg && tg->resume)
468 tg->resume(par);
469 par->blanked = 0;
571 } 470 }
572 return 0; 471 return 0;
573} 472}
574#else 473#else
575#define w100fb_suspend NULL 474#define w100fb_suspend NULL
576#define w100fb_resume NULL 475#define w100fb_resume NULL
577#endif 476#endif
578 477
579 478
580int __init w100fb_probe(struct device *dev) 479int __init w100fb_probe(struct device *dev)
581{ 480{
481 int err = -EIO;
582 struct w100fb_mach_info *inf; 482 struct w100fb_mach_info *inf;
583 struct fb_info *info; 483 struct fb_info *info = NULL;
584 struct w100fb_par *par; 484 struct w100fb_par *par;
585 struct platform_device *pdev = to_platform_device(dev); 485 struct platform_device *pdev = to_platform_device(dev);
586 struct resource *mem = platform_get_resource(pdev, IORESOURCE_MEM, 0); 486 struct resource *mem = platform_get_resource(pdev, IORESOURCE_MEM, 0);
487 unsigned int chip_id;
587 488
588 if (!mem) 489 if (!mem)
589 return -EINVAL; 490 return -EINVAL;
590 491
591 /* remap the areas we're going to use */ 492 /* Remap the chip base address */
592 remapped_base = ioremap_nocache(mem->start+W100_CFG_BASE, W100_CFG_LEN); 493 remapped_base = ioremap_nocache(mem->start+W100_CFG_BASE, W100_CFG_LEN);
593 if (remapped_base == NULL) 494 if (remapped_base == NULL)
594 return -EIO; 495 goto out;
595 496
497 /* Map the register space */
596 remapped_regs = ioremap_nocache(mem->start+W100_REG_BASE, W100_REG_LEN); 498 remapped_regs = ioremap_nocache(mem->start+W100_REG_BASE, W100_REG_LEN);
597 if (remapped_regs == NULL) { 499 if (remapped_regs == NULL)
598 iounmap(remapped_base); 500 goto out;
599 return -EIO; 501
502 /* Identify the chip */
503 printk("Found ");
504 chip_id = readl(remapped_regs + mmCHIP_ID);
505 switch(chip_id) {
506 case CHIP_ID_W100: printk("w100"); break;
507 case CHIP_ID_W3200: printk("w3200"); break;
508 case CHIP_ID_W3220: printk("w3220"); break;
509 default:
510 printk("Unknown imageon chip ID\n");
511 err = -ENODEV;
512 goto out;
600 } 513 }
514 printk(" at 0x%08lx.\n", mem->start+W100_CFG_BASE);
601 515
602 remapped_fbuf = ioremap_nocache(mem->start+MEM_EXT_BASE_VALUE, REMAPPED_FB_LEN); 516 /* Remap the framebuffer */
603 if (remapped_fbuf == NULL) { 517 remapped_fbuf = ioremap_nocache(mem->start+MEM_WINDOW_BASE, MEM_WINDOW_SIZE);
604 iounmap(remapped_base); 518 if (remapped_fbuf == NULL)
605 iounmap(remapped_regs); 519 goto out;
606 return -EIO;
607 }
608 520
609 info=framebuffer_alloc(sizeof(struct w100fb_par), dev); 521 info=framebuffer_alloc(sizeof(struct w100fb_par), dev);
610 if (!info) { 522 if (!info) {
611 iounmap(remapped_base); 523 err = -ENOMEM;
612 iounmap(remapped_regs); 524 goto out;
613 iounmap(remapped_fbuf);
614 return -ENOMEM;
615 } 525 }
616 526
617 info->device=dev;
618 par = info->par; 527 par = info->par;
619 current_par=info->par;
620 dev_set_drvdata(dev, info); 528 dev_set_drvdata(dev, info);
621 529
622 inf = dev->platform_data; 530 inf = dev->platform_data;
623 par->phadadj = inf->phadadj; 531 par->chip_id = chip_id;
624 par->comadj = inf->comadj; 532 par->mach = inf;
625 par->fastsysclk_mode = 75; 533 par->fastpll_mode = 0;
626 par->lcdMode = LCD_MODE_INIT; 534 par->blanked = 0;
627 par->rotation_flag=0; 535
628 par->blanking_flag=0; 536 par->pll_table=w100_get_xtal_table(inf->xtal_freq);
629 w100fb_ssp_send = inf->w100fb_ssp_send; 537 if (!par->pll_table) {
630 538 printk(KERN_ERR "No matching Xtal definition found\n");
631 w100_hw_init(); 539 err = -EINVAL;
632 w100_pwm_setup(); 540 goto out;
541 }
633 542
634 info->pseudo_palette = kmalloc(sizeof (u32) * MAX_PALETTES, GFP_KERNEL); 543 info->pseudo_palette = kmalloc(sizeof (u32) * MAX_PALETTES, GFP_KERNEL);
635 if (!info->pseudo_palette) { 544 if (!info->pseudo_palette) {
636 iounmap(remapped_base); 545 err = -ENOMEM;
637 iounmap(remapped_regs); 546 goto out;
638 iounmap(remapped_fbuf);
639 return -ENOMEM;
640 } 547 }
641 548
642 info->fbops = &w100fb_ops; 549 info->fbops = &w100fb_ops;
643 info->flags = FBINFO_DEFAULT; 550 info->flags = FBINFO_DEFAULT;
644 info->node = -1; 551 info->node = -1;
645 info->screen_base = remapped_fbuf; 552 info->screen_base = remapped_fbuf + (W100_FB_BASE-MEM_WINDOW_BASE);
646 info->screen_size = REMAPPED_FB_LEN; 553 info->screen_size = REMAPPED_FB_LEN;
647 554
648 info->var.xres = 640; 555 strcpy(info->fix.id, "w100fb");
556 info->fix.type = FB_TYPE_PACKED_PIXELS;
557 info->fix.type_aux = 0;
558 info->fix.accel = FB_ACCEL_NONE;
559 info->fix.smem_start = mem->start+W100_FB_BASE;
560 info->fix.mmio_start = mem->start+W100_REG_BASE;
561 info->fix.mmio_len = W100_REG_LEN;
562
563 if (fb_alloc_cmap(&info->cmap, 256, 0) < 0) {
564 err = -ENOMEM;
565 goto out;
566 }
567
568 par->mode = &inf->modelist[0];
569 if(inf->init_mode & INIT_MODE_ROTATED) {
570 info->var.xres = par->mode->yres;
571 info->var.yres = par->mode->xres;
572 }
573 else {
574 info->var.xres = par->mode->xres;
575 info->var.yres = par->mode->yres;
576 }
577
578 if(inf->init_mode &= INIT_MODE_FLIPPED)
579 par->flip = 1;
580 else
581 par->flip = 0;
582
649 info->var.xres_virtual = info->var.xres; 583 info->var.xres_virtual = info->var.xres;
650 info->var.yres = 480;
651 info->var.yres_virtual = info->var.yres; 584 info->var.yres_virtual = info->var.yres;
652 info->var.pixclock = 0x04; /* 171521; */ 585 info->var.pixclock = 0x04; /* 171521; */
653 info->var.sync = 0; 586 info->var.sync = 0;
654 info->var.grayscale = 0; 587 info->var.grayscale = 0;
655 info->var.xoffset = info->var.yoffset = 0; 588 info->var.xoffset = info->var.yoffset = 0;
656 info->var.accel_flags = 0; 589 info->var.accel_flags = 0;
657 info->var.activate = FB_ACTIVATE_NOW; 590 info->var.activate = FB_ACTIVATE_NOW;
658 591
659 strcpy(info->fix.id, "w100fb"); 592 w100_hw_init(par);
660 info->fix.type = FB_TYPE_PACKED_PIXELS; 593
661 info->fix.type_aux = 0; 594 if (w100fb_check_var(&info->var, info) < 0) {
662 info->fix.accel = FB_ACCEL_NONE; 595 err = -EINVAL;
663 info->fix.smem_start = mem->start+MEM_EXT_BASE_VALUE; 596 goto out;
664 info->fix.mmio_start = mem->start+W100_REG_BASE; 597 }
665 info->fix.mmio_len = W100_REG_LEN;
666 598
667 w100fb_check_var(&info->var, info);
668 w100fb_set_par(info); 599 w100fb_set_par(info);
669 600
670 if (register_framebuffer(info) < 0) { 601 if (register_framebuffer(info) < 0) {
671 kfree(info->pseudo_palette); 602 err = -EINVAL;
672 iounmap(remapped_base); 603 goto out;
673 iounmap(remapped_regs);
674 iounmap(remapped_fbuf);
675 return -EINVAL;
676 } 604 }
677 605
678 device_create_file(dev, &dev_attr_fastsysclk); 606 device_create_file(dev, &dev_attr_fastpllclk);
679 device_create_file(dev, &dev_attr_reg_read); 607 device_create_file(dev, &dev_attr_reg_read);
680 device_create_file(dev, &dev_attr_reg_write); 608 device_create_file(dev, &dev_attr_reg_write);
681 device_create_file(dev, &dev_attr_rotation); 609 device_create_file(dev, &dev_attr_flip);
682 610
683 printk(KERN_INFO "fb%d: %s frame buffer device\n", info->node, info->fix.id); 611 printk(KERN_INFO "fb%d: %s frame buffer device\n", info->node, info->fix.id);
684 return 0; 612 return 0;
613out:
614 fb_dealloc_cmap(&info->cmap);
615 kfree(info->pseudo_palette);
616 if (remapped_fbuf != NULL)
617 iounmap(remapped_fbuf);
618 if (remapped_regs != NULL)
619 iounmap(remapped_regs);
620 if (remapped_base != NULL)
621 iounmap(remapped_base);
622 if (info)
623 framebuffer_release(info);
624 return err;
685} 625}
686 626
687 627
688static int w100fb_remove(struct device *dev) 628static int w100fb_remove(struct device *dev)
689{ 629{
690 struct fb_info *info = dev_get_drvdata(dev); 630 struct fb_info *info = dev_get_drvdata(dev);
631 struct w100fb_par *par=info->par;
691 632
692 device_remove_file(dev, &dev_attr_fastsysclk); 633 device_remove_file(dev, &dev_attr_fastpllclk);
693 device_remove_file(dev, &dev_attr_reg_read); 634 device_remove_file(dev, &dev_attr_reg_read);
694 device_remove_file(dev, &dev_attr_reg_write); 635 device_remove_file(dev, &dev_attr_reg_write);
695 device_remove_file(dev, &dev_attr_rotation); 636 device_remove_file(dev, &dev_attr_flip);
696 637
697 unregister_framebuffer(info); 638 unregister_framebuffer(info);
698 639
699 w100fb_clear_buffer(); 640 vfree(par->saved_intmem);
641 vfree(par->saved_extmem);
700 kfree(info->pseudo_palette); 642 kfree(info->pseudo_palette);
643 fb_dealloc_cmap(&info->cmap);
701 644
702 iounmap(remapped_base); 645 iounmap(remapped_base);
703 iounmap(remapped_regs); 646 iounmap(remapped_regs);
@@ -721,10 +664,54 @@ static void w100_soft_reset(void)
721 udelay(100); 664 udelay(100);
722} 665}
723 666
667static void w100_update_disable(void)
668{
669 union disp_db_buf_cntl_wr_u disp_db_buf_wr_cntl;
670
671 /* Prevent display updates */
672 disp_db_buf_wr_cntl.f.db_buf_cntl = 0x1e;
673 disp_db_buf_wr_cntl.f.update_db_buf = 0;
674 disp_db_buf_wr_cntl.f.en_db_buf = 0;
675 writel((u32) (disp_db_buf_wr_cntl.val), remapped_regs + mmDISP_DB_BUF_CNTL);
676}
677
678static void w100_update_enable(void)
679{
680 union disp_db_buf_cntl_wr_u disp_db_buf_wr_cntl;
681
682 /* Enable display updates */
683 disp_db_buf_wr_cntl.f.db_buf_cntl = 0x1e;
684 disp_db_buf_wr_cntl.f.update_db_buf = 1;
685 disp_db_buf_wr_cntl.f.en_db_buf = 1;
686 writel((u32) (disp_db_buf_wr_cntl.val), remapped_regs + mmDISP_DB_BUF_CNTL);
687}
688
689unsigned long w100fb_gpio_read(int port)
690{
691 unsigned long value;
692
693 if (port==W100_GPIO_PORT_A)
694 value = readl(remapped_regs + mmGPIO_DATA);
695 else
696 value = readl(remapped_regs + mmGPIO_DATA2);
697
698 return value;
699}
700
701void w100fb_gpio_write(int port, unsigned long value)
702{
703 if (port==W100_GPIO_PORT_A)
704 value = writel(value, remapped_regs + mmGPIO_DATA);
705 else
706 value = writel(value, remapped_regs + mmGPIO_DATA2);
707}
708EXPORT_SYMBOL(w100fb_gpio_read);
709EXPORT_SYMBOL(w100fb_gpio_write);
710
724/* 711/*
725 * Initialization of critical w100 hardware 712 * Initialization of critical w100 hardware
726 */ 713 */
727static void w100_hw_init(void) 714static void w100_hw_init(struct w100fb_par *par)
728{ 715{
729 u32 temp32; 716 u32 temp32;
730 union cif_cntl_u cif_cntl; 717 union cif_cntl_u cif_cntl;
@@ -735,8 +722,8 @@ static void w100_hw_init(void)
735 union cpu_defaults_u cpu_default; 722 union cpu_defaults_u cpu_default;
736 union cif_write_dbg_u cif_write_dbg; 723 union cif_write_dbg_u cif_write_dbg;
737 union wrap_start_dir_u wrap_start_dir; 724 union wrap_start_dir_u wrap_start_dir;
738 union mc_ext_mem_location_u mc_ext_mem_loc;
739 union cif_io_u cif_io; 725 union cif_io_u cif_io;
726 struct w100_gpio_regs *gpio = par->mach->gpio;
740 727
741 w100_soft_reset(); 728 w100_soft_reset();
742 729
@@ -791,19 +778,6 @@ static void w100_hw_init(void)
791 cfgreg_base.f.cfgreg_base = W100_CFG_BASE; 778 cfgreg_base.f.cfgreg_base = W100_CFG_BASE;
792 writel((u32) (cfgreg_base.val), remapped_regs + mmCFGREG_BASE); 779 writel((u32) (cfgreg_base.val), remapped_regs + mmCFGREG_BASE);
793 780
794 /* This location is relative to internal w100 addresses */
795 writel(0x15FF1000, remapped_regs + mmMC_FB_LOCATION);
796
797 mc_ext_mem_loc.val = defMC_EXT_MEM_LOCATION;
798 mc_ext_mem_loc.f.mc_ext_mem_start = MEM_EXT_BASE_VALUE >> 8;
799 mc_ext_mem_loc.f.mc_ext_mem_top = MEM_EXT_TOP_VALUE >> 8;
800 writel((u32) (mc_ext_mem_loc.val), remapped_regs + mmMC_EXT_MEM_LOCATION);
801
802 if ((current_par->lcdMode == LCD_MODE_240) || (current_par->lcdMode == LCD_MODE_320))
803 w100_InitExtMem(LCD_SHARP_QVGA);
804 else
805 w100_InitExtMem(LCD_SHARP_VGA);
806
807 wrap_start_dir.val = defWRAP_START_DIR; 781 wrap_start_dir.val = defWRAP_START_DIR;
808 wrap_start_dir.f.start_addr = WRAP_BUF_BASE_VALUE >> 1; 782 wrap_start_dir.f.start_addr = WRAP_BUF_BASE_VALUE >> 1;
809 writel((u32) (wrap_start_dir.val), remapped_regs + mmWRAP_START_DIR); 783 writel((u32) (wrap_start_dir.val), remapped_regs + mmWRAP_START_DIR);
@@ -813,21 +787,24 @@ static void w100_hw_init(void)
813 writel((u32) (wrap_top_dir.val), remapped_regs + mmWRAP_TOP_DIR); 787 writel((u32) (wrap_top_dir.val), remapped_regs + mmWRAP_TOP_DIR);
814 788
815 writel((u32) 0x2440, remapped_regs + mmRBBM_CNTL); 789 writel((u32) 0x2440, remapped_regs + mmRBBM_CNTL);
816}
817 790
791 /* Set the hardware to 565 colour */
792 temp32 = readl(remapped_regs + mmDISP_DEBUG2);
793 temp32 &= 0xff7fffff;
794 temp32 |= 0x00800000;
795 writel(temp32, remapped_regs + mmDISP_DEBUG2);
818 796
819/* 797 /* Initialise the GPIO lines */
820 * Types 798 if (gpio) {
821 */ 799 writel(gpio->init_data1, remapped_regs + mmGPIO_DATA);
800 writel(gpio->init_data2, remapped_regs + mmGPIO_DATA2);
801 writel(gpio->gpio_dir1, remapped_regs + mmGPIO_CNTL1);
802 writel(gpio->gpio_oe1, remapped_regs + mmGPIO_CNTL2);
803 writel(gpio->gpio_dir2, remapped_regs + mmGPIO_CNTL3);
804 writel(gpio->gpio_oe2, remapped_regs + mmGPIO_CNTL4);
805 }
806}
822 807
823struct pll_parm {
824 u16 freq; /* desired Fout for PLL */
825 u8 M;
826 u8 N_int;
827 u8 N_fac;
828 u8 tfgoal;
829 u8 lock_time;
830};
831 808
832struct power_state { 809struct power_state {
833 union clk_pin_cntl_u clk_pin_cntl; 810 union clk_pin_cntl_u clk_pin_cntl;
@@ -835,317 +812,275 @@ struct power_state {
835 union pll_cntl_u pll_cntl; 812 union pll_cntl_u pll_cntl;
836 union sclk_cntl_u sclk_cntl; 813 union sclk_cntl_u sclk_cntl;
837 union pclk_cntl_u pclk_cntl; 814 union pclk_cntl_u pclk_cntl;
838 union clk_test_cntl_u clk_test_cntl;
839 union pwrmgt_cntl_u pwrmgt_cntl; 815 union pwrmgt_cntl_u pwrmgt_cntl;
840 u32 freq; /* Fout for PLL calibration */ 816 int auto_mode; /* system clock auto changing? */
841 u8 tf100; /* for pll calibration */
842 u8 tf80; /* for pll calibration */
843 u8 tf20; /* for pll calibration */
844 u8 M; /* for pll calibration */
845 u8 N_int; /* for pll calibration */
846 u8 N_fac; /* for pll calibration */
847 u8 lock_time; /* for pll calibration */
848 u8 tfgoal; /* for pll calibration */
849 u8 auto_mode; /* hardware auto switch? */
850 u8 pwm_mode; /* 0 fast, 1 normal/slow */
851 u16 fast_sclk; /* fast clk freq */
852 u16 norm_sclk; /* slow clk freq */
853}; 817};
854 818
855 819
856/*
857 * Global state variables
858 */
859
860static struct power_state w100_pwr_state; 820static struct power_state w100_pwr_state;
861 821
862/* This table is specific for 12.5MHz ref crystal. */ 822/* The PLL Fout is determined by (XtalFreq/(M+1)) * ((N_int+1) + (N_fac/8)) */
863static struct pll_parm gPLLTable[] = { 823
864 /*freq M N_int N_fac tfgoal lock_time */ 824/* 12.5MHz Crystal PLL Table */
865 { 50, 0, 1, 0, 0xE0, 56}, /* 50.00 MHz */ 825static struct w100_pll_info xtal_12500000[] = {
866 { 75, 0, 5, 0, 0xDE, 37}, /* 75.00 MHz */ 826 /*freq M N_int N_fac tfgoal lock_time */
867 {100, 0, 7, 0, 0xE0, 28}, /* 100.00 MHz */ 827 { 50, 0, 1, 0, 0xe0, 56}, /* 50.00 MHz */
868 {125, 0, 9, 0, 0xE0, 22}, /* 125.00 MHz */ 828 { 75, 0, 5, 0, 0xde, 37}, /* 75.00 MHz */
869 {150, 0, 11, 0, 0xE0, 17}, /* 150.00 MHz */ 829 {100, 0, 7, 0, 0xe0, 28}, /* 100.00 MHz */
870 { 0, 0, 0, 0, 0, 0} /* Terminator */ 830 {125, 0, 9, 0, 0xe0, 22}, /* 125.00 MHz */
831 {150, 0, 11, 0, 0xe0, 17}, /* 150.00 MHz */
832 { 0, 0, 0, 0, 0, 0}, /* Terminator */
871}; 833};
872 834
835/* 14.318MHz Crystal PLL Table */
836static struct w100_pll_info xtal_14318000[] = {
837 /*freq M N_int N_fac tfgoal lock_time */
838 { 40, 4, 13, 0, 0xe0, 80}, /* tfgoal guessed */
839 { 50, 1, 6, 0, 0xe0, 64}, /* 50.05 MHz */
840 { 57, 2, 11, 0, 0xe0, 53}, /* tfgoal guessed */
841 { 75, 0, 4, 3, 0xe0, 43}, /* 75.08 MHz */
842 {100, 0, 6, 0, 0xe0, 32}, /* 100.10 MHz */
843 { 0, 0, 0, 0, 0, 0},
844};
873 845
874static u8 w100_pll_get_testcount(u8 testclk_sel) 846/* 16MHz Crystal PLL Table */
847static struct w100_pll_info xtal_16000000[] = {
848 /*freq M N_int N_fac tfgoal lock_time */
849 { 72, 1, 8, 0, 0xe0, 48}, /* tfgoal guessed */
850 { 95, 1, 10, 7, 0xe0, 38}, /* tfgoal guessed */
851 { 96, 1, 11, 0, 0xe0, 36}, /* tfgoal guessed */
852 { 0, 0, 0, 0, 0, 0},
853};
854
855static struct pll_entries {
856 int xtal_freq;
857 struct w100_pll_info *pll_table;
858} w100_pll_tables[] = {
859 { 12500000, &xtal_12500000[0] },
860 { 14318000, &xtal_14318000[0] },
861 { 16000000, &xtal_16000000[0] },
862 { 0 },
863};
864
865struct w100_pll_info *w100_get_xtal_table(unsigned int freq)
875{ 866{
867 struct pll_entries *pll_entry = w100_pll_tables;
868
869 do {
870 if (freq == pll_entry->xtal_freq)
871 return pll_entry->pll_table;
872 pll_entry++;
873 } while (pll_entry->xtal_freq);
874 return 0;
875}
876
877
878static unsigned int w100_get_testcount(unsigned int testclk_sel)
879{
880 union clk_test_cntl_u clk_test_cntl;
881
876 udelay(5); 882 udelay(5);
877 883
878 w100_pwr_state.clk_test_cntl.f.start_check_freq = 0x0; 884 /* Select the test clock source and reset */
879 w100_pwr_state.clk_test_cntl.f.testclk_sel = testclk_sel; 885 clk_test_cntl.f.start_check_freq = 0x0;
880 w100_pwr_state.clk_test_cntl.f.tstcount_rst = 0x1; /*reset test count */ 886 clk_test_cntl.f.testclk_sel = testclk_sel;
881 writel((u32) (w100_pwr_state.clk_test_cntl.val), remapped_regs + mmCLK_TEST_CNTL); 887 clk_test_cntl.f.tstcount_rst = 0x1; /* set reset */
882 w100_pwr_state.clk_test_cntl.f.tstcount_rst = 0x0; 888 writel((u32) (clk_test_cntl.val), remapped_regs + mmCLK_TEST_CNTL);
883 writel((u32) (w100_pwr_state.clk_test_cntl.val), remapped_regs + mmCLK_TEST_CNTL);
884 889
885 w100_pwr_state.clk_test_cntl.f.start_check_freq = 0x1; 890 clk_test_cntl.f.tstcount_rst = 0x0; /* clear reset */
886 writel((u32) (w100_pwr_state.clk_test_cntl.val), remapped_regs + mmCLK_TEST_CNTL); 891 writel((u32) (clk_test_cntl.val), remapped_regs + mmCLK_TEST_CNTL);
887 892
893 /* Run clock test */
894 clk_test_cntl.f.start_check_freq = 0x1;
895 writel((u32) (clk_test_cntl.val), remapped_regs + mmCLK_TEST_CNTL);
896
897 /* Give the test time to complete */
888 udelay(20); 898 udelay(20);
889 899
890 w100_pwr_state.clk_test_cntl.val = readl(remapped_regs + mmCLK_TEST_CNTL); 900 /* Return the result */
891 w100_pwr_state.clk_test_cntl.f.start_check_freq = 0x0; 901 clk_test_cntl.val = readl(remapped_regs + mmCLK_TEST_CNTL);
892 writel((u32) (w100_pwr_state.clk_test_cntl.val), remapped_regs + mmCLK_TEST_CNTL); 902 clk_test_cntl.f.start_check_freq = 0x0;
903 writel((u32) (clk_test_cntl.val), remapped_regs + mmCLK_TEST_CNTL);
893 904
894 return w100_pwr_state.clk_test_cntl.f.test_count; 905 return clk_test_cntl.f.test_count;
895} 906}
896 907
897 908
898static u8 w100_pll_adjust(void) 909static int w100_pll_adjust(struct w100_pll_info *pll)
899{ 910{
911 unsigned int tf80;
912 unsigned int tf20;
913
914 /* Initial Settings */
915 w100_pwr_state.pll_cntl.f.pll_pwdn = 0x0; /* power down */
916 w100_pwr_state.pll_cntl.f.pll_reset = 0x0; /* not reset */
917 w100_pwr_state.pll_cntl.f.pll_tcpoff = 0x1; /* Hi-Z */
918 w100_pwr_state.pll_cntl.f.pll_pvg = 0x0; /* VCO gain = 0 */
919 w100_pwr_state.pll_cntl.f.pll_vcofr = 0x0; /* VCO frequency range control = off */
920 w100_pwr_state.pll_cntl.f.pll_ioffset = 0x0; /* current offset inside VCO = 0 */
921 w100_pwr_state.pll_cntl.f.pll_ring_off = 0x0;
922
923 /* Wai Ming 80 percent of VDD 1.3V gives 1.04V, minimum operating voltage is 1.08V
924 * therefore, commented out the following lines
925 * tf80 meant tf100
926 */
900 do { 927 do {
901 /* Wai Ming 80 percent of VDD 1.3V gives 1.04V, minimum operating voltage is 1.08V 928 /* set VCO input = 0.8 * VDD */
902 * therefore, commented out the following lines
903 * tf80 meant tf100
904 * set VCO input = 0.8 * VDD
905 */
906 w100_pwr_state.pll_cntl.f.pll_dactal = 0xd; 929 w100_pwr_state.pll_cntl.f.pll_dactal = 0xd;
907 writel((u32) (w100_pwr_state.pll_cntl.val), remapped_regs + mmPLL_CNTL); 930 writel((u32) (w100_pwr_state.pll_cntl.val), remapped_regs + mmPLL_CNTL);
908 931
909 w100_pwr_state.tf80 = w100_pll_get_testcount(0x1); /* PLLCLK */ 932 tf80 = w100_get_testcount(TESTCLK_SRC_PLL);
910 if (w100_pwr_state.tf80 >= (w100_pwr_state.tfgoal)) { 933 if (tf80 >= (pll->tfgoal)) {
911 /* set VCO input = 0.2 * VDD */ 934 /* set VCO input = 0.2 * VDD */
912 w100_pwr_state.pll_cntl.f.pll_dactal = 0x7; 935 w100_pwr_state.pll_cntl.f.pll_dactal = 0x7;
913 writel((u32) (w100_pwr_state.pll_cntl.val), remapped_regs + mmPLL_CNTL); 936 writel((u32) (w100_pwr_state.pll_cntl.val), remapped_regs + mmPLL_CNTL);
914 937
915 w100_pwr_state.tf20 = w100_pll_get_testcount(0x1); /* PLLCLK */ 938 tf20 = w100_get_testcount(TESTCLK_SRC_PLL);
916 if (w100_pwr_state.tf20 <= (w100_pwr_state.tfgoal)) 939 if (tf20 <= (pll->tfgoal))
917 return 1; // Success 940 return 1; /* Success */
918 941
919 if ((w100_pwr_state.pll_cntl.f.pll_vcofr == 0x0) && 942 if ((w100_pwr_state.pll_cntl.f.pll_vcofr == 0x0) &&
920 ((w100_pwr_state.pll_cntl.f.pll_pvg == 0x7) || 943 ((w100_pwr_state.pll_cntl.f.pll_pvg == 0x7) ||
921 (w100_pwr_state.pll_cntl.f.pll_ioffset == 0x0))) { 944 (w100_pwr_state.pll_cntl.f.pll_ioffset == 0x0))) {
922 /* slow VCO config */ 945 /* slow VCO config */
923 w100_pwr_state.pll_cntl.f.pll_vcofr = 0x1; 946 w100_pwr_state.pll_cntl.f.pll_vcofr = 0x1;
924 w100_pwr_state.pll_cntl.f.pll_pvg = 0x0; 947 w100_pwr_state.pll_cntl.f.pll_pvg = 0x0;
925 w100_pwr_state.pll_cntl.f.pll_ioffset = 0x0; 948 w100_pwr_state.pll_cntl.f.pll_ioffset = 0x0;
926 writel((u32) (w100_pwr_state.pll_cntl.val),
927 remapped_regs + mmPLL_CNTL);
928 continue; 949 continue;
929 } 950 }
930 } 951 }
931 if ((w100_pwr_state.pll_cntl.f.pll_ioffset) < 0x3) { 952 if ((w100_pwr_state.pll_cntl.f.pll_ioffset) < 0x3) {
932 w100_pwr_state.pll_cntl.f.pll_ioffset += 0x1; 953 w100_pwr_state.pll_cntl.f.pll_ioffset += 0x1;
933 writel((u32) (w100_pwr_state.pll_cntl.val), remapped_regs + mmPLL_CNTL); 954 } else if ((w100_pwr_state.pll_cntl.f.pll_pvg) < 0x7) {
934 continue;
935 }
936 if ((w100_pwr_state.pll_cntl.f.pll_pvg) < 0x7) {
937 w100_pwr_state.pll_cntl.f.pll_ioffset = 0x0; 955 w100_pwr_state.pll_cntl.f.pll_ioffset = 0x0;
938 w100_pwr_state.pll_cntl.f.pll_pvg += 0x1; 956 w100_pwr_state.pll_cntl.f.pll_pvg += 0x1;
939 writel((u32) (w100_pwr_state.pll_cntl.val), remapped_regs + mmPLL_CNTL); 957 } else {
940 continue; 958 return 0; /* Error */
941 } 959 }
942 return 0; // error
943 } while(1); 960 } while(1);
944} 961}
945 962
946 963
947/* 964/*
948 * w100_pll_calibration 965 * w100_pll_calibration
949 * freq = target frequency of the PLL
950 * (note: crystal = 14.3MHz)
951 */ 966 */
952static u8 w100_pll_calibration(u32 freq) 967static int w100_pll_calibration(struct w100_pll_info *pll)
953{ 968{
954 u8 status; 969 int status;
955
956 /* initial setting */
957 w100_pwr_state.pll_cntl.f.pll_pwdn = 0x0; /* power down */
958 w100_pwr_state.pll_cntl.f.pll_reset = 0x0; /* not reset */
959 w100_pwr_state.pll_cntl.f.pll_tcpoff = 0x1; /* Hi-Z */
960 w100_pwr_state.pll_cntl.f.pll_pvg = 0x0; /* VCO gain = 0 */
961 w100_pwr_state.pll_cntl.f.pll_vcofr = 0x0; /* VCO frequency range control = off */
962 w100_pwr_state.pll_cntl.f.pll_ioffset = 0x0; /* current offset inside VCO = 0 */
963 w100_pwr_state.pll_cntl.f.pll_ring_off = 0x0;
964 writel((u32) (w100_pwr_state.pll_cntl.val), remapped_regs + mmPLL_CNTL);
965 970
966 /* check for (tf80 >= tfgoal) && (tf20 =< tfgoal) */ 971 status = w100_pll_adjust(pll);
967 if ((w100_pwr_state.tf80 < w100_pwr_state.tfgoal) || (w100_pwr_state.tf20 > w100_pwr_state.tfgoal)) {
968 status=w100_pll_adjust();
969 }
970 /* PLL Reset And Lock */
971 972
973 /* PLL Reset And Lock */
972 /* set VCO input = 0.5 * VDD */ 974 /* set VCO input = 0.5 * VDD */
973 w100_pwr_state.pll_cntl.f.pll_dactal = 0xa; 975 w100_pwr_state.pll_cntl.f.pll_dactal = 0xa;
974 writel((u32) (w100_pwr_state.pll_cntl.val), remapped_regs + mmPLL_CNTL); 976 writel((u32) (w100_pwr_state.pll_cntl.val), remapped_regs + mmPLL_CNTL);
975 977
976 /* reset time */ 978 udelay(1); /* reset time */
977 udelay(1);
978 979
979 /* enable charge pump */ 980 /* enable charge pump */
980 w100_pwr_state.pll_cntl.f.pll_tcpoff = 0x0; /* normal */ 981 w100_pwr_state.pll_cntl.f.pll_tcpoff = 0x0; /* normal */
981 writel((u32) (w100_pwr_state.pll_cntl.val), remapped_regs + mmPLL_CNTL); 982 writel((u32) (w100_pwr_state.pll_cntl.val), remapped_regs + mmPLL_CNTL);
982 983
983 /* set VCO input = Hi-Z */ 984 /* set VCO input = Hi-Z, disable DAC */
984 /* disable DAC */
985 w100_pwr_state.pll_cntl.f.pll_dactal = 0x0; 985 w100_pwr_state.pll_cntl.f.pll_dactal = 0x0;
986 writel((u32) (w100_pwr_state.pll_cntl.val), remapped_regs + mmPLL_CNTL); 986 writel((u32) (w100_pwr_state.pll_cntl.val), remapped_regs + mmPLL_CNTL);
987 987
988 /* lock time */ 988 udelay(400); /* lock time */
989 udelay(400); /* delay 400 us */
990 989
991 /* PLL locked */ 990 /* PLL locked */
992 991
993 w100_pwr_state.sclk_cntl.f.sclk_src_sel = 0x1; /* PLL clock */
994 writel((u32) (w100_pwr_state.sclk_cntl.val), remapped_regs + mmSCLK_CNTL);
995
996 w100_pwr_state.tf100 = w100_pll_get_testcount(0x1); /* PLLCLK */
997
998 return status; 992 return status;
999} 993}
1000 994
1001 995
1002static u8 w100_pll_set_clk(void) 996static int w100_pll_set_clk(struct w100_pll_info *pll)
1003{ 997{
1004 u8 status; 998 int status;
1005 999
1006 if (w100_pwr_state.auto_mode == 1) /* auto mode */ 1000 if (w100_pwr_state.auto_mode == 1) /* auto mode */
1007 { 1001 {
1008 w100_pwr_state.pwrmgt_cntl.f.pwm_fast_noml_hw_en = 0x0; /* disable fast to normal */ 1002 w100_pwr_state.pwrmgt_cntl.f.pwm_fast_noml_hw_en = 0x0; /* disable fast to normal */
1009 w100_pwr_state.pwrmgt_cntl.f.pwm_noml_fast_hw_en = 0x0; /* disable normal to fast */ 1003 w100_pwr_state.pwrmgt_cntl.f.pwm_noml_fast_hw_en = 0x0; /* disable normal to fast */
1010 writel((u32) (w100_pwr_state.pwrmgt_cntl.val), remapped_regs + mmPWRMGT_CNTL); 1004 writel((u32) (w100_pwr_state.pwrmgt_cntl.val), remapped_regs + mmPWRMGT_CNTL);
1011 } 1005 }
1012 1006
1013 w100_pwr_state.sclk_cntl.f.sclk_src_sel = 0x0; /* crystal clock */ 1007 /* Set system clock source to XTAL whilst adjusting the PLL! */
1008 w100_pwr_state.sclk_cntl.f.sclk_src_sel = CLK_SRC_XTAL;
1014 writel((u32) (w100_pwr_state.sclk_cntl.val), remapped_regs + mmSCLK_CNTL); 1009 writel((u32) (w100_pwr_state.sclk_cntl.val), remapped_regs + mmSCLK_CNTL);
1015 1010
1016 w100_pwr_state.pll_ref_fb_div.f.pll_ref_div = w100_pwr_state.M; 1011 w100_pwr_state.pll_ref_fb_div.f.pll_ref_div = pll->M;
1017 w100_pwr_state.pll_ref_fb_div.f.pll_fb_div_int = w100_pwr_state.N_int; 1012 w100_pwr_state.pll_ref_fb_div.f.pll_fb_div_int = pll->N_int;
1018 w100_pwr_state.pll_ref_fb_div.f.pll_fb_div_frac = w100_pwr_state.N_fac; 1013 w100_pwr_state.pll_ref_fb_div.f.pll_fb_div_frac = pll->N_fac;
1019 w100_pwr_state.pll_ref_fb_div.f.pll_lock_time = w100_pwr_state.lock_time; 1014 w100_pwr_state.pll_ref_fb_div.f.pll_lock_time = pll->lock_time;
1020 writel((u32) (w100_pwr_state.pll_ref_fb_div.val), remapped_regs + mmPLL_REF_FB_DIV); 1015 writel((u32) (w100_pwr_state.pll_ref_fb_div.val), remapped_regs + mmPLL_REF_FB_DIV);
1021 1016
1022 w100_pwr_state.pwrmgt_cntl.f.pwm_mode_req = 0; 1017 w100_pwr_state.pwrmgt_cntl.f.pwm_mode_req = 0;
1023 writel((u32) (w100_pwr_state.pwrmgt_cntl.val), remapped_regs + mmPWRMGT_CNTL); 1018 writel((u32) (w100_pwr_state.pwrmgt_cntl.val), remapped_regs + mmPWRMGT_CNTL);
1024 1019
1025 status = w100_pll_calibration (w100_pwr_state.freq); 1020 status = w100_pll_calibration(pll);
1026 1021
1027 if (w100_pwr_state.auto_mode == 1) /* auto mode */ 1022 if (w100_pwr_state.auto_mode == 1) /* auto mode */
1028 { 1023 {
1029 w100_pwr_state.pwrmgt_cntl.f.pwm_fast_noml_hw_en = 0x1; /* reenable fast to normal */ 1024 w100_pwr_state.pwrmgt_cntl.f.pwm_fast_noml_hw_en = 0x1; /* reenable fast to normal */
1030 w100_pwr_state.pwrmgt_cntl.f.pwm_noml_fast_hw_en = 0x1; /* reenable normal to fast */ 1025 w100_pwr_state.pwrmgt_cntl.f.pwm_noml_fast_hw_en = 0x1; /* reenable normal to fast */
1031 writel((u32) (w100_pwr_state.pwrmgt_cntl.val), remapped_regs + mmPWRMGT_CNTL); 1026 writel((u32) (w100_pwr_state.pwrmgt_cntl.val), remapped_regs + mmPWRMGT_CNTL);
1032 } 1027 }
1033 return status; 1028 return status;
1034} 1029}
1035 1030
1036 1031/* freq = target frequency of the PLL */
1037/* assume reference crystal clk is 12.5MHz, 1032static int w100_set_pll_freq(struct w100fb_par *par, unsigned int freq)
1038 * and that doubling is not enabled.
1039 *
1040 * Freq = 12 == 12.5MHz.
1041 */
1042static u16 w100_set_slowsysclk(u16 freq)
1043{
1044 if (w100_pwr_state.norm_sclk == freq)
1045 return freq;
1046
1047 if (w100_pwr_state.auto_mode == 1) /* auto mode */
1048 return 0;
1049
1050 if (freq == 12) {
1051 w100_pwr_state.norm_sclk = freq;
1052 w100_pwr_state.sclk_cntl.f.sclk_post_div_slow = 0x0; /* Pslow = 1 */
1053 w100_pwr_state.sclk_cntl.f.sclk_src_sel = 0x0; /* crystal src */
1054
1055 writel((u32) (w100_pwr_state.sclk_cntl.val), remapped_regs + mmSCLK_CNTL);
1056
1057 w100_pwr_state.clk_pin_cntl.f.xtalin_pm_en = 0x1;
1058 writel((u32) (w100_pwr_state.clk_pin_cntl.val), remapped_regs + mmCLK_PIN_CNTL);
1059
1060 w100_pwr_state.pwrmgt_cntl.f.pwm_enable = 0x1;
1061 w100_pwr_state.pwrmgt_cntl.f.pwm_mode_req = 0x1;
1062 writel((u32) (w100_pwr_state.pwrmgt_cntl.val), remapped_regs + mmPWRMGT_CNTL);
1063 w100_pwr_state.pwm_mode = 1; /* normal mode */
1064 return freq;
1065 } else
1066 return 0;
1067}
1068
1069
1070static u16 w100_set_fastsysclk(u16 freq)
1071{ 1033{
1072 u16 pll_freq; 1034 struct w100_pll_info *pll = par->pll_table;
1073 int i;
1074
1075 while(1) {
1076 pll_freq = (u16) (freq * (w100_pwr_state.sclk_cntl.f.sclk_post_div_fast + 1));
1077 i = 0;
1078 do {
1079 if (pll_freq == gPLLTable[i].freq) {
1080 w100_pwr_state.freq = gPLLTable[i].freq * 1000000;
1081 w100_pwr_state.M = gPLLTable[i].M;
1082 w100_pwr_state.N_int = gPLLTable[i].N_int;
1083 w100_pwr_state.N_fac = gPLLTable[i].N_fac;
1084 w100_pwr_state.tfgoal = gPLLTable[i].tfgoal;
1085 w100_pwr_state.lock_time = gPLLTable[i].lock_time;
1086 w100_pwr_state.tf20 = 0xff; /* set highest */
1087 w100_pwr_state.tf80 = 0x00; /* set lowest */
1088
1089 w100_pll_set_clk();
1090 w100_pwr_state.pwm_mode = 0; /* fast mode */
1091 w100_pwr_state.fast_sclk = freq;
1092 return freq;
1093 }
1094 i++;
1095 } while(gPLLTable[i].freq);
1096 1035
1097 if (w100_pwr_state.auto_mode == 1) 1036 do {
1098 break; 1037 if (freq == pll->freq) {
1099 1038 return w100_pll_set_clk(pll);
1100 if (w100_pwr_state.sclk_cntl.f.sclk_post_div_fast == 0) 1039 }
1101 break; 1040 pll++;
1102 1041 } while(pll->freq);
1103 w100_pwr_state.sclk_cntl.f.sclk_post_div_fast -= 1;
1104 writel((u32) (w100_pwr_state.sclk_cntl.val), remapped_regs + mmSCLK_CNTL);
1105 }
1106 return 0; 1042 return 0;
1107} 1043}
1108 1044
1109
1110/* Set up an initial state. Some values/fields set 1045/* Set up an initial state. Some values/fields set
1111 here will be overwritten. */ 1046 here will be overwritten. */
1112static void w100_pwm_setup(void) 1047static void w100_pwm_setup(struct w100fb_par *par)
1113{ 1048{
1114 w100_pwr_state.clk_pin_cntl.f.osc_en = 0x1; 1049 w100_pwr_state.clk_pin_cntl.f.osc_en = 0x1;
1115 w100_pwr_state.clk_pin_cntl.f.osc_gain = 0x1f; 1050 w100_pwr_state.clk_pin_cntl.f.osc_gain = 0x1f;
1116 w100_pwr_state.clk_pin_cntl.f.dont_use_xtalin = 0x0; 1051 w100_pwr_state.clk_pin_cntl.f.dont_use_xtalin = 0x0;
1117 w100_pwr_state.clk_pin_cntl.f.xtalin_pm_en = 0x0; 1052 w100_pwr_state.clk_pin_cntl.f.xtalin_pm_en = 0x0;
1118 w100_pwr_state.clk_pin_cntl.f.xtalin_dbl_en = 0x0; /* no freq doubling */ 1053 w100_pwr_state.clk_pin_cntl.f.xtalin_dbl_en = par->mach->xtal_dbl ? 1 : 0;
1119 w100_pwr_state.clk_pin_cntl.f.cg_debug = 0x0; 1054 w100_pwr_state.clk_pin_cntl.f.cg_debug = 0x0;
1120 writel((u32) (w100_pwr_state.clk_pin_cntl.val), remapped_regs + mmCLK_PIN_CNTL); 1055 writel((u32) (w100_pwr_state.clk_pin_cntl.val), remapped_regs + mmCLK_PIN_CNTL);
1121 1056
1122 w100_pwr_state.sclk_cntl.f.sclk_src_sel = 0x0; /* Crystal Clk */ 1057 w100_pwr_state.sclk_cntl.f.sclk_src_sel = CLK_SRC_XTAL;
1123 w100_pwr_state.sclk_cntl.f.sclk_post_div_fast = 0x0; /* Pfast = 1 */ 1058 w100_pwr_state.sclk_cntl.f.sclk_post_div_fast = 0x0; /* Pfast = 1 */
1124 w100_pwr_state.sclk_cntl.f.sclk_clkon_hys = 0x3; 1059 w100_pwr_state.sclk_cntl.f.sclk_clkon_hys = 0x3;
1125 w100_pwr_state.sclk_cntl.f.sclk_post_div_slow = 0x0; /* Pslow = 1 */ 1060 w100_pwr_state.sclk_cntl.f.sclk_post_div_slow = 0x0; /* Pslow = 1 */
1126 w100_pwr_state.sclk_cntl.f.disp_cg_ok2switch_en = 0x0; 1061 w100_pwr_state.sclk_cntl.f.disp_cg_ok2switch_en = 0x0;
1127 w100_pwr_state.sclk_cntl.f.sclk_force_reg = 0x0; /* Dynamic */ 1062 w100_pwr_state.sclk_cntl.f.sclk_force_reg = 0x0; /* Dynamic */
1128 w100_pwr_state.sclk_cntl.f.sclk_force_disp = 0x0; /* Dynamic */ 1063 w100_pwr_state.sclk_cntl.f.sclk_force_disp = 0x0; /* Dynamic */
1129 w100_pwr_state.sclk_cntl.f.sclk_force_mc = 0x0; /* Dynamic */ 1064 w100_pwr_state.sclk_cntl.f.sclk_force_mc = 0x0; /* Dynamic */
1130 w100_pwr_state.sclk_cntl.f.sclk_force_extmc = 0x0; /* Dynamic */ 1065 w100_pwr_state.sclk_cntl.f.sclk_force_extmc = 0x0; /* Dynamic */
1131 w100_pwr_state.sclk_cntl.f.sclk_force_cp = 0x0; /* Dynamic */ 1066 w100_pwr_state.sclk_cntl.f.sclk_force_cp = 0x0; /* Dynamic */
1132 w100_pwr_state.sclk_cntl.f.sclk_force_e2 = 0x0; /* Dynamic */ 1067 w100_pwr_state.sclk_cntl.f.sclk_force_e2 = 0x0; /* Dynamic */
1133 w100_pwr_state.sclk_cntl.f.sclk_force_e3 = 0x0; /* Dynamic */ 1068 w100_pwr_state.sclk_cntl.f.sclk_force_e3 = 0x0; /* Dynamic */
1134 w100_pwr_state.sclk_cntl.f.sclk_force_idct = 0x0; /* Dynamic */ 1069 w100_pwr_state.sclk_cntl.f.sclk_force_idct = 0x0; /* Dynamic */
1135 w100_pwr_state.sclk_cntl.f.sclk_force_bist = 0x0; /* Dynamic */ 1070 w100_pwr_state.sclk_cntl.f.sclk_force_bist = 0x0; /* Dynamic */
1136 w100_pwr_state.sclk_cntl.f.busy_extend_cp = 0x0; 1071 w100_pwr_state.sclk_cntl.f.busy_extend_cp = 0x0;
1137 w100_pwr_state.sclk_cntl.f.busy_extend_e2 = 0x0; 1072 w100_pwr_state.sclk_cntl.f.busy_extend_e2 = 0x0;
1138 w100_pwr_state.sclk_cntl.f.busy_extend_e3 = 0x0; 1073 w100_pwr_state.sclk_cntl.f.busy_extend_e3 = 0x0;
1139 w100_pwr_state.sclk_cntl.f.busy_extend_idct = 0x0; 1074 w100_pwr_state.sclk_cntl.f.busy_extend_idct = 0x0;
1140 writel((u32) (w100_pwr_state.sclk_cntl.val), remapped_regs + mmSCLK_CNTL); 1075 writel((u32) (w100_pwr_state.sclk_cntl.val), remapped_regs + mmSCLK_CNTL);
1141 1076
1142 w100_pwr_state.pclk_cntl.f.pclk_src_sel = 0x0; /* Crystal Clk */ 1077 w100_pwr_state.pclk_cntl.f.pclk_src_sel = CLK_SRC_XTAL;
1143 w100_pwr_state.pclk_cntl.f.pclk_post_div = 0x1; /* P = 2 */ 1078 w100_pwr_state.pclk_cntl.f.pclk_post_div = 0x1; /* P = 2 */
1144 w100_pwr_state.pclk_cntl.f.pclk_force_disp = 0x0; /* Dynamic */ 1079 w100_pwr_state.pclk_cntl.f.pclk_force_disp = 0x0; /* Dynamic */
1145 writel((u32) (w100_pwr_state.pclk_cntl.val), remapped_regs + mmPCLK_CNTL); 1080 writel((u32) (w100_pwr_state.pclk_cntl.val), remapped_regs + mmPCLK_CNTL);
1146 1081
1147 w100_pwr_state.pll_ref_fb_div.f.pll_ref_div = 0x0; /* M = 1 */ 1082 w100_pwr_state.pll_ref_fb_div.f.pll_ref_div = 0x0; /* M = 1 */
1148 w100_pwr_state.pll_ref_fb_div.f.pll_fb_div_int = 0x0; /* N = 1.0 */ 1083 w100_pwr_state.pll_ref_fb_div.f.pll_fb_div_int = 0x0; /* N = 1.0 */
1149 w100_pwr_state.pll_ref_fb_div.f.pll_fb_div_frac = 0x0; 1084 w100_pwr_state.pll_ref_fb_div.f.pll_fb_div_frac = 0x0;
1150 w100_pwr_state.pll_ref_fb_div.f.pll_reset_time = 0x5; 1085 w100_pwr_state.pll_ref_fb_div.f.pll_reset_time = 0x5;
1151 w100_pwr_state.pll_ref_fb_div.f.pll_lock_time = 0xff; 1086 w100_pwr_state.pll_ref_fb_div.f.pll_lock_time = 0xff;
@@ -1154,7 +1089,7 @@ static void w100_pwm_setup(void)
1154 w100_pwr_state.pll_cntl.f.pll_pwdn = 0x1; 1089 w100_pwr_state.pll_cntl.f.pll_pwdn = 0x1;
1155 w100_pwr_state.pll_cntl.f.pll_reset = 0x1; 1090 w100_pwr_state.pll_cntl.f.pll_reset = 0x1;
1156 w100_pwr_state.pll_cntl.f.pll_pm_en = 0x0; 1091 w100_pwr_state.pll_cntl.f.pll_pm_en = 0x0;
1157 w100_pwr_state.pll_cntl.f.pll_mode = 0x0; /* uses VCO clock */ 1092 w100_pwr_state.pll_cntl.f.pll_mode = 0x0; /* uses VCO clock */
1158 w100_pwr_state.pll_cntl.f.pll_refclk_sel = 0x0; 1093 w100_pwr_state.pll_cntl.f.pll_refclk_sel = 0x0;
1159 w100_pwr_state.pll_cntl.f.pll_fbclk_sel = 0x0; 1094 w100_pwr_state.pll_cntl.f.pll_fbclk_sel = 0x0;
1160 w100_pwr_state.pll_cntl.f.pll_tcpoff = 0x0; 1095 w100_pwr_state.pll_cntl.f.pll_tcpoff = 0x0;
@@ -1164,220 +1099,275 @@ static void w100_pwm_setup(void)
1164 w100_pwr_state.pll_cntl.f.pll_ioffset = 0x0; 1099 w100_pwr_state.pll_cntl.f.pll_ioffset = 0x0;
1165 w100_pwr_state.pll_cntl.f.pll_pecc_mode = 0x0; 1100 w100_pwr_state.pll_cntl.f.pll_pecc_mode = 0x0;
1166 w100_pwr_state.pll_cntl.f.pll_pecc_scon = 0x0; 1101 w100_pwr_state.pll_cntl.f.pll_pecc_scon = 0x0;
1167 w100_pwr_state.pll_cntl.f.pll_dactal = 0x0; /* Hi-Z */ 1102 w100_pwr_state.pll_cntl.f.pll_dactal = 0x0; /* Hi-Z */
1168 w100_pwr_state.pll_cntl.f.pll_cp_clip = 0x3; 1103 w100_pwr_state.pll_cntl.f.pll_cp_clip = 0x3;
1169 w100_pwr_state.pll_cntl.f.pll_conf = 0x2; 1104 w100_pwr_state.pll_cntl.f.pll_conf = 0x2;
1170 w100_pwr_state.pll_cntl.f.pll_mbctrl = 0x2; 1105 w100_pwr_state.pll_cntl.f.pll_mbctrl = 0x2;
1171 w100_pwr_state.pll_cntl.f.pll_ring_off = 0x0; 1106 w100_pwr_state.pll_cntl.f.pll_ring_off = 0x0;
1172 writel((u32) (w100_pwr_state.pll_cntl.val), remapped_regs + mmPLL_CNTL); 1107 writel((u32) (w100_pwr_state.pll_cntl.val), remapped_regs + mmPLL_CNTL);
1173 1108
1174 w100_pwr_state.clk_test_cntl.f.testclk_sel = 0x1; /* PLLCLK (for testing) */
1175 w100_pwr_state.clk_test_cntl.f.start_check_freq = 0x0;
1176 w100_pwr_state.clk_test_cntl.f.tstcount_rst = 0x0;
1177 writel((u32) (w100_pwr_state.clk_test_cntl.val), remapped_regs + mmCLK_TEST_CNTL);
1178
1179 w100_pwr_state.pwrmgt_cntl.f.pwm_enable = 0x0; 1109 w100_pwr_state.pwrmgt_cntl.f.pwm_enable = 0x0;
1180 w100_pwr_state.pwrmgt_cntl.f.pwm_mode_req = 0x1; /* normal mode (0, 1, 3) */ 1110 w100_pwr_state.pwrmgt_cntl.f.pwm_mode_req = 0x1; /* normal mode (0, 1, 3) */
1181 w100_pwr_state.pwrmgt_cntl.f.pwm_wakeup_cond = 0x0; 1111 w100_pwr_state.pwrmgt_cntl.f.pwm_wakeup_cond = 0x0;
1182 w100_pwr_state.pwrmgt_cntl.f.pwm_fast_noml_hw_en = 0x0; 1112 w100_pwr_state.pwrmgt_cntl.f.pwm_fast_noml_hw_en = 0x0;
1183 w100_pwr_state.pwrmgt_cntl.f.pwm_noml_fast_hw_en = 0x0; 1113 w100_pwr_state.pwrmgt_cntl.f.pwm_noml_fast_hw_en = 0x0;
1184 w100_pwr_state.pwrmgt_cntl.f.pwm_fast_noml_cond = 0x1; /* PM4,ENG */ 1114 w100_pwr_state.pwrmgt_cntl.f.pwm_fast_noml_cond = 0x1; /* PM4,ENG */
1185 w100_pwr_state.pwrmgt_cntl.f.pwm_noml_fast_cond = 0x1; /* PM4,ENG */ 1115 w100_pwr_state.pwrmgt_cntl.f.pwm_noml_fast_cond = 0x1; /* PM4,ENG */
1186 w100_pwr_state.pwrmgt_cntl.f.pwm_idle_timer = 0xFF; 1116 w100_pwr_state.pwrmgt_cntl.f.pwm_idle_timer = 0xFF;
1187 w100_pwr_state.pwrmgt_cntl.f.pwm_busy_timer = 0xFF; 1117 w100_pwr_state.pwrmgt_cntl.f.pwm_busy_timer = 0xFF;
1188 writel((u32) (w100_pwr_state.pwrmgt_cntl.val), remapped_regs + mmPWRMGT_CNTL); 1118 writel((u32) (w100_pwr_state.pwrmgt_cntl.val), remapped_regs + mmPWRMGT_CNTL);
1189 1119
1190 w100_pwr_state.auto_mode = 0; /* manual mode */ 1120 w100_pwr_state.auto_mode = 0; /* manual mode */
1191 w100_pwr_state.pwm_mode = 1; /* normal mode (0, 1, 2) */
1192 w100_pwr_state.freq = 50000000; /* 50 MHz */
1193 w100_pwr_state.M = 3; /* M = 4 */
1194 w100_pwr_state.N_int = 6; /* N = 7.0 */
1195 w100_pwr_state.N_fac = 0;
1196 w100_pwr_state.tfgoal = 0xE0;
1197 w100_pwr_state.lock_time = 56;
1198 w100_pwr_state.tf20 = 0xff; /* set highest */
1199 w100_pwr_state.tf80 = 0x00; /* set lowest */
1200 w100_pwr_state.tf100 = 0x00; /* set lowest */
1201 w100_pwr_state.fast_sclk = 50; /* 50.0 MHz */
1202 w100_pwr_state.norm_sclk = 12; /* 12.5 MHz */
1203} 1121}
1204 1122
1205 1123
1206static void w100_init_sharp_lcd(u32 mode) 1124/*
1125 * Setup the w100 clocks for the specified mode
1126 */
1127static void w100_init_clocks(struct w100fb_par *par)
1207{ 1128{
1208 u32 temp32; 1129 struct w100_mode *mode = par->mode;
1209 union disp_db_buf_cntl_wr_u disp_db_buf_wr_cntl;
1210 1130
1211 /* Prevent display updates */ 1131 if (mode->pixclk_src == CLK_SRC_PLL || mode->sysclk_src == CLK_SRC_PLL)
1212 disp_db_buf_wr_cntl.f.db_buf_cntl = 0x1e; 1132 w100_set_pll_freq(par, (par->fastpll_mode && mode->fast_pll_freq) ? mode->fast_pll_freq : mode->pll_freq);
1213 disp_db_buf_wr_cntl.f.update_db_buf = 0;
1214 disp_db_buf_wr_cntl.f.en_db_buf = 0;
1215 writel((u32) (disp_db_buf_wr_cntl.val), remapped_regs + mmDISP_DB_BUF_CNTL);
1216 1133
1217 switch(mode) { 1134 w100_pwr_state.sclk_cntl.f.sclk_src_sel = mode->sysclk_src;
1218 case LCD_SHARP_QVGA: 1135 w100_pwr_state.sclk_cntl.f.sclk_post_div_fast = mode->sysclk_divider;
1219 w100_set_slowsysclk(12); /* use crystal -- 12.5MHz */ 1136 w100_pwr_state.sclk_cntl.f.sclk_post_div_slow = mode->sysclk_divider;
1220 /* not use PLL */ 1137 writel((u32) (w100_pwr_state.sclk_cntl.val), remapped_regs + mmSCLK_CNTL);
1221 1138}
1222 writel(0x7FFF8000, remapped_regs + mmMC_EXT_MEM_LOCATION); 1139
1223 writel(0x85FF8000, remapped_regs + mmMC_FB_LOCATION); 1140static void w100_init_lcd(struct w100fb_par *par)
1224 writel(0x00000003, remapped_regs + mmLCD_FORMAT); 1141{
1225 writel(0x00CF1C06, remapped_regs + mmGRAPHIC_CTRL); 1142 u32 temp32;
1226 writel(0x01410145, remapped_regs + mmCRTC_TOTAL); 1143 struct w100_mode *mode = par->mode;
1227 writel(0x01170027, remapped_regs + mmACTIVE_H_DISP); 1144 struct w100_gen_regs *regs = par->mach->regs;
1228 writel(0x01410001, remapped_regs + mmACTIVE_V_DISP); 1145 union active_h_disp_u active_h_disp;
1229 writel(0x01170027, remapped_regs + mmGRAPHIC_H_DISP); 1146 union active_v_disp_u active_v_disp;
1230 writel(0x01410001, remapped_regs + mmGRAPHIC_V_DISP); 1147 union graphic_h_disp_u graphic_h_disp;
1231 writel(0x81170027, remapped_regs + mmCRTC_SS); 1148 union graphic_v_disp_u graphic_v_disp;
1232 writel(0xA0140000, remapped_regs + mmCRTC_LS); 1149 union crtc_total_u crtc_total;
1233 writel(0x00400008, remapped_regs + mmCRTC_REV); 1150
1234 writel(0xA0000000, remapped_regs + mmCRTC_DCLK); 1151 /* w3200 doesnt like undefined bits being set so zero register values first */
1235 writel(0xC0140014, remapped_regs + mmCRTC_GS); 1152
1236 writel(0x00010141, remapped_regs + mmCRTC_VPOS_GS); 1153 active_h_disp.val = 0;
1237 writel(0x8015010F, remapped_regs + mmCRTC_GCLK); 1154 active_h_disp.f.active_h_start=mode->left_margin;
1238 writel(0x80100110, remapped_regs + mmCRTC_GOE); 1155 active_h_disp.f.active_h_end=mode->left_margin + mode->xres;
1239 writel(0x00000000, remapped_regs + mmCRTC_FRAME); 1156 writel(active_h_disp.val, remapped_regs + mmACTIVE_H_DISP);
1240 writel(0x00000000, remapped_regs + mmCRTC_FRAME_VPOS); 1157
1241 writel(0x01CC0000, remapped_regs + mmLCDD_CNTL1); 1158 active_v_disp.val = 0;
1242 writel(0x0003FFFF, remapped_regs + mmLCDD_CNTL2); 1159 active_v_disp.f.active_v_start=mode->upper_margin;
1243 writel(0x00FFFF0D, remapped_regs + mmGENLCD_CNTL1); 1160 active_v_disp.f.active_v_end=mode->upper_margin + mode->yres;
1244 writel(0x003F3003, remapped_regs + mmGENLCD_CNTL2); 1161 writel(active_v_disp.val, remapped_regs + mmACTIVE_V_DISP);
1245 writel(0x00000000, remapped_regs + mmCRTC_DEFAULT_COUNT); 1162
1246 writel(0x0000FF00, remapped_regs + mmLCD_BACKGROUND_COLOR); 1163 graphic_h_disp.val = 0;
1247 writel(0x000102aa, remapped_regs + mmGENLCD_CNTL3); 1164 graphic_h_disp.f.graphic_h_start=mode->left_margin;
1248 writel(0x00800000, remapped_regs + mmGRAPHIC_OFFSET); 1165 graphic_h_disp.f.graphic_h_end=mode->left_margin + mode->xres;
1249 writel(0x000001e0, remapped_regs + mmGRAPHIC_PITCH); 1166 writel(graphic_h_disp.val, remapped_regs + mmGRAPHIC_H_DISP);
1250 writel(0x000000bf, remapped_regs + mmGPIO_DATA); 1167
1251 writel(0x03c0feff, remapped_regs + mmGPIO_CNTL2); 1168 graphic_v_disp.val = 0;
1252 writel(0x00000000, remapped_regs + mmGPIO_CNTL1); 1169 graphic_v_disp.f.graphic_v_start=mode->upper_margin;
1253 writel(0x41060010, remapped_regs + mmCRTC_PS1_ACTIVE); 1170 graphic_v_disp.f.graphic_v_end=mode->upper_margin + mode->yres;
1254 break; 1171 writel(graphic_v_disp.val, remapped_regs + mmGRAPHIC_V_DISP);
1255 case LCD_SHARP_VGA: 1172
1256 w100_set_slowsysclk(12); /* use crystal -- 12.5MHz */ 1173 crtc_total.val = 0;
1257 w100_set_fastsysclk(current_par->fastsysclk_mode); /* use PLL -- 75.0MHz */ 1174 crtc_total.f.crtc_h_total=mode->left_margin + mode->xres + mode->right_margin;
1258 w100_pwr_state.pclk_cntl.f.pclk_src_sel = 0x1; 1175 crtc_total.f.crtc_v_total=mode->upper_margin + mode->yres + mode->lower_margin;
1259 w100_pwr_state.pclk_cntl.f.pclk_post_div = 0x2; 1176 writel(crtc_total.val, remapped_regs + mmCRTC_TOTAL);
1260 writel((u32) (w100_pwr_state.pclk_cntl.val), remapped_regs + mmPCLK_CNTL); 1177
1261 writel(0x15FF1000, remapped_regs + mmMC_FB_LOCATION); 1178 writel(mode->crtc_ss, remapped_regs + mmCRTC_SS);
1262 writel(0x9FFF8000, remapped_regs + mmMC_EXT_MEM_LOCATION); 1179 writel(mode->crtc_ls, remapped_regs + mmCRTC_LS);
1263 writel(0x00000003, remapped_regs + mmLCD_FORMAT); 1180 writel(mode->crtc_gs, remapped_regs + mmCRTC_GS);
1264 writel(0x00DE1D66, remapped_regs + mmGRAPHIC_CTRL); 1181 writel(mode->crtc_vpos_gs, remapped_regs + mmCRTC_VPOS_GS);
1265 1182 writel(mode->crtc_rev, remapped_regs + mmCRTC_REV);
1266 writel(0x0283028B, remapped_regs + mmCRTC_TOTAL); 1183 writel(mode->crtc_dclk, remapped_regs + mmCRTC_DCLK);
1267 writel(0x02360056, remapped_regs + mmACTIVE_H_DISP); 1184 writel(mode->crtc_gclk, remapped_regs + mmCRTC_GCLK);
1268 writel(0x02830003, remapped_regs + mmACTIVE_V_DISP); 1185 writel(mode->crtc_goe, remapped_regs + mmCRTC_GOE);
1269 writel(0x02360056, remapped_regs + mmGRAPHIC_H_DISP); 1186 writel(mode->crtc_ps1_active, remapped_regs + mmCRTC_PS1_ACTIVE);
1270 writel(0x02830003, remapped_regs + mmGRAPHIC_V_DISP); 1187
1271 writel(0x82360056, remapped_regs + mmCRTC_SS); 1188 writel(regs->lcd_format, remapped_regs + mmLCD_FORMAT);
1272 writel(0xA0280000, remapped_regs + mmCRTC_LS); 1189 writel(regs->lcdd_cntl1, remapped_regs + mmLCDD_CNTL1);
1273 writel(0x00400008, remapped_regs + mmCRTC_REV); 1190 writel(regs->lcdd_cntl2, remapped_regs + mmLCDD_CNTL2);
1274 writel(0xA0000000, remapped_regs + mmCRTC_DCLK); 1191 writel(regs->genlcd_cntl1, remapped_regs + mmGENLCD_CNTL1);
1275 writel(0x80280028, remapped_regs + mmCRTC_GS); 1192 writel(regs->genlcd_cntl2, remapped_regs + mmGENLCD_CNTL2);
1276 writel(0x02830002, remapped_regs + mmCRTC_VPOS_GS); 1193 writel(regs->genlcd_cntl3, remapped_regs + mmGENLCD_CNTL3);
1277 writel(0x8015010F, remapped_regs + mmCRTC_GCLK); 1194
1278 writel(0x80100110, remapped_regs + mmCRTC_GOE); 1195 writel(0x00000000, remapped_regs + mmCRTC_FRAME);
1279 writel(0x00000000, remapped_regs + mmCRTC_FRAME); 1196 writel(0x00000000, remapped_regs + mmCRTC_FRAME_VPOS);
1280 writel(0x00000000, remapped_regs + mmCRTC_FRAME_VPOS); 1197 writel(0x00000000, remapped_regs + mmCRTC_DEFAULT_COUNT);
1281 writel(0x01CC0000, remapped_regs + mmLCDD_CNTL1); 1198 writel(0x0000FF00, remapped_regs + mmLCD_BACKGROUND_COLOR);
1282 writel(0x0003FFFF, remapped_regs + mmLCDD_CNTL2);
1283 writel(0x00FFFF0D, remapped_regs + mmGENLCD_CNTL1);
1284 writel(0x003F3003, remapped_regs + mmGENLCD_CNTL2);
1285 writel(0x00000000, remapped_regs + mmCRTC_DEFAULT_COUNT);
1286 writel(0x0000FF00, remapped_regs + mmLCD_BACKGROUND_COLOR);
1287 writel(0x000102aa, remapped_regs + mmGENLCD_CNTL3);
1288 writel(0x00800000, remapped_regs + mmGRAPHIC_OFFSET);
1289 writel(0x000003C0, remapped_regs + mmGRAPHIC_PITCH);
1290 writel(0x000000bf, remapped_regs + mmGPIO_DATA);
1291 writel(0x03c0feff, remapped_regs + mmGPIO_CNTL2);
1292 writel(0x00000000, remapped_regs + mmGPIO_CNTL1);
1293 writel(0x41060010, remapped_regs + mmCRTC_PS1_ACTIVE);
1294 break;
1295 default:
1296 break;
1297 }
1298 1199
1299 /* Hack for overlay in ext memory */ 1200 /* Hack for overlay in ext memory */
1300 temp32 = readl(remapped_regs + mmDISP_DEBUG2); 1201 temp32 = readl(remapped_regs + mmDISP_DEBUG2);
1301 temp32 |= 0xc0000000; 1202 temp32 |= 0xc0000000;
1302 writel(temp32, remapped_regs + mmDISP_DEBUG2); 1203 writel(temp32, remapped_regs + mmDISP_DEBUG2);
1303
1304 /* Re-enable display updates */
1305 disp_db_buf_wr_cntl.f.db_buf_cntl = 0x1e;
1306 disp_db_buf_wr_cntl.f.update_db_buf = 1;
1307 disp_db_buf_wr_cntl.f.en_db_buf = 1;
1308 writel((u32) (disp_db_buf_wr_cntl.val), remapped_regs + mmDISP_DB_BUF_CNTL);
1309} 1204}
1310 1205
1311 1206
1312static void w100_set_vga_rotation_regs(u16 divider, unsigned long ctrl, unsigned long offset, unsigned long pitch) 1207static void w100_setup_memory(struct w100fb_par *par)
1313{ 1208{
1314 w100_pwr_state.pclk_cntl.f.pclk_src_sel = 0x1; 1209 union mc_ext_mem_location_u extmem_location;
1315 w100_pwr_state.pclk_cntl.f.pclk_post_div = divider; 1210 union mc_fb_location_u intmem_location;
1316 writel((u32) (w100_pwr_state.pclk_cntl.val), remapped_regs + mmPCLK_CNTL); 1211 struct w100_mem_info *mem = par->mach->mem;
1212 struct w100_bm_mem_info *bm_mem = par->mach->bm_mem;
1317 1213
1318 writel(ctrl, remapped_regs + mmGRAPHIC_CTRL); 1214 if (!par->extmem_active) {
1319 writel(offset, remapped_regs + mmGRAPHIC_OFFSET); 1215 w100_suspend(W100_SUSPEND_EXTMEM);
1320 writel(pitch, remapped_regs + mmGRAPHIC_PITCH);
1321 1216
1322 /* Re-enable display updates */ 1217 /* Map Internal Memory at FB Base */
1323 writel(0x0000007b, remapped_regs + mmDISP_DB_BUF_CNTL); 1218 intmem_location.f.mc_fb_start = W100_FB_BASE >> 8;
1324} 1219 intmem_location.f.mc_fb_top = (W100_FB_BASE+MEM_INT_SIZE) >> 8;
1220 writel((u32) (intmem_location.val), remapped_regs + mmMC_FB_LOCATION);
1325 1221
1222 /* Unmap External Memory - value is *probably* irrelevant but may have meaning
1223 to acceleration libraries */
1224 extmem_location.f.mc_ext_mem_start = MEM_EXT_BASE_VALUE >> 8;
1225 extmem_location.f.mc_ext_mem_top = (MEM_EXT_BASE_VALUE-1) >> 8;
1226 writel((u32) (extmem_location.val), remapped_regs + mmMC_EXT_MEM_LOCATION);
1227 } else {
1228 /* Map Internal Memory to its default location */
1229 intmem_location.f.mc_fb_start = MEM_INT_BASE_VALUE >> 8;
1230 intmem_location.f.mc_fb_top = (MEM_INT_BASE_VALUE+MEM_INT_SIZE) >> 8;
1231 writel((u32) (intmem_location.val), remapped_regs + mmMC_FB_LOCATION);
1326 1232
1327static void w100_init_vga_rotation(u16 deg) 1233 /* Map External Memory at FB Base */
1328{ 1234 extmem_location.f.mc_ext_mem_start = W100_FB_BASE >> 8;
1329 switch(deg) { 1235 extmem_location.f.mc_ext_mem_top = (W100_FB_BASE+par->mach->mem->size) >> 8;
1330 case 0: 1236 writel((u32) (extmem_location.val), remapped_regs + mmMC_EXT_MEM_LOCATION);
1331 w100_set_vga_rotation_regs(0x02, 0x00DE1D66, 0x00800000, 0x000003c0); 1237
1332 break; 1238 writel(0x00007800, remapped_regs + mmMC_BIST_CTRL);
1333 case 90: 1239 writel(mem->ext_cntl, remapped_regs + mmMEM_EXT_CNTL);
1334 w100_set_vga_rotation_regs(0x06, 0x00DE1D0e, 0x00895b00, 0x00000500); 1240 writel(0x00200021, remapped_regs + mmMEM_SDRAM_MODE_REG);
1335 break; 1241 udelay(100);
1336 case 180: 1242 writel(0x80200021, remapped_regs + mmMEM_SDRAM_MODE_REG);
1337 w100_set_vga_rotation_regs(0x02, 0x00DE1D7e, 0x00895ffc, 0x000003c0); 1243 udelay(100);
1338 break; 1244 writel(mem->sdram_mode_reg, remapped_regs + mmMEM_SDRAM_MODE_REG);
1339 case 270: 1245 udelay(100);
1340 w100_set_vga_rotation_regs(0x06, 0x00DE1D16, 0x008004fc, 0x00000500); 1246 writel(mem->ext_timing_cntl, remapped_regs + mmMEM_EXT_TIMING_CNTL);
1341 break; 1247 writel(mem->io_cntl, remapped_regs + mmMEM_IO_CNTL);
1342 default: 1248 if (bm_mem) {
1343 /* not-support */ 1249 writel(bm_mem->ext_mem_bw, remapped_regs + mmBM_EXT_MEM_BANDWIDTH);
1344 break; 1250 writel(bm_mem->offset, remapped_regs + mmBM_OFFSET);
1251 writel(bm_mem->ext_timing_ctl, remapped_regs + mmBM_MEM_EXT_TIMING_CNTL);
1252 writel(bm_mem->ext_cntl, remapped_regs + mmBM_MEM_EXT_CNTL);
1253 writel(bm_mem->mode_reg, remapped_regs + mmBM_MEM_MODE_REG);
1254 writel(bm_mem->io_cntl, remapped_regs + mmBM_MEM_IO_CNTL);
1255 writel(bm_mem->config, remapped_regs + mmBM_CONFIG);
1256 }
1345 } 1257 }
1346} 1258}
1347 1259
1348 1260static void w100_set_dispregs(struct w100fb_par *par)
1349static void w100_set_qvga_rotation_regs(unsigned long ctrl, unsigned long offset, unsigned long pitch)
1350{ 1261{
1351 writel(ctrl, remapped_regs + mmGRAPHIC_CTRL); 1262 unsigned long rot=0, divider, offset=0;
1352 writel(offset, remapped_regs + mmGRAPHIC_OFFSET); 1263 union graphic_ctrl_u graphic_ctrl;
1353 writel(pitch, remapped_regs + mmGRAPHIC_PITCH); 1264
1265 /* See if the mode has been rotated */
1266 if (par->xres == par->mode->xres) {
1267 if (par->flip) {
1268 rot=3; /* 180 degree */
1269 offset=(par->xres * par->yres) - 1;
1270 } /* else 0 degree */
1271 divider = par->mode->pixclk_divider;
1272 } else {
1273 if (par->flip) {
1274 rot=2; /* 270 degree */
1275 offset=par->xres - 1;
1276 } else {
1277 rot=1; /* 90 degree */
1278 offset=par->xres * (par->yres - 1);
1279 }
1280 divider = par->mode->pixclk_divider_rotated;
1281 }
1354 1282
1355 /* Re-enable display updates */ 1283 graphic_ctrl.val = 0; /* w32xx doesn't like undefined bits */
1356 writel(0x0000007b, remapped_regs + mmDISP_DB_BUF_CNTL); 1284 switch (par->chip_id) {
1285 case CHIP_ID_W100:
1286 graphic_ctrl.f_w100.color_depth=6;
1287 graphic_ctrl.f_w100.en_crtc=1;
1288 graphic_ctrl.f_w100.en_graphic_req=1;
1289 graphic_ctrl.f_w100.en_graphic_crtc=1;
1290 graphic_ctrl.f_w100.lcd_pclk_on=1;
1291 graphic_ctrl.f_w100.lcd_sclk_on=1;
1292 graphic_ctrl.f_w100.low_power_on=0;
1293 graphic_ctrl.f_w100.req_freq=0;
1294 graphic_ctrl.f_w100.portrait_mode=rot;
1295
1296 /* Zaurus needs this */
1297 switch(par->xres) {
1298 case 240:
1299 case 320:
1300 default:
1301 graphic_ctrl.f_w100.total_req_graphic=0xa0;
1302 break;
1303 case 480:
1304 case 640:
1305 switch(rot) {
1306 case 0: /* 0 */
1307 case 3: /* 180 */
1308 graphic_ctrl.f_w100.low_power_on=1;
1309 graphic_ctrl.f_w100.req_freq=5;
1310 break;
1311 case 1: /* 90 */
1312 case 2: /* 270 */
1313 graphic_ctrl.f_w100.req_freq=4;
1314 break;
1315 default:
1316 break;
1317 }
1318 graphic_ctrl.f_w100.total_req_graphic=0xf0;
1319 break;
1320 }
1321 break;
1322 case CHIP_ID_W3200:
1323 case CHIP_ID_W3220:
1324 graphic_ctrl.f_w32xx.color_depth=6;
1325 graphic_ctrl.f_w32xx.en_crtc=1;
1326 graphic_ctrl.f_w32xx.en_graphic_req=1;
1327 graphic_ctrl.f_w32xx.en_graphic_crtc=1;
1328 graphic_ctrl.f_w32xx.lcd_pclk_on=1;
1329 graphic_ctrl.f_w32xx.lcd_sclk_on=1;
1330 graphic_ctrl.f_w32xx.low_power_on=0;
1331 graphic_ctrl.f_w32xx.req_freq=0;
1332 graphic_ctrl.f_w32xx.total_req_graphic=par->mode->xres >> 1; /* panel xres, not mode */
1333 graphic_ctrl.f_w32xx.portrait_mode=rot;
1334 break;
1335 }
1336
1337 /* Set the pixel clock source and divider */
1338 w100_pwr_state.pclk_cntl.f.pclk_src_sel = par->mode->pixclk_src;
1339 w100_pwr_state.pclk_cntl.f.pclk_post_div = divider;
1340 writel((u32) (w100_pwr_state.pclk_cntl.val), remapped_regs + mmPCLK_CNTL);
1341
1342 writel(graphic_ctrl.val, remapped_regs + mmGRAPHIC_CTRL);
1343 writel(W100_FB_BASE + ((offset * BITS_PER_PIXEL/8)&~0x03UL), remapped_regs + mmGRAPHIC_OFFSET);
1344 writel((par->xres*BITS_PER_PIXEL/8), remapped_regs + mmGRAPHIC_PITCH);
1357} 1345}
1358 1346
1359 1347
1360static void w100_init_qvga_rotation(u16 deg) 1348/*
1349 * Work out how long the sync pulse lasts
1350 * Value is 1/(time in seconds)
1351 */
1352static void calc_hsync(struct w100fb_par *par)
1361{ 1353{
1362 switch(deg) { 1354 unsigned long hsync;
1363 case 0: 1355 struct w100_mode *mode = par->mode;
1364 w100_set_qvga_rotation_regs(0x00d41c06, 0x00800000, 0x000001e0); 1356 union crtc_ss_u crtc_ss;
1365 break; 1357
1366 case 90: 1358 if (mode->pixclk_src == CLK_SRC_XTAL)
1367 w100_set_qvga_rotation_regs(0x00d41c0E, 0x00825580, 0x00000280); 1359 hsync=par->mach->xtal_freq;
1368 break; 1360 else
1369 case 180: 1361 hsync=((par->fastpll_mode && mode->fast_pll_freq) ? mode->fast_pll_freq : mode->pll_freq)*100000;
1370 w100_set_qvga_rotation_regs(0x00d41c1e, 0x008257fc, 0x000001e0);
1371 break;
1372 case 270:
1373 w100_set_qvga_rotation_regs(0x00d41c16, 0x0080027c, 0x00000280);
1374 break;
1375 default:
1376 /* not-support */
1377 break;
1378 }
1379}
1380 1362
1363 hsync /= (w100_pwr_state.pclk_cntl.f.pclk_post_div + 1);
1364
1365 crtc_ss.val = readl(remapped_regs + mmCRTC_SS);
1366 if (crtc_ss.val)
1367 par->hsync_len = hsync / (crtc_ss.f.ss_end-crtc_ss.f.ss_start);
1368 else
1369 par->hsync_len = 0;
1370}
1381 1371
1382static void w100_suspend(u32 mode) 1372static void w100_suspend(u32 mode)
1383{ 1373{
@@ -1387,30 +1377,28 @@ static void w100_suspend(u32 mode)
1387 writel(0x00FF0000, remapped_regs + mmMC_PERF_MON_CNTL); 1377 writel(0x00FF0000, remapped_regs + mmMC_PERF_MON_CNTL);
1388 1378
1389 val = readl(remapped_regs + mmMEM_EXT_TIMING_CNTL); 1379 val = readl(remapped_regs + mmMEM_EXT_TIMING_CNTL);
1390 val &= ~(0x00100000); /* bit20=0 */ 1380 val &= ~(0x00100000); /* bit20=0 */
1391 val |= 0xFF000000; /* bit31:24=0xff */ 1381 val |= 0xFF000000; /* bit31:24=0xff */
1392 writel(val, remapped_regs + mmMEM_EXT_TIMING_CNTL); 1382 writel(val, remapped_regs + mmMEM_EXT_TIMING_CNTL);
1393 1383
1394 val = readl(remapped_regs + mmMEM_EXT_CNTL); 1384 val = readl(remapped_regs + mmMEM_EXT_CNTL);
1395 val &= ~(0x00040000); /* bit18=0 */ 1385 val &= ~(0x00040000); /* bit18=0 */
1396 val |= 0x00080000; /* bit19=1 */ 1386 val |= 0x00080000; /* bit19=1 */
1397 writel(val, remapped_regs + mmMEM_EXT_CNTL); 1387 writel(val, remapped_regs + mmMEM_EXT_CNTL);
1398 1388
1399 udelay(1); /* wait 1us */ 1389 udelay(1); /* wait 1us */
1400 1390
1401 if (mode == W100_SUSPEND_EXTMEM) { 1391 if (mode == W100_SUSPEND_EXTMEM) {
1402
1403 /* CKE: Tri-State */ 1392 /* CKE: Tri-State */
1404 val = readl(remapped_regs + mmMEM_EXT_CNTL); 1393 val = readl(remapped_regs + mmMEM_EXT_CNTL);
1405 val |= 0x40000000; /* bit30=1 */ 1394 val |= 0x40000000; /* bit30=1 */
1406 writel(val, remapped_regs + mmMEM_EXT_CNTL); 1395 writel(val, remapped_regs + mmMEM_EXT_CNTL);
1407 1396
1408 /* CLK: Stop */ 1397 /* CLK: Stop */
1409 val = readl(remapped_regs + mmMEM_EXT_CNTL); 1398 val = readl(remapped_regs + mmMEM_EXT_CNTL);
1410 val &= ~(0x00000001); /* bit0=0 */ 1399 val &= ~(0x00000001); /* bit0=0 */
1411 writel(val, remapped_regs + mmMEM_EXT_CNTL); 1400 writel(val, remapped_regs + mmMEM_EXT_CNTL);
1412 } else { 1401 } else {
1413
1414 writel(0x00000000, remapped_regs + mmSCLK_CNTL); 1402 writel(0x00000000, remapped_regs + mmSCLK_CNTL);
1415 writel(0x000000BF, remapped_regs + mmCLK_PIN_CNTL); 1403 writel(0x000000BF, remapped_regs + mmCLK_PIN_CNTL);
1416 writel(0x00000015, remapped_regs + mmPWRMGT_CNTL); 1404 writel(0x00000015, remapped_regs + mmPWRMGT_CNTL);
@@ -1418,43 +1406,16 @@ static void w100_suspend(u32 mode)
1418 udelay(5); 1406 udelay(5);
1419 1407
1420 val = readl(remapped_regs + mmPLL_CNTL); 1408 val = readl(remapped_regs + mmPLL_CNTL);
1421 val |= 0x00000004; /* bit2=1 */ 1409 val |= 0x00000004; /* bit2=1 */
1422 writel(val, remapped_regs + mmPLL_CNTL); 1410 writel(val, remapped_regs + mmPLL_CNTL);
1423 writel(0x0000001d, remapped_regs + mmPWRMGT_CNTL); 1411 writel(0x0000001d, remapped_regs + mmPWRMGT_CNTL);
1424 } 1412 }
1425} 1413}
1426 1414
1427
1428static void w100_resume(void)
1429{
1430 u32 temp32;
1431
1432 w100_hw_init();
1433 w100_pwm_setup();
1434
1435 temp32 = readl(remapped_regs + mmDISP_DEBUG2);
1436 temp32 &= 0xff7fffff;
1437 temp32 |= 0x00800000;
1438 writel(temp32, remapped_regs + mmDISP_DEBUG2);
1439
1440 if (current_par->lcdMode == LCD_MODE_480 || current_par->lcdMode == LCD_MODE_640) {
1441 w100_init_sharp_lcd(LCD_SHARP_VGA);
1442 if (current_par->lcdMode == LCD_MODE_640) {
1443 w100_init_vga_rotation(current_par->rotation_flag ? 270 : 90);
1444 }
1445 } else {
1446 w100_init_sharp_lcd(LCD_SHARP_QVGA);
1447 if (current_par->lcdMode == LCD_MODE_320) {
1448 w100_init_qvga_rotation(current_par->rotation_flag ? 270 : 90);
1449 }
1450 }
1451}
1452
1453
1454static void w100_vsync(void) 1415static void w100_vsync(void)
1455{ 1416{
1456 u32 tmp; 1417 u32 tmp;
1457 int timeout = 30000; /* VSync timeout = 30[ms] > 16.8[ms] */ 1418 int timeout = 30000; /* VSync timeout = 30[ms] > 16.8[ms] */
1458 1419
1459 tmp = readl(remapped_regs + mmACTIVE_V_DISP); 1420 tmp = readl(remapped_regs + mmACTIVE_V_DISP);
1460 1421
@@ -1490,363 +1451,6 @@ static void w100_vsync(void)
1490 writel(0x00000002, remapped_regs + mmGEN_INT_STATUS); 1451 writel(0x00000002, remapped_regs + mmGEN_INT_STATUS);
1491} 1452}
1492 1453
1493
1494static void w100_InitExtMem(u32 mode)
1495{
1496 switch(mode) {
1497 case LCD_SHARP_QVGA:
1498 /* QVGA doesn't use external memory
1499 nothing to do, really. */
1500 break;
1501 case LCD_SHARP_VGA:
1502 writel(0x00007800, remapped_regs + mmMC_BIST_CTRL);
1503 writel(0x00040003, remapped_regs + mmMEM_EXT_CNTL);
1504 writel(0x00200021, remapped_regs + mmMEM_SDRAM_MODE_REG);
1505 udelay(100);
1506 writel(0x80200021, remapped_regs + mmMEM_SDRAM_MODE_REG);
1507 udelay(100);
1508 writel(0x00650021, remapped_regs + mmMEM_SDRAM_MODE_REG);
1509 udelay(100);
1510 writel(0x10002a4a, remapped_regs + mmMEM_EXT_TIMING_CNTL);
1511 writel(0x7ff87012, remapped_regs + mmMEM_IO_CNTL);
1512 break;
1513 default:
1514 break;
1515 }
1516}
1517
1518
1519#define RESCTL_ADRS 0x00
1520#define PHACTRL_ADRS 0x01
1521#define DUTYCTRL_ADRS 0x02
1522#define POWERREG0_ADRS 0x03
1523#define POWERREG1_ADRS 0x04
1524#define GPOR3_ADRS 0x05
1525#define PICTRL_ADRS 0x06
1526#define POLCTRL_ADRS 0x07
1527
1528#define RESCTL_QVGA 0x01
1529#define RESCTL_VGA 0x00
1530
1531#define POWER1_VW_ON 0x01 /* VW Supply FET ON */
1532#define POWER1_GVSS_ON 0x02 /* GVSS(-8V) Power Supply ON */
1533#define POWER1_VDD_ON 0x04 /* VDD(8V),SVSS(-4V) Power Supply ON */
1534
1535#define POWER1_VW_OFF 0x00 /* VW Supply FET OFF */
1536#define POWER1_GVSS_OFF 0x00 /* GVSS(-8V) Power Supply OFF */
1537#define POWER1_VDD_OFF 0x00 /* VDD(8V),SVSS(-4V) Power Supply OFF */
1538
1539#define POWER0_COM_DCLK 0x01 /* COM Voltage DC Bias DAC Serial Data Clock */
1540#define POWER0_COM_DOUT 0x02 /* COM Voltage DC Bias DAC Serial Data Out */
1541#define POWER0_DAC_ON 0x04 /* DAC Power Supply ON */
1542#define POWER0_COM_ON 0x08 /* COM Powewr Supply ON */
1543#define POWER0_VCC5_ON 0x10 /* VCC5 Power Supply ON */
1544
1545#define POWER0_DAC_OFF 0x00 /* DAC Power Supply OFF */
1546#define POWER0_COM_OFF 0x00 /* COM Powewr Supply OFF */
1547#define POWER0_VCC5_OFF 0x00 /* VCC5 Power Supply OFF */
1548
1549#define PICTRL_INIT_STATE 0x01
1550#define PICTRL_INIOFF 0x02
1551#define PICTRL_POWER_DOWN 0x04
1552#define PICTRL_COM_SIGNAL_OFF 0x08
1553#define PICTRL_DAC_SIGNAL_OFF 0x10
1554
1555#define PICTRL_POWER_ACTIVE (0)
1556
1557#define POLCTRL_SYNC_POL_FALL 0x01
1558#define POLCTRL_EN_POL_FALL 0x02
1559#define POLCTRL_DATA_POL_FALL 0x04
1560#define POLCTRL_SYNC_ACT_H 0x08
1561#define POLCTRL_EN_ACT_L 0x10
1562
1563#define POLCTRL_SYNC_POL_RISE 0x00
1564#define POLCTRL_EN_POL_RISE 0x00
1565#define POLCTRL_DATA_POL_RISE 0x00
1566#define POLCTRL_SYNC_ACT_L 0x00
1567#define POLCTRL_EN_ACT_H 0x00
1568
1569#define PHACTRL_PHASE_MANUAL 0x01
1570
1571#define PHAD_QVGA_DEFAULT_VAL (9)
1572#define COMADJ_DEFAULT (125)
1573
1574static void lcdtg_ssp_send(u8 adrs, u8 data)
1575{
1576 w100fb_ssp_send(adrs,data);
1577}
1578
1579/*
1580 * This is only a psuedo I2C interface. We can't use the standard kernel
1581 * routines as the interface is write only. We just assume the data is acked...
1582 */
1583static void lcdtg_ssp_i2c_send(u8 data)
1584{
1585 lcdtg_ssp_send(POWERREG0_ADRS, data);
1586 udelay(10);
1587}
1588
1589static void lcdtg_i2c_send_bit(u8 data)
1590{
1591 lcdtg_ssp_i2c_send(data);
1592 lcdtg_ssp_i2c_send(data | POWER0_COM_DCLK);
1593 lcdtg_ssp_i2c_send(data);
1594}
1595
1596static void lcdtg_i2c_send_start(u8 base)
1597{
1598 lcdtg_ssp_i2c_send(base | POWER0_COM_DCLK | POWER0_COM_DOUT);
1599 lcdtg_ssp_i2c_send(base | POWER0_COM_DCLK);
1600 lcdtg_ssp_i2c_send(base);
1601}
1602
1603static void lcdtg_i2c_send_stop(u8 base)
1604{
1605 lcdtg_ssp_i2c_send(base);
1606 lcdtg_ssp_i2c_send(base | POWER0_COM_DCLK);
1607 lcdtg_ssp_i2c_send(base | POWER0_COM_DCLK | POWER0_COM_DOUT);
1608}
1609
1610static void lcdtg_i2c_send_byte(u8 base, u8 data)
1611{
1612 int i;
1613 for (i = 0; i < 8; i++) {
1614 if (data & 0x80)
1615 lcdtg_i2c_send_bit(base | POWER0_COM_DOUT);
1616 else
1617 lcdtg_i2c_send_bit(base);
1618 data <<= 1;
1619 }
1620}
1621
1622static void lcdtg_i2c_wait_ack(u8 base)
1623{
1624 lcdtg_i2c_send_bit(base);
1625}
1626
1627static void lcdtg_set_common_voltage(u8 base_data, u8 data)
1628{
1629 /* Set Common Voltage to M62332FP via I2C */
1630 lcdtg_i2c_send_start(base_data);
1631 lcdtg_i2c_send_byte(base_data, 0x9c);
1632 lcdtg_i2c_wait_ack(base_data);
1633 lcdtg_i2c_send_byte(base_data, 0x00);
1634 lcdtg_i2c_wait_ack(base_data);
1635 lcdtg_i2c_send_byte(base_data, data);
1636 lcdtg_i2c_wait_ack(base_data);
1637 lcdtg_i2c_send_stop(base_data);
1638}
1639
1640static struct lcdtg_register_setting {
1641 u8 adrs;
1642 u8 data;
1643 u32 wait;
1644} lcdtg_power_on_table[] = {
1645
1646 /* Initialize Internal Logic & Port */
1647 { PICTRL_ADRS,
1648 PICTRL_POWER_DOWN | PICTRL_INIOFF | PICTRL_INIT_STATE |
1649 PICTRL_COM_SIGNAL_OFF | PICTRL_DAC_SIGNAL_OFF,
1650 0 },
1651
1652 { POWERREG0_ADRS,
1653 POWER0_COM_DCLK | POWER0_COM_DOUT | POWER0_DAC_OFF | POWER0_COM_OFF |
1654 POWER0_VCC5_OFF,
1655 0 },
1656
1657 { POWERREG1_ADRS,
1658 POWER1_VW_OFF | POWER1_GVSS_OFF | POWER1_VDD_OFF,
1659 0 },
1660
1661 /* VDD(+8V),SVSS(-4V) ON */
1662 { POWERREG1_ADRS,
1663 POWER1_VW_OFF | POWER1_GVSS_OFF | POWER1_VDD_ON /* VDD ON */,
1664 3000 },
1665
1666 /* DAC ON */
1667 { POWERREG0_ADRS,
1668 POWER0_COM_DCLK | POWER0_COM_DOUT | POWER0_DAC_ON /* DAC ON */ |
1669 POWER0_COM_OFF | POWER0_VCC5_OFF,
1670 0 },
1671
1672 /* INIB = H, INI = L */
1673 { PICTRL_ADRS,
1674 /* PICTL[0] = H , PICTL[1] = PICTL[2] = PICTL[4] = L */
1675 PICTRL_INIT_STATE | PICTRL_COM_SIGNAL_OFF,
1676 0 },
1677
1678 /* Set Common Voltage */
1679 { 0xfe, 0, 0 },
1680
1681 /* VCC5 ON */
1682 { POWERREG0_ADRS,
1683 POWER0_COM_DCLK | POWER0_COM_DOUT | POWER0_DAC_ON /* DAC ON */ |
1684 POWER0_COM_OFF | POWER0_VCC5_ON /* VCC5 ON */,
1685 0 },
1686
1687 /* GVSS(-8V) ON */
1688 { POWERREG1_ADRS,
1689 POWER1_VW_OFF | POWER1_GVSS_ON /* GVSS ON */ |
1690 POWER1_VDD_ON /* VDD ON */,
1691 2000 },
1692
1693 /* COM SIGNAL ON (PICTL[3] = L) */
1694 { PICTRL_ADRS,
1695 PICTRL_INIT_STATE,
1696 0 },
1697
1698 /* COM ON */
1699 { POWERREG0_ADRS,
1700 POWER0_COM_DCLK | POWER0_COM_DOUT | POWER0_DAC_ON /* DAC ON */ |
1701 POWER0_COM_ON /* COM ON */ | POWER0_VCC5_ON /* VCC5_ON */,
1702 0 },
1703
1704 /* VW ON */
1705 { POWERREG1_ADRS,
1706 POWER1_VW_ON /* VW ON */ | POWER1_GVSS_ON /* GVSS ON */ |
1707 POWER1_VDD_ON /* VDD ON */,
1708 0 /* Wait 100ms */ },
1709
1710 /* Signals output enable */
1711 { PICTRL_ADRS,
1712 0 /* Signals output enable */,
1713 0 },
1714
1715 { PHACTRL_ADRS,
1716 PHACTRL_PHASE_MANUAL,
1717 0 },
1718
1719 /* Initialize for Input Signals from ATI */
1720 { POLCTRL_ADRS,
1721 POLCTRL_SYNC_POL_RISE | POLCTRL_EN_POL_RISE | POLCTRL_DATA_POL_RISE |
1722 POLCTRL_SYNC_ACT_L | POLCTRL_EN_ACT_H,
1723 1000 /*100000*/ /* Wait 100ms */ },
1724
1725 /* end mark */
1726 { 0xff, 0, 0 }
1727};
1728
1729static void lcdtg_resume(void)
1730{
1731 if (current_par->lcdMode == LCD_MODE_480 || current_par->lcdMode == LCD_MODE_640) {
1732 lcdtg_hw_init(LCD_SHARP_VGA);
1733 } else {
1734 lcdtg_hw_init(LCD_SHARP_QVGA);
1735 }
1736}
1737
1738static void lcdtg_suspend(void)
1739{
1740 int i;
1741
1742 for (i = 0; i < (current_par->xres * current_par->yres); i++) {
1743 writew(0xffff, remapped_fbuf + (2*i));
1744 }
1745
1746 /* 60Hz x 2 frame = 16.7msec x 2 = 33.4 msec */
1747 mdelay(34);
1748
1749 /* (1)VW OFF */
1750 lcdtg_ssp_send(POWERREG1_ADRS, POWER1_VW_OFF | POWER1_GVSS_ON | POWER1_VDD_ON);
1751
1752 /* (2)COM OFF */
1753 lcdtg_ssp_send(PICTRL_ADRS, PICTRL_COM_SIGNAL_OFF);
1754 lcdtg_ssp_send(POWERREG0_ADRS, POWER0_DAC_ON | POWER0_COM_OFF | POWER0_VCC5_ON);
1755
1756 /* (3)Set Common Voltage Bias 0V */
1757 lcdtg_set_common_voltage(POWER0_DAC_ON | POWER0_COM_OFF | POWER0_VCC5_ON, 0);
1758
1759 /* (4)GVSS OFF */
1760 lcdtg_ssp_send(POWERREG1_ADRS, POWER1_VW_OFF | POWER1_GVSS_OFF | POWER1_VDD_ON);
1761
1762 /* (5)VCC5 OFF */
1763 lcdtg_ssp_send(POWERREG0_ADRS, POWER0_DAC_ON | POWER0_COM_OFF | POWER0_VCC5_OFF);
1764
1765 /* (6)Set PDWN, INIOFF, DACOFF */
1766 lcdtg_ssp_send(PICTRL_ADRS, PICTRL_INIOFF | PICTRL_DAC_SIGNAL_OFF |
1767 PICTRL_POWER_DOWN | PICTRL_COM_SIGNAL_OFF);
1768
1769 /* (7)DAC OFF */
1770 lcdtg_ssp_send(POWERREG0_ADRS, POWER0_DAC_OFF | POWER0_COM_OFF | POWER0_VCC5_OFF);
1771
1772 /* (8)VDD OFF */
1773 lcdtg_ssp_send(POWERREG1_ADRS, POWER1_VW_OFF | POWER1_GVSS_OFF | POWER1_VDD_OFF);
1774
1775}
1776
1777static void lcdtg_set_phadadj(u32 mode)
1778{
1779 int adj;
1780
1781 if (mode == LCD_SHARP_VGA) {
1782 /* Setting for VGA */
1783 adj = current_par->phadadj;
1784 if (adj < 0) {
1785 adj = PHACTRL_PHASE_MANUAL;
1786 } else {
1787 adj = ((adj & 0x0f) << 1) | PHACTRL_PHASE_MANUAL;
1788 }
1789 } else {
1790 /* Setting for QVGA */
1791 adj = (PHAD_QVGA_DEFAULT_VAL << 1) | PHACTRL_PHASE_MANUAL;
1792 }
1793 lcdtg_ssp_send(PHACTRL_ADRS, adj);
1794}
1795
1796static void lcdtg_hw_init(u32 mode)
1797{
1798 int i;
1799 int comadj;
1800
1801 i = 0;
1802 while(lcdtg_power_on_table[i].adrs != 0xff) {
1803 if (lcdtg_power_on_table[i].adrs == 0xfe) {
1804 /* Set Common Voltage */
1805 comadj = current_par->comadj;
1806 if (comadj < 0) {
1807 comadj = COMADJ_DEFAULT;
1808 }
1809 lcdtg_set_common_voltage((POWER0_DAC_ON | POWER0_COM_OFF | POWER0_VCC5_OFF), comadj);
1810 } else if (lcdtg_power_on_table[i].adrs == PHACTRL_ADRS) {
1811 /* Set Phase Adjuct */
1812 lcdtg_set_phadadj(mode);
1813 } else {
1814 /* Other */
1815 lcdtg_ssp_send(lcdtg_power_on_table[i].adrs, lcdtg_power_on_table[i].data);
1816 }
1817 if (lcdtg_power_on_table[i].wait != 0)
1818 udelay(lcdtg_power_on_table[i].wait);
1819 i++;
1820 }
1821
1822 switch(mode) {
1823 case LCD_SHARP_QVGA:
1824 /* Set Lcd Resolution (QVGA) */
1825 lcdtg_ssp_send(RESCTL_ADRS, RESCTL_QVGA);
1826 break;
1827 case LCD_SHARP_VGA:
1828 /* Set Lcd Resolution (VGA) */
1829 lcdtg_ssp_send(RESCTL_ADRS, RESCTL_VGA);
1830 break;
1831 default:
1832 break;
1833 }
1834}
1835
1836static void lcdtg_lcd_change(u32 mode)
1837{
1838 /* Set Phase Adjuct */
1839 lcdtg_set_phadadj(mode);
1840
1841 if (mode == LCD_SHARP_VGA)
1842 /* Set Lcd Resolution (VGA) */
1843 lcdtg_ssp_send(RESCTL_ADRS, RESCTL_VGA);
1844 else if (mode == LCD_SHARP_QVGA)
1845 /* Set Lcd Resolution (QVGA) */
1846 lcdtg_ssp_send(RESCTL_ADRS, RESCTL_QVGA);
1847}
1848
1849
1850static struct device_driver w100fb_driver = { 1454static struct device_driver w100fb_driver = {
1851 .name = "w100fb", 1455 .name = "w100fb",
1852 .bus = &platform_bus_type, 1456 .bus = &platform_bus_type,
@@ -1870,4 +1474,4 @@ module_init(w100fb_init);
1870module_exit(w100fb_cleanup); 1474module_exit(w100fb_cleanup);
1871 1475
1872MODULE_DESCRIPTION("ATI Imageon w100 framebuffer driver"); 1476MODULE_DESCRIPTION("ATI Imageon w100 framebuffer driver");
1873MODULE_LICENSE("GPLv2"); 1477MODULE_LICENSE("GPL");
diff --git a/drivers/video/w100fb.h b/drivers/video/w100fb.h
index 41624f96123..7a58a1e3e42 100644
--- a/drivers/video/w100fb.h
+++ b/drivers/video/w100fb.h
@@ -5,9 +5,12 @@
5 * 5 *
6 * Copyright (C) 2002, ATI Corp. 6 * Copyright (C) 2002, ATI Corp.
7 * Copyright (C) 2004-2005 Richard Purdie 7 * Copyright (C) 2004-2005 Richard Purdie
8 * Copyright (c) 2005 Ian Molton <spyro@f2s.com>
8 * 9 *
9 * Modified to work with 2.6 by Richard Purdie <rpurdie@rpsys.net> 10 * Modified to work with 2.6 by Richard Purdie <rpurdie@rpsys.net>
10 * 11 *
12 * w32xx support by Ian Molton
13 *
11 * This program is free software; you can redistribute it and/or modify 14 * 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 15 * it under the terms of the GNU General Public License version 2 as
13 * published by the Free Software Foundation. 16 * published by the Free Software Foundation.
@@ -19,7 +22,7 @@
19 22
20/* Block CIF Start: */ 23/* Block CIF Start: */
21#define mmCHIP_ID 0x0000 24#define mmCHIP_ID 0x0000
22#define mmREVISION_ID 0x0004 25#define mmREVISION_ID 0x0004
23#define mmWRAP_BUF_A 0x0008 26#define mmWRAP_BUF_A 0x0008
24#define mmWRAP_BUF_B 0x000C 27#define mmWRAP_BUF_B 0x000C
25#define mmWRAP_TOP_DIR 0x0010 28#define mmWRAP_TOP_DIR 0x0010
@@ -88,7 +91,7 @@
88#define mmDISP_DEBUG 0x04D4 91#define mmDISP_DEBUG 0x04D4
89#define mmDISP_DB_BUF_CNTL 0x04D8 92#define mmDISP_DB_BUF_CNTL 0x04D8
90#define mmDISP_CRC_SIG 0x04DC 93#define mmDISP_CRC_SIG 0x04DC
91#define mmCRTC_DEFAULT_COUNT 0x04E0 94#define mmCRTC_DEFAULT_COUNT 0x04E0
92#define mmLCD_BACKGROUND_COLOR 0x04E4 95#define mmLCD_BACKGROUND_COLOR 0x04E4
93#define mmCRTC_PS2 0x04E8 96#define mmCRTC_PS2 0x04E8
94#define mmCRTC_PS2_VPOS 0x04EC 97#define mmCRTC_PS2_VPOS 0x04EC
@@ -119,17 +122,17 @@
119/* Block DISPLAY End: */ 122/* Block DISPLAY End: */
120 123
121/* Block GFX Start: */ 124/* Block GFX Start: */
122#define mmBRUSH_OFFSET 0x108C 125#define mmBRUSH_OFFSET 0x108C
123#define mmBRUSH_Y_X 0x1074 126#define mmBRUSH_Y_X 0x1074
124#define mmDEFAULT_PITCH_OFFSET 0x10A0 127#define mmDEFAULT_PITCH_OFFSET 0x10A0
125#define mmDEFAULT_SC_BOTTOM_RIGHT 0x10A8 128#define mmDEFAULT_SC_BOTTOM_RIGHT 0x10A8
126#define mmDEFAULT2_SC_BOTTOM_RIGHT 0x10AC 129#define mmDEFAULT2_SC_BOTTOM_RIGHT 0x10AC
127#define mmGLOBAL_ALPHA 0x1210 130#define mmGLOBAL_ALPHA 0x1210
128#define mmFILTER_COEF 0x1214 131#define mmFILTER_COEF 0x1214
129#define mmMVC_CNTL_START 0x11E0 132#define mmMVC_CNTL_START 0x11E0
130#define mmE2_ARITHMETIC_CNTL 0x1220 133#define mmE2_ARITHMETIC_CNTL 0x1220
131#define mmENG_CNTL 0x13E8 134#define mmENG_CNTL 0x13E8
132#define mmENG_PERF_CNT 0x13F0 135#define mmENG_PERF_CNT 0x13F0
133/* Block GFX End: */ 136/* Block GFX End: */
134 137
135/* Block IDCT Start: */ 138/* Block IDCT Start: */
@@ -141,22 +144,38 @@
141/* Block IDCT End: */ 144/* Block IDCT End: */
142 145
143/* Block MC Start: */ 146/* Block MC Start: */
144#define mmMEM_CNTL 0x0180 147#define mmMEM_CNTL 0x0180
145#define mmMEM_ARB 0x0184 148#define mmMEM_ARB 0x0184
146#define mmMC_FB_LOCATION 0x0188 149#define mmMC_FB_LOCATION 0x0188
147#define mmMEM_EXT_CNTL 0x018C 150#define mmMEM_EXT_CNTL 0x018C
148#define mmMC_EXT_MEM_LOCATION 0x0190 151#define mmMC_EXT_MEM_LOCATION 0x0190
149#define mmMEM_EXT_TIMING_CNTL 0x0194 152#define mmMEM_EXT_TIMING_CNTL 0x0194
150#define mmMEM_SDRAM_MODE_REG 0x0198 153#define mmMEM_SDRAM_MODE_REG 0x0198
151#define mmMEM_IO_CNTL 0x019C 154#define mmMEM_IO_CNTL 0x019C
152#define mmMC_DEBUG 0x01A0 155#define mmMC_DEBUG 0x01A0
153#define mmMC_BIST_CTRL 0x01A4 156#define mmMC_BIST_CTRL 0x01A4
154#define mmMC_BIST_COLLAR_READ 0x01A8 157#define mmMC_BIST_COLLAR_READ 0x01A8
155#define mmTC_MISMATCH 0x01AC 158#define mmTC_MISMATCH 0x01AC
156#define mmMC_PERF_MON_CNTL 0x01B0 159#define mmMC_PERF_MON_CNTL 0x01B0
157#define mmMC_PERF_COUNTERS 0x01B4 160#define mmMC_PERF_COUNTERS 0x01B4
158/* Block MC End: */ 161/* Block MC End: */
159 162
163/* Block BM Start: */
164#define mmBM_EXT_MEM_BANDWIDTH 0x0A00
165#define mmBM_OFFSET 0x0A04
166#define mmBM_MEM_EXT_TIMING_CNTL 0x0A08
167#define mmBM_MEM_EXT_CNTL 0x0A0C
168#define mmBM_MEM_MODE_REG 0x0A10
169#define mmBM_MEM_IO_CNTL 0x0A18
170#define mmBM_CONFIG 0x0A1C
171#define mmBM_STATUS 0x0A20
172#define mmBM_DEBUG 0x0A24
173#define mmBM_PERF_MON_CNTL 0x0A28
174#define mmBM_PERF_COUNTERS 0x0A2C
175#define mmBM_PERF2_MON_CNTL 0x0A30
176#define mmBM_PERF2_COUNTERS 0x0A34
177/* Block BM End: */
178
160/* Block RBBM Start: */ 179/* Block RBBM Start: */
161#define mmWAIT_UNTIL 0x1400 180#define mmWAIT_UNTIL 0x1400
162#define mmISYNC_CNTL 0x1404 181#define mmISYNC_CNTL 0x1404
@@ -176,439 +195,575 @@
176/* Block CG End: */ 195/* Block CG End: */
177 196
178/* default value definitions */ 197/* default value definitions */
179#define defWRAP_TOP_DIR 0x00000000 198#define defWRAP_TOP_DIR 0x00000000
180#define defWRAP_START_DIR 0x00000000 199#define defWRAP_START_DIR 0x00000000
181#define defCFGREG_BASE 0x00000000 200#define defCFGREG_BASE 0x00000000
182#define defCIF_IO 0x000C0902 201#define defCIF_IO 0x000C0902
183#define defINTF_CNTL 0x00000011 202#define defINTF_CNTL 0x00000011
184#define defCPU_DEFAULTS 0x00000006 203#define defCPU_DEFAULTS 0x00000006
185#define defHW_INT 0x00000000 204#define defHW_INT 0x00000000
186#define defMC_EXT_MEM_LOCATION 0x07ff0000 205#define defMC_EXT_MEM_LOCATION 0x07ff0000
187#define defTC_MISMATCH 0x00000000 206#define defTC_MISMATCH 0x00000000
188 207
189#define W100_CFG_BASE 0x0 208#define W100_CFG_BASE 0x0
190#define W100_CFG_LEN 0x10 209#define W100_CFG_LEN 0x10
191#define W100_REG_BASE 0x10000 210#define W100_REG_BASE 0x10000
192#define W100_REG_LEN 0x2000 211#define W100_REG_LEN 0x2000
193#define MEM_INT_BASE_VALUE 0x100000 212#define MEM_INT_BASE_VALUE 0x100000
194#define MEM_INT_TOP_VALUE_W100 0x15ffff
195#define MEM_EXT_BASE_VALUE 0x800000 213#define MEM_EXT_BASE_VALUE 0x800000
196#define MEM_EXT_TOP_VALUE 0x9fffff 214#define MEM_INT_SIZE 0x05ffff
215#define MEM_WINDOW_BASE 0x100000
216#define MEM_WINDOW_SIZE 0xf00000
217
197#define WRAP_BUF_BASE_VALUE 0x80000 218#define WRAP_BUF_BASE_VALUE 0x80000
198#define WRAP_BUF_TOP_VALUE 0xbffff 219#define WRAP_BUF_TOP_VALUE 0xbffff
199 220
221#define CHIP_ID_W100 0x57411002
222#define CHIP_ID_W3200 0x56441002
223#define CHIP_ID_W3220 0x57441002
200 224
201/* data structure definitions */ 225/* Register structure definitions */
202 226
203struct wrap_top_dir_t { 227struct wrap_top_dir_t {
204 unsigned long top_addr : 23; 228 unsigned long top_addr : 23;
205 unsigned long : 9; 229 unsigned long : 9;
206} __attribute__((packed)); 230} __attribute__((packed));
207 231
208union wrap_top_dir_u { 232union wrap_top_dir_u {
209 unsigned long val : 32; 233 unsigned long val : 32;
210 struct wrap_top_dir_t f; 234 struct wrap_top_dir_t f;
211} __attribute__((packed)); 235} __attribute__((packed));
212 236
213struct wrap_start_dir_t { 237struct wrap_start_dir_t {
214 unsigned long start_addr : 23; 238 unsigned long start_addr : 23;
215 unsigned long : 9; 239 unsigned long : 9;
216} __attribute__((packed)); 240} __attribute__((packed));
217 241
218union wrap_start_dir_u { 242union wrap_start_dir_u {
219 unsigned long val : 32; 243 unsigned long val : 32;
220 struct wrap_start_dir_t f; 244 struct wrap_start_dir_t f;
221} __attribute__((packed)); 245} __attribute__((packed));
222 246
223struct cif_cntl_t { 247struct cif_cntl_t {
224 unsigned long swap_reg : 2; 248 unsigned long swap_reg : 2;
225 unsigned long swap_fbuf_1 : 2; 249 unsigned long swap_fbuf_1 : 2;
226 unsigned long swap_fbuf_2 : 2; 250 unsigned long swap_fbuf_2 : 2;
227 unsigned long swap_fbuf_3 : 2; 251 unsigned long swap_fbuf_3 : 2;
228 unsigned long pmi_int_disable : 1; 252 unsigned long pmi_int_disable : 1;
229 unsigned long pmi_schmen_disable : 1; 253 unsigned long pmi_schmen_disable : 1;
230 unsigned long intb_oe : 1; 254 unsigned long intb_oe : 1;
231 unsigned long en_wait_to_compensate_dq_prop_dly : 1; 255 unsigned long en_wait_to_compensate_dq_prop_dly : 1;
232 unsigned long compensate_wait_rd_size : 2; 256 unsigned long compensate_wait_rd_size : 2;
233 unsigned long wait_asserted_timeout_val : 2; 257 unsigned long wait_asserted_timeout_val : 2;
234 unsigned long wait_masked_val : 2; 258 unsigned long wait_masked_val : 2;
235 unsigned long en_wait_timeout : 1; 259 unsigned long en_wait_timeout : 1;
236 unsigned long en_one_clk_setup_before_wait : 1; 260 unsigned long en_one_clk_setup_before_wait : 1;
237 unsigned long interrupt_active_high : 1; 261 unsigned long interrupt_active_high : 1;
238 unsigned long en_overwrite_straps : 1; 262 unsigned long en_overwrite_straps : 1;
239 unsigned long strap_wait_active_hi : 1; 263 unsigned long strap_wait_active_hi : 1;
240 unsigned long lat_busy_count : 2; 264 unsigned long lat_busy_count : 2;
241 unsigned long lat_rd_pm4_sclk_busy : 1; 265 unsigned long lat_rd_pm4_sclk_busy : 1;
242 unsigned long dis_system_bits : 1; 266 unsigned long dis_system_bits : 1;
243 unsigned long dis_mr : 1; 267 unsigned long dis_mr : 1;
244 unsigned long cif_spare_1 : 4; 268 unsigned long cif_spare_1 : 4;
245} __attribute__((packed)); 269} __attribute__((packed));
246 270
247union cif_cntl_u { 271union cif_cntl_u {
248 unsigned long val : 32; 272 unsigned long val : 32;
249 struct cif_cntl_t f; 273 struct cif_cntl_t f;
250} __attribute__((packed)); 274} __attribute__((packed));
251 275
252struct cfgreg_base_t { 276struct cfgreg_base_t {
253 unsigned long cfgreg_base : 24; 277 unsigned long cfgreg_base : 24;
254 unsigned long : 8; 278 unsigned long : 8;
255} __attribute__((packed)); 279} __attribute__((packed));
256 280
257union cfgreg_base_u { 281union cfgreg_base_u {
258 unsigned long val : 32; 282 unsigned long val : 32;
259 struct cfgreg_base_t f; 283 struct cfgreg_base_t f;
260} __attribute__((packed)); 284} __attribute__((packed));
261 285
262struct cif_io_t { 286struct cif_io_t {
263 unsigned long dq_srp : 1; 287 unsigned long dq_srp : 1;
264 unsigned long dq_srn : 1; 288 unsigned long dq_srn : 1;
265 unsigned long dq_sp : 4; 289 unsigned long dq_sp : 4;
266 unsigned long dq_sn : 4; 290 unsigned long dq_sn : 4;
267 unsigned long waitb_srp : 1; 291 unsigned long waitb_srp : 1;
268 unsigned long waitb_srn : 1; 292 unsigned long waitb_srn : 1;
269 unsigned long waitb_sp : 4; 293 unsigned long waitb_sp : 4;
270 unsigned long waitb_sn : 4; 294 unsigned long waitb_sn : 4;
271 unsigned long intb_srp : 1; 295 unsigned long intb_srp : 1;
272 unsigned long intb_srn : 1; 296 unsigned long intb_srn : 1;
273 unsigned long intb_sp : 4; 297 unsigned long intb_sp : 4;
274 unsigned long intb_sn : 4; 298 unsigned long intb_sn : 4;
275 unsigned long : 2; 299 unsigned long : 2;
276} __attribute__((packed)); 300} __attribute__((packed));
277 301
278union cif_io_u { 302union cif_io_u {
279 unsigned long val : 32; 303 unsigned long val : 32;
280 struct cif_io_t f; 304 struct cif_io_t f;
281} __attribute__((packed)); 305} __attribute__((packed));
282 306
283struct cif_read_dbg_t { 307struct cif_read_dbg_t {
284 unsigned long unpacker_pre_fetch_trig_gen : 2; 308 unsigned long unpacker_pre_fetch_trig_gen : 2;
285 unsigned long dly_second_rd_fetch_trig : 1; 309 unsigned long dly_second_rd_fetch_trig : 1;
286 unsigned long rst_rd_burst_id : 1; 310 unsigned long rst_rd_burst_id : 1;
287 unsigned long dis_rd_burst_id : 1; 311 unsigned long dis_rd_burst_id : 1;
288 unsigned long en_block_rd_when_packer_is_not_emp : 1; 312 unsigned long en_block_rd_when_packer_is_not_emp : 1;
289 unsigned long dis_pre_fetch_cntl_sm : 1; 313 unsigned long dis_pre_fetch_cntl_sm : 1;
290 unsigned long rbbm_chrncy_dis : 1; 314 unsigned long rbbm_chrncy_dis : 1;
291 unsigned long rbbm_rd_after_wr_lat : 2; 315 unsigned long rbbm_rd_after_wr_lat : 2;
292 unsigned long dis_be_during_rd : 1; 316 unsigned long dis_be_during_rd : 1;
293 unsigned long one_clk_invalidate_pulse : 1; 317 unsigned long one_clk_invalidate_pulse : 1;
294 unsigned long dis_chnl_priority : 1; 318 unsigned long dis_chnl_priority : 1;
295 unsigned long rst_read_path_a_pls : 1; 319 unsigned long rst_read_path_a_pls : 1;
296 unsigned long rst_read_path_b_pls : 1; 320 unsigned long rst_read_path_b_pls : 1;
297 unsigned long dis_reg_rd_fetch_trig : 1; 321 unsigned long dis_reg_rd_fetch_trig : 1;
298 unsigned long dis_rd_fetch_trig_from_ind_addr : 1; 322 unsigned long dis_rd_fetch_trig_from_ind_addr : 1;
299 unsigned long dis_rd_same_byte_to_trig_fetch : 1; 323 unsigned long dis_rd_same_byte_to_trig_fetch : 1;
300 unsigned long dis_dir_wrap : 1; 324 unsigned long dis_dir_wrap : 1;
301 unsigned long dis_ring_buf_to_force_dec : 1; 325 unsigned long dis_ring_buf_to_force_dec : 1;
302 unsigned long dis_addr_comp_in_16bit : 1; 326 unsigned long dis_addr_comp_in_16bit : 1;
303 unsigned long clr_w : 1; 327 unsigned long clr_w : 1;
304 unsigned long err_rd_tag_is_3 : 1; 328 unsigned long err_rd_tag_is_3 : 1;
305 unsigned long err_load_when_ful_a : 1; 329 unsigned long err_load_when_ful_a : 1;
306 unsigned long err_load_when_ful_b : 1; 330 unsigned long err_load_when_ful_b : 1;
307 unsigned long : 7; 331 unsigned long : 7;
308} __attribute__((packed)); 332} __attribute__((packed));
309 333
310union cif_read_dbg_u { 334union cif_read_dbg_u {
311 unsigned long val : 32; 335 unsigned long val : 32;
312 struct cif_read_dbg_t f; 336 struct cif_read_dbg_t f;
313} __attribute__((packed)); 337} __attribute__((packed));
314 338
315struct cif_write_dbg_t { 339struct cif_write_dbg_t {
316 unsigned long packer_timeout_count : 2; 340 unsigned long packer_timeout_count : 2;
317 unsigned long en_upper_load_cond : 1; 341 unsigned long en_upper_load_cond : 1;
318 unsigned long en_chnl_change_cond : 1; 342 unsigned long en_chnl_change_cond : 1;
319 unsigned long dis_addr_comp_cond : 1; 343 unsigned long dis_addr_comp_cond : 1;
320 unsigned long dis_load_same_byte_addr_cond : 1; 344 unsigned long dis_load_same_byte_addr_cond : 1;
321 unsigned long dis_timeout_cond : 1; 345 unsigned long dis_timeout_cond : 1;
322 unsigned long dis_timeout_during_rbbm : 1; 346 unsigned long dis_timeout_during_rbbm : 1;
323 unsigned long dis_packer_ful_during_rbbm_timeout : 1; 347 unsigned long dis_packer_ful_during_rbbm_timeout : 1;
324 unsigned long en_dword_split_to_rbbm : 1; 348 unsigned long en_dword_split_to_rbbm : 1;
325 unsigned long en_dummy_val : 1; 349 unsigned long en_dummy_val : 1;
326 unsigned long dummy_val_sel : 1; 350 unsigned long dummy_val_sel : 1;
327 unsigned long mask_pm4_wrptr_dec : 1; 351 unsigned long mask_pm4_wrptr_dec : 1;
328 unsigned long dis_mc_clean_cond : 1; 352 unsigned long dis_mc_clean_cond : 1;
329 unsigned long err_two_reqi_during_ful : 1; 353 unsigned long err_two_reqi_during_ful : 1;
330 unsigned long err_reqi_during_idle_clk : 1; 354 unsigned long err_reqi_during_idle_clk : 1;
331 unsigned long err_global : 1; 355 unsigned long err_global : 1;
332 unsigned long en_wr_buf_dbg_load : 1; 356 unsigned long en_wr_buf_dbg_load : 1;
333 unsigned long en_wr_buf_dbg_path : 1; 357 unsigned long en_wr_buf_dbg_path : 1;
334 unsigned long sel_wr_buf_byte : 3; 358 unsigned long sel_wr_buf_byte : 3;
335 unsigned long dis_rd_flush_wr : 1; 359 unsigned long dis_rd_flush_wr : 1;
336 unsigned long dis_packer_ful_cond : 1; 360 unsigned long dis_packer_ful_cond : 1;
337 unsigned long dis_invalidate_by_ops_chnl : 1; 361 unsigned long dis_invalidate_by_ops_chnl : 1;
338 unsigned long en_halt_when_reqi_err : 1; 362 unsigned long en_halt_when_reqi_err : 1;
339 unsigned long cif_spare_2 : 5; 363 unsigned long cif_spare_2 : 5;
340 unsigned long : 1; 364 unsigned long : 1;
341} __attribute__((packed)); 365} __attribute__((packed));
342 366
343union cif_write_dbg_u { 367union cif_write_dbg_u {
344 unsigned long val : 32; 368 unsigned long val : 32;
345 struct cif_write_dbg_t f; 369 struct cif_write_dbg_t f;
346} __attribute__((packed)); 370} __attribute__((packed));
347 371
348 372
349struct intf_cntl_t { 373struct intf_cntl_t {
350 unsigned char ad_inc_a : 1; 374 unsigned char ad_inc_a : 1;
351 unsigned char ring_buf_a : 1; 375 unsigned char ring_buf_a : 1;
352 unsigned char rd_fetch_trigger_a : 1; 376 unsigned char rd_fetch_trigger_a : 1;
353 unsigned char rd_data_rdy_a : 1; 377 unsigned char rd_data_rdy_a : 1;
354 unsigned char ad_inc_b : 1; 378 unsigned char ad_inc_b : 1;
355 unsigned char ring_buf_b : 1; 379 unsigned char ring_buf_b : 1;
356 unsigned char rd_fetch_trigger_b : 1; 380 unsigned char rd_fetch_trigger_b : 1;
357 unsigned char rd_data_rdy_b : 1; 381 unsigned char rd_data_rdy_b : 1;
358} __attribute__((packed)); 382} __attribute__((packed));
359 383
360union intf_cntl_u { 384union intf_cntl_u {
361 unsigned char val : 8; 385 unsigned char val : 8;
362 struct intf_cntl_t f; 386 struct intf_cntl_t f;
363} __attribute__((packed)); 387} __attribute__((packed));
364 388
365struct cpu_defaults_t { 389struct cpu_defaults_t {
366 unsigned char unpack_rd_data : 1; 390 unsigned char unpack_rd_data : 1;
367 unsigned char access_ind_addr_a: 1; 391 unsigned char access_ind_addr_a : 1;
368 unsigned char access_ind_addr_b: 1; 392 unsigned char access_ind_addr_b : 1;
369 unsigned char access_scratch_reg : 1; 393 unsigned char access_scratch_reg : 1;
370 unsigned char pack_wr_data : 1; 394 unsigned char pack_wr_data : 1;
371 unsigned char transition_size : 1; 395 unsigned char transition_size : 1;
372 unsigned char en_read_buf_mode : 1; 396 unsigned char en_read_buf_mode : 1;
373 unsigned char rd_fetch_scratch : 1; 397 unsigned char rd_fetch_scratch : 1;
374} __attribute__((packed)); 398} __attribute__((packed));
375 399
376union cpu_defaults_u { 400union cpu_defaults_u {
377 unsigned char val : 8; 401 unsigned char val : 8;
378 struct cpu_defaults_t f; 402 struct cpu_defaults_t f;
403} __attribute__((packed));
404
405struct crtc_total_t {
406 unsigned long crtc_h_total : 10;
407 unsigned long : 6;
408 unsigned long crtc_v_total : 10;
409 unsigned long : 6;
410} __attribute__((packed));
411
412union crtc_total_u {
413 unsigned long val : 32;
414 struct crtc_total_t f;
415} __attribute__((packed));
416
417struct crtc_ss_t {
418 unsigned long ss_start : 10;
419 unsigned long : 6;
420 unsigned long ss_end : 10;
421 unsigned long : 2;
422 unsigned long ss_align : 1;
423 unsigned long ss_pol : 1;
424 unsigned long ss_run_mode : 1;
425 unsigned long ss_en : 1;
426} __attribute__((packed));
427
428union crtc_ss_u {
429 unsigned long val : 32;
430 struct crtc_ss_t f;
431} __attribute__((packed));
432
433struct active_h_disp_t {
434 unsigned long active_h_start : 10;
435 unsigned long : 6;
436 unsigned long active_h_end : 10;
437 unsigned long : 6;
438} __attribute__((packed));
439
440union active_h_disp_u {
441 unsigned long val : 32;
442 struct active_h_disp_t f;
443} __attribute__((packed));
444
445struct active_v_disp_t {
446 unsigned long active_v_start : 10;
447 unsigned long : 6;
448 unsigned long active_v_end : 10;
449 unsigned long : 6;
450} __attribute__((packed));
451
452union active_v_disp_u {
453 unsigned long val : 32;
454 struct active_v_disp_t f;
455} __attribute__((packed));
456
457struct graphic_h_disp_t {
458 unsigned long graphic_h_start : 10;
459 unsigned long : 6;
460 unsigned long graphic_h_end : 10;
461 unsigned long : 6;
462} __attribute__((packed));
463
464union graphic_h_disp_u {
465 unsigned long val : 32;
466 struct graphic_h_disp_t f;
467} __attribute__((packed));
468
469struct graphic_v_disp_t {
470 unsigned long graphic_v_start : 10;
471 unsigned long : 6;
472 unsigned long graphic_v_end : 10;
473 unsigned long : 6;
474} __attribute__((packed));
475
476union graphic_v_disp_u{
477 unsigned long val : 32;
478 struct graphic_v_disp_t f;
479} __attribute__((packed));
480
481struct graphic_ctrl_t_w100 {
482 unsigned long color_depth : 3;
483 unsigned long portrait_mode : 2;
484 unsigned long low_power_on : 1;
485 unsigned long req_freq : 4;
486 unsigned long en_crtc : 1;
487 unsigned long en_graphic_req : 1;
488 unsigned long en_graphic_crtc : 1;
489 unsigned long total_req_graphic : 9;
490 unsigned long lcd_pclk_on : 1;
491 unsigned long lcd_sclk_on : 1;
492 unsigned long pclk_running : 1;
493 unsigned long sclk_running : 1;
494 unsigned long : 6;
495} __attribute__((packed));
496
497struct graphic_ctrl_t_w32xx {
498 unsigned long color_depth : 3;
499 unsigned long portrait_mode : 2;
500 unsigned long low_power_on : 1;
501 unsigned long req_freq : 4;
502 unsigned long en_crtc : 1;
503 unsigned long en_graphic_req : 1;
504 unsigned long en_graphic_crtc : 1;
505 unsigned long total_req_graphic : 10;
506 unsigned long lcd_pclk_on : 1;
507 unsigned long lcd_sclk_on : 1;
508 unsigned long pclk_running : 1;
509 unsigned long sclk_running : 1;
510 unsigned long : 5;
511} __attribute__((packed));
512
513union graphic_ctrl_u {
514 unsigned long val : 32;
515 struct graphic_ctrl_t_w100 f_w100;
516 struct graphic_ctrl_t_w32xx f_w32xx;
379} __attribute__((packed)); 517} __attribute__((packed));
380 518
381struct video_ctrl_t { 519struct video_ctrl_t {
382 unsigned long video_mode : 1; 520 unsigned long video_mode : 1;
383 unsigned long keyer_en : 1; 521 unsigned long keyer_en : 1;
384 unsigned long en_video_req : 1; 522 unsigned long en_video_req : 1;
385 unsigned long en_graphic_req_video : 1; 523 unsigned long en_graphic_req_video : 1;
386 unsigned long en_video_crtc : 1; 524 unsigned long en_video_crtc : 1;
387 unsigned long video_hor_exp : 2; 525 unsigned long video_hor_exp : 2;
388 unsigned long video_ver_exp : 2; 526 unsigned long video_ver_exp : 2;
389 unsigned long uv_combine : 1; 527 unsigned long uv_combine : 1;
390 unsigned long total_req_video : 9; 528 unsigned long total_req_video : 9;
391 unsigned long video_ch_sel : 1; 529 unsigned long video_ch_sel : 1;
392 unsigned long video_portrait : 2; 530 unsigned long video_portrait : 2;
393 unsigned long yuv2rgb_en : 1; 531 unsigned long yuv2rgb_en : 1;
394 unsigned long yuv2rgb_option : 1; 532 unsigned long yuv2rgb_option : 1;
395 unsigned long video_inv_hor : 1; 533 unsigned long video_inv_hor : 1;
396 unsigned long video_inv_ver : 1; 534 unsigned long video_inv_ver : 1;
397 unsigned long gamma_sel : 2; 535 unsigned long gamma_sel : 2;
398 unsigned long dis_limit : 1; 536 unsigned long dis_limit : 1;
399 unsigned long en_uv_hblend : 1; 537 unsigned long en_uv_hblend : 1;
400 unsigned long rgb_gamma_sel : 2; 538 unsigned long rgb_gamma_sel : 2;
401} __attribute__((packed)); 539} __attribute__((packed));
402 540
403union video_ctrl_u { 541union video_ctrl_u {
404 unsigned long val : 32; 542 unsigned long val : 32;
405 struct video_ctrl_t f; 543 struct video_ctrl_t f;
406} __attribute__((packed)); 544} __attribute__((packed));
407 545
408struct disp_db_buf_cntl_rd_t { 546struct disp_db_buf_cntl_rd_t {
409 unsigned long en_db_buf : 1; 547 unsigned long en_db_buf : 1;
410 unsigned long update_db_buf_done : 1; 548 unsigned long update_db_buf_done : 1;
411 unsigned long db_buf_cntl : 6; 549 unsigned long db_buf_cntl : 6;
412 unsigned long : 24; 550 unsigned long : 24;
413} __attribute__((packed)); 551} __attribute__((packed));
414 552
415union disp_db_buf_cntl_rd_u { 553union disp_db_buf_cntl_rd_u {
416 unsigned long val : 32; 554 unsigned long val : 32;
417 struct disp_db_buf_cntl_rd_t f; 555 struct disp_db_buf_cntl_rd_t f;
418} __attribute__((packed)); 556} __attribute__((packed));
419 557
420struct disp_db_buf_cntl_wr_t { 558struct disp_db_buf_cntl_wr_t {
421 unsigned long en_db_buf : 1; 559 unsigned long en_db_buf : 1;
422 unsigned long update_db_buf : 1; 560 unsigned long update_db_buf : 1;
423 unsigned long db_buf_cntl : 6; 561 unsigned long db_buf_cntl : 6;
424 unsigned long : 24; 562 unsigned long : 24;
425} __attribute__((packed)); 563} __attribute__((packed));
426 564
427union disp_db_buf_cntl_wr_u { 565union disp_db_buf_cntl_wr_u {
428 unsigned long val : 32; 566 unsigned long val : 32;
429 struct disp_db_buf_cntl_wr_t f; 567 struct disp_db_buf_cntl_wr_t f;
430} __attribute__((packed)); 568} __attribute__((packed));
431 569
432struct gamma_value1_t { 570struct gamma_value1_t {
433 unsigned long gamma1 : 8; 571 unsigned long gamma1 : 8;
434 unsigned long gamma2 : 8; 572 unsigned long gamma2 : 8;
435 unsigned long gamma3 : 8; 573 unsigned long gamma3 : 8;
436 unsigned long gamma4 : 8; 574 unsigned long gamma4 : 8;
437} __attribute__((packed)); 575} __attribute__((packed));
438 576
439union gamma_value1_u { 577union gamma_value1_u {
440 unsigned long val : 32; 578 unsigned long val : 32;
441 struct gamma_value1_t f; 579 struct gamma_value1_t f;
442} __attribute__((packed)); 580} __attribute__((packed));
443 581
444struct gamma_value2_t { 582struct gamma_value2_t {
445 unsigned long gamma5 : 8; 583 unsigned long gamma5 : 8;
446 unsigned long gamma6 : 8; 584 unsigned long gamma6 : 8;
447 unsigned long gamma7 : 8; 585 unsigned long gamma7 : 8;
448 unsigned long gamma8 : 8; 586 unsigned long gamma8 : 8;
449} __attribute__((packed)); 587} __attribute__((packed));
450 588
451union gamma_value2_u { 589union gamma_value2_u {
452 unsigned long val : 32; 590 unsigned long val : 32;
453 struct gamma_value2_t f; 591 struct gamma_value2_t f;
454} __attribute__((packed)); 592} __attribute__((packed));
455 593
456struct gamma_slope_t { 594struct gamma_slope_t {
457 unsigned long slope1 : 3; 595 unsigned long slope1 : 3;
458 unsigned long slope2 : 3; 596 unsigned long slope2 : 3;
459 unsigned long slope3 : 3; 597 unsigned long slope3 : 3;
460 unsigned long slope4 : 3; 598 unsigned long slope4 : 3;
461 unsigned long slope5 : 3; 599 unsigned long slope5 : 3;
462 unsigned long slope6 : 3; 600 unsigned long slope6 : 3;
463 unsigned long slope7 : 3; 601 unsigned long slope7 : 3;
464 unsigned long slope8 : 3; 602 unsigned long slope8 : 3;
465 unsigned long : 8; 603 unsigned long : 8;
466} __attribute__((packed)); 604} __attribute__((packed));
467 605
468union gamma_slope_u { 606union gamma_slope_u {
469 unsigned long val : 32; 607 unsigned long val : 32;
470 struct gamma_slope_t f; 608 struct gamma_slope_t f;
471} __attribute__((packed)); 609} __attribute__((packed));
472 610
473struct mc_ext_mem_location_t { 611struct mc_ext_mem_location_t {
474 unsigned long mc_ext_mem_start : 16; 612 unsigned long mc_ext_mem_start : 16;
475 unsigned long mc_ext_mem_top : 16; 613 unsigned long mc_ext_mem_top : 16;
476} __attribute__((packed)); 614} __attribute__((packed));
477 615
478union mc_ext_mem_location_u { 616union mc_ext_mem_location_u {
479 unsigned long val : 32; 617 unsigned long val : 32;
480 struct mc_ext_mem_location_t f; 618 struct mc_ext_mem_location_t f;
619} __attribute__((packed));
620
621struct mc_fb_location_t {
622 unsigned long mc_fb_start : 16;
623 unsigned long mc_fb_top : 16;
624} __attribute__((packed));
625
626union mc_fb_location_u {
627 unsigned long val : 32;
628 struct mc_fb_location_t f;
481} __attribute__((packed)); 629} __attribute__((packed));
482 630
483struct clk_pin_cntl_t { 631struct clk_pin_cntl_t {
484 unsigned long osc_en : 1; 632 unsigned long osc_en : 1;
485 unsigned long osc_gain : 5; 633 unsigned long osc_gain : 5;
486 unsigned long dont_use_xtalin : 1; 634 unsigned long dont_use_xtalin : 1;
487 unsigned long xtalin_pm_en : 1; 635 unsigned long xtalin_pm_en : 1;
488 unsigned long xtalin_dbl_en : 1; 636 unsigned long xtalin_dbl_en : 1;
489 unsigned long : 7; 637 unsigned long : 7;
490 unsigned long cg_debug : 16; 638 unsigned long cg_debug : 16;
491} __attribute__((packed)); 639} __attribute__((packed));
492 640
493union clk_pin_cntl_u { 641union clk_pin_cntl_u {
494 unsigned long val : 32; 642 unsigned long val : 32;
495 struct clk_pin_cntl_t f; 643 struct clk_pin_cntl_t f;
496} __attribute__((packed)); 644} __attribute__((packed));
497 645
498struct pll_ref_fb_div_t { 646struct pll_ref_fb_div_t {
499 unsigned long pll_ref_div : 4; 647 unsigned long pll_ref_div : 4;
500 unsigned long : 4; 648 unsigned long : 4;
501 unsigned long pll_fb_div_int : 6; 649 unsigned long pll_fb_div_int : 6;
502 unsigned long : 2; 650 unsigned long : 2;
503 unsigned long pll_fb_div_frac : 3; 651 unsigned long pll_fb_div_frac : 3;
504 unsigned long : 1; 652 unsigned long : 1;
505 unsigned long pll_reset_time : 4; 653 unsigned long pll_reset_time : 4;
506 unsigned long pll_lock_time : 8; 654 unsigned long pll_lock_time : 8;
507} __attribute__((packed)); 655} __attribute__((packed));
508 656
509union pll_ref_fb_div_u { 657union pll_ref_fb_div_u {
510 unsigned long val : 32; 658 unsigned long val : 32;
511 struct pll_ref_fb_div_t f; 659 struct pll_ref_fb_div_t f;
512} __attribute__((packed)); 660} __attribute__((packed));
513 661
514struct pll_cntl_t { 662struct pll_cntl_t {
515 unsigned long pll_pwdn : 1; 663 unsigned long pll_pwdn : 1;
516 unsigned long pll_reset : 1; 664 unsigned long pll_reset : 1;
517 unsigned long pll_pm_en : 1; 665 unsigned long pll_pm_en : 1;
518 unsigned long pll_mode : 1; 666 unsigned long pll_mode : 1;
519 unsigned long pll_refclk_sel : 1; 667 unsigned long pll_refclk_sel : 1;
520 unsigned long pll_fbclk_sel : 1; 668 unsigned long pll_fbclk_sel : 1;
521 unsigned long pll_tcpoff : 1; 669 unsigned long pll_tcpoff : 1;
522 unsigned long pll_pcp : 3; 670 unsigned long pll_pcp : 3;
523 unsigned long pll_pvg : 3; 671 unsigned long pll_pvg : 3;
524 unsigned long pll_vcofr : 1; 672 unsigned long pll_vcofr : 1;
525 unsigned long pll_ioffset : 2; 673 unsigned long pll_ioffset : 2;
526 unsigned long pll_pecc_mode : 2; 674 unsigned long pll_pecc_mode : 2;
527 unsigned long pll_pecc_scon : 2; 675 unsigned long pll_pecc_scon : 2;
528 unsigned long pll_dactal : 4; 676 unsigned long pll_dactal : 4;
529 unsigned long pll_cp_clip : 2; 677 unsigned long pll_cp_clip : 2;
530 unsigned long pll_conf : 3; 678 unsigned long pll_conf : 3;
531 unsigned long pll_mbctrl : 2; 679 unsigned long pll_mbctrl : 2;
532 unsigned long pll_ring_off : 1; 680 unsigned long pll_ring_off : 1;
533} __attribute__((packed)); 681} __attribute__((packed));
534 682
535union pll_cntl_u { 683union pll_cntl_u {
536 unsigned long val : 32; 684 unsigned long val : 32;
537 struct pll_cntl_t f; 685 struct pll_cntl_t f;
538} __attribute__((packed)); 686} __attribute__((packed));
539 687
540struct sclk_cntl_t { 688struct sclk_cntl_t {
541 unsigned long sclk_src_sel : 2; 689 unsigned long sclk_src_sel : 2;
542 unsigned long : 2; 690 unsigned long : 2;
543 unsigned long sclk_post_div_fast : 4; 691 unsigned long sclk_post_div_fast : 4;
544 unsigned long sclk_clkon_hys : 3; 692 unsigned long sclk_clkon_hys : 3;
545 unsigned long sclk_post_div_slow : 4; 693 unsigned long sclk_post_div_slow : 4;
546 unsigned long disp_cg_ok2switch_en : 1; 694 unsigned long disp_cg_ok2switch_en : 1;
547 unsigned long sclk_force_reg : 1; 695 unsigned long sclk_force_reg : 1;
548 unsigned long sclk_force_disp : 1; 696 unsigned long sclk_force_disp : 1;
549 unsigned long sclk_force_mc : 1; 697 unsigned long sclk_force_mc : 1;
550 unsigned long sclk_force_extmc : 1; 698 unsigned long sclk_force_extmc : 1;
551 unsigned long sclk_force_cp : 1; 699 unsigned long sclk_force_cp : 1;
552 unsigned long sclk_force_e2 : 1; 700 unsigned long sclk_force_e2 : 1;
553 unsigned long sclk_force_e3 : 1; 701 unsigned long sclk_force_e3 : 1;
554 unsigned long sclk_force_idct : 1; 702 unsigned long sclk_force_idct : 1;
555 unsigned long sclk_force_bist : 1; 703 unsigned long sclk_force_bist : 1;
556 unsigned long busy_extend_cp : 1; 704 unsigned long busy_extend_cp : 1;
557 unsigned long busy_extend_e2 : 1; 705 unsigned long busy_extend_e2 : 1;
558 unsigned long busy_extend_e3 : 1; 706 unsigned long busy_extend_e3 : 1;
559 unsigned long busy_extend_idct : 1; 707 unsigned long busy_extend_idct : 1;
560 unsigned long : 3; 708 unsigned long : 3;
561} __attribute__((packed)); 709} __attribute__((packed));
562 710
563union sclk_cntl_u { 711union sclk_cntl_u {
564 unsigned long val : 32; 712 unsigned long val : 32;
565 struct sclk_cntl_t f; 713 struct sclk_cntl_t f;
566} __attribute__((packed)); 714} __attribute__((packed));
567 715
568struct pclk_cntl_t { 716struct pclk_cntl_t {
569 unsigned long pclk_src_sel : 2; 717 unsigned long pclk_src_sel : 2;
570 unsigned long : 2; 718 unsigned long : 2;
571 unsigned long pclk_post_div : 4; 719 unsigned long pclk_post_div : 4;
572 unsigned long : 8; 720 unsigned long : 8;
573 unsigned long pclk_force_disp : 1; 721 unsigned long pclk_force_disp : 1;
574 unsigned long : 15; 722 unsigned long : 15;
575} __attribute__((packed)); 723} __attribute__((packed));
576 724
577union pclk_cntl_u { 725union pclk_cntl_u {
578 unsigned long val : 32; 726 unsigned long val : 32;
579 struct pclk_cntl_t f; 727 struct pclk_cntl_t f;
580} __attribute__((packed)); 728} __attribute__((packed));
581 729
730
731#define TESTCLK_SRC_PLL 0x01
732#define TESTCLK_SRC_SCLK 0x02
733#define TESTCLK_SRC_PCLK 0x03
734/* 4 and 5 seem to by XTAL/M */
735#define TESTCLK_SRC_XTAL 0x06
736
582struct clk_test_cntl_t { 737struct clk_test_cntl_t {
583 unsigned long testclk_sel : 4; 738 unsigned long testclk_sel : 4;
584 unsigned long : 3; 739 unsigned long : 3;
585 unsigned long start_check_freq : 1; 740 unsigned long start_check_freq : 1;
586 unsigned long tstcount_rst : 1; 741 unsigned long tstcount_rst : 1;
587 unsigned long : 15; 742 unsigned long : 15;
588 unsigned long test_count : 8; 743 unsigned long test_count : 8;
589} __attribute__((packed)); 744} __attribute__((packed));
590 745
591union clk_test_cntl_u { 746union clk_test_cntl_u {
592 unsigned long val : 32; 747 unsigned long val : 32;
593 struct clk_test_cntl_t f; 748 struct clk_test_cntl_t f;
594} __attribute__((packed)); 749} __attribute__((packed));
595 750
596struct pwrmgt_cntl_t { 751struct pwrmgt_cntl_t {
597 unsigned long pwm_enable : 1; 752 unsigned long pwm_enable : 1;
598 unsigned long : 1; 753 unsigned long : 1;
599 unsigned long pwm_mode_req : 2; 754 unsigned long pwm_mode_req : 2;
600 unsigned long pwm_wakeup_cond : 2; 755 unsigned long pwm_wakeup_cond : 2;
601 unsigned long pwm_fast_noml_hw_en : 1; 756 unsigned long pwm_fast_noml_hw_en : 1;
602 unsigned long pwm_noml_fast_hw_en : 1; 757 unsigned long pwm_noml_fast_hw_en : 1;
603 unsigned long pwm_fast_noml_cond : 4; 758 unsigned long pwm_fast_noml_cond : 4;
604 unsigned long pwm_noml_fast_cond : 4; 759 unsigned long pwm_noml_fast_cond : 4;
605 unsigned long pwm_idle_timer : 8; 760 unsigned long pwm_idle_timer : 8;
606 unsigned long pwm_busy_timer : 8; 761 unsigned long pwm_busy_timer : 8;
607} __attribute__((packed)); 762} __attribute__((packed));
608 763
609union pwrmgt_cntl_u { 764union pwrmgt_cntl_u {
610 unsigned long val : 32; 765 unsigned long val : 32;
611 struct pwrmgt_cntl_t f; 766 struct pwrmgt_cntl_t f;
612} __attribute__((packed)); 767} __attribute__((packed));
613 768
614#endif 769#endif